def _check_memory(self, num_running_commands): rss = mem_clean('periodic memory clean') if not num_running_commands and rss > _CHECK_RAM_MAX_RSS_MB: log.critical("Max allowed RSS memory exceeded: %s MB, exiting." % _CHECK_RAM_MAX_RSS_MB) reactor.stop() del rss
def _processCommand(self, message): log.debug('Process Command') if self.public_key: if not self._verify_message(message): log.critical('[RSA CHECK: Failed] Command from %s has bad signature (Ignored)' % message.from_) result = (_E_UNVERIFIED_COMMAND, '', 'Bad signature', 0) self._onCallFinished(result, message) return else: # No public key, RSA functions are not available on this system log.warn('[RSA CHECK: No available] WARNING: Running unverified Command from %s' % message.from_) flush_callback = self._Flush message.command_replaced = message.command.replace('.', '_') d = self.command_runner.run_command(message.command_replaced, message.command_args, flush_callback, message) if d: d.addCallbacks(self._onCallFinished, self._onCallFailed, callbackKeywords={'message': message}, errbackKeywords={'message': message}, ) return d else: log.info("Command Ignored: Unknown command: %s" % message.command) result = (_E_RUNNING_COMMAND, '', "Unknown command: %s" % message.command, 0) self._onCallFinished(result, message) return
def _check_memory(self, running_commands): rss, vms = mem_usage() log.info("Running commands: %i" % running_commands) log.info("Current Memory usage: rss=%sMB | vms=%sMB" % (rss, vms)) if not running_commands and rss > _CHECK_RAM_MAX_RSS_MB: log.critical("Max allowed RSS memory exceeded: %s MB, exiting." % _CHECK_RAM_MAX_RSS_MB) reactor.stop()
def signature(self, message): if self.public_key: if not self._verify_message(message): log.critical('[RSA CHECK: Failed] Command from %s has bad signature (Ignored)' % message.from_) del message return False del message return True
def _read_pub_key(self): log.debug('Reading public certificate') public_key = None try: cert_file = os.path.join(os.path.dirname(__file__), _CERTIFICATE_FILE) if os.path.isfile(cert_file): f = open(cert_file, 'r') public_key = f.read() f.close() except: log.critical("Unable to read certificate file") return public_key
def _on_config_failed(self, failure): log.critical("Configuration check failed with: %s, exiting." % failure) log.critical("Please try configuring the XMPP subsystem manually.") reactor.stop()