#!/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 olddir = File.expand_path(".") Dir.chdir("..") require "html" load "config.rb" require "poll" Dir.chdir(olddir) # BUGFIX for Time.parse, which handles the zone indeterministically class << Time alias_method :old_parse, :parse def Time.parse(date, now=self.now) Time.old_parse("2009-10-25 00:30") Time.old_parse(date) end end acusers = {} if $cgi.include?("revision") REVISION=$cgi["revision"].to_i table = YAML::load(VCS.cat(REVISION, "data.yaml")) VCS.cat(REVISION,".htdigest").each_line{|l| v,k = l.scan(/^(.*):(.*):.*$/).flatten acusers[k] = v } else table = YAML::load_file("data.yaml") File.open(".htdigest","r").each_line{|l| user,realm = l.scan(/^(.*):(.*):.*$/).flatten acusers[user] = realm } if $cgi.include?("add_participant") if $cgi.include?("delete_participant") table.delete($cgi["olduser"]) else table.add_participant($cgi["olduser"],$cgi["add_participant"],{}) end end table.edit_column($cgi["columnid"],$cgi["new_columnname"],$cgi) if $cgi.include?("new_columnname") table.delete_column($cgi["deletecolumn"]) if $cgi.include?("deletecolumn") def writehtaccess(acusers) File.open(".htaccess","w"){|htaccess| if acusers.values.include?("config") htaccess << < AuthType digest AuthName "config" AuthUserFile "#{File.expand_path(".").gsub('"','\\\\"')}/.htdigest" Require valid-user HTACCESS end if acusers.values.include?("vote") htaccess << <

#{table.name}

#{table.to_html($cgi["edituser"],true,$cgi["editcolumn"])}
TABLE # ADD/REMOVE COLUMN $html << < #{table.edit_column_htmlform($cgi["editcolumn"])} ADD_EDIT # ACCESS CONTROL $accesslevels = { "vote" => "Vote Interface", "config" => "Config Interface" } $html << <
Change Access Control Settings
ACL acusers.each{|user,action| $html << < USER } $html << < ACL $html << < #{usercreatenotice} ACL $html << <
Delete the Whole Poll
Warning: This is an irreversible action!
REMOVE $html << "" $html.out($cgi) end
Access toUsernamePasswordPassword (repeat)
#{$accesslevels[action]} #{user} ***************** *****************