def main(): ''' Run the torweb server from command line arguments. ''' parser = argparse.ArgumentParser(prog="torweb") parser.add_argument("port", nargs='?', metavar="PORT", default=8082, type=int, help="Port to listen on. Default: 8082") parser.add_argument("--listen-address", metavar="IP", help=("USE CAREFULLY! Set the IP-Address " "on which torweb listens."), default='127.0.0.1') parser.add_argument("-t", "--tls", action="store_true", help="Use TLS encryption.") parser.add_argument("-c", "--config", default="None", help="Set the configuration file.") parser.add_argument("-k", "--private-key", default=None, help=("Path to the private key in PEM " "format for TLS encryption.")) parser.add_argument("-C", "--certificate", default=None, help=("Path to the public certificate in PEM " "format for TLS encryption.")) parser.add_argument( "-q", "--quiet", help="Don't log messages.", action="store_true") args = parser.parse_args() if not args.quiet: python.log.startLogging(sys.stdout) root_folder = data.get_path() if args.private_key is None: args.private_key = os.path.join(root_folder, 'key.pem') if args.certificate is None: args.certificate = os.path.join(root_folder, 'cert.pem') config = get_configuration() torweb_resource = TorwebResource(data.get_app_dir(), config.connections) site = server.Site(torweb_resource) if args.tls: try: from twisted.internet import ssl except ImportError as why: parser.error("Failed to import ssl: " + str(why)) if not os.path.isfile(args.private_key): parser.error("Key file {} doesn't exist".format(args.private_key)) if not os.path.isfile(args.certificate): parser.error( "Certificate file {} doesn't exist".format(args.certificate)) cert_data = "" with open(args.private_key) as cert_file: cert_data = cert_file.read() with open(args.certificate) as cert_file: cert_data += cert_file.read() certificate = ssl.PrivateCertificate.loadPEM(cert_data) reactor.listenSSL(args.port, site, certificate.options(), interface=args.listen_address) else: reactor.listenTCP(args.port, site, interface=args.listen_address) reactor.run()
def test_app_path(self): path = os.path.join(self.data_path, 'app') self.assertEqual(path, data.get_app_dir())