Mercurial > traipse
diff plugins/xxcherrypy.py @ 8:33582ce538b5 grumpy-goblin
CherryPy improvements.
author | sirebral |
---|---|
date | Sat, 18 Jul 2009 11:40:34 -0500 |
parents | 4385a7d0efd1 |
children | 5df1340bda13 |
line wrap: on
line diff
--- a/plugins/xxcherrypy.py Fri Jul 17 01:56:41 2009 -0500 +++ b/plugins/xxcherrypy.py Sat Jul 18 11:40:34 2009 -0500 @@ -5,6 +5,7 @@ import cherrypy._cpserver as server import socket import wx +from orpg.orpgCore import * # VEG (march 21, 2007): Now remembers your last web server on/off setting @@ -32,32 +33,25 @@ self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On') self.topframe.Bind(wx.EVT_MENU, self.cherrypy_toggle, self.toggle) - ports = wx.Menu() - self.portClient = ports.AppendRadioItem(wx.ID_ANY, 'Client:9557') - self.portServer = ports.AppendRadioItem(wx.ID_ANY, 'Server:9558') - self.topframe.Bind(wx.EVT_MENU, self.port_change, self.portClient) - self.topframe.Bind(wx.EVT_MENU, self.port_change, self.portServer) - self.menu.AppendMenu(wx.ID_ANY, 'Port', ports) - - def port_change(self, evt): - if self.portClient.IsChecked() == True: self.on_cherrypy("port 9557") - if self.portServer.IsChecked() == True: self.on_cherrypy("port 9558") - def cherrypy_toggle(self, evt): if self.toggle.IsChecked() == True: self.on_cherrypy("on") if self.toggle.IsChecked() == False: self.on_cherrypy("off") def plugin_enabled(self): - self.port = 9557 + cpport = 0 # Container object so we can call port instead of an assigned ## + self.port = 6775 if not int(self.plugindb.GetString("xxcherrypy", "port", cpport)) else int(self.plugindb.GetString("xxcherrypy", "port", cpport)); del cpport #Deletes port container. self.plugin_addcommand('/cherrypy', self.on_cherrypy, '[on | off | port | status] - This controls the CherryPy Web Server') - tmp = socket.gethostbyname_ex(socket.gethostname()) - for ip in tmp[2]: - self.host = ip - if ip[:7] == '192.168' or ip[:3] == '10.' or ip == '127.0.0.1' or (ip[:3] == '172' and (int(ip[5:6]) >= 16 and int(ip[5:6]) <=32)) : - self.chat.InfoPost("[WARNING] Cherrypy has detected that you may be behind a router. This is your internal IP. For other users to properly connect, you may have to use your external IP, with port forwarding on port 80.<br />This feature is not suported in any way.") - - #if str(self.plugindb.GetString("xxcherrypy", "auto_start", "off")) == "on": # VEG - # self.on_cherrypy("on") # VEG + import urllib + url = urllib.URLopener() + resp = url.open('http://www.knowledgearcana.com/vgt/ip_scrape.php') + html = resp.read(19+19) + ip = html[19:]; self.host = ip[1:len(ip)-1] + cpobj = 0 + if str(self.plugindb.GetString("xxcherrypy", "auto_start", cpobj)) == "on": # VEG + self.on_cherrypy("on") # VEG + del cpobj + self.cherryhost = 'http://' + self.host + ':' + str(self.port) + '/webfiles/' + open_rpg.add_component("cherrypy", self.cherryhost) def plugin_disabled(self): #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin @@ -68,7 +62,7 @@ self.isServerRunning = 'off' else: pass - + open_rpg.del_component("cherrypy") def on_cherrypy(self, cmdargs): args = cmdargs.split(None,-1) @@ -92,13 +86,14 @@ elif args[0] == 'port': if self.isServerRunning == 'on': - self.port = int(args[1]) - server.stop() - self.webserver = thread.start_new_thread(self.startServer, (self.port,)) + self.chat.InfoPost('Please turn CherryPy off first!') + return self.port = int(args[1]) + self.plugindb.SetString("xxcherrypy", "port", str(self.port)) # TAS self.chat.InfoPost("CherryPy Web Server is currently: " + self.isServerRunning) - self.chat.InfoPost("CherryPy Web Server address is: http://" + str(self.host) + ':' + str(self.port) + '/webfiles/') - + self.cherryhost = 'http://' + self.host + ':' + str(self.port) + '/webfiles/' + open_rpg.del_component("cherrypy"); open_rpg.add_component("cherrypy", self.cherryhost) + self.chat.InfoPost('CherryPy Web Server address is: ' + self.cherryhost) def startServer(self, port):