def create_server(ui, app): if ui.config('web', 'certificate'): if sys.version_info >= (2, 6): handler = _httprequesthandlerssl else: handler = _httprequesthandleropenssl else: handler = _httprequesthandler if ui.configbool('web', 'ipv6'): cls = IPv6HTTPServer else: cls = MercurialHTTPServer # ugly hack due to python issue5853 (for threaded use) import mimetypes; mimetypes.init() address = ui.config('web', 'address', '') port = util.getport(ui.config('web', 'port', 8000)) try: return cls(ui, app, (address, port), handler) except socket.error, inst: raise util.Abort(_("cannot start server at '%s:%d': %s") % (address, port, inst.args[1]))
def proxy(ui, serverurl, cachepath, **opts): """start stand-alone caching hgweb proxy Start a local HTTP server that acts as a caching proxy for a remote server SERVERURL. Fetched data will be stored locally in the directory CACHEPATH and reused for future requests for the same data. By default, the server logs accesses to stdout and errors to stderr. Use the -A/--accesslog and -E/--errorlog options to log to files. To have the server choose a free port number to listen on, specify a port number of 0; in this case, the server will print the port number it uses. See :hg:`hg help hgwebcachingproxy` for more details. Returns 0 on success. """ if opts.get('port'): opts['port'] = util.getport(opts.get('port')) optlist = ("address port prefix ipv6 accesslog errorlog certificate") for o in optlist.split(): val = opts.get(o, '') if val not in (None, ''): ui.setconfig("web", o, val) app = proxyserver(ui, serverurl, cachepath, opts.get('anonymous'), index=opts.get('index')) service = httpservice(ui, app, opts) service_fn(opts, initfn=service.init, runfn=service.run)
def debuggethostfingerprint(ui, repo, source='default'): """retrieve a fingerprint of the server certificate The server certificate is not verified. """ source = ui.expandpath(source) u = util.url(source) scheme = (u.scheme or '').split('+')[-1] host = u.host port = util.getport(u.port or scheme or '-1') if scheme != 'https' or not host or not (0 <= port <= 65535): raise util.Abort(_('unsupported URL: %s') % source) sock = socket.socket() try: sock.connect((host, port)) sock = sslutil.wrapsocket(sock, None, None, ui, serverhostname=host) peercert = sock.getpeercert(True) if not peercert: raise util.Abort(_('%s certificate error: no certificate received') % host) finally: sock.close() s = util.sha1(peercert).hexdigest() ui.write(':'.join([s[x:x + 2] for x in xrange(0, len(s), 2)]), '\n')
def __init__(self, repo, name=None, baseui=None): super(hgwebzc, self).__init__(repo, name=name, baseui=baseui) name = self.reponame or os.path.basename(self.repo.root) path = self.repo.ui.config("web", "prefix", "").strip('/') desc = self.repo.ui.config("web", "description", name) publish(name, desc, path, util.getport(self.repo.ui.config("web", "port", 8000)))
def __init__(self, conf, baseui=None): super(hgwebdirzc, self).__init__(conf, baseui=baseui) prefix = self.ui.config("web", "prefix", "").strip('/') + '/' for repo, path in self.repos: u = self.ui.copy() u.readconfig(os.path.join(path, '.hg', 'hgrc')) name = os.path.basename(repo) path = (prefix + repo).strip('/') desc = u.config('web', 'description', name) publish(name, desc, path, util.getport(u.config("web", "port", 8000)))
def create_server(ui, app): if ui.config('web', 'certificate'): if sys.version_info >= (2, 6): handler = _httprequesthandlerssl else: handler = _httprequesthandleropenssl else: handler = _httprequesthandler if ui.configbool('web', 'ipv6'): cls = IPv6HTTPServer else: cls = MercurialHTTPServer # ugly hack due to python issue5853 (for threaded use) try: import mimetypes mimetypes.init() except UnicodeDecodeError: # Python 2.x's mimetypes module attempts to decode strings # from Windows' ANSI APIs as ascii (fail), then re-encode them # as ascii (clown fail), because the default Python Unicode # codec is hardcoded as ascii. sys.argv # unwrap demand-loader so that reload() works reload(sys) # resurrect sys.setdefaultencoding() oldenc = sys.getdefaultencoding() sys.setdefaultencoding("latin1") # or any full 8-bit encoding mimetypes.init() sys.setdefaultencoding(oldenc) address = ui.config('web', 'address', '') port = util.getport(ui.config('web', 'port', 8000)) try: return cls(ui, app, (address, port), handler) except socket.error as inst: raise util.Abort( _("cannot start server at '%s:%d': %s") % (address, port, inst.args[1]))
def create_server(ui, app): if ui.config('web', 'certificate'): if sys.version_info >= (2, 6): handler = _httprequesthandlerssl else: handler = _httprequesthandleropenssl else: handler = _httprequesthandler if ui.configbool('web', 'ipv6'): cls = IPv6HTTPServer else: cls = MercurialHTTPServer # ugly hack due to python issue5853 (for threaded use) try: import mimetypes mimetypes.init() except UnicodeDecodeError: # Python 2.x's mimetypes module attempts to decode strings # from Windows' ANSI APIs as ascii (fail), then re-encode them # as ascii (clown fail), because the default Python Unicode # codec is hardcoded as ascii. sys.argv # unwrap demand-loader so that reload() works reload(sys) # resurrect sys.setdefaultencoding() oldenc = sys.getdefaultencoding() sys.setdefaultencoding("latin1") # or any full 8-bit encoding mimetypes.init() sys.setdefaultencoding(oldenc) address = ui.config('web', 'address', '') port = util.getport(ui.config('web', 'port', 8000)) try: return cls(ui, app, (address, port), handler) except socket.error as inst: raise error.Abort(_("cannot start server at '%s:%d': %s") % (address, port, inst.args[1]))