def _ssl_query(self, path, postdata=None, headers=None): t = time.time() if self.ssltimeout<>None and self.ssltimeout<t: self._ssl_close() if self.sslsocket==None: self._ssl_connect() if headers==None: headers=[] headers.append('Connection: Keep-Alive') rh,v = HTTPS.do_http_query(self.sslsocket, self.sslhost, path, postdata, headers=headers) closeit = True kaparams = {} for h in rh: if h=='Connection: Keep-Alive': closeit = False elif h.startswith('Keep-Alive:'): x,y = h.split(':',1) kaps = y.strip().split(',') for kaparam in kaps: x,y = kaparam.split('=',1) kaparams[x.strip()] = y.strip() if closeit: self._ssl_close() self.ssltimeout = None elif kaparams.get('timeout'): self.ssltimeout = t+float(kaparams['timeout']) return rh,v
def __call__(self, environ, start_response): request = webob.Request(environ) if request.path_info == '/HTTP': application = HTTP.Application() return application(environ, start_response) else: if request.path_info == '/HTTPS': application = HTTPS.Application() return application(environ, start_response) response = webob.Response(None, 200, None, None) return response(environ, start_response)
def _q(self, path, postdata=None): if self.config.get('digest')==None: raise Exception('you must provide an SSL certificate digest') headers,v = HTTPS.do_https_query( 'https://%s:%d/%s'%( self.config['host'], int(ifnull(self.config['port'],443)), path.lstrip('/') ), postdata, digest=self.config['digest'], digesttype=(self.config.get('digest.type') or 'sha1'), proxy=(self.config.get('proxy.host'),int(self.config.get('proxy.port') or 0)), proxytype=self.config.get('proxy.type'), ) return v
def thread_logic(): srv = HTTPS.Server(self.keys, self.channels, self.config, self.port) srv.run()
def main(): # Argument parsing parser = argparse.ArgumentParser() parser.add_argument('op', action="store", choices=[ 'server', 'channels', 'ls', 'download', 'sync', 'client', 'run' ], help="Operation") group = parser.add_argument_group('Common parameters') group.add_argument('--confdir', action="store", help="Customized configuration directory", default=utils.get_basedir_default()) group.add_argument('--debug', action="store_true", help="Enable debugging") group = parser.add_argument_group('Server') group.add_argument('--port', action="store", help="Customized HTTPS port (Default: 443)", type=int) group.add_argument('--key', action="store_true", help="Serve public key from /key") group = parser.add_argument_group('Client') group.add_argument('--downloads', action="store", help="Downloads directory", metavar="PATH", default=utils.get_downloads_default()) group.add_argument('--name', action="store", help="Name of the host to connect to") group.add_argument('--channels', action="store", help="Channels", metavar="NAMES") group.add_argument('--file', action="store", help="Filename") ns = parser.parse_args() if ns.debug: logging.basicConfig(level=logging.DEBUG) # Key manager keys = Keys.Manager(ns.confdir) # Config config = Config.Config(ns.confdir) # Channels channels = Channels.Manager(config) # Server if ns.op == 'server': srv = HTTPS.Server(keys, channels, config, ns.port, ns.key) srv.run() # Client elif ns.op == 'channels': utils.assert_cli_args(['name'], ns) lst = Client.ChannelList(config, keys, ns.name) channels = lst.execute() for channel in channels: print(channel) elif ns.op == 'ls': utils.assert_cli_args(['name', 'channels'], ns) lst = Client.FileList(config, keys, ns.name, ns.channels) files = lst.execute() for f in files: print("%s (%s) size=%s" % (f['path'], f['md5'], f['size'])) elif ns.op == 'download': time_start = time.time() def step_callback(downloaded): lapse = time.time() - time_start print "%s: %s (%s/s)%s\r" % (ns.file, utils.format_size( downloaded), utils.format_size(downloaded / lapse), ' ' * 10), utils.assert_cli_args(['name', 'channels', 'file'], ns) dwn = Client.Download(config, ns.downloads, keys, ns.name, ns.channels, ns.file, step_callback) dwn.execute() elif ns.op == 'sync': utils.assert_cli_args(['name'], ns) sync = Client.Sync(config, ns.downloads, keys, ns.name) sync.execute() elif ns.op == 'client': utils.assert_cli_args(['name'], ns) client = Client.Client(config, ns.downloads, keys, ns.name) client.execute() # Server + Client elif ns.op == 'run': client_server = Client.Client_Server(config, ns.downloads, keys, channels, ns.port, ns.key) client_server.execute()