X-Git-Url: https://codewiz.org/gitweb?p=geekigeeki.git;a=blobdiff_plain;f=geekigeeki.py;h=01027ee23b69b7da0a60f32c2925ab4f04dcfb1c;hp=a36eced13ff809056a7aae93d66ef79e4fbd32ed;hb=4d8eca8c234926b3770f3fc4d150128ad18cea87;hpb=e8e48e36abeab2e05f2e6cde0a8072ef76f20ba5 diff --git a/geekigeeki.py b/geekigeeki.py index a36eced..01027ee 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -18,23 +18,27 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = '$Id$'[4:12] +__version__ = '4.0-' + '$Id$'[4:11] from time import clock start_time = clock() title_done = False -import cgi, sys, os, re, errno, stat +import cgi, sys, os, re, errno, stat, glob -# FIXME: we accept stuff like foo/../bar and we shouldn't -file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)") +image_ext = 'png|gif|jpg|jpeg|bmp|ico' video_ext = "ogg|ogv|oga" # Not supported by Firefox 3.5: mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt -img_re = re.compile(r".*\.(png|gif|jpg|jpeg|bmp|ico|" + video_ext + ")", re.IGNORECASE) +image_re = re.compile(r".*\.(" + image_ext + "|" + video_ext + ")", re.IGNORECASE) video_re = re.compile(r".*\.(" + video_ext + ")", re.IGNORECASE) -url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S") -ext_re = re.compile(r"\.([^\./]+)$") +# FIXME: we accept stuff like foo/../bar and we shouldn't +file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)") +url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S") +ext_re = re.compile(r"\.([^\./]+)$") # CGI stuff --------------------------------------------------------- +def config_get(key, default=None): + return globals().get(key, default) + def script_name(): return os.environ.get('SCRIPT_NAME', '') @@ -46,7 +50,7 @@ def query_string(): return os.environ.get('QUERY_STRING', '') or 'FrontPage' def privileged_path(): - return privileged_url or script_name() + return config_get('privileged_url') or script_name() def remote_user(): user = os.environ.get('REMOTE_USER', '') @@ -80,20 +84,20 @@ def permalink(s): return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip()) def humanlink(s): - return re.sub(r'([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' ')) + return re.sub(r'(?:.*[/:]|)([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' ')) -# Split arg lists like "blah| blah blah| width=100 | align = center", +# Split arg lists like "blah|blah blah| width=100 | align = center", # return a list containing anonymous arguments and a map containing the named arguments def parse_args(s): args = [] - kwargs = {} + kvargs = {} for arg in s.strip('<[{}]>').split('|'): m = re.match('\s*(\w+)\s*=\s*(.+)\s*', arg) if m is not None: - kwargs[m.group(1)] = m.group(2) + kvargs[m.group(1)] = m.group(2) else: args.append(arg.strip()) - return (args, kwargs) + return (args, kvargs) def url_args(kvargs): argv = [] @@ -112,7 +116,7 @@ def send_guru(msg_text, msg_type): print('
')
     if msg_type == 'error':
         print('    Software Failure.  Press left mouse button to continue.\n')
-    print(msg_text)
+    print(cgi.escape(msg_text))
     if msg_type == 'error':
         print '\n           Guru Meditation #DEADBEEF.ABADC0DE'
     print('
' \ @@ -128,31 +132,32 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal print(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">') print('') - print("%s: %s" % (site_name, text)) + print("%s: %s" % (config_get('site_name', "Unconfigured Wiki"), text)) print(' ') if not name: print(' ') - for meta in meta_urls: - http_equiv, content = meta + for http_equiv, content in config_get('meta_urls', {}): print(' ' % (http_equiv, relative_url(content))) - for link in link_urls: + for link in config_get('link_urls', {}): rel, href = link print(' ' % (rel, relative_url(href))) - if name and writable and privileged_url is not None: + editable = name and writable and config_get('privileged_url') is not None + if editable: print(' ' \ % (privileged_path() + '?a=edit&q=' + name)) - if history_url is not None: + history = config_get('history_url') + if history is not None: print(' ' \ - % relative_url(history_url + '?a=rss')) + % relative_url(history + '?a=rss')) print('') # Body - if name and writable and privileged_url is not None: + if editable: print('') else: print('') @@ -162,20 +167,20 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal # Navbar print('