本文整理汇总了Python中twisted.conch.manhole.ColoredManhole方法的典型用法代码示例。如果您正苦于以下问题:Python manhole.ColoredManhole方法的具体用法?Python manhole.ColoredManhole怎么用?Python manhole.ColoredManhole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.conch.manhole
的用法示例。
在下文中一共展示了manhole.ColoredManhole方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from twisted.conch import manhole [as 别名]
# 或者: from twisted.conch.manhole import ColoredManhole [as 别名]
def __call__(self):
return insults.ServerProtocol(manhole.ColoredManhole, self.namespace)
示例2: create_remote_factory
# 需要导入模块: from twisted.conch import manhole [as 别名]
# 或者: from twisted.conch.manhole import ColoredManhole [as 别名]
def create_remote_factory(namespace, users):
realm = manhole_ssh.TerminalRealm()
def create_remote_protocol(_):
return manhole.ColoredManhole(namespace)
realm.chainedProtocolFactory.protocolFactory = create_remote_protocol
p = portal.Portal(realm)
users = {key: value.encode() for key, value in users.items()}
p.registerChecker(
checkers.InMemoryUsernamePasswordDatabaseDontUse(**users))
f = manhole_ssh.ConchFactory(p)
ssh_key_base_path = path.join(config.config_dir, "ssh-keys")
ssh_pubkey_path = path.join(ssh_key_base_path,
"ssh_host_rsa_key.pub")
ssh_privkey_path = path.join(ssh_key_base_path,
"ssh_host_rsa_key")
try:
f.publicKeys[b"ssh-rsa"] = keys.Key.fromFile(ssh_pubkey_path)
f.privateKeys[b"ssh-rsa"] = keys.Key.fromFile(ssh_privkey_path)
except FileNotFoundError:
print("ERROR: You don't have any keys in the host key location")
print("Generate one with:")
print(" mkdir {}".format(ssh_key_base_path))
print(" ssh-keygen -f {} -t rsa".format(ssh_privkey_path))
print("make sure to specify no password")
sys.exit(1)
return f
示例3: makeService
# 需要导入模块: from twisted.conch import manhole [as 别名]
# 或者: from twisted.conch.manhole import ColoredManhole [as 别名]
def makeService(options):
"""Create a manhole server service.
@type options: C{dict}
@param options: A mapping describing the configuration of
the desired service. Recognized key/value pairs are::
"telnetPort": strports description of the address on which
to listen for telnet connections. If None,
no telnet service will be started.
"sshPort": strports description of the address on which to
listen for ssh connections. If None, no ssh
service will be started.
"namespace": dictionary containing desired initial locals
for manhole connections. If None, an empty
dictionary will be used.
"passwd": Name of a passwd(5)-format username/password file.
@rtype: L{twisted.application.service.IService}
@return: A manhole service.
"""
svc = service.MultiService()
namespace = options['namespace']
if namespace is None:
namespace = {}
checker = checkers.FilePasswordDB(options['passwd'])
if options['telnetPort']:
telnetRealm = _StupidRealm(telnet.TelnetBootstrapProtocol,
insults.ServerProtocol,
manhole.ColoredManhole,
namespace)
telnetPortal = portal.Portal(telnetRealm, [checker])
telnetFactory = protocol.ServerFactory()
telnetFactory.protocol = makeTelnetProtocol(telnetPortal)
telnetService = strports.service(options['telnetPort'],
telnetFactory)
telnetService.setServiceParent(svc)
if options['sshPort']:
sshRealm = manhole_ssh.TerminalRealm()
sshRealm.chainedProtocolFactory = chainedProtocolFactory(namespace)
sshPortal = portal.Portal(sshRealm, [checker])
sshFactory = manhole_ssh.ConchFactory(sshPortal)
sshService = strports.service(options['sshPort'],
sshFactory)
sshService.setServiceParent(svc)
return svc
示例4: makeService
# 需要导入模块: from twisted.conch import manhole [as 别名]
# 或者: from twisted.conch.manhole import ColoredManhole [as 别名]
def makeService(self, options):
try:
logger.info('Initializing configuration')
try:
self._init_config(options)
except Exception as e:
logger.error("Aborting service startup due to configuration error: {}".format(e))
raise e
logger.info('Initializing logging')
self._init_logging()
self._check_enabled()
#logger.enable_bootstrap_logging(self.tapname)
assert issubclass(self.service_cls, ApiService)
self.anchore_service = self.service_cls(options=options)
self.anchore_service.initialize(self.global_configuration)
# application object
application = service.Application("Service-" + '-'.join(self.anchore_service.name))
self.twistd_service = service.MultiService()
self.twistd_service.setServiceParent(application)
if self.anchore_service.task_handlers_enabled:
logger.info('Starting monitor thread')
lc = self._get_api_monitor(self.anchore_service)
lc.start(1)
else:
logger.warn('Skipped start of monitor threads due to task_handlers_enabled=false in config, or found ANCHORE_ENGINE_DISABLE_MONITORS in env')
thread_stats_interval = int(self.service_config.get('debug_thread_stats_dump_interval', 0))
if thread_stats_interval > 0:
logger.info('Based on service config, starting the thread stats dumper')
monitor = LoopingCall(dump_stats)
monitor.start(thread_stats_interval)
logger.info('Building api handlers')
s = self._build_api_service()
s.setServiceParent(self.twistd_service)
if enable_dangerous_debug_cli:
logger.warn('Loading *dangerous* debug/telnet service as specified by debug config')
self.makeDebugCLIService({'protocolFactory': ColoredManhole,
'protocolArgs': (None,),
'telnet': 6023,
}).setServiceParent(self.twistd_service)
return self.twistd_service
except Exception as err:
logger.exception("cannot create/init/register service: " + self.service_cls.__service_name__ + " - exception: " + str(err))
raise Exception("cannot start service (see above for information)")
finally:
pass
#logger.disable_bootstrap_logging()