Mercurial > traipse
comparison plugins/xxcherrypy.py @ 8:33582ce538b5 grumpy-goblin
CherryPy improvements.
author | sirebral |
---|---|
date | Sat, 18 Jul 2009 11:40:34 -0500 |
parents | 4385a7d0efd1 |
children | 5df1340bda13 |
comparison
equal
deleted
inserted
replaced
7:d63ad196cc0d | 8:33582ce538b5 |
---|---|
3 import orpg.pluginhandler | 3 import orpg.pluginhandler |
4 import thread | 4 import thread |
5 import cherrypy._cpserver as server | 5 import cherrypy._cpserver as server |
6 import socket | 6 import socket |
7 import wx | 7 import wx |
8 from orpg.orpgCore import * | |
8 | 9 |
9 # VEG (march 21, 2007): Now remembers your last web server on/off setting | 10 # VEG (march 21, 2007): Now remembers your last web server on/off setting |
10 | 11 |
11 class Plugin(orpg.pluginhandler.PluginHandler): | 12 class Plugin(orpg.pluginhandler.PluginHandler): |
12 # Initialization subroutine. | 13 # Initialization subroutine. |
30 def plugin_menu(self): | 31 def plugin_menu(self): |
31 self.menu = wx.Menu() | 32 self.menu = wx.Menu() |
32 self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On') | 33 self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On') |
33 self.topframe.Bind(wx.EVT_MENU, self.cherrypy_toggle, self.toggle) | 34 self.topframe.Bind(wx.EVT_MENU, self.cherrypy_toggle, self.toggle) |
34 | 35 |
35 ports = wx.Menu() | |
36 self.portClient = ports.AppendRadioItem(wx.ID_ANY, 'Client:9557') | |
37 self.portServer = ports.AppendRadioItem(wx.ID_ANY, 'Server:9558') | |
38 self.topframe.Bind(wx.EVT_MENU, self.port_change, self.portClient) | |
39 self.topframe.Bind(wx.EVT_MENU, self.port_change, self.portServer) | |
40 self.menu.AppendMenu(wx.ID_ANY, 'Port', ports) | |
41 | |
42 def port_change(self, evt): | |
43 if self.portClient.IsChecked() == True: self.on_cherrypy("port 9557") | |
44 if self.portServer.IsChecked() == True: self.on_cherrypy("port 9558") | |
45 | |
46 def cherrypy_toggle(self, evt): | 36 def cherrypy_toggle(self, evt): |
47 if self.toggle.IsChecked() == True: self.on_cherrypy("on") | 37 if self.toggle.IsChecked() == True: self.on_cherrypy("on") |
48 if self.toggle.IsChecked() == False: self.on_cherrypy("off") | 38 if self.toggle.IsChecked() == False: self.on_cherrypy("off") |
49 | 39 |
50 def plugin_enabled(self): | 40 def plugin_enabled(self): |
51 self.port = 9557 | 41 cpport = 0 # Container object so we can call port instead of an assigned ## |
42 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. | |
52 self.plugin_addcommand('/cherrypy', self.on_cherrypy, '[on | off | port | status] - This controls the CherryPy Web Server') | 43 self.plugin_addcommand('/cherrypy', self.on_cherrypy, '[on | off | port | status] - This controls the CherryPy Web Server') |
53 tmp = socket.gethostbyname_ex(socket.gethostname()) | 44 import urllib |
54 for ip in tmp[2]: | 45 url = urllib.URLopener() |
55 self.host = ip | 46 resp = url.open('http://www.knowledgearcana.com/vgt/ip_scrape.php') |
56 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)) : | 47 html = resp.read(19+19) |
57 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.") | 48 ip = html[19:]; self.host = ip[1:len(ip)-1] |
58 | 49 cpobj = 0 |
59 #if str(self.plugindb.GetString("xxcherrypy", "auto_start", "off")) == "on": # VEG | 50 if str(self.plugindb.GetString("xxcherrypy", "auto_start", cpobj)) == "on": # VEG |
60 # self.on_cherrypy("on") # VEG | 51 self.on_cherrypy("on") # VEG |
52 del cpobj | |
53 self.cherryhost = 'http://' + self.host + ':' + str(self.port) + '/webfiles/' | |
54 open_rpg.add_component("cherrypy", self.cherryhost) | |
61 | 55 |
62 def plugin_disabled(self): | 56 def plugin_disabled(self): |
63 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin | 57 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin |
64 #such as closing windows created by the plugin | 58 #such as closing windows created by the plugin |
65 self.plugin_removecmd('/cherrypy') | 59 self.plugin_removecmd('/cherrypy') |
66 if self.isServerRunning == 'on': | 60 if self.isServerRunning == 'on': |
67 server.stop() | 61 server.stop() |
68 self.isServerRunning = 'off' | 62 self.isServerRunning = 'off' |
69 else: | 63 else: |
70 pass | 64 pass |
71 | 65 open_rpg.del_component("cherrypy") |
72 | 66 |
73 def on_cherrypy(self, cmdargs): | 67 def on_cherrypy(self, cmdargs): |
74 args = cmdargs.split(None,-1) | 68 args = cmdargs.split(None,-1) |
75 | 69 |
76 if len(args) == 0 or args[0] == 'status': | 70 if len(args) == 0 or args[0] == 'status': |
90 self.chat.InfoPost("CherryPy Web Server is now disabled") | 84 self.chat.InfoPost("CherryPy Web Server is now disabled") |
91 self.plugindb.SetString("xxcherrypy", "auto_start", "off") # VEG | 85 self.plugindb.SetString("xxcherrypy", "auto_start", "off") # VEG |
92 | 86 |
93 elif args[0] == 'port': | 87 elif args[0] == 'port': |
94 if self.isServerRunning == 'on': | 88 if self.isServerRunning == 'on': |
95 self.port = int(args[1]) | 89 self.chat.InfoPost('Please turn CherryPy off first!') |
96 server.stop() | 90 return |
97 self.webserver = thread.start_new_thread(self.startServer, (self.port,)) | |
98 self.port = int(args[1]) | 91 self.port = int(args[1]) |
92 self.plugindb.SetString("xxcherrypy", "port", str(self.port)) # TAS | |
99 self.chat.InfoPost("CherryPy Web Server is currently: " + self.isServerRunning) | 93 self.chat.InfoPost("CherryPy Web Server is currently: " + self.isServerRunning) |
100 self.chat.InfoPost("CherryPy Web Server address is: http://" + str(self.host) + ':' + str(self.port) + '/webfiles/') | 94 self.cherryhost = 'http://' + self.host + ':' + str(self.port) + '/webfiles/' |
101 | 95 open_rpg.del_component("cherrypy"); open_rpg.add_component("cherrypy", self.cherryhost) |
96 self.chat.InfoPost('CherryPy Web Server address is: ' + self.cherryhost) | |
102 | 97 |
103 | 98 |
104 def startServer(self, port): | 99 def startServer(self, port): |
105 try: | 100 try: |
106 if self.host == 0: | 101 if self.host == 0: |