Merge lp:~guydmann/anonplus/guydmann_dev into lp:anonplus

Proposed by Guy Mann
Status: Merged
Approved by: aj00200
Approved revision: 204
Merged at revision: 204
Proposed branch: lp:~guydmann/anonplus/guydmann_dev
Merge into: lp:anonplus
Diff against target: 181 lines (+80/-41)
2 files modified
src/setup.py (+1/-1)
src/uis/web/handler.py (+79/-40)
To merge this branch: bzr merge lp:~guydmann/anonplus/guydmann_dev
Reviewer Review Type Date Requested Status
aj00200 Approve
Review via email: mp+94911@code.launchpad.net

Description of the change

bug fix for #938221 Old versions of PyCrypto do not have Crypto.version_info

refactoring of the uis/web/handler.py to use an array to store the list of requests available and moving the code for those requests into separate functions.

To post a comment you must log in.
Revision history for this message
aj00200 (aj00200) wrote :

The code looks acceptable. The fix for bug #938221 is perfect. However, the additional web-ui code in r204 is not needed as the web-ui is being rewritten anyways.

I will try to include this new structure in the web-ui as I rewrite it.

Thanks for your help.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/setup.py'
--- src/setup.py 2012-02-22 00:45:53 +0000
+++ src/setup.py 2012-02-28 05:50:23 +0000
@@ -30,7 +30,7 @@
3030
31# Check PyCrypto version basics - require v2.4.x or higher31# Check PyCrypto version basics - require v2.4.x or higher
32# The version in PyCrypto is incorrect. See bug #89294432# The version in PyCrypto is incorrect. See bug #892944
33if Crypto.version_info[0] < 2 or Crypto.version_info[1] < 1:33if not hasattr(Crypto,'version_info') or Crypto.version_info[0] < 2 or Crypto.version_info[1] < 1:
34 raise Exception(_(34 raise Exception(_(
35 'Please update PyCrypto: https://www.dlitz.net/software/pycrypto/'))35 'Please update PyCrypto: https://www.dlitz.net/software/pycrypto/'))
3636
3737
=== modified file 'src/uis/web/handler.py'
--- src/uis/web/handler.py 2012-02-09 01:53:56 +0000
+++ src/uis/web/handler.py 2012-02-28 05:50:23 +0000
@@ -29,41 +29,19 @@
29 self.posts.insert(0, Post(name, sha256, post))29 self.posts.insert(0, Post(name, sha256, post))
3030
31 def web_ui_request(self, path, connection):31 def web_ui_request(self, path, connection):
32 if path == '/':32 request_array = [['/','==','root'],['/global.css','==','global_css'], ['/friends.html', '==', 'friends_html'], ['/settings.html', '==', 'settings_html'], ['/shutdown.html','==','shutdown_html'], ['/make_post.cgi?',"<-",'make_post_cgi'], ['/forward.cgi?',"<-",'forward_cgi'], ['/reply.cgi?',"<-",'reply_cgi'], ['/add_friend.cgi?',"<-",'add_friend_cgi'], ['/keys.html', '==','keys_html']]
33 connection.send_response(200)33 for request in request_array:
34 connection.send_header('Content-type', 'text/html')34 if request[1] == "==":
35 connection.end_headers()35 if path ==request[0]:
36 connection.wfile.write(uis.web.content.template.format(36 getattr(self, request[2],self.__defaultFailure)(path, connection)
37 title = 'Anon+ News Feed',37 elif request[1] == "<-":
38 pagetitle = 'Anon+ News Feed',38 if path.startswith(request[0]):
39 main = uis.web.content.post_box + self.__generate_news_feed(),39 getattr(self, request[2],self.__defaultFailure)(path, connection)
40 sidecontent = self.__friends2html()40
41 ))41 def __defaultFailure(self, path, connection):
42 elif path == '/global.css':42 connection.wfile.write('unrecognized request')
43 connection.send_response(200)43
44 connection.send_header('Content-type', 'text/css')44 def make_post_cgi(self, path, connection):
45 connection.end_headers()
46 connection.wfile.write(uis.web.content.globalcss)
47 elif path == '/settings.html':
48 connection.send_response(200)
49 connection.send_header('Content-type', 'text/html')
50 connection.end_headers()
51 connection.wfile.write('Connections page')
52 elif path == '/shutdown.html':
53 connection.send_response(200)
54 connection.send_header('Content-type', 'text/html')
55 connection.end_headers()
56 print('Got shutdown request from web server')
57 connection.wfile.write(uis.web.content.template.format(
58 title = 'Shutting down',
59 pagetitle = 'Shutdown',
60 main = 'We are quitting now. Threads are being killed.',
61 sidecontent = 'Goodbye :)'
62 ))
63 libs.globals['running'] = False
64 libs.threadmanager.killall()
65 libs.threadmanager.close_sockets()
66 elif path.startswith('/make_post.cgi?'):
67 parameters = unquote_plus(path.split('?')[-1]).split('&')45 parameters = unquote_plus(path.split('?')[-1]).split('&')
68 for parameter in parameters:46 for parameter in parameters:
69 item = parameter.split('=')47 item = parameter.split('=')
@@ -83,7 +61,45 @@
83 connection.send_header('Location', 'http://localhost:7777/')61 connection.send_header('Location', 'http://localhost:7777/')
84 connection.end_headers()62 connection.end_headers()
85 connection.wfile.write('Redirecting')63 connection.wfile.write('Redirecting')
86 elif path.startswith('/forward.cgi?'):64
65 def shutdown_html(self, path, connection):
66 connection.send_response(200)
67 connection.send_header('Content-type', 'text/html')
68 connection.end_headers()
69 print('Got shutdown request from web server')
70 connection.wfile.write(uis.web.content.template.format(
71 title = 'Shutting down',
72 pagetitle = 'Shutdown',
73 main = 'We are quitting now. Threads are being killed.',
74 sidecontent = 'Goodbye :)'
75 ))
76 libs.globals['running'] = False
77 libs.threadmanager.killall()
78 libs.threadmanager.close_sockets()
79
80 def settings_html(self, path, connection):
81 connection.send_response(200)
82 connection.send_header('Content-type', 'text/html')
83 connection.end_headers()
84 connection.wfile.write('Connections page')
85
86
87 def forward_cgi(self, path, connection):
88 connection.send_response(200)
89 connection.send_header('Content-type', 'text/html')
90 connection.end_headers()
91 print('Got shutdown request from web server')
92 connection.wfile.write(uis.web.content.template.format(
93 title = 'Shutting down',
94 pagetitle = 'Shutdown',
95 main = 'We are quitting now. Threads are being killed.',
96 sidecontent = 'Goodbye :)'
97 ))
98 libs.globals['running'] = False
99 libs.threadmanager.killall()
100 libs.threadmanager.close_sockets()
101
102 def forward_cgi(self, path, connection):
87 parameters = unquote_plus(path.split('?')[-1])103 parameters = unquote_plus(path.split('?')[-1])
88 post_hash = parameters.split('=')[-1]104 post_hash = parameters.split('=')[-1]
89105
@@ -103,12 +119,14 @@
103 connection.send_header('Location', 'http://localhost:7777/')119 connection.send_header('Location', 'http://localhost:7777/')
104 connection.end_headers()120 connection.end_headers()
105 connection.wfile.write('Redirecting')121 connection.wfile.write('Redirecting')
106 elif path.startswith('/reply.cgi?'):122
123 def reply_cgi(self, path, connection):
107 connection.send_response(301)124 connection.send_response(301)
108 connection.send_header('Location', 'http://localhost:7777/')125 connection.send_header('Location', 'http://localhost:7777/')
109 connection.end_headers()126 connection.end_headers()
110 connection.wfile.write('Redirecting')127 connection.wfile.write('Redirecting')
111 elif path == '/friends.html':128
129 def friends_html(self, path, connection):
112 connection.send_response(200)130 connection.send_response(200)
113 connection.send_header('Content-type', 'text/html')131 connection.send_header('Content-type', 'text/html')
114 connection.end_headers()132 connection.end_headers()
@@ -122,7 +140,9 @@
122 ),140 ),
123 sidecontent = self.__friends2html()141 sidecontent = self.__friends2html()
124 ))142 ))
125 elif path.startswith('/add_friend.cgi?'):143
144
145 def add_friend_cgi(self, path, connection):
126 parameters = unquote_plus(path.split('?')[-1]).split('&')146 parameters = unquote_plus(path.split('?')[-1]).split('&')
127 keydata = ''147 keydata = ''
128 tunnel = ''148 tunnel = ''
@@ -156,7 +176,9 @@
156 '<br />Key: %s' % result,176 '<br />Key: %s' % result,
157 sidecontent = self.__friends2html()177 sidecontent = self.__friends2html()
158 ))178 ))
159 elif path == '/keys.html':179
180
181 def keys_html(self, path, connection):
160 connection.send_response(200)182 connection.send_response(200)
161 connection.send_header('Content-type', 'text/html')183 connection.send_header('Content-type', 'text/html')
162 connection.end_headers()184 connection.end_headers()
@@ -167,6 +189,23 @@
167 sidecontent = self.__friends2html()189 sidecontent = self.__friends2html()
168 ))190 ))
169191
192 def root(self,path,connection):
193 connection.send_response(200)
194 connection.send_header('Content-type', 'text/html')
195 connection.end_headers()
196 connection.wfile.write(uis.web.content.template.format(
197 title = 'Anon+ News Feed',
198 pagetitle = 'Anon+ News Feed',
199 main = uis.web.content.post_box + self.__generate_news_feed(),
200 sidecontent = self.__friends2html()
201 ))
202
203 def global_css(self,path,connection):
204 connection.send_response(200)
205 connection.send_header('Content-type', 'text/css')
206 connection.end_headers()
207 connection.wfile.write(uis.web.content.globalcss)
208
170 def __friends2html(self):209 def __friends2html(self):
171 '''Convert our friends list into some nice HTML'''210 '''Convert our friends list into some nice HTML'''
172 return uis.web.content.friends_box.format(211 return uis.web.content.friends_box.format(

Subscribers

People subscribed via source and target branches

to all changes: