From d67da9fd0f5fd21e0438d6676d7353342a517bea Mon Sep 17 00:00:00 2001 From: Benjamin Kellermann Date: Tue, 6 Oct 2009 13:20:12 +0200 Subject: new feature access control (requires .ht* in each dir) --- .htaccess | 5 +++ config_poll.rb | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.cgi | 6 ++-- 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 .htaccess diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..01447f6 --- /dev/null +++ b/.htaccess @@ -0,0 +1,5 @@ + + deny from all + satisfy all + ErrorDocument 403 "You are not allowed to access .ht* files!" + diff --git a/config_poll.rb b/config_poll.rb index 0055790..c88b0e9 100755 --- a/config_poll.rb +++ b/config_poll.rb @@ -41,15 +41,79 @@ class << Time 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| + v,k = l.scan(/^(.*):(.*):.*$/).flatten + acusers[k] = v + } table.invite_delete($cgi["invite_delete"]) if $cgi.include?("invite_delete") and $cgi["invite_delete"] != "" table.add_remove_column($cgi["add_remove_column"],$cgi["columndescription"]) if $cgi.include?("add_remove_column") table.toggle_hidden if $cgi.include?("toggle_hidden") + + def writehtaccess(acusers) + File.open(".htaccess","w"){|htaccess| + if acusers["admin"] + htaccess << < + AuthType digest + AuthName "admin" + AuthUserFile #{File.expand_path(".")}/.htdigest + Require valid-user + +HTACCESS + end + if acusers["participant"] + htaccess << < ADD_REMOVE +$htmlout +=< +
+ Change Access Control settings + If you want to restrict the poll, add the participant user. + If you want to restrict the configuration interface seperately, please add an admin user! +
+ + + + +ACL +acusers.each{|action,user| + $htmlout += < + + + + +USER +} +$htmlout += < + + + + +
NamePassword
#{user}***************** + +
+ + + + + +
+
+
+ +ACL + $htmlout +=<
diff --git a/index.cgi b/index.cgi index 36d2e3c..2119781 100755 --- a/index.cgi +++ b/index.cgi @@ -57,8 +57,10 @@ if $cgi.include?("create_poll") File.symlink("../atom_single.rb","atom.cgi") File.symlink("../config_poll.rb","config.cgi") File.symlink("../remove_poll.rb","remove.cgi") - File.open("data.yaml","w").close - VCS.add("data.yaml") + ["data.yaml",".htaccess",".htdigest"].each{|f| + File.open(f,"w").close + VCS.add(f) + } case $cgi["poll_type"] when "Poll" Poll.new SITE -- cgit v1.2.3