#!/usr/bin/env ruby ################################ # Author: Benjamin Kellermann # # License: CC-by-sa 3.0 # # see License # ################################ require "yaml" require "cgi" if __FILE__ == $0 $cgi = CGI.new TYPE = "text/html" #TYPE = "application/xhtml+xml" CHARSET = "utf-8" $htmlout = < HEAD load "charset.rb" if File.exists?("config.rb") load "config.rb" else puts "\nPlease configure me in the file config.rb" exit end require "poll" require "datepoll" require "timepoll" $htmlout += < dudle HEAD $htmlout += '' if File.exists?("atom.cgi") $htmlout += "" if $cgi.include?("create_poll") SITE=$cgi["create_poll"].gsub(/^\//,"") unless File.exist?(SITE) Dir.mkdir(SITE) Dir.chdir(SITE) VCS.init File.symlink("../participate.rb","index.cgi") File.symlink("../atom_single.rb","atom.cgi") File.symlink("../config_poll.rb","config.cgi") File.symlink("../remove_poll.rb","remove.cgi") ["data.yaml",".htaccess",".htdigest"].each{|f| File.open(f,"w").close VCS.add(f) } case $cgi["poll_type"] when "Poll" Poll.new SITE when "TimePoll" TimePoll.new SITE end Dir.chdir("..") else $htmlout += "
ErrorThis poll already exists!
" end end $htmlout += "
Available Polls" $htmlout += "" Dir.glob("*/data.yaml").sort_by{|f| File.new(f).mtime }.reverse.collect{|f| f.gsub(/\/data\.yaml$/,'') }.each{|site| unless YAML::load_file("#{site}/data.yaml").hidden $htmlout += "" $htmlout += "" $htmlout += "" $htmlout += "" end } $htmlout += "
PollLast change
#{CGI.escapeHTML(site)}#{File.new(site + "/data.yaml").mtime.strftime('%d.%m, %H:%M')}
" $htmlout += "
" $htmlout += <change charset #{UTFASCII} CHARSET $htmlout += <Create new Poll
CREATE $htmlout += NOTICE $htmlout += "" $htmlout += "" $cgi.out("type" => TYPE ,"charset" => CHARSET,"cookie" => $utfcookie, "Cache-Control" => "no-cache"){$htmlout} end