X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=57992d288b93eb1774a2a82ce051dba49cfea5ab;hb=10a9870db7d40c7375470061274902fc9f38f3a6;hp=190964478d979134e3c699776a5656923f0ed183;hpb=01057766514a73e0df07470e71c94b0508b2e5bf;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index 1909644..57992d2 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -19,7 +19,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = '$Revision: 1.63+gerry+bernie $'[11:-2]; +__version__ = '$Revision: 1.63+gerry+bernie $'[11:-2] import cgi, sys, string, os, re, errno, time, stat from os import path, environ @@ -36,11 +36,17 @@ title_done = False # CGI stuff --------------------------------------------------------- -def get_scriptname(): +def script_name(): return environ.get('SCRIPT_NAME', '') +def privileged_path(): + return privileged_url or script_name() + def remote_user(): - return environ.get('REMOTE_USER', 'AnonymousCoward') + user = environ.get('REMOTE_USER', '') + if user is None or user == '' or user == 'anonymous': + user = 'AnonymousCoward' + return user def remote_host(): return environ.get('REMOTE_ADDR', '') @@ -50,7 +56,7 @@ def get_hostname(addr): from socket import gethostbyaddr return gethostbyaddr(addr)[0] + ' (' + addr + ')' except: - return addr; + return addr # Formatting stuff -------------------------------------------------- @@ -59,7 +65,7 @@ def emit_header(type="text/html"): print def send_guru(msg, msg_type): - if msg is None or len(msg) == 0: return + if msg is None or msg == '': return print '
'
     if msg_type == 'error':
         print '    Software Failure.  Press left mouse button to continue.\n'
@@ -67,7 +73,7 @@ def send_guru(msg, msg_type):
     if msg_type == 'error':
         print '      Guru Meditation #DEADBEEF.ABADC0DE'
     print '
' - # FIXME: This simple JS code is harder to pass than ACID 3.0 + # FIXME: This simple JS snippet is harder to pass than ACID 3.0 print """ """ -def send_title(name, text="Limbo", msg=None, msg_type = 'error'): +def send_title(name, text="Limbo", msg=None, msg_type='error'): global title_done if title_done: return @@ -101,60 +107,62 @@ def send_title(name, text="Limbo", msg=None, msg_type = 'error'): """ print "%s: %s" % (site_name, text) - print ' ' + print ' ' if not name: - print ' ' + print ' ' if css_url: print ' ' % css_url print '' # Body - if name and allow_edit: - print '' + if name and privileged_url is not None: + print '' else: print '' + title_done = True send_guru(msg, msg_type) # Navbar - print '' -def link_tag(params, text=None, ss_class=None): +def link_tag(params, text=None, ss_class=None, authentication=False): if text is None: text = params # default classattr = '' - # Prevent crawlers from following links to generated pages - # and links added by potential spammers - if ss_class == 'external' or ss_class == 'navlink': - classattr += 'rel="nofollow" ' if ss_class: classattr += 'class="%s" ' % ss_class - return '%s' % (classattr, get_scriptname(), - params, text) + # Prevent crawlers from following links to generated pages + # and links added by potential spammers + if ss_class == 'external' or ss_class == 'navlink': + classattr += 'rel="nofollow" ' + if authentication: + path = privileged_path() + else: + path = script_name() + return '%s' % (classattr, path, params, text) # Search --------------------------------------------------- @@ -212,7 +220,7 @@ def do_raw(pagename): Page(pagename).send_raw() def do_savepage(pagename): - if not allow_edit: + if privileged_url is None: raise 'editing disallowed for ' + pagename global form @@ -243,9 +251,14 @@ def page_list(): def send_footer(name, mod_string=None): - print '" @@ -600,7 +663,7 @@ class Page: + ' for ' + cgi.escape(remote_user()) + ' from ' + cgi.escape(get_hostname(remote_host())) + '

') - print '
' % (get_scriptname(), self.page_name) + print '
' % (script_name(), self.page_name) print '' % (self.page_name) print """""" % (preview or self.get_raw_body()) print """ @@ -616,6 +679,7 @@ class Page: print "
" PageFormatter(preview).print_html() print "
" + send_footer(self.page_name) def send_raw(self): emit_header("text/plain") @@ -661,20 +725,26 @@ def send_verbatim(filename, mime_type='application/octet-stream'): emit_header(mime_type) sys.stdout.write(data) -# --------------------------------------------------------------- +# Main --------------------------------------------------------------- try: # Configuration values + site_name = 'Codewiz' + + # set to None for read-only sites + # leave empty ('') to allow anonymous edits + # otherwise, set to a URL that requires authentication + privileged_url = 'https://www.codewiz.org/~bernie/wiki' + data_dir = '/home/bernie/public_html/wiki' text_dir = path.join(data_dir, 'text') - allow_edit = True # Is it possible to edit pages? - site_name = 'codewiz.org' - changed_time_fmt = '[%I:%M %p] ' - date_fmt = '%a %d %b %Y' + css_url = '../wikidata/geekigeeki.css' # optional stylesheet link + history_url = '../wikigit/wiki.git' + post_edit_hook = './post_edit_hook.sh' datetime_fmt = '%a %d %b %Y %I:%M %p' + allow_edit = True # Is it possible to edit pages? show_hosts = True # show hostnames? - css_url = '../wikidata/geekigeeki.css' # optional stylesheet link nonexist_qm = False # show '?' for nonexistent? - post_edit_hook = './post_edit_hook.sh' + debug_cgi = False # Set to True for CGI var dump form = cgi.FieldStorage() @@ -699,6 +769,7 @@ try: if word_re.match(query): Page(query).send_page() elif img_re.match(query): + #FIXME: use correct mime type send_verbatim(query, 'image/jpeg') else: send_verbatim(query)