def init(loop, host='0.0.0.0', port=10000): from ircb.storeclient import initialize initialize() load_config() policy = auth.SessionTktAuthentication(settings.WEB_SALT, 60, include_ip=True) middlewares = [ session_middleware(EncryptedCookieStorage(settings.WEB_SALT)), auth.auth_middleware(policy) ] app = web.Application(middlewares=middlewares) app.router.add_route('GET', '/', index) app.router.add_route('*', '/api/v1/signup', SignupView, name='signup') app.router.add_route('*', '/api/v1/signin', SigninView, name='signin') app.router.add_route('*', '/api/v1/signout', SignoutView, name='signout') app.router.add_route('*', '/api/v1/networks', NetworkListView, name='networks') app.router.add_route('*', '/api/v1/network/{id}', NetworkView, name='network') app.router.add_route('PUT', '/api/v1/network/{id}/{action}', NetworkConnectionView, name='network_connection') srv = yield from loop.create_server( app.make_handler(logger=logger, access_log=logger), host, port) return srv
def init(loop, host='0.0.0.0', port=10000): from ircb.storeclient import initialize initialize() load_config() policy = auth.SessionTktAuthentication( settings.WEB_SALT, 60, include_ip=True) middlewares = [ session_middleware(EncryptedCookieStorage(settings.WEB_SALT)), auth.auth_middleware(policy) ] app = web.Application(middlewares=middlewares) app.router.add_route('GET', '/', index) app.router.add_route('*', '/api/v1/signup', SignupView, name='signup') app.router.add_route('*', '/api/v1/signin', SigninView, name='signin') app.router.add_route('*', '/api/v1/signout', SignoutView, name='signout') app.router.add_route('*', '/api/v1/networks', NetworkListView, name='networks') app.router.add_route('*', '/api/v1/network/{id}', NetworkView, name='network') app.router.add_route('PUT', '/api/v1/network/{id}/{action}', NetworkConnectionView, name='network_connection') srv = yield from loop.create_server( app.make_handler(logger=logger, access_log=logger), host, port) return srv
def __init__(self): this_directory = os.path.dirname(__file__) self.config = load_config( os.path.join(this_directory, '../config/config.yaml')) logger.info("Init CraftBeerPI") policy = auth.SessionTktAuthentication(urandom(32), 60, include_ip=True) middlewares = [ session_middleware(EncryptedCookieStorage(urandom(32))), auth.auth_middleware(policy) ] self.app = web.Application(middlewares=middlewares) self.initializer = [] setup(self.app, self) self.bus = EventBus(self.app.loop, self) self.ws = WebSocket(self) self.actor = ActorController(self) self.sensor = SensorController(self) self.plugin = PluginController(self) self.system = SystemController(self) self.config2 = ConfigController(self) self.kettle = KettleController(self) self.step = StepController(self) self.notification = NotificationController(self) self.login = Login(self) self.register_events(self.ws)
def __init__(self): self.path = os.sep.join(os.path.abspath(__file__).split( os.sep)[:-1]) # The path to the package dir self.version = __version__ self.static_config = load_config( os.path.join(".", 'config', "config.yaml")) self.database_file = os.path.join(".", 'config', "craftbeerpi.db") logger.info("Init CraftBeerPI") policy = auth.SessionTktAuthentication(urandom(32), 60, include_ip=True) middlewares = [ web.normalize_path_middleware(), session_middleware(EncryptedCookieStorage(urandom(32))), auth.auth_middleware(policy), error_middleware ] self.app = web.Application(middlewares=middlewares) self.app["cbpi"] = self self._setup_shutdownhook() self.initializer = [] self.bus = CBPiEventBus(self.app.loop, self) self.job = JobController(self) self.config = ConfigController(self) self.ws = CBPiWebSocket(self) self.actor = ActorController(self) self.sensor = SensorController(self) self.plugin = PluginController(self) self.log = LogController(self) self.system = SystemController(self) self.kettle = KettleController(self) self.step: StepController = StepController(self) self.recipe: RecipeController = RecipeController(self) self.notification: NotificationController = NotificationController( self) self.satellite = None if self.static_config.get("mqtt", False) is True: self.satellite: SatelliteController = SatelliteController(self) self.dashboard = DashboardController(self) self.http_step = StepHttpEndpoints(self) self.http_recipe = RecipeHttpEndpoints(self) self.http_sensor = SensorHttpEndpoints(self) self.http_config = ConfigHttpEndpoints(self) self.http_actor = ActorHttpEndpoints(self) self.http_kettle = KettleHttpEndpoints(self) self.http_dashboard = DashBoardHttpEndpoints(self) self.http_plugin = PluginHttpEndpoints(self) self.http_system = SystemHttpEndpoints(self) self.http_log = LogHttpEndpoints(self) self.http_notification = NotificationHttpEndpoints(self) self.login = Login(self)
async def test_middleware_setup(app): secret = b'01234567890abcdef' policy = auth.CookieTktAuthentication(secret, 15, cookie_name='auth') auth.setup(app, policy) middleware = auth.auth_middleware(policy) assert app.middlewares[-1].__name__ == middleware.__name__
def main(): loop = asyncio.get_event_loop() policy = auth.CookieTktAuthentication(os.urandom(32), 60000, include_ip=True) middlewares = [auth.auth_middleware(policy)] if os.environ['NODE_ENV'] == 'production': middlewares.append(index_middleware) app = aiohttp.web.Application(loop=loop, middlewares=middlewares) # print(loop.run_until_complete(db.users.find({}, {'_id': 1}))) # app['ws_clients'] = {r['_id']: None for r in loop.run_until_complete(db.users.find({}, {'_id': 1}))} app['admin_subscribed_bid'] = '' app.on_startup.append(prepare_ws_clients) app.on_shutdown.append(shutdown_websockets) app.router.add_get('/index/', indx) r1 = app.router.add_route('GET', '/test_auth/', test_auth) r2 = app.router.add_route('POST', '/login/', login) r3 = app.router.add_route('GET', '/ws', websocket_handler) app.router.add_get('/rest/bids/', bids) r4 = app.router.add_get('/rest/bid_report/', bid_report) r5 = app.router.add_get('/rest/sdd_report/', sdd_report) r6 = app.router.add_get('/rest/sdd_section_limits/', sdd_section_limits) r7 = app.router.add_post('/rest/upload_file/', upload_file) r8 = app.router.add_get('/rest/sleep/', sleep) if os.environ['NODE_ENV'] == 'production': app.router.add_route('GET', '/', index) app.router.add_static('/', '../client/dist') else: cors = aiohttp_cors.setup(app, defaults={ '*': aiohttp_cors.ResourceOptions( expose_headers='*', allow_headers='*', allow_credentials=True), }) cors.add(r1) cors.add(r2) cors.add(r3) cors.add(r4) cors.add(r5) cors.add(r6) cors.add(r7) cors.add(r8) aiohttp.web.run_app(app, host=HOST, port=PORT)
def __init__(self): self.version = "4.0.0.1" self.static_config = load_config("./config/config.yaml") self.database_file = "./craftbeerpi.db" logger.info("Init CraftBeerPI") policy = auth.SessionTktAuthentication(urandom(32), 60, include_ip=True) middlewares = [ web.normalize_path_middleware(), session_middleware(EncryptedCookieStorage(urandom(32))), auth.auth_middleware(policy), error_middleware ] self.app = web.Application(middlewares=middlewares) self.app["cbpi"] = self self._setup_shutdownhook() self.initializer = [] self.bus = CBPiEventBus(self.app.loop, self) self.job = JobController(self) self.config = ConfigController(self) self.ws = CBPiWebSocket(self) self.translation = TranslationController(self) self.actor = ActorController(self) self.sensor = SensorController(self) self.plugin = PluginController(self) self.log = LogController(self) self.system = SystemController(self) self.kettle = KettleController(self) self.step = StepController(self) self.dashboard = DashboardController(self) self.http_step = StepHttpEndpoints(self) self.http_sensor = SensorHttpEndpoints(self) self.http_config = ConfigHttpEndpoints(self) self.http_actor = ActorHttpEndpoints(self) self.http_kettle = KettleHttpEndpoints(self) self.http_dashboard = DashBoardHttpEndpoints(self) self.http_translation = TranslationHttpEndpoint(self) self.http_plugin = PluginHttpEndpoints(self) self.http_system = SystemHttpEndpoints(self) self.notification = NotificationController(self) self.http_log = LogHttpEndpoints(self) self.login = Login(self)
async def test_aiohttp_auth_middleware_setup(loop): app = web.Application(loop=loop) secret = b'01234567890abcdef' storage = aiohttp_session.SimpleCookieStorage() aiohttp_session.setup(app, storage) auth_policy = auth.SessionTktAuthentication(secret, 15, cookie_name='auth') class ACLAutzPolicy(acl.AbstractACLAutzPolicy): async def acl_groups(self, user_identity): return None # pragma: no cover autz_policy = ACLAutzPolicy() aiohttp_auth.setup(app, auth_policy, autz_policy) middleware = auth.auth_middleware(auth_policy) assert app.middlewares[-2].__name__ == middleware.__name__ middleware = autz.autz_middleware(autz_policy) assert app.middlewares[-1].__name__ == middleware.__name__
def init(): policy = auth.CookieTktAuthentication(urandom(32), 600, include_ip=True) middlewares = [auth.auth_middleware(policy)] app = web.Application(middlewares=middlewares) utils.connect_to_mysql() app.router.add_route('GET', '/', hello) app.router.add_route('POST', '/', createTable) app.router.add_route('GET', '/check', checkIfLoggedIn) app.router.add_route('POST', '/login', login) app.router.add_route('POST', '/logout', logout) # Players app.router.add_route('GET', '/allplayers', dbutils.get_players) app.router.add_route('POST', '/addplayer', dbutils.add_player) app.router.add_route('POST', '/stats/player', dbutils.update_player_stats) # Referee app.router.add_route('GET', '/stats/referees', dbutils.get_referees_stats) app.router.add_route('POST', '/addreferee', dbutils.add_referee) # Clubs app.router.add_route('GET', '/stats/clubs', dbutils.get_clubs_stats) app.router.add_route('GET', '/club/{club}', dbutils.get_single_club_info) app.router.add_route('POST', '/add/club', dbutils.add_new_club) # Matches app.router.add_route('GET', '/matches', dbutils.get_matches) app.router.add_route('POST', '/matches/add', dbutils.add_match) # League app.router.add_route('GET', '/league/{league}', dbutils.get_league_stats) # Stadiums app.router.add_route('GET', '/stadiums', dbutils.get_stadiums_stats) logging.info("Backend server started") web.run_app(app) logging.info("Closing connection")
auth.cookie_ticket_auth.CookieTktAuthentication.process_response = process_response import jinja2 from motor import motor_asyncio as motor import xlsxwriter import aiofiles from multidict import MultiDict import rest import settings as S auth_policy = auth.CookieTktAuthentication(os.urandom(32), 6000000, include_ip=True) auth_middleware = auth.auth_middleware(auth_policy) @aiohttp_jinja2.template('sign-up.html') async def ask_for_password(request): msg = '' if request.query.get('msg') == 'unequal-pwds': msg = 'пароль подтвержден неправильно!' return { 'id': request.query.get('id', ''), 'msg': msg, } @aiohttp_jinja2.template('login.html') async def login(request):
def __init__(self, configFolder): operationsystem= sys.platform if operationsystem.startswith('win'): set_event_loop_policy(WindowsSelectorEventLoopPolicy()) self.path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-1]) # The path to the package dir self.version = __version__ self.codename = __codename__ self.config_folder = configFolder self.static_config = load_config(configFolder.get_file_path("config.yaml")) logger.info("Init CraftBeerPI") policy = auth.SessionTktAuthentication(urandom(32), 60, include_ip=True) middlewares = [web.normalize_path_middleware(), session_middleware(EncryptedCookieStorage(urandom(32))), auth.auth_middleware(policy), error_middleware] # max upload size increased to 5 Mb. Default is 1 Mb -> config and svg upload self.app = web.Application(middlewares=middlewares, client_max_size=5*1024*1024) self.app["cbpi"] = self self._setup_shutdownhook() self.initializer = [] self.bus = CBPiEventBus(self.app.loop, self) self.job = JobController(self) self.config = ConfigController(self) self.ws = CBPiWebSocket(self) self.actor = ActorController(self) self.sensor = SensorController(self) self.plugin = PluginController(self) self.log = LogController(self) self.system = SystemController(self) self.kettle = KettleController(self) self.fermenter : FermentationController = FermentationController(self) self.step : StepController = StepController(self) self.recipe : RecipeController = RecipeController(self) self.fermenterrecipe : FermenterRecipeController = FermenterRecipeController(self) self.upload : UploadController = UploadController(self) self.notification : NotificationController = NotificationController(self) self.satellite = None if str(self.static_config.get("mqtt", False)).lower() == "true": self.satellite: SatelliteController = SatelliteController(self) self.dashboard = DashboardController(self) self.http_step = StepHttpEndpoints(self) self.http_recipe = RecipeHttpEndpoints(self) self.http_fermenterrecipe = FermenterRecipeHttpEndpoints(self) self.http_sensor = SensorHttpEndpoints(self) self.http_config = ConfigHttpEndpoints(self) self.http_actor = ActorHttpEndpoints(self) self.http_kettle = KettleHttpEndpoints(self) self.http_dashboard = DashBoardHttpEndpoints(self) self.http_plugin = PluginHttpEndpoints(self) self.http_system = SystemHttpEndpoints(self) self.http_log = LogHttpEndpoints(self) self.http_notification = NotificationHttpEndpoints(self) self.http_upload = UploadHttpEndpoints(self) self.http_fermenter = FermentationHttpEndpoints(self) self.login = Login(self)