コード例 #1
0
ファイル: hooks.py プロジェクト: AKJ/sage
	def run(self):
		for name, fn in self.functions.items():
			try:
				fn()
			except:
				core.error_handler("Hook %s failure. Unloading..." % name)
				self.remove(name)
コード例 #2
0
ファイル: telnetProxy.py プロジェクト: AKJ/sage
	def dataReceived(self, data):
		if len(data) == 0:
			return

		# Don't try to parse stuff that has telnet crap
		if self.IAC in data:
			try:
				self.client.transport.write(data)
			except AttributeError:
				pass
			return

		if self.NL in data:
			data = data.replace(self.CR, '')
			data = data.split(self.NL)[:-1]

			for item in data:
				try:
					output = input.outgoing_line_reciever(item)
				except Exception:
					core.error_handler('Untrapped Outbound Error')
					output = None

				try:
					if output != '' and output != None:
						self.client.transport.write(output + self.CR + self.NL)
					elif output == '' and output != None:
						self.client.transport.write(self.CR + self.NL)
				except AttributeError:
					pass

			if output != '' and output != None:
				core.last_output = output
コード例 #3
0
ファイル: aliases.py プロジェクト: AKJ/sage
	def function_dispatch(self, functions, line, time, backrefs = False):
		if type(functions) is not list:
			functions = [functions]

		for function in functions:
			#try:
				result = None
				embedded = False
				if ' ' in function:
					function = function.partition(' ')
					arg = function[2]
					function = function[0]
					embedded = True

					# TODO: make enable/disables for aliases
					#enable_trigger = False
					#enable_group = False
					#disable_trigger = False
					#disable_group = False

					if function == 'send':
						result = alias_dispatch[function](arg)

				try:
					if embedded is False:
						result = alias_dispatch[function](line, time, backrefs)
				except KeyError:
					exc = sys.exc_info()
					#print "Alias dispatch error for %s:\nType: %s\nTypeError: %s\nTraceback: %s" % (function, exc[0], exc[1], exc[2])
					core.error_handler('Alias dispatch error')

		return result
コード例 #4
0
ファイル: telnetProxy.py プロジェクト: AKJ/sage
	def applicationDataReceived(self, data):
		data = self.buffer + data
		self.buffer = ''

		if IAC+GA in data:
			data = data.split(IAC + GA)
			self.buffer = data[len(data) - 1]
			data = data[:-1]
		else:
			self.buffer = data
			return

		line_buffer = ''

		data = data[0].split('\n')

		prompt = data[len(data) - 1]

		for line in data[:-1]:
			line = line_buffer + line
			line_buffer = ''

			# We get unwanted newlines sometimes so lets ignore them if the packet is only a few lines
			if len(line) == 0 and len(data[:-1]) < 4:
				continue

			line = line.strip('\r')

			if len(line) == 7 and line[0:4] == self.color_prefix:
				line_buffer += line
				continue

			try:
				line = input.incoming_line_receiver(line)
			except Exception:
				core.error_handler('Untrapped Inbound Line Error')
				line = "%s[0m%s[1;37m%s[41m!!!%s[0m %s" % (chr(27), chr(27), chr(27), chr(27), line)

			if line is not None:
				if NL not in line:
					line = NL + line

				self.write_to_client(line)

		try:
			prompt = input.prompt_receiver(prompt.strip('\r'))
		except Exception:
			core.error_handler('Untrapped Prompt-Execution Error')
			prompt = "%s[0m%s[1;37m%s[41m!!!%s[0m %s" % (chr(27), chr(27), chr(27), chr(27), prompt)

		prompt = CR + NL + prompt + IAC + GA
		self.write_to_client(prompt)
コード例 #5
0
def init_app(mode='web') -> Flask:
    this_app = Flask(__name__)
    this_app.config.from_object(configs)
    this_app.env = configs.APP_ENV

    if mode == 'web':
        # configure the app to log to a file.
        configure_loggers(this_app)
        core.error_handler(this_app)
        core.cache.init_app(this_app, config=configs.CACHE_CONFIG)
        this_app.wsgi_app = core.Middleware(this_app.wsgi_app, this_app.debug)
        core.Router(this_app)

    db.init_app(this_app)
    this_app.mail = Mail(this_app).send

    return this_app