32
32
include_html_syntax = 1
34
34
def user2Link(user):
35
"""given a username, return some representation of that user
36
Generally, this will be an anchor ref of a mailto URL
38
# could also look up mail addrs via a table lookup, etc
39
return '<a href="mailto:%(user)s@somewebsite.com">%(user)s</a>' % {"user": user}
35
"""given a username, return some representation of that user
36
Generally, this will be an anchor ref of a mailto URL
38
# could also look up mail addrs via a table lookup, etc
39
return '<a href="mailto:%(user)s@somewebsite.com">%(user)s</a>' % {"user": user}
41
41
# Nothing below here should need to be tailored...
43
43
def get_blog_dirs():
45
os.path.walk(blog_root, lambda arg, dirPath, paths: logdirs.append(dirPath[len(blog_root)+1:]), None)
45
os.path.walk(blog_root, lambda arg, dirPath, paths: logdirs.append(dirPath[len(blog_root)+1:]), None)
49
49
def getUser(): return os.environ.get("REMOTE_USER", None)
51
51
def validPath(category, filename):
53
category = "" # special case for main directory
54
categories=get_blog_dirs()
55
if category not in categories:
56
# XXX: I should escape any html in category to prevent
57
# error page from cross site scripting (of course, it's
58
# assumed that the person submitting has been authenticated
60
raise RuntimeError, "Category `%s' does not exist" % category
61
for hostile_char in r"/.`$&*?|;":
62
if hostile_char in filename:
63
raise RuntimeError, "Invalid character `%s' in filename. Try to stay with alphanumerics, space, and underscore." % hostile_char
64
return os.path.join(blog_root, category, filename +".txt")
53
category = "" # special case for main directory
54
categories=get_blog_dirs()
55
if category not in categories:
56
# XXX: I should escape any html in category to prevent
57
# error page from cross site scripting (of course, it's
58
# assumed that the person submitting has been authenticated
60
raise RuntimeError, "Category `%s' does not exist" % category
61
for hostile_char in r"/.`$&*?|;":
62
if hostile_char in filename:
63
raise RuntimeError, "Invalid character `%s' in filename. Try to stay with alphanumerics, space, and underscore." % hostile_char
64
return os.path.join(blog_root, category, filename +".txt")
67
categories=get_blog_dirs()
67
categories=get_blog_dirs()
71
71
<title>content creation</title>
74
74
<form action="weblog-add.py">
76
76
<select name="category">"""
77
for path in categories:
79
if path == "": # special case for root
82
print """<option value="%s">%s</option>""" %(path, name)
77
for path in categories:
79
if path == "": # special case for root
82
print """<option value="%s">%s</option>""" %(path, name)
88
88
<input type=text name="title" size=80 value="">
90
90
<b>Filename (no path and no extension):</b>
92
92
<input type=text name="filename" size=40 value="">
96
if include_html_syntax:
96
if include_html_syntax:
98
98
<b>HTML Summary:</b>
101
101
<tr><th>Hypertext link</th><td><a href="URL">linked text</a></td></tr>
102
102
<tr><th>Paragraph</th><td><p>Text</p></td></tr>
105
105
<tr><th>Strongly emphasized text</th><td><strong><strong>Text to emphasize</strong></strong></td></tr>
111
111
<textarea cols=80 rows=10 name="text"></textarea>
113
113
<input type=submit>
119
print "<html><head><title>Content Error!</title></head><body><h1>Content Error!</h1>%s</body></html>" % msg
119
print "<html><head><title>Content Error!</title></head><body><h1>Content Error!</h1>%s</body></html>" % msg
122
122
def addContent(form):
124
filename=validPath(form.getfirst("category"), form.getfirst("filename"))
125
except RuntimeError, msg:
127
# XXX: should perhaps do more error checking here
128
datafile=open(filename, "w")
129
print >>datafile, form.getfirst("title")
130
print >>datafile, '#author %s' % user2Link(getUser())
131
print >>datafile, form.getfirst("text")
133
print '<html><body><h1>Posted!</h1><a href="/">Return to webroot</a></body></html>'
134
# XXX: return page should probably link to page to which
135
# content was added... HTTP_REFERRER seems to be broken for
124
filename=validPath(form.getfirst("category"), form.getfirst("filename"))
125
except RuntimeError, msg:
127
# XXX: should perhaps do more error checking here
128
datafile=open(filename, "w")
129
print >>datafile, form.getfirst("title")
130
print >>datafile, '#author %s' % user2Link(getUser())
131
print >>datafile, form.getfirst("text")
133
print '<html><body><h1>Posted!</h1><a href="/">Return to webroot</a></body></html>'
134
# XXX: return page should probably link to page to which
135
# content was added... HTTP_REFERRER seems to be broken for
138
138
if __name__ == '__main__':
139
form = cgi.FieldStorage()
140
print "Content-type: text/html\n"
142
error("User not authenticated.")
143
if form.has_key("text"):
139
form = cgi.FieldStorage()
140
print "Content-type: text/html\n"
142
error("User not authenticated.")
143
if form.has_key("text"):