diff options
author | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2011-04-18 08:52:02 +0200 |
---|---|---|
committer | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2011-04-18 08:52:02 +0200 |
commit | 451383433d842f4a6734573a37aaf9098dd245c7 (patch) | |
tree | 5c0f3fab84181c700cdebffe8b6251ec030bf033 | |
parent | e8a6206719edc70b0ce7257da5b34471f7f8e71f (diff) |
complete change of configuration
-rw-r--r-- | README | 4 | ||||
-rwxr-xr-x | about.cgi | 4 | ||||
-rwxr-xr-x | atom.rb | 6 | ||||
-rwxr-xr-x | authorization_required.cgi | 2 | ||||
-rw-r--r-- | config_defaults.rb | 78 | ||||
-rw-r--r-- | config_sample.rb | 148 | ||||
-rwxr-xr-x | delete_poll.rb | 2 | ||||
-rw-r--r-- | dudle.rb | 12 | ||||
-rwxr-xr-x | error.cgi | 14 | ||||
-rwxr-xr-x | example.cgi | 10 | ||||
-rwxr-xr-x | index.cgi | 16 | ||||
-rwxr-xr-x | not_found.cgi | 2 | ||||
-rwxr-xr-x | overview.rb | 4 | ||||
-rwxr-xr-x | participate.rb | 4 | ||||
-rw-r--r-- | vcs_bzr.rb (renamed from bzr.rb) | 0 | ||||
-rw-r--r-- | vcs_git.rb (renamed from git.rb) | 0 | ||||
-rw-r--r-- | vcs_test.rb | 2 |
17 files changed, 186 insertions, 122 deletions
@@ -11,7 +11,9 @@ License: === Installation === 1. Place this application into a directory where cgi-scripts are evaluated. -2. Copy config_sample.rb to config.rb to start with a default configuration. +2. If you want to change some configuration, state it in the file »config.rb« + (see config_sample.rb for help) + to start with a default configuration. 3. The webserver needs the permission to write into the directory 4. You have to build a .mo file from the .po file in order to use the localization. Type: @@ -32,9 +32,9 @@ $d << "<div><h2>" + _("--verbose") + "</h2>" $d << _("The sourcecode of this application is available under the terms of <a href='http://www.fsf.org/licensing/licenses/agpl-3.0.html'>AGPL Version 3</a>") $d << "<br />" $d << _("You can get the sourcecode, using <a href='http://bazaar-vcs.org/'>bazaar</a>:") -$d << "<pre>bzr branch #{SITEURL} dudle</pre></div>" +$d << "<pre>bzr branch #{$conf.siteurl} dudle</pre></div>" -$d << ABOUTNOTICE +$d << $conf.aboutnotice $d.out end @@ -44,14 +44,14 @@ feed.title = poll.name feed.id = "urn:dudle:#{poll.class}:#{poll.name}" feed.updated = File.new("data.yaml").mtime feed.authors << Atom::Person.new(:name => 'dudle automatic notificator') -feed.links << Atom::Link.new(:href => SITEURL + "atom.cgi", :rel => "self") +feed.links << Atom::Link.new(:href => $conf.siteurl + "atom.cgi", :rel => "self") log = VCS.history log.reverse_each {|l| feed.entries << Atom::Entry.new do |e| e.title = l.comment -# e.content = Atom::Content::Xhtml.new("<p><a href=\"#{SITEURL}history.cgi?revision=#{l.rev}\">permalink</a>, <a href='#{SITEURL}' >current version</a></p>") - e.links << Atom::Link.new(:href => "#{SITEURL}history.cgi?revision=#{l.rev}") +# e.content = Atom::Content::Xhtml.new("<p><a href=\"#{$conf.siteurl}history.cgi?revision=#{l.rev}\">permalink</a>, <a href='#{$conf.siteurl}' >current version</a></p>") + e.links << Atom::Link.new(:href => "#{$conf.siteurl}history.cgi?revision=#{l.rev}") e.id = "urn:#{poll.class}:#{poll.name}:rev=#{l.rev}" e.updated = l.timestamp end diff --git a/authorization_required.cgi b/authorization_required.cgi index c79926c..47c60c5 100755 --- a/authorization_required.cgi +++ b/authorization_required.cgi @@ -56,7 +56,7 @@ else $d << <<END <p>#{authstr}</p> <ul> - <li><a href='#{SITEURL}'>#{returnstr}</a></li> + <li><a href='#{$conf.siteurl}'>#{returnstr}</a></li> </ul> </p> END diff --git a/config_defaults.rb b/config_defaults.rb new file mode 100644 index 0000000..18ccded --- /dev/null +++ b/config_defaults.rb @@ -0,0 +1,78 @@ +# coding: utf-8 +############################################################################ +# Copyright 2009,2010 Benjamin Kellermann # +# # +# This file is part of dudle. # +# # +# Dudle is free software: you can redistribute it and/or modify it under # +# the terms of the GNU Affero General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# Dudle is distributed in the hope that it will be useful, but WITHOUT ANY # +# WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public # +# License for more details. # +# # +# You should have received a copy of the GNU Affero General Public License # +# along with dudle. If not, see <http://www.gnu.org/licenses/>. # +############################################################################ + +require "ostruct" +$conf = OpenStruct.new + +$conf.vcs = "git" + +case $cgi.server_port +when 80 + protocol = "http" + port = "" +when 443 + protocol = "https" + port = "" +else + protocol = "http" + port = ":#{$cgi.server_port}" +end +$conf.siteurl = "#{protocol}://#{$cgi.server_name}#{port}#{$cgi.script_name.gsub(/[^\/]*$/,"")}" + +$conf.breadcrumbs = [] + +$conf.errorlog = "" +$conf.bugreportmail = "Benjamin.Kellermann@tu-dresden.de" +$conf.auto_send_report = false + +$conf.indexnotice = <<INDEXNOTICE +<h2>Available Polls</h2> +<table> + <tr> + <th>Poll</th><th>Last change</th> + </tr> +INDEXNOTICE +Dir.glob("*/data.yaml").sort_by{|f| + File.new(f).mtime +}.reverse.collect{|f| f.gsub(/\/data\.yaml$/,'') }.each{|site| + $conf.indexnotice += <<INDEXNOTICE +<tr class='participantrow'> + <td class='polls'><a href='./#{CGI.escapeHTML(site).gsub("'","%27")}/'>#{CGI.escapeHTML(site)}</a></td> + <td class='mtime'>#{File.new(site + "/data.yaml").mtime.strftime('%d.%m, %H:%M')}</td> +</tr> +INDEXNOTICE +} +$conf.indexnotice += "</table>" + +$conf.examples = [] + +$conf.examplenotice = "" + +$conf.aboutnotice = "" + +$conf.default_css = "default.css" + + +if File.exists?("config.rb") + require "config" +end + +require "vcs_#{$conf.vcs}" + diff --git a/config_sample.rb b/config_sample.rb index d54ff24..53bbead 100644 --- a/config_sample.rb +++ b/config_sample.rb @@ -19,34 +19,23 @@ ############################################################################ # Choose your favorite version control system -# bzr and git is implemented +# bzr and git are implemented # Warning: bzr is slow! # Warning: git needs git >=1.6.5 -require "git" +# $conf.vcs = "git" -# Change the SITEURL if the url is not determined correctly -case $cgi.server_port -when 80 - protocol = "http" - port = "" -when 443 - protocol = "https" - port = "" -else - protocol = "http" - port = ":#{$cgi.server_port}" -end -SITEURL = "#{protocol}://#{$cgi.server_name}#{port}#{$cgi.script_name.gsub(/[^\/]*$/,"")}" +# Change only if the url is not determined correctly (e.g. at the start page) +# $conf.siteurl = "http://example.org:9999/exampledir" # You may insert some sites, which are under your site # A breadcrumb will be generated in the way: # TUD -> ... -> Fakultät Informatik -> Professur DuD -> dudle -> poll -BREADCRUMBS = [ - "<a href='http://tu-dresden.de'>TUD</a>", - "...", - "<a href='http://www.inf.tu-dresden.de'>Fakultät Informatik</a>", - "<a href='http://dud.inf.tu-dresden.de'>Professur Datenschutz und Datensicherheit</a>" -] +#$conf.breadcrumbs = [ +# "<a href='http://tu-dresden.de'>TUD</a>", +# "...", +# "<a href='http://www.inf.tu-dresden.de'>Fakultät Informatik</a>", +# "<a href='http://dud.inf.tu-dresden.de'>Professur Datenschutz und Datensicherheit</a>" +#] # If you want to encourage the user to send bug reports, state the errorlog, # which you have configured in your apache conf with the ErrorLog directive. @@ -54,44 +43,44 @@ BREADCRUMBS = [ # receive the mails instead of me (the developer). # You would do me a favor, if you configure this with my address, however, # if you do not want people to read parts of your error log, leave the -# ERRORLOG variable unset! +# $conf.errorlog unset! # Make sure, that your apache can read this file # (which usually is not the case for /var/log/apache2/*) # You have 2 Options: # 1. change logrotate to allow /var/log/apache2/* to be read by apache # (=> change the line »create 640 root adm«) -# 2. change ERRORLOG to another file and creat a new rule for logrotate. +# 2. change $conf.errorlog to another file and creat a new rule for logrotate. # DO NOT FORGET TO ADD THE ERROR LOG TO LOGROTATE IF YOU CHANGE THE PATH # TO OTHER THAN /var/log/apache2/* ! # If you do not know what to do what I am speaking about, just do not uncomment # the next line -#ERRORLOG = "/var/log/dudle_error.log" -BUGREPORTMAIL = "Benjamin.Kellermann@tu-dresden.de" +#$conf.errorlog = "/var/log/dudle_error.log" +#$conf.bugreportmail = "Benjamin.Kellermann@tu-dresden.de" # Send bug reports automatically with the programm “mail” -AUTO_SEND_REPORT = false +#$conf.auto_send_report = false # add the htmlcode in the Variable INDEXNOTICE to the startpage # Example: displays all available Polls -indexnotice = <<INDEXNOTICE -<h2>Available Polls</h2> -<table> - <tr> - <th>Poll</th><th>Last change</th> - </tr> -INDEXNOTICE -Dir.glob("*/data.yaml").sort_by{|f| - File.new(f).mtime -}.reverse.collect{|f| f.gsub(/\/data\.yaml$/,'') }.each{|site| - indexnotice += <<INDEXNOTICE -<tr class='participantrow'> - <td class='polls'><a href='./#{CGI.escapeHTML(site).gsub("'","%27")}/'>#{CGI.escapeHTML(site)}</a></td> - <td class='mtime'>#{File.new(site + "/data.yaml").mtime.strftime('%d.%m, %H:%M')}</td> -</tr> -INDEXNOTICE -} -indexnotice += "</table>" -INDEXNOTICE = indexnotice +#$conf.indexnotice = <<INDEXNOTICE +#<h2>Available Polls</h2> +#<table> +# <tr> +# <th>Poll</th><th>Last change</th> +# </tr> +#INDEXNOTICE +#Dir.glob("*/data.yaml").sort_by{|f| +# File.new(f).mtime +#}.reverse.collect{|f| f.gsub(/\/data\.yaml$/,'') }.each{|site| +# $conf.indexnotice += <<INDEXNOTICE +#<tr class='participantrow'> +# <td class='polls'><a href='./#{CGI.escapeHTML(site).gsub("'","%27")}/'>#{CGI.escapeHTML(site)}</a></td> +# <td class='mtime'>#{File.new(site + "/data.yaml").mtime.strftime('%d.%m, %H:%M')}</td> +#</tr> +#INDEXNOTICE +#} +#$conf.indexnotice += "</table>" + # Add some Example Polls to the example page # you may create those using the normal interface @@ -99,45 +88,44 @@ INDEXNOTICE = indexnotice # .htaccess and .htdigest are deleted after # example creation (defining password protected # examples is not possible therefore) -EXAMPLES = [ - { - :url => "coffeebreak", - :description => _("Event Schedule Poll"), - :new_environment => true, - },{ - :url => "coffee", - :description => _("Normal Poll"), - :revno => 34 - },{ - :url => "Cheater", - :description => "Cheater", - :hidden => true - } -] +#$conf.examples = [ +# { +# :url => "coffeebreak", +# :description => _("Event Schedule Poll"), +# :new_environment => true, +# },{ +# :url => "coffee", +# :description => _("Normal Poll"), +# :revno => 34 +# },{ +# :url => "Cheater", +# :description => "Cheater", +# :hidden => true +# } +#] # add the htmlcode in the Variable EXAMPLENOTICE to the example page -examplenotice = <<EXAMPLENOTICE - <h2>Screencasts</h2> - <ol> - <li><a href="0-register.ogv">Register a new user</a></li> - <li><a href="1-setup.ogv">Setup a new poll</a></li> - <li><a href="2-participate.ogv">Participate in a poll</a></li> - </ol> -EXAMPLENOTICE -EXAMPLENOTICE = examplenotice +#$conf.examplenotice = <<EXAMPLENOTICE +# <h2>Screencasts</h2> +# <ol> +# <li><a href="0-register.ogv">Register a new user</a></li> +# <li><a href="1-setup.ogv">Setup a new poll</a></li> +# <li><a href="2-participate.ogv">Participate in a poll</a></li> +# </ol> +#EXAMPLENOTICE # add the htmlcode in the Variable ABOUTNOTICE to the about page -aboutnotice = <<ABOUTNOTICE -<div class='textcolumn'> - <h2>Bugs/Features</h2> - <ul> - <li><a href="Bugs">Report a Bug</a></li> - <li><a href="Features">Request a Feature</a></li> - </ul> -</div> -ABOUTNOTICE -ABOUTNOTICE = aboutnotice +#$conf.aboutnotice = <<ABOUTNOTICE +#<div class='textcolumn'> +# <h2>Bugs/Features</h2> +# <ul> +# <li><a href="Bugs">Report a Bug</a></li> +# <li><a href="Features">Request a Feature</a></li> +# </ul> +#</div> +#ABOUTNOTICE + # choose a default stylesheet # e.g., "classic.css", "css/foobar.css", ... -DEFAULT_CSS = "default.css" +#$conf.default_css = "default.css" diff --git a/delete_poll.rb b/delete_poll.rb index 6f47301..059a941 100755 --- a/delete_poll.rb +++ b/delete_poll.rb @@ -40,7 +40,7 @@ if $cgi.include?("confirmnumber") if $cgi.include?("return") $d.html.header["status"] = "REDIRECT" $d.html.header["Cache-Control"] = "no-cache" - $d.html.header["Location"] = SITEURL + $cgi["return"] + $d.html.header["Location"] = $conf.siteurl + $cgi["return"] $d.out exit end @@ -44,7 +44,7 @@ require "date_locale" require "html" require "poll" -require "config" +require "config_defaults" require "charset" class Dudle @@ -96,11 +96,7 @@ class Dudle @requested_revision || VCS.revno end def breadcrumbs - if defined?(BREADCRUMBS) - crumbs = BREADCRUMBS - else - crumbs = [] - end + crumbs = $conf.breadcrumbs crumbs << "<a href='#{@basedir}'>" + _("Dudle Home") + "</a>" if is_poll? if @tab == "." @@ -157,10 +153,10 @@ class Dudle } if $cgi.include?("css") @user_css = $cgi["css"] - @html.add_cookie("css",@user_css,"/",Time.now + (1*60*60*24*365 * (@user_css == DEFAULT_CSS ? -1 : 1 ))) + @html.add_cookie("css",@user_css,"/",Time.now + (1*60*60*24*365 * (@user_css == $conf.default_css ? -1 : 1 ))) else @user_css = $cgi.cookies["css"][0] - @user_css ||= DEFAULT_CSS + @user_css ||= $conf.default_css end if $cgi.user_agent =~ /.*MSIE [567]\..*/ @@ -32,11 +32,11 @@ def urlescape(str) end -if defined?(ERRORLOG) +if File.exists?($conf.errorlog) begin - a = File.open(ERRORLOG,"r").to_a + a = File.open($conf.errorlog,"r").to_a rescue Exception => e - errorstr = "Exception while opening #{ERRORLOG}:\n#{e}" + errorstr = "Exception while opening #{$conf.errorlog}:\n#{e}" else s = [a.pop] s << a.pop while s.last.scan(/^\[([^\]]*)\] \[/).flatten[0] == a.last.scan(/^\[([^\]]*)\] \[/).flatten[0] || a.last =~ /^[^\[]/ @@ -47,10 +47,10 @@ if defined?(ERRORLOG) end - errormessagebody = _("Hi!\n\nI found a bug in your application at %{urlofsite}.\nI did the following:\n\n<please describe what you did>\n<e.g., I wanted to sent a comment to the poll.>\n\nI am using <please state your browser and operating system>\n%{errormessage}\nYours,\n") % {:errormessage => errormessage, :urlofsite => SITEURL} + errormessagebody = _("Hi!\n\nI found a bug in your application at %{urlofsite}.\nI did the following:\n\n<please describe what you did>\n<e.g., I wanted to sent a comment to the poll.>\n\nI am using <please state your browser and operating system>\n%{errormessage}\nYours,\n") % {:errormessage => errormessage, :urlofsite => $conf.siteurl} subject = _("Bug in dudle") - $d << _("An error occured while executing dudle.<br/>Please send an error report, including your browser, operating system, and what you did to %{admin}.") % {:admin => "<a href='mailto:#{BUGREPORTMAIL}?subject=#{urlescape(subject)}&body=#{urlescape(errormessagebody)}'>#{BUGREPORTMAIL}</a>"} + $d << _("An error occured while executing dudle.<br/>Please send an error report, including your browser, operating system, and what you did to %{admin}.") % {:admin => "<a href='mailto:#{$conf.bugreportmail}?subject=#{urlescape(subject)}&body=#{urlescape(errormessagebody)}'>#{$conf.bugreportmail}</a>"} if (errorstr) errorheadstr = _("Please include the following as well:") @@ -64,13 +64,13 @@ end $d.out -if AUTO_SEND_REPORT +if $conf.auto_send_report tmpfile = "/tmp/error.#{rand(10000)}" File.open(tmpfile,"w"){|f| f << errorstr } - `mail -s "Bug in dudle" #{BUGREPORTMAIL} < #{tmpfile}` + `mail -s "Bug in dudle" #{$conf.bugreportmail} < #{tmpfile}` File.delete(tmpfile) diff --git a/example.cgi b/example.cgi index d2bf9cd..2122bb7 100755 --- a/example.cgi +++ b/example.cgi @@ -28,7 +28,7 @@ $d = Dudle.new if $cgi.include?("poll") poll = nil - EXAMPLES.each{|p| + $conf.examples.each{|p| poll = p if $cgi["poll"] == p[:url] } @@ -53,20 +53,20 @@ if $cgi.include?("poll") $d.html.header["status"] = "REDIRECT" $d.html.header["Cache-Control"] = "no-cache" - $d.html.header["Location"] = SITEURL + targeturl + $d.html.header["Location"] = $conf.siteurl + targeturl else - if defined?(EXAMPLES) + unless $conf.examples.empty? $d << "<div class='textcolumn'><h2>" + _("Examples") + "</h2>" $d << _("If you want to play with the application, you may want to take a look at these example polls:") $d << "<ul>" - EXAMPLES.each{|poll| + $conf.examples.each{|poll| $d << "<li><a href='example.cgi?poll=#{poll[:url]}'>#{poll[:description]}</a></li>" unless poll[:hidden] } $d << "</ul></div>" end - $d << EXAMPLENOTICE + $d << $conf.examplenotice end @@ -22,12 +22,12 @@ if __FILE__ == $0 -if File.exists?("config.rb") +# if File.exists?("config.rb") require "dudle" -else - puts "\nPlease configure me in the file config.rb" - exit -end +# else +# puts "\nPlease configure me in the file config.rb" +# exit +# end $d = Dudle.new @@ -70,7 +70,7 @@ if $cgi.include?("create_poll") && $cgi.include?("poll_url") Dir.chdir("..") $d.html.header["status"] = "REDIRECT" $d.html.header["Cache-Control"] = "no-cache" - $d.html.header["Location"] = SITEURL + POLLURL + "/edit_columns.cgi" + $d.html.header["Location"] = $conf.siteurl + POLLURL + "/edit_columns.cgi" $d << _("The poll was created successfully. The link to your new poll is: %{link}") % {:link => "<br /><a href=\"#{POLLURL}\">#{POLLURL}</a>"} end end @@ -114,7 +114,7 @@ unless $d.html.header["status"] == "REDIRECT" <span class='hint'>#{customaddrhintstr}</span></td> </tr> <tr> - <td colspan='2'><label for="poll_url">#{SITEURL}</label><input id="poll_url" size='16' type='text' name='poll_url' value="#{CGI.escapeHTML($cgi["poll_url"])}" /> + <td colspan='2'><label for="poll_url">#{$conf.siteurl}</label><input id="poll_url" size='16' type='text' name='poll_url' value="#{CGI.escapeHTML($cgi["poll_url"])}" /> </td> </tr> CREATE @@ -133,7 +133,7 @@ NOTICE CREATE - $d << INDEXNOTICE + $d << $conf.indexnotice end $d.out diff --git a/not_found.cgi b/not_found.cgi index 425bf65..52ad19a 100755 --- a/not_found.cgi +++ b/not_found.cgi @@ -47,7 +47,7 @@ $d << <<END </ul> #{str[4]} <ul> - <li><a href='#{SITEURL}'>#{str[5]}</a></li> + <li><a href='#{$conf.siteurl}'>#{str[5]}</a></li> </ul> </p> END diff --git a/overview.rb b/overview.rb index b42d56f..0556732 100755 --- a/overview.rb +++ b/overview.rb @@ -35,8 +35,8 @@ nextstr = _("To the Vote interface") subjectstr = _("Link to dudle poll about %{polltitle}") % {:polltitle => $d.title} $d << <<END -<pre id="humanReadableURL">#{SITEURL}</pre> -<a id="mailtoURL" href='mailto:?subject=#{CGI.escapeHTML(CGI.escape(subjectstr).gsub("+","%20"))}&body=#{SITEURL}'>#{mailstr}</a> +<pre id="humanReadableURL">#{$conf.siteurl}</pre> +<a id="mailtoURL" href='mailto:?subject=#{CGI.escapeHTML(CGI.escape(subjectstr).gsub("+","%20"))}&body=#{$conf.siteurl}'>#{mailstr}</a> <form id='clickURL' method='get' action='.'> <div style='margin-top:1ex'> <input type='submit' value='#{nextstr}' /> diff --git a/participate.rb b/participate.rb index 5153f0d..6b37fae 100755 --- a/participate.rb +++ b/participate.rb @@ -55,8 +55,8 @@ end if edit $d.html.header["status"] = "REDIRECT" $d.html.header["Cache-Control"] = "no-cache" - $d.html.header["Location"] = SITEURL - $d << _("The changes were saved, you should be redirected to %{link}.") % {:link => "<a href=\"#{SITEURL}\">#{SITEURL}</a>"} + $d.html.header["Location"] = $conf.siteurl + $d << _("The changes were saved, you should be redirected to %{link}.") % {:link => "<a href=\"#{$conf.siteurl}\">#{$conf.siteurl}</a>"} else diff --git a/vcs_test.rb b/vcs_test.rb index 91b6609..2111cc5 100644 --- a/vcs_test.rb +++ b/vcs_test.rb @@ -24,7 +24,7 @@ unless ARGV[0] puts "Usage: ruby #{$0} (git|bzr)" exit end -require ARGV[0] +require "vcs_#{ARGV[0]}" require "benchmark" class VCS_test < Test::Unit::TestCase |