def _handleLaunchMissile(self): self.logger.info("Handling command 'launch-missile'") self.manager.sendLine(dedent(""" Error: {launched} """).format( launched=colorError("Another missile has already been launched!"))) return True
def _shouldSendToSubprocess(self, line): if match("\s*!enable-disarm", line): self.manager.sendLine(dedent(""" {failed} Please check the entered password.. """).format(failed=colorError("Failed to enable the disarm command!"))) return False return super(HelloBOFHandler, self)._shouldSendToSubprocess(line)
def _shouldSendToSubprocess(self, line): if match("\s*!unlock-console", line): self.manager.sendLine(dedent(""" {failed} Please check the entered password.. """).format(failed=colorError("Failed to unlock the console!"))) return False return super(PyJailHandler, self)._shouldSendToSubprocess(line)
def _shouldSendToSubprocess(self, line): if match("\s*!disarm-missile", line): self.manager.sendLine(dedent(""" {failed} Please check the entered ID and/or password.. """).format(failed=colorError("Failed to disarm missile!"))) return False return super(GoodBadHandler, self)._shouldSendToSubprocess(line)
def _shouldSendToSubprocess(self, line): if match("\s*!disarm-missile", line): self.manager.sendLine( dedent(""" {failed} Please check the entered ID and/or password.. """).format(failed=colorError("Failed to disarm missile!"))) return False return super(GoodBadHandler, self)._shouldSendToSubprocess(line)
def _shouldSendToSubprocess(self, line): if match("\s*!enable-disarm", line): self.manager.sendLine( dedent(""" {failed} Please check the entered password.. """).format( failed=colorError("Failed to enable the disarm command!"))) return False return super(HelloBOFHandler, self)._shouldSendToSubprocess(line)
class NLaunchReceiver(LineReceiver): WELCOME_MSG = dedent(""" ------------------------------------------------------------------------ {welcome}.. To get started on available commands run: '{helpCommand}' """).format(welcome=colorInfo( "Welcome to the (hidden) NSA missile launcher console"), helpCommand=colorToken("!help")) UNRECOGNIZED_CMD_MSG = dedent(""" {commandNotRecognized} The incident will be reported! """).format(commandNotRecognized=colorError("Command not recognized.")) GOODBYE_MSG = dedent(""" {goodbye} """).format(goodbye=colorInfo("Goodbye...")) delimiter = "\n".encode("utf8") def __init__(self, pwdFile): super(NLaunchReceiver, self).__init__() self.logger = getLogger("nlaunch.receiver") self.dal = DAL(pwdFile) self.manager = NLaunchManager(self) self.handler = InitialHandler(self.dal, self.manager) def connectionMade(self): self.logger.info("Made new connection with a client") self.manager.sendLine(self.WELCOME_MSG) def connectionLost(self, reason): self.logger.info("Lost connection with a client") self.manager.sendLine(self.GOODBYE_MSG) def lineReceived(self, line): line = line.decode("utf8").rstrip("\r") self.logger.info( "A new line has been received: '{line}'".format(line=line)) handled = self.handler.handle(line) if not handled: self.manager.sendLine(self.UNRECOGNIZED_CMD_MSG)