From: <bel...@us...> - 2003-03-02 02:52:42
|
Update of /cvsroot/btplusplus/BT++/src/WebServer In directory sc8-pr-cvs1:/tmp/cvs-serv32506/WebServer Modified Files: BTWebServer.py HTTPConfigFile.py Log Message: Bug in logging fixed & additional templates I Index: BTWebServer.py =================================================================== RCS file: /cvsroot/btplusplus/BT++/src/WebServer/BTWebServer.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BTWebServer.py 27 Feb 2003 00:44:40 -0000 1.3 --- BTWebServer.py 2 Mar 2003 02:52:39 -0000 1.4 *************** *** 17,80 **** __version__ = "0.1" - Checked = {0: '', 1:'CHECKED', '0': '', '1':'CHECKED'} - - HTTP_ROOT = """\ - <html> - <head> - <title>WebTorrent++</title> - </head> - <frameset rows="50,*"> - <frame name="top" src="menu"> - <frame name="body" src="torrents"> - </frameset> - </html> - """ - - HTTP_MENU = """\ - <head> - <title>Success</title> - </head> - <body bgcolor=#%s> - <table width=100%%><tr> - <td><form method=get action="torrents" target="body"><button type=submit>Torrents</button></form></td> - <td nowrap><form method=get action="log" target="body"><button type=submit>View Log</button></form></td> - <td><form method=get action="config" target="body"><button type=submit>Config</button></form></td> - <td width=80%%><form method=post action="torrents" target="body"> - <table width=100%% border=1 bgcolor=#%s><tr> - <td width=100%%><input type=text style="width:100%%" name=torr title="Paste Torrent URLs here"></td> - <td><input type=hidden name=command value=Add><button type=submit>Add</button></td> - </tr></table> - </form></td> - <td nowrap><form method=get action="exit" target="body"><button type=submit>Kill server</button></form></td> - </tr></table> - </body> - """ - - HTTP_EXIT = """\ - <head> - <title>Exit</title> - </head> - <body> - <h1>Server Killed.</h1> - </body> - """ - - HTTP_DL_ERROR = """\ - <head> - <title>Download Error</title> - </head> - <body> - <h1>Error downloading Torrent %s</h1> - </body> - """ - - LOG_LEVEL_DESC = """\ - <table style="font-size:x-small"> - <tr><td width=1%%></td><td align=right>0</td><td width=100%%>Trivial</td></tr> - <tr><td width=1%%></td><td align=right>1</td><td width=100%%>Info</td></tr> - <tr><td width=1%%></td><td align=right>2</td><td width=100%%>Errors</td></tr> - <tr><td width=1%%></td><td align=right>3</td><td width=100%%>Critical Errors</td></tr> - </table> - """ ########################################################################################################### --- 17,20 ---- *************** *** 84,98 **** BTWait = Event() ! try: ! remove("WebTemplates/torrent.tmplc") ! except: ! pass templateTorrent = TemplateManager().prepare("WebTemplates/torrent.tmpl") ! try: ! remove("WebTemplates/log.tmplc") ! except: ! pass templateLog = TemplateManager().prepare("WebTemplates/log.tmpl") ########################################################################################################### ########################################################################################################### --- 24,71 ---- BTWait = Event() ! ! chdir( ! path.abspath( ! path.dirname(sys.argv[0]) ! ) ! ) ! ! try: mkdir(Config.Get('Paths', 'Incoming')) ! except: pass ! try: mkdir(Config.Get('Paths', 'Torrent')) ! except: pass ! try: mkdir(Config.Get('Paths', 'History')) ! except: pass ! try: mkdir(Config.Get('Paths', 'Temp')) ! except: pass ! ! try: remove("WebTemplates/root.tmplc") ! except: pass ! templateRoot = TemplateManager().prepare("WebTemplates/root.tmpl") ! ! try: remove("WebTemplates/menu.tmplc") ! except: pass ! templateMenu = TemplateManager().prepare("WebTemplates/menu.tmpl") ! ! try: remove("WebTemplates/exit.tmplc") ! except: pass ! templateExit = TemplateManager().prepare("WebTemplates/exit.tmpl") ! ! try: remove("WebTemplates/dl_fail.tmplc") ! except: pass ! templateDLFail = TemplateManager().prepare("WebTemplates/dl_fail.tmpl") ! ! try: remove("WebTemplates/torrent.tmplc") ! except: pass templateTorrent = TemplateManager().prepare("WebTemplates/torrent.tmpl") ! ! try: remove("WebTemplates/log.tmplc") ! except: pass templateLog = TemplateManager().prepare("WebTemplates/log.tmpl") + try: remove("WebTemplates/config.tmplc") + except: pass + templateConfig = TemplateManager().prepare("WebTemplates/config.tmpl") + ########################################################################################################### ########################################################################################################### *************** *** 121,141 **** WebLog.append( log ) if len(WebLog) > int(HTTPConfig.Get('Display', 'LogCount')): ! WebLog.pop() - chdir( - path.abspath( - path.dirname(sys.argv[0]) - ) - ) - - try: mkdir(Config.Get('Paths', 'Incoming')) - except: pass - try: mkdir(Config.Get('Paths', 'Torrent')) - except: pass - try: mkdir(Config.Get('Paths', 'History')) - except: pass - try: mkdir(Config.Get('Paths', 'Temp')) - except: pass - BTHandler = LoaderManager(log = WebLogit) --- 94,99 ---- WebLog.append( log ) if len(WebLog) > int(HTTPConfig.Get('Display', 'LogCount')): ! WebLog.remove( len(WebLog) - 1 ) BTHandler = LoaderManager(log = WebLogit) *************** *** 151,157 **** def do_GET(self): """Serve a GET request.""" self.send_head() if self.requested == '': ! self.wfile.write(HTTP_ROOT) elif self.requested == 'torrents': BTHandler.Update() --- 109,116 ---- def do_GET(self): """Serve a GET request.""" + tproc = TemplateProcessor() self.send_head() if self.requested == '': ! self.wfile.write(tproc.process(templateRoot)) elif self.requested == 'torrents': BTHandler.Update() *************** *** 161,169 **** self.send_config() elif self.requested == 'menu': ! self.wfile.write(HTTP_MENU % (HTTPConfig.Get('WebColors','MenuBackground'),HTTPConfig.Get('WebColors','MenuAddbar'))) elif self.requested == 'log': self.send_log() elif self.requested == 'exit': ! self.wfile.write(HTTP_EXIT) for loader in BTHandler.Loaders: if loader.IsRunning(): loader.PauseDownload() --- 120,128 ---- self.send_config() elif self.requested == 'menu': ! self.wfile.write(tproc.process(templateMenu)) elif self.requested == 'log': self.send_log() elif self.requested == 'exit': ! self.wfile.write(tproc.process(templateExit)) for loader in BTHandler.Loaders: if loader.IsRunning(): loader.PauseDownload() *************** *** 226,230 **** f.close() except: ! self.wfile.write(HTTP_DL_ERROR % url) return elif result['command']=='Config': --- 185,191 ---- f.close() except: ! tproc = TemplateProcessor() ! tproc.set('torrent', url) ! self.wfile.write(tproc.process(templateDLFail)) return elif result['command']=='Config': *************** *** 451,505 **** def send_config(self): ! ret = "<html>\n<head>\n<title>WebTorrent++ Configuration</title>\n" ! ret = ret + "</head>\n<body bgcolor=#%s>\n<form method=post action=\"torrents\">\n" % HTTPConfig.Get('WebColors','ConfBackground') ! ret = ret + "<table width=100%% border=1 bgcolor=#%s><tr><th colspan=2 align=left>Directories</th></tr>\n" % HTTPConfig.Get('WebColors','ConfTable') ! ret = ret + "<tr><td>Torrent</td><td width=80%%><input type=text style=\"width:100%%\" name=Paths_Torrent value=\"%s\"></td></tr>\n" % (Config.Get('Paths', 'Torrent')) ! ret = ret + "<tr><td>History</td><td width=80%%><input type=text style=\"width:100%%\" name=Paths_History value=\"%s\"></td></tr>\n" % (Config.Get('Paths', 'History')) ! ret = ret + "<tr><td>Incoming</td><td width=80%%><input type=text style=\"width:100%%\" name=Paths_Incoming value=\"%s\"></td></tr>\n" % (Config.Get('Paths', 'Incoming')) ! ret = ret + "<tr><td>Temp</td><td width=80%%><input type=text style=\"width:100%%\" name=Paths_Temp value=\"%s\"></td></tr>\n" % (Config.Get('Paths', 'Temp')) ! ret = ret + "</table>\n" ! ret = ret + "<p><table width=100%% border=1 bgcolor=#%s><tr><th align=left>Basic</th></tr>\n" % HTTPConfig.Get('WebColors','ConfTable') ! ret = ret + "<tr><td><table border=1 width=100%>" ! ret = ret + "<tr><td>Automatically start new downloads</td><td width=5%% align=center><input type=checkbox name=Download_AutoStart %s value=\"1\"></td></tr>\n" % (Checked[Config.Get('Download', 'AutoStart')]) ! ret = ret + "<tr><td>Automatically pause downloads (if current>max)</td><td width=5%% align=center><input type=checkbox name=Download_AutoPause %s value=\"1\"></td></tr>\n" % (Checked[Config.Get('Download', 'AutoPause')]) ! ret = ret + "<tr><td>Maximal simultanous downloads (1-10)</td><td width=5%%><input type=text style=\"width:100%%\" name=Download_MaxSimDown value=\"%s\"></td></tr>\n" % (Config.Get('Download', 'MaxSimDown')) ! ret = ret + "</table></td></tr>" ! ## ret = ret + "<tr><td><table border=1 width=100%>" ! ## ret = ret + "<tr><td>Automatically pause downloads (if current>max)</td><td width=5%% align=center><input type=checkbox name=Seed_AutoPause %s value=\"1\"></td></tr>\n" % (Checked[HTTPConfig.Get('Seed', 'AutoStart')]) ! ## ret = ret + "<tr><td>Maximal simultanous downloads (1-10)</td><td width=5%%><input type=text style=\"width:100%%\" name=Seed_MaxSimDown value=\"%s\"></td></tr>\n" % (HTTPConfig.Get('Seed', 'MaxSimSeed')) ! ## ret = ret + "</table></td></tr>" ! ret = ret + "<tr><td><table border=1 width=100%>" ! ret = ret + "<tr><td>Maximal download speed (0=unlimited)</td><td width=5%%><input type=text style=\"width:100%%\" name=Download_MaxSpeedDown value=\"%s\"></td></tr>\n" % (Config.Get('Download', 'MaxSpeedDown')) ! ret = ret + "<tr><td>Maximal upload speed (0=unlimited)</td><td width=5%%><input type=text style=\"width:100%%\" name=Download_MaxSpeedUp value=\"%s\"></td></tr>\n" % (Config.Get('Download', 'MaxSpeedUp')) ! ret = ret + "</table></td></tr>" ! ret = ret + "<tr><td><table border=1 width=100%>" ! ret = ret + "<tr><td>Use background hashing</td><td width=5%% align=center><input type=checkbox name=Hash_Background %s value=\"1\"></td></tr>\n" % (Checked[Config.Get('Hash', 'Background')]) ! ret = ret + "<tr><td>Maximal simultanous files hashed (1-5)</td><td width=5%%><input type=text style=\"width:100%%\" name=Hash_NumSimHash value=\"%s\"></td></tr>\n" % (Config.Get('Hash', 'NumSimHash')) ! ret = ret + "</table></td></tr>" ! ret = ret + "</table>\n" ! ret = ret + "<p><table width=100%% border=1 bgcolor=#%s><tr><th align=left>Net Config</th></tr>\n" % HTTPConfig.Get('WebColors','ConfTable') ! ret = ret + "<tr><td><table border=1 width=100%>" ! ret = ret + "<tr><td>Bind to IP for BitTorrent (*)</td><td width=10%%><input type=text style=\"width:100%%\" name=Bind_Ip value=\"%s\"></td></tr>\n" % (Config.Get('Bind', 'Ip')) ! ret = ret + "<tr><td>First Port for BitTorrent (*)</td><td width=5%%><input type=text style=\"width:100%%\" name=Bind_PortMin value=\"%s\"></td></tr>\n" % (Config.Get('Bind', 'PortMin')) ! ret = ret + "<tr><td>Last Port for BitTorrent (*)</td><td width=5%%><input type=text style=\"width:100%%\" name=Bind_PortMax value=\"%s\"></td></tr>\n" % (Config.Get('Bind', 'PortMax')) ! ret = ret + "</table></td></tr>" ! ret = ret + "<tr><td><table border=1 width=100%>" ! ret = ret + "<tr><td>Bind to IP for webserver (*)</td><td width=10%%><input type=text style=\"width:100%%\" name=Host_IP value=\"%s\"></td></tr>\n" % (HTTPConfig.Get('Host', 'IP')) ! ret = ret + "<tr><td>Webserver port (*)</td><td width=5%%><input type=text style=\"width:100%%\" name=Host_Port value=\"%s\"></td></tr>\n" % (HTTPConfig.Get('Host', 'Port')) ! ## ret = ret + "</table></td></tr>" ! ## ret = ret + "<tr><td><table border=1 width=100%>" ! ret = ret + "<tr><td>Allow access from localhost</td><td width=5%% align=center><input type=checkbox name=Access_AllowLocal %s value=\"1\"></td></tr>\n" % (Checked[HTTPConfig.Get('Access', 'AllowLocal')]) ! ret = ret + "<tr><td>Allow access from external IPs (separated by space)</td><td width=30%%><input type=text style=\"width:100%%\" name=Access_ValidIPs value=\"%s\"></td></tr>\n" % (HTTPConfig.Get('Access', 'ValidIPs')) ! ret = ret + "</table></td></tr>" ! ret = ret + "<tr><td><table border=1 width=100%>" ! ret = ret + "<tr><td>Refresh torrent page every (seconds)</td><td width=5%%><input type=text style=\"width:100%%\" name=Display_Refresh value=\"%s\"></td></tr>\n" % (HTTPConfig.Get('Display', 'Refresh')) ! ret = ret + "<tr><td>Log Level (default = 1)<br>" + LOG_LEVEL_DESC + "</td><td width=5%%><input type=text style=\"width:100%%\" name=Display_LogLevel value=\"%s\"></td></tr>\n" % (HTTPConfig.Get('Display', 'LogLevel')) ! ret = ret + "<tr><td>Number of kept Log entries (default = 200)</td><td width=5%%><input type=text style=\"width:100%%\" name=Display_LogCount value=\"%s\"></td></tr>\n" % (HTTPConfig.Get('Display', 'LogCount')) ! ret = ret + "</table></td></tr>" ! ret = ret + "</table>\n" ! ret = ret + "(*) changes require restart.\n" ! ! ret = ret + "<p><center><input type=hidden name=command value=Config><button type=submit>Submit Changes</button></center>\n</form>\n</body>\n</html>\n" ! self.wfile.write(ret) def send_log(self): --- 412,438 ---- def send_config(self): ! tproc = TemplateProcessor() ! tproc.set('paths_torrent', Config.Get('Paths', 'Torrent')) ! tproc.set('paths_history', Config.Get('Paths', 'History')) ! tproc.set('paths_incoming', Config.Get('Paths', 'Incoming')) ! tproc.set('paths_temp', Config.Get('Paths', 'Temp')) ! tproc.set('download_autostart', int(Config.Get('Download', 'AutoStart'))) ! tproc.set('download_autopause', int(Config.Get('Download', 'AutoPause'))) ! tproc.set('download_maxsimdown', Config.Get('Download', 'MaxSimDown')) ! tproc.set('download_maxspeeddown', Config.Get('Download', 'MaxSpeedDown')) ! tproc.set('download_maxspeedup', Config.Get('Download', 'MaxSpeedUp')) ! tproc.set('hash_background', int(Config.Get('Hash', 'Background'))) ! tproc.set('hash_numsimhash', Config.Get('Hash', 'NumSimHash')) ! tproc.set('bind_ip', Config.Get('Bind', 'Ip')) ! tproc.set('bind_portmin', Config.Get('Bind', 'PortMin')) ! tproc.set('bind_portmax', Config.Get('Bind', 'PortMax')) ! tproc.set('host_ip', HTTPConfig.Get('Host', 'IP')) ! tproc.set('host_port', HTTPConfig.Get('Host', 'Port')) ! tproc.set('access_allowlocal', int(HTTPConfig.Get('Access', 'AllowLocal'))) ! tproc.set('access_validips', HTTPConfig.Get('Access', 'ValidIPs')) ! tproc.set('display_refresh', HTTPConfig.Get('Display', 'Refresh')) ! tproc.set('display_loglevel', HTTPConfig.Get('Display', 'LogLevel')) ! tproc.set('display_logcount', HTTPConfig.Get('Display', 'LogCount')) ! self.wfile.write(tproc.process(templateConfig)) def send_log(self): Index: HTTPConfigFile.py =================================================================== RCS file: /cvsroot/btplusplus/BT++/src/WebServer/HTTPConfigFile.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** HTTPConfigFile.py 27 Feb 2003 00:44:40 -0000 1.3 --- HTTPConfigFile.py 2 Mar 2003 02:52:39 -0000 1.4 *************** *** 19,28 **** ## 'MaxSimSeed': 3 ## }, - 'WebColors': { - 'MenuBackground': 'FFFFCC', - 'MenuAddbar': 'FFCCCC', - 'ConfBackground': '6666AA', - 'ConfTable': 'CCCCFF', - } } --- 19,22 ---- |