-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.cgi~
executable file
·55 lines (39 loc) · 1.3 KB
/
index.cgi~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/local/bin/python
import cgi,cgitb
cgitb.enable()
import imports
from postcontroller import PostController
from commentcontroller import CommentController
from usercontroller import UserController
#import header and footer
header = open("header.html", "r").read()
footer = open("footer.html", "r").read()
url_args = cgi.FieldStorage()
# map controller names to their classes
classes = {
'user' : UserController,
'post' : PostController,
'comment' : CommentController
}
parameters = None
controllerName = None
# get class name from url args
className = url_args.getvalue('class') if 'class' in url_args.keys() else 'post'
# defaults fo PostController
controller = classes[className]()
# get method from url -- defaults to show()
methodName = url_args.getvalue('method') if 'method' in url_args.keys() else 'show'
#build argument list
args = dict()
arg_keys = url_args.keys()
for key in arg_keys:
args[key] = url_args.getvalue(key)
#if className == 'post' and methodName == 'show':
print "Content-Type: text/html" # HTML is following
print # blank line, end of headers
print header
#call the class and method from the URL
getattr(controller, methodName)(args)
#print url_args
if className == 'Post' and methodName == 'show':
print footer