Changeset 291
- Timestamp:
- 06/22/08 22:13:09 (7 months ago)
- Location:
- branches/0.5/daemon
- Files:
-
- 2 added
- 6 modified
-
orbited.cfg (added)
-
orbited/config.py (modified) (3 diffs)
-
orbited/control.py (added)
-
orbited/logger/log.py (modified) (3 diffs)
-
orbited/proxy.py (modified) (3 diffs)
-
orbited/start.py (modified) (3 diffs)
-
orbited/tcp.py (modified) (5 diffs)
-
setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.5/daemon/orbited/config.py
r290 r291 1 import os 2 import sys 3 1 4 map = { 2 5 '[global]': { 3 'http.port': '7000',4 'log.enabled': '0'5 6 }, 6 '[access]': [7 ('localhost', 9998), # Allow WebSocket test daemon8 ('irc.freenode.net', 6667), # Allow chat demo9 ('www.google.com', 80)10 ],11 12 7 '[logging]': { 13 8 'debug': 'SCREEN', … … 19 14 }, 20 15 '[loggers]': { 16 17 }, 18 'default_config': 1, # set to 0 later if we load a config file 19 '[listen]': [ 20 ], 21 '[access]': [ 22 ], 23 } 24 25 defaults = { 26 '[access]': [ 27 ('localhost', 9998), # Allow WebSocket test daemon 28 ('irc.freenode.net', 6667), # Allow chat demo 29 ('www.google.com', 80) # Telnet demo defaults 30 ], 31 '[listen]': [ 32 'http://:8000', 33 # 'https://:8043' 34 ], 35 # '[ssl]': { 36 # 'key': 'orbited.key', 37 # 'crt': 'orbited.crt' 38 # }, 39 '[loggers]': { 21 40 'WebSocket': 'debug,info,access,warn,error', 22 41 }, 23 'default_config': 1, # set to 0 later if we load a config file24 42 } 25 43 … … 28 46 return True 29 47 30 def load(filename):48 def setup(): 31 49 try: 32 f = open(filename) 33 lines = [line.strip() for line in f.readlines()] 34 map['default_config'] = 0 50 path = os.path.join('/', 'etc', 'orbited.cfg') 51 configfile = open(path, 'r') 52 print "using config file:", path 53 return load(configfile) 54 except: 55 pass 56 try: 57 path = os.path.join('/', 'Program Files', 'Orbited', 'etc', 'orbited.cfg') 58 configfile = open(path, 'r') 59 print "using config file:", path 60 return load(configfile) 61 except: 62 pass 63 try: 64 configfile = open('orbited.cfg', 'r') 65 print "using config file: ./orbited.cfg" 66 return load(configfile) 67 except: 68 pass 69 print "Could not locate configuration file. Using default configuration" 70 map.update(defaults) 35 71 36 except IOError: 37 print filename, 'could not be found. Using default configuration' 38 return False 39 # lines = default.split('\n') 40 72 def load(f): 73 lines = [line.strip() for line in f.readlines()] 74 map['default_config'] = 0 41 75 section = None 42 for line in lines: 43 44 # ignore comments 45 if '#' in line: 46 line, comment = line.split('#', 1) 47 if not line: 48 continue 49 50 # start of new section; create a dictionary for it in map if one 51 # doesn't already exist 52 if line.startswith('[') and line.endswith(']'): 53 section = line 54 if section not in map: 55 map[section] = {} 56 continue 57 58 # assign each source in the proxy section to a target address and port 59 if section == '[access]': 60 if ':' in target: 61 addr, port = target.split(':', 1) 62 port = int(port) 63 else: 64 addr, port = target, 80 65 map[section].append((addr, port)) 66 continue 67 68 # skip lines which do not assign a value to a key 69 if '=' not in line: 70 continue 71 72 key, value = [side.strip() for side in line.split('=', 1)] 73 74 # in log section, value should be a tuple of one or two values 75 if section == '[log]': 76 value = tuple([val.strip() for val in value.split(',', 1)]) 77 78 map[section][key] = value 79 76 try: 77 for (i, line) in enumerate(lines): 78 print i, line 79 # ignore comments 80 if '#' in line: 81 line, comment = line.split('#', 1) 82 if not line: 83 continue 84 85 # start of new section; create a dictionary for it in map if one 86 # doesn't already exist 87 if line.startswith('[') and line.endswith(']'): 88 section = line 89 if section not in map: 90 map[section] = {} 91 continue 92 93 # assign each source in the proxy section to a target address and port 94 if section == '[access]': 95 if ':' in line: 96 addr, port = line.split(':', 1) 97 port = int(port) 98 else: 99 addr, port = target, 80 100 map[section].append((addr, port)) 101 continue 102 if section == '[listen]': 103 map[section].append(line) 104 continue 105 106 # skip lines which do not assign a value to a key 107 if '=' not in line: 108 print "Configuration parse error on line", i 109 sys.exit(0) 110 111 key, value = [side.strip() for side in line.split('=', 1)] 112 113 # in log section, value should be a tuple of one or two values 114 if section == '[log]': 115 value = tuple([val.strip() for val in value.split(',', 1)]) 116 117 map[section][key] = value 118 except Exception, e: 119 print e 120 sys.exit(0) 80 121 return True 122 123 setup() -
branches/0.5/daemon/orbited/logger/log.py
r289 r291 39 39 self.overrides = overrides 40 40 self.loggers = {} 41 42 41 43 42 def create_logger(self, name): … … 147 146 exception, instance, tb = traceback.sys.exc_info() 148 147 output += "".join(traceback.format_tb(tb)) 148 self.debug(output) 149 149 if kwargs.get('stack', False): 150 150 output += "".join(traceback.format_stack()[:-1]) … … 155 155 class ScreenLog(object): 156 156 def __init__(self): 157 self.enabled = True 157 158 pass 158 159 159 160 def log(self, data): 160 sys.stdout.write(data) 161 161 if not self.enabled: 162 return 163 # Something weird was happening with the daemonization stuff 164 # that made this just break. 165 try: 166 sys.stdout.write(data) 167 except: 168 self.enabled = False 162 169 def open(self): 163 170 pass -
branches/0.5/daemon/orbited/proxy.py
r289 r291 5 5 from logger import get_logger 6 6 7 log = get_logger("TCPConnection")7 logger = get_logger("Proxy") 8 8 class ProxyProtocol(Protocol): 9 10 9 def send(self, msg): 11 # print "%s:%s (%s) -> %s" % ( self.host, self.port, len(msg), msg.replace('\r', '\\r').replace('\n', '\\n'))10 logger.debug("%s:%s (%s) -> %s" % ( self.host, self.port, len(msg), msg.replace('\r', '\\r').replace('\n', '\\n'))) 12 11 self.transport.write(msg) 13 12 14 13 def dataReceived(self, data): 14 logger.debug("%s:%s (%s) <- %s" % ( self.host, self.port, len(data), data.replace('\r', '\\r').replace('\n', '\\n\n'))) 15 15 self.proxy_conn.send(data) 16 16 … … 25 25 def connect(self, host, port): 26 26 d = defer.Deferred() 27 # print "opening remote connection to %s:%s" % (host, port)27 logger.debug("opening remote connection to %s:%s" % (host, port)) 28 28 self.c.connectTCP(host, port).addCallback(self.connected, d, host, port) 29 29 return d … … 59 59 self.port = int(port) 60 60 if (self.host, self.port) not in config['[access]']: 61 print 'unauthorized', data61 logger.warn('unauthorized', data) 62 62 raise (Exception("Unauthorized"), "(host, port) pair not authorized for proxying") 63 log .access(self.getClientIP(), "TCP/raw", " -> ", self.host, ":", self.port, " [ ", self.getClientIP(), " ]")63 logger.access(self.getClientIP(), "TCP/raw", " -> ", self.host, ":", self.port, " [ ", self.getClientIP(), " ]") 64 64 self.factory.client.connect(self.host, self.port).addCallback(self.connected_remote) 65 65 self.state = 'proxy' 66 66 except Exception, x: 67 logger.warn("Invalid handshake: " + str(x) + " (payload: %s)" % data) 67 68 self.send("Invalid handshake: " + str(x) + " (payload: %s)" % data) 68 69 self.loseConnection() -
branches/0.5/daemon/orbited/start.py
r289 r291 1 import urlparse 1 2 import sys 2 3 import os … … 16 17 from echo import EchoFactory 17 18 from proxy import SimpleProxyFactory 18 # from jsonproxy import JsonProxyFactory19 19 from binaryproxy import BinaryProxyFactory 20 20 from websocket import WebSocketFactory … … 23 23 root.putChild('binaryproxy', BinaryProxyFactory()) 24 24 root.putChild('websocket', WebSocketFactory()) 25 port = int(config['[global]']['http.port']) 26 logger.info('Listening HTTP@%s' % port) 27 reactor.listenTCP(port, site) 28 # Listen on SSL port 29 # reactor.listenSSL(8043, site, ssl.DefaultOpenSSLContextFactory("orbited.key", "orbited.crt")) 25 for addr in config['[listen]']: 26 url = urlparse.urlparse(addr) 27 hostname = url.hostname 28 if hostname == None: 29 hostname = '' 30 if url.scheme == 'http': 31 logger.info('Listening http@%s' % url.port) 32 reactor.listenTCP(url.port, site, interface=hostname) 33 elif url.scheme == 'https': 34 crt = config['[ssl]']['crt'] 35 key = config['[ssl]']['key'] 36 try: 37 ssl_context = ssl.DefaultOpenSSLContextFactory(key, crt) 38 except ImportError: 39 raise 40 except: 41 logger.error("Error opening key or crt file: %s, %s" % (key, crt)) 42 sys.exit(0) 43 logger.info('Listening https@%s (%s, %s)' % (url.port, key, crt)) 44 reactor.listenSSL(url.port, site, ssl_context) 45 else: 46 logger.error("Invalid Listen URI: %s" % addr) 47 sys.exit(0) 30 48 reactor.run() 31 49 -
branches/0.5/daemon/orbited/tcp.py
r290 r291 3 3 from twisted.web import server, resource, static, error 4 4 from twisted.internet import reactor, defer 5 from logger import get_logger 5 6 import transports 6 7 … … 10 11 11 12 class TCPConnection(resource.Resource): 13 logger = get_logger("TCPConnection") 12 14 ping_timeout = 20 13 15 ping_interval = 20 … … 132 134 133 135 def render(self, request): 134 # print '===' 135 # print request 136 print request 137 # print request 138 # print request 139 # print request 140 # print request 141 # print '===' 136 self.logger.debug(request) 142 137 transport_name = request.args.get('transport', [None])[0] 143 138 if transport_name: … … 204 199 class TCPConnectionFactory(resource.Resource): 205 200 protocol = TCPConnection 201 logger = get_logger("TCPConnectionFactory") 206 202 def __init__(self): 207 203 resource.Resource.__init__(self) … … 215 211 216 212 def render(self, request): 213 self.logger.debug(request) 217 214 id = self.create_session(request) 218 215 return id -
branches/0.5/daemon/setup.py
r213 r291 35 35 [console_scripts] 36 36 orbited = orbited.start:main 37 orbitedctl = orbited.control:main 37 38 ''', 38 39