2
# Copyright (C) 2007-2008 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
# This is an IVLE application.
23
# A SMF forum application for IVLE.
25
from common import util
26
from common import interpret
34
Handler for the Forum application.
36
This application implements a general purpose PHP CGI loader
40
#forum_base = "/var/www/default/smf"
41
forum_base = "php/phpBB3"
42
#default_page = "index.php"
44
# Set request attributes
46
# These files don't really exist - just a test of our linking
48
#req.styles = ["media/dummy/dummy.css"]
49
#req.scripts = ["media/dummy/dummy.js", "media/dummy/hello.js"]
51
# Process URL for special directives
52
url = urlparse.urlparse(req.path)
53
hierarchical_part = url[2]
55
forum_page = "" # use the default forum page
58
board = re.match('board/(.*?)(/|$)',hierarchical_part)
60
framequery += 'f=' + board.group(1) + "&"
61
forum_page = "viewforum.php"
63
topic = re.search('topic/(.*?)(/|$)',hierarchical_part)
65
framequery += 't=' + topic.group(1)
66
forum_page = "viewtopic.php"
69
#req.write(framequery + '\n')
71
# If the tail of the forum url is empty or a known special request
72
# then wrap the page in the headers and footer and load the default or
73
# special page in the ivlebody frame
76
location = forum_page + framequery
78
frameurl = util.make_path(path.join(forum_base,location))
79
req.content_type = "text/html"
80
req.write_html_head_foot = True
85
' data="' + frameurl + framequery + '"' +
88
# Otherwise serve the page without the wrapper
91
# req.throw_error(req.HTTP_BAD_REQUEST)
95
# Let the Server determine the MIME type
96
# req.content_type = ""
98
# Don't write header or footer - we can't tell if it's HTML or
99
# something else like an image
100
# req.write_html_head_foot = False
102
# Do some basic dispatch, if it ends in .php interpret with php-cgi
103
# if re.search('\.php$',hierarchical_part,re.IGNORECASE):
104
# interpret.execute_cgi(
105
# ['/usr/bin/php5-cgi'],
109
# Otherwise just ship the file directly
111
#req.content_type = "application/x-httpd-php"
112
# file_path = os.path.join(forum_base, req.path)
113
# if os.access(file_path,os.R_OK):
114
# req.sendfile(path.join(forum_base, req.path))
115
# If we can't read the file, throw HTTP Error
117
# req.throw_error(req.HTTP_BAD_REQUEST)