from lisa.server.libs import RulesEngine, Commands from twisted.internet.protocol import Factory from twisted.protocols.basic import LineReceiver from twisted.internet import ssl from twisted.python import log from OpenSSL import SSL from lisa.server.libs.txscheduler.manager import ScheduledTaskManager from lisa.server.libs.txscheduler.service import ScheduledTaskService from lisa.server.plugins.PluginManager import PluginManagerSingleton import gettext from lisa.server.ConfigManager import ConfigManagerSingleton from lisa.server.web.manageplugins.models import Intent, Rule # Create a task manager to pass it to other services configuration = ConfigManagerSingleton.get().getConfiguration() dir_path = ConfigManagerSingleton.get().getPath() path = '/'.join([ConfigManagerSingleton.get().getPath(), 'lang']) _ = translation = gettext.translation(domain='lisa', localedir=path, fallback=True, languages=[configuration['lang']]).ugettext taskman = ScheduledTaskManager(configuration) scheduler = ScheduledTaskService(taskman) class ServerTLSContext(ssl.DefaultOpenSSLContextFactory): def __init__(self, *args, **kw): kw['sslmethod'] = SSL.TLSv1_METHOD ssl.DefaultOpenSSLContextFactory.__init__(self, *args, **kw)
# -*- coding: UTF-8 -*- import gettext from pymongo import MongoClient from twisted.python.reflect import namedAny from twisted.python import log from wit import Wit import json from lisa.server.ConfigManager import ConfigManagerSingleton configuration = ConfigManagerSingleton.get().getConfiguration() path = '/'.join([ConfigManagerSingleton.get().getPath(), 'lang']) _ = translation = gettext.translation(domain='lisa', localedir=path, fallback=True, languages=[configuration['lang'] ]).ugettext class RulesEngine(): def __init__(self): client = MongoClient(configuration['database']['server'], configuration['database']['port']) self.database = client.lisa self.wit = Wit(configuration['wit_server_token']) def Rules(self, jsonData, lisaprotocol): rulescollection = self.database.rules intentscollection = self.database.intents if "outcome" in jsonData.keys():
from twisted.python import log from twisted.internet.protocol import ReconnectingClientFactory from twisted.protocols.basic import LineReceiver from OpenSSL import SSL import os import json from twisted.internet import reactor, ssl from twisted.internet.protocol import Protocol import gettext from lisa.server.ConfigManager import ConfigManagerSingleton configuration = ConfigManagerSingleton.get().getConfiguration() path = ''.join([ConfigManagerSingleton.get().getPath(), '/lang/']) _ = translation = gettext.translation(domain='lisa', localedir=path, fallback=True, languages=[configuration['lang']]).ugettext class CtxFactory(ssl.ClientContextFactory): def __init__(self, dir_path): self.dir_path = dir_path def getContext(self): self.method = SSL.SSLv23_METHOD ctx = ssl.ClientContextFactory.getContext(self) ctx.use_certificate_file(os.path.normpath(self.dir_path + '/' + 'configuration/ssl/public/websocket.crt')) ctx.use_privatekey_file(os.path.normpath(self.dir_path + '/' + 'configuration/ssl/websocket.key')) return ctx class WebSocketProtocol(Protocol): def connectionMade(self):
def makeService(config): from django.core.handlers.wsgi import WSGIHandler os.environ['DJANGO_SETTINGS_MODULE'] = 'lisa.server.web.weblisa.settings' if config['configuration']: ConfigManagerSingleton.get().setConfiguration(config['configuration']) configuration = ConfigManagerSingleton.get().getConfiguration() dir_path = ConfigManagerSingleton.get().getPath() from lisa.server import libs # Creating MultiService multi = service.MultiService() pool = threadpool.ThreadPool() tps = ThreadPoolService(pool) tps.setServiceParent(multi) # Creating the web stuff resource_wsgi = wsgi.WSGIResource(reactor, tps.pool, WSGIHandler()) root = libs.Root(resource_wsgi) staticrsrc = static.File('/'.join([dir_path,'web/interface/static'])) root.putChild("static", staticrsrc) # Create the websocket if configuration['enable_secure_mode']: socketfactory = WebSocketServerFactory("wss://" + configuration['lisa_url'] + ":" + str(configuration['lisa_web_port_ssl']),debug=False) else: socketfactory = WebSocketServerFactory("ws://" + configuration['lisa_url'] + ":" + str(configuration['lisa_web_port']),debug=False) socketfactory.protocol = libs.WebSocketProtocol socketfactory.protocol.configuration, socketfactory.protocol.dir_path = configuration, dir_path socketresource = WebSocketResource(socketfactory) root.putChild("websocket", socketresource) # Configuring servers to launch if configuration['enable_secure_mode'] or configuration['enable_unsecure_mode']: if configuration['enable_secure_mode']: SSLContextFactoryEngine = ssl.DefaultOpenSSLContextFactory( os.path.normpath(dir_path + '/' + 'configuration/ssl/server.key'), os.path.normpath(dir_path + '/' + 'configuration/ssl/server.crt') ) SSLContextFactoryWeb = ssl.DefaultOpenSSLContextFactory( os.path.normpath(dir_path + '/' + 'configuration/ssl/server.key'), os.path.normpath(dir_path + '/' + 'configuration/ssl/server.crt') ) ctx = SSLContextFactoryEngine.getContext() ctx.set_verify( SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, libs.verifyCallback ) # Since we have self-signed certs we have to explicitly # tell the server to trust them. with open(os.path.normpath(dir_path + '/' + 'configuration/ssl/server.pem'), 'w') as outfile: for file in os.listdir(os.path.normpath(dir_path + '/' + 'configuration/ssl/public/')): with open(os.path.normpath(dir_path + '/' + 'configuration/ssl/public/'+file)) as infile: for line in infile: outfile.write(line) ctx.load_verify_locations(os.path.normpath(dir_path + '/' + 'configuration/ssl/server.pem')) internet.SSLServer(configuration['lisa_web_port_ssl'], server.Site(root), SSLContextFactoryWeb).setServiceParent(multi) internet.SSLServer(configuration['lisa_engine_port_ssl'], libs.LisaFactorySingleton.get(), SSLContextFactoryEngine).setServiceParent(multi) if configuration['enable_unsecure_mode']: # Serve it up: internet.TCPServer(configuration['lisa_web_port'], server.Site(root)).setServiceParent(multi) internet.TCPServer(configuration['lisa_engine_port'], libs.LisaFactorySingleton.get()).setServiceParent(multi) else: exit(1) libs.scheduler.setServiceParent(multi) multi.setServiceParent(application) libs.Initialize() return multi
def makeService(config): from django.core.handlers.wsgi import WSGIHandler os.environ['DJANGO_SETTINGS_MODULE'] = 'lisa.server.web.weblisa.settings' if config['configuration']: ConfigManagerSingleton.get().setConfiguration(config['configuration']) configuration = ConfigManagerSingleton.get().getConfiguration() dir_path = ConfigManagerSingleton.get().getPath() from lisa.server import libs # Creating MultiService multi = service.MultiService() pool = threadpool.ThreadPool() tps = ThreadPoolService(pool) tps.setServiceParent(multi) # Creating the web stuff resource_wsgi = wsgi.WSGIResource(reactor, tps.pool, WSGIHandler()) root = static.File('/'.join([dir_path, 'web/frontend/build'])) backendsrc = libs.Root(resource_wsgi) root.putChild("backend", backendsrc) staticrsrc = static.File('/'.join([dir_path, 'web/interface/static'])) root.putChild("static", staticrsrc) socketfactory = SockJSFactory(Factory.forProtocol(libs.WebSocketProtocol)) root.putChild("websocket", socketfactory) # Configuring servers to launch if configuration['enable_secure_mode'] or configuration[ 'enable_unsecure_mode']: if configuration['enable_secure_mode']: SSLContextFactoryEngine = ssl.DefaultOpenSSLContextFactory( os.path.normpath(dir_path + '/' + 'configuration/ssl/server.key'), os.path.normpath(dir_path + '/' + 'configuration/ssl/server.crt')) SSLContextFactoryWeb = ssl.DefaultOpenSSLContextFactory( os.path.normpath(dir_path + '/' + 'configuration/ssl/server.key'), os.path.normpath(dir_path + '/' + 'configuration/ssl/server.crt')) ctx = SSLContextFactoryEngine.getContext() ctx.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, libs.verifyCallback) # Since we have self-signed certs we have to explicitly # tell the server to trust them. with open( os.path.normpath(dir_path + '/' + 'configuration/ssl/server.pem'), 'w') as outfile: for file in os.listdir( os.path.normpath(dir_path + '/' + 'configuration/ssl/public/')): with open( os.path.normpath(dir_path + '/' + 'configuration/ssl/public/' + file)) as infile: for line in infile: outfile.write(line) ctx.load_verify_locations( os.path.normpath(dir_path + '/' + 'configuration/ssl/server.pem')) internet.SSLServer(configuration['lisa_web_port_ssl'], server.Site(root), SSLContextFactoryWeb).setServiceParent(multi) internet.SSLServer(configuration['lisa_engine_port_ssl'], libs.LisaFactorySingleton.get(), SSLContextFactoryEngine).setServiceParent(multi) if configuration['enable_unsecure_mode']: # Serve it up: internet.TCPServer(configuration['lisa_web_port'], server.Site(root)).setServiceParent(multi) internet.TCPServer( configuration['lisa_engine_port'], libs.LisaFactorySingleton.get()).setServiceParent(multi) configuration['enable_cloud_mode'] = True #if configuration['enable_cloud_mode']: # portforward.ProxyClient.dataReceived = client_dataReceived # portforward.ProxyServer.dataReceived = server_dataReceived # reactor.listenTCP(1080, portforward.ProxyFactory('localhost', 8000)) else: exit(1) libs.scheduler.setServiceParent(multi) multi.setServiceParent(application) libs.Initialize() return multi
# Django settings for blog project. import os import sys from lisa.server.ConfigManager import ConfigManagerSingleton DBNAME = 'lisa' configuration = ConfigManagerSingleton.get().getConfiguration() dir_path = ConfigManagerSingleton.get().getPath() APP_DIR = os.path.dirname(globals()['__file__']) PROJECT_PATH = os.path.abspath(os.path.dirname(__file__) + '/../') sys.path.append(PROJECT_PATH) DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( ('Julien Syx', '*****@*****.**'), ) MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.dummy', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. } } # Local time zone for this installation. Choices can be found here:
# Django settings for blog project. import os import sys from lisa.server.ConfigManager import ConfigManagerSingleton DBNAME = 'lisa' configuration = ConfigManagerSingleton.get().getConfiguration() dir_path = ConfigManagerSingleton.get().getPath() APP_DIR = os.path.dirname(globals()['__file__']) PROJECT_PATH = os.path.abspath(os.path.dirname(__file__) + '/../') sys.path.append(PROJECT_PATH) DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = (('Julien Syx', '*****@*****.**'), ) MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.dummy', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. } } # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems.
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t; python-indent: 4 -*- from pymongo import MongoClient from lisa.server.libs import LisaFactorySingleton from lisa.server.ConfigManager import ConfigManagerSingleton configuration = ConfigManagerSingleton.get().getConfiguration() class IPlugin(object): """ The most simple interface to be inherited when creating a plugin. """ def __init__(self): """ Set the basic variables. """ self.lisa = LisaFactorySingleton.get() self.configuration_lisa = configuration self.mongo = MongoClient(host=self.configuration_lisa['database']['server'], port=self.configuration_lisa['database']['port'])
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t; python-indent: 4 -*- from pymongo import MongoClient from lisa.server.libs import LisaFactorySingleton from lisa.server.ConfigManager import ConfigManagerSingleton configuration = ConfigManagerSingleton.get().getConfiguration() class IPlugin(object): """ The most simple interface to be inherited when creating a plugin. """ def __init__(self): """ Set the basic variables. """ self.lisa = LisaFactorySingleton.get() self.configuration_lisa = configuration self.mongo = MongoClient( host=self.configuration_lisa['database']['server'], port=self.configuration_lisa['database']['port'])