import cgi, sys, string, os, re, errno, time, stat
from os import path, environ
-from socket import gethostbyaddr
-from time import localtime, strftime
# Regular expression defining a WikiWord
# (but this definition is also assumed in other places)
title_done = False
-def emit_header(type="text/html"):
- print "Content-type: " + type + "; charset=utf-8"
- print
-
-# Formatting stuff --------------------------------------------------
+# CGI stuff ---------------------------------------------------------
def get_scriptname():
return environ.get('SCRIPT_NAME', '')
+def remote_user():
+ return environ.get('REMOTE_USER', 'AnonymousCoward')
+
+def remote_host():
+ return environ.get('REMOTE_ADDR', '')
+
def get_hostname(addr):
try:
+ from socket import gethostbyaddr
return gethostbyaddr(addr)[0] + ' (' + addr + ')'
except:
return addr;
+# Formatting stuff --------------------------------------------------
+
+def emit_header(type="text/html"):
+ print "Content-type: " + type + "; charset=utf-8"
+ print
+
def send_guru(msg, msg_type):
if msg is None or len(msg) == 0: return
print '<pre id="guru" onclick="this.style.display = \'none\'" class="' + msg_type + '">'
# Navbar
print '<div class="navigator">'
- print '<b>' + site_name + ': '
+ print ' <b>' + site_name + ': '
if name:
print link_tag('?fullsearch=' + name, text) + '</b> '
else:
print ' | ' + link_tag('FrontPage', 'Front Page', 'navlink')
print ' | ' + link_tag('FindPage', 'Find Page', 'navlink')
print ' | <a href="/wikigit/wiki.git" class="navlink">Recent Changes</a>'
+
if name:
print ' | <a href="/wikigit/wiki.git?a=history;f=' + name + '" class="navlink">Page History</a>'
print ' | ' + link_tag('?raw=' + name, 'Raw Text', 'navlink')
print ' | ' + link_tag('?edit=' + name, 'Edit Page', 'navlink')
else:
print ' | <i>Immutable Page</i>'
- print '</div>'
+ user = remote_user()
+ if user != 'AnonymousCoward':
+ print ' | <i>logged in as <b>' + cgi.escape(user) + '</b></i>'
+
+ print '</div>'
title_done = True
class Page:
def __init__(self, page_name):
self.page_name = page_name
- self.remote_user = 'AnonymousCoward'
- self.remote_host = environ.get('REMOTE_ADDR', '')
self.msg = ''
self.msg_type = 'error'
self.attrs = {}
# and insert a space there
return re.sub('([a-z])([A-Z])', r'\1 \2', self.page_name)
-
def _text_filename(self):
return path.join(text_dir, self.page_name)
-
def _tmp_filename(self):
return path.join(text_dir, ('#' + self.page_name + '.' + `os.getpid()` + '#'))
-
def exists(self):
try:
os.stat(self._text_filename())
acl = attrs["acl"]
for rule in acl.split():
(user,perms) = acl.split(':')
- if user == self.remote_user or user == "All":
+ if user == remote_user() or user == "All":
if 'write' in perms.split(','):
return True
return False
def _last_modified(self):
if not self.exists():
return None
+ from time import localtime, strftime
modtime = localtime(os.stat(self._text_filename())[stat.ST_MTIME])
return strftime(datetime_fmt, modtime)
send_title(None, 'Edit ' + self.split_title(), msg=self.msg, msg_type=self.msg_type)
print ('<p><b>Editing ' + self.page_name
- + ' for ' + self.remote_user
- + ' from ' + get_hostname(self.remote_host)
+ + ' for ' + cgi.escape(remote_user())
+ + ' from ' + cgi.escape(get_hostname(remote_host()))
+ '</b></p>')
print '<div class="editor"><form method="post" action="%s/%s">' % (get_scriptname(), self.page_name)
print '<input type="hidden" name="savepage" value="%s">' % (self.page_name)
self._write_file(newtext)
rc = 0
if post_edit_hook:
+ # FIXME: what's the std way to perform shell quoting in python?
cmd = ( post_edit_hook
- + ' ' + text_dir + '/' + self.page_name
- + ' ' + self.remote_user
- + ' ' + self.remote_host
+ + " '" + text_dir + '/' + self.page_name
+ + "' '" + remote_user()
+ + "' '" + remote_host() + "'"
)
out = os.popen(cmd)
msg = out.read()