Changeset 332
- Timestamp:
- 06/15/09 20:28:07 (3 years ago)
- Files:
-
- 1 modified
-
trunk/sandbox/jhb/webwallet/cgi/wallet.cgi (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sandbox/jhb/webwallet/cgi/wallet.cgi
r331 r332 2 2 3 3 libdir = '/home/joerg/opencoin' 4 datadir = '/home/joerg/opencoin/webwallet '4 datadir = '/home/joerg/opencoin/webwallet/data' 5 5 6 6 ################################## … … 14 14 from oc2 import wallet, transports 15 15 16 16 #for key,value in os.environ.items(): 17 # print '%s: %s<br>\n' % (key,value) 18 #print str(username) 17 19 18 20 class CGIWallet: … … 33 35 print "\r" 34 36 if self.mimetype == 'text/html': 35 print '<html><body><small>%s</small>' % (baseserver+baseurl) 37 print '<html><body>' 38 #print '<small><a href="%s?action=logout">Logout</a></small>' % (baseurl) 36 39 print '<br/>\n'.join(self.output) 37 40 print '</body></html>' … … 47 50 def dispatchRequest(self): 48 51 self.env = os.environ 49 self.form = cgi.FieldStorage(keep_blank_values=1)50 52 self.action = action = self.form.getfirst('action','') 51 53 self.method = method = self.env['REQUEST_METHOD'].lower() … … 55 57 redeem = self.redeemCoins, 56 58 delcurrency = self.delCurrency, 57 spend = self.spendCoins) 59 spend = self.spendCoins, 60 login = self.displayMain) 58 61 59 62 getmapping = dict(addcurrency = self.displayAddCurrency, … … 276 279 self.out(answer.toString(True)) 277 280 281 form = cgi.FieldStorage(keep_blank_values=1) 282 278 283 baseserver = "http://%s:%s" % (os.environ['SERVER_NAME'],os.environ['SERVER_PORT']) 279 baseurl = os.environ['SCRIPT_NAME'] 280 284 username = os.environ.get('PATH_INFO','') 285 baseurl = os.environ['SCRIPT_NAME']+username 286 287 def die(string): 288 print 'Content-type:text/plain\r\n' 289 print string 290 sys.exit(0) 291 292 if username == '/' or not username: 293 die('username required, no direct access allowed. Try %s%s/YOURNAME' % (baseserver,baseurl)) 294 username = username[1:] 295 if username.startswith('.') or '/' in username: 296 die('hacking in, ey') 297 298 if 0: 299 password = None 300 301 if form.has_key('password'): 302 password = form.getfirst('password') 303 print "Set-Cookie:%s=%s" % (username,password) 304 elif form.getfirst('action','') == 'logout': 305 print "Set-Cookie:%s=%s" % (username,'') 306 elif os.environ.has_key('HTTP_COOKIE'): 307 for cookie in [c.strip() for c in os.environ['HTTP_COOKIE'].split(';')]: 308 if not cookie: 309 continue 310 (key, value ) = cookie.split('='); 311 if key == username: 312 password = value 313 314 315 filepath = datadir+'/%s.bin' % username 316 storage = oc2storage.CryptedStorage() 317 storage.setPassword(password) 318 storage.setFilename(filepath) 319 message = '' 320 if password and not os.path.exists(filepath): 321 storage.save() 322 elif form.getfirst('action','') not in ['logout','']: 323 try: 324 storage.restore() 325 storage.save() 326 except: 327 print "Set-Cookie:%s=%s" % (username,'') 328 password = None 329 message = 'Wrong password<br>' 330 331 if not password: 332 print """Content-type:text/html 333 334 <html><body> 335 <form action='%s' method='post'> 336 %s 337 Enter your password: <input type='password' name='password'> <input type='submit'> 338 <input type='hidden' name='action' value='login' /> 339 </form> 340 </body></html> 341 """ % (baseurl,message) 342 sys.exit(0) 343 filepath = datadir+'/%s.bin' % username 281 344 storage = oc2storage.Storage() 282 storage.setFilename( datadir+'/wallet.bin')345 storage.setFilename(filepath) 283 346 storage.restore() 284 347 w = CGIWallet(storage) 348 w.form = form 285 349 w.dispatchRequest() 286 350 w.printout() 351 352 353 354 #for key,value in os.environ.items(): 355 # print '%s: %s<br>\n' % (key,value) 356 #print str(username)
