Пример #1
0
def javascript_exe_button(n_clicks, session_id):
    trigger = dash.callback_context.triggered[-1]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if not callback_utils.ensure_triggered(trigger):
        return no_update, no_update, no_update

    elif 'new-session' in trigger[
            'prop_id'] or session_utils.is_expired_session(
                session_id, cache, app.logger):
        cache = keydb.KeyDB(connection_pool=keydb_pool)
        new_session_id = session_utils.initiate_session(
            cache, app.logger, keydb_timeout)
        return "location.reload();", no_update, new_session_id

    else:
        app.logger.info('Fetching example data')
        try:
            session_utils.load_session('user_1', 46, session_id, cache,
                                       app.logger)
        except (psycopg2.OperationalError, AttributeError) as e:
            app.logger.error('Unable to fetch example data: {}'.format(e))
            return no_update, components.ExampleSessionConnectionErrorModal(
            ), no_update
        return "location.reload();", no_update, no_update
Пример #2
0
def manage_stored_sessions(delete_clicks, load_click, stop_share, load_share,
                           session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if session_utils.is_expired_session(session_id, cache, app.logger):
        return components.SessionTimedOutToast(), no_update, no_update
    elif not callback_utils.ensure_triggered(trigger):
        return no_update, no_update, no_update

    selected_session_pkid, action = callback_utils.get_session_action(trigger)
    username, current_session_pkid = session_utils.get_current_info(
        session_id, cache)

    if action == callback_utils.ButtonActions.delete:
        return session_utils.delete_session(selected_session_pkid,
                                            current_session_pkid, session_id,
                                            app.logger)
    elif action == callback_utils.ButtonActions.load:
        return session_utils.load_session(username, selected_session_pkid,
                                          session_id, cache, app.logger)
    elif action == callback_utils.ButtonActions.stop:
        return session_utils.stop_share_session(username,
                                                selected_session_pkid,
                                                current_session_pkid,
                                                session_id, app.logger)
Пример #3
0
def create_ConPlot(plot_click, refresh_click, factor, contact_marker_size,
                   track_marker_size, track_separation, track_selection,
                   cmap_selection, transparent, superimpose, distance_matrix,
                   verbose_labels, selected_palettes, session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if not callback_utils.ensure_triggered(trigger):
        return no_update, None, no_update, no_update
    elif session_utils.is_expired_session(session_id, cache, app.logger):
        return components.PlotPlaceHolder(), components.SessionTimedOutModal(
        ), components.DisplayControlCard(), True

    app.logger.info('Session {} plot requested'.format(session_id))

    if any([
            True for x in (factor, contact_marker_size, track_marker_size,
                           track_separation) if x is None or x < 0
    ]):
        app.logger.info(
            'Session {} invalid display control value detected'.format(
                session_id))
        return no_update, components.InvalidInputModal(), no_update, no_update
    elif superimpose and ('--- Empty ---' in cmap_selection
                          or len(set(cmap_selection)) == 1):
        return no_update, components.InvalidMapSelectionModal(
        ), no_update, no_update

    app.logger.info('Session {} creating conplot'.format(session_id))
    return plot_utils.create_ConPlot(
        session_id, cache, trigger, track_selection, cmap_selection,
        selected_palettes, factor, contact_marker_size, track_marker_size,
        track_separation, transparent, superimpose, distance_matrix,
        verbose_labels)
Пример #4
0
def serve_layout():
    try:
        cache = keydb.KeyDB(connection_pool=keydb_pool)
        cache.ping()
    except (keydb.ConnectionError, TypeError, KeyError) as e:
        app.logger.error('Redis connection error! {}'.format(e))
        return layouts.RedisConnectionError()
    session_id = session_utils.initiate_session(cache, app.logger,
                                                keydb_timeout)
    return layouts.Base(session_id)
Пример #5
0
def store_session(n_clicks, session_name, session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if session_utils.is_expired_session(session_id, cache, app.logger):
        return components.SessionTimedOutToast()
    elif not callback_utils.ensure_triggered(trigger):
        return no_update

    return session_utils.store_session(session_name, session_id, cache,
                                       app.logger)
Пример #6
0
def change_password(n_clicks, old_password, new_password, session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if session_utils.is_expired_session(session_id, cache, app.logger):
        return components.SessionTimedOutToast()
    elif not callback_utils.ensure_triggered(trigger):
        return no_update

    return app_utils.change_password(new_password, old_password, cache,
                                     session_id, app.logger)
Пример #7
0
def require_user_login(n_clicks, username, password, session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if session_utils.is_expired_session(session_id, cache, app.logger):
        return no_update, components.SessionTimedOutToast()
    elif not callback_utils.ensure_triggered(trigger):
        return no_update, no_update

    return app_utils.user_login(username, password, session_id, cache,
                                app.logger)[:-1]
Пример #8
0
def create_user(n_clicks, username, password, email, session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if session_utils.is_expired_session(session_id, cache, app.logger):
        return no_update, components.SessionTimedOutModal(
        ), no_update, no_update, no_update, no_update
    elif not callback_utils.ensure_triggered(trigger):
        return no_update, no_update, no_update, no_update, no_update, no_update

    return app_utils.create_user(username, password, email, session_id, cache,
                                 app.logger)
Пример #9
0
def remove_dataset(alerts_open, session_id):
    trigger = dash.callback_context.triggered[-1]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if not callback_utils.ensure_triggered(trigger):
        return None
    elif session_utils.is_expired_session(session_id, cache, app.logger):
        return components.SessionTimedOutModal()

    data_utils.remove_dataset(trigger, cache, session_id, app.logger)

    return None
Пример #10
0
def submit_contact_form(n_clicks, name, email, subject, description,
                        session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if session_utils.is_expired_session(session_id, cache, app.logger):
        return components.SessionTimedOutModal(), None, None, None, None
    elif not callback_utils.ensure_triggered(trigger):
        return no_update, no_update, no_update, no_update, no_update

    return callback_utils.submit_form(name, email, subject, description,
                                      app.logger), None, None, None, None
Пример #11
0
def display_page(url, session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if url is None:
        return no_update
    elif session_utils.is_expired_session(session_id, cache, app.logger):
        return layouts.SessionTimeout(session_id)
    elif not callback_utils.ensure_triggered(trigger):
        return no_update

    app.logger.info('Session {} requested url {}'.format(session_id, url))
    return app_utils.serve_url(url, session_id, cache, app.logger)
Пример #12
0
    def __init__(self, socketFile, dbfile):
        super(ControlThread, self).__init__()
        self.log = logging.getLogger('main')
        self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        self.db = keydb.KeyDB(dbfile)

        try:
            self.sock.bind(socketFile)
            self.sock.listen(1)
        except:
            self.sock.close()
            self.log.error('Socket ' + socketFile + ' in use')
            sys.exit(1)
Пример #13
0
def upload_additional_track(fname, fcontent, input_format, fname_alerts,
                            session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if session_utils.is_expired_session(session_id, cache, app.logger):
        return no_update, None, components.SessionTimedOutModal()
    elif not callback_utils.ensure_triggered(trigger):
        return callback_utils.retrieve_additional_fnames(session_id,
                                                         cache), None, None

    return data_utils.upload_dataset(fname, fcontent, input_format,
                                     fname_alerts, session_id, cache,
                                     app.logger)
Пример #14
0
def upload_sequence(fname, fcontent, session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if session_utils.is_expired_session(session_id, cache, app.logger):
        return no_update, None, components.SessionTimedOutModal()
    elif not callback_utils.ensure_triggered(trigger):
        return callback_utils.retrieve_sequence_fname(session_id,
                                                      cache), None, None
    elif not cache_utils.is_valid_fname(fname):
        return no_update, no_update, components.InvalidFnameModal(fname)

    return data_utils.upload_sequence(fname, fcontent, session_id, cache,
                                      app.logger)
Пример #15
0
def share_session(share_click, share_with, session_pkid, session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)
    session_pkid = session_pkid['index']

    if session_utils.is_expired_session(session_id, cache, app.logger):
        return components.SessionTimedOutToast()
    elif not callback_utils.ensure_triggered(trigger):
        return no_update

    username, current_session_pkid = session_utils.get_current_info(
        session_id, cache)
    if not share_with:
        return components.InvalidUsernameToast()
    elif username == share_with:
        return components.ShareWithOwnerToast()

    return session_utils.share_session(session_pkid, share_with, app.logger)
Пример #16
0
    def run(self):
        self.db = keydb.KeyDB(self.dbfile)

        while(True):
            self.log.debug('Server started, waiting for data...')
            command = self.ser.readCommand()
            self.log.debug('Data received')
            if (command == 0x01): # Key auth
                self.log.debug('Key auth cmd received')
                self.ser.timeout_en()

                cipher = hashlib.sha256()
                keyid = self.ser.readID()
                self.log.debug('Received id %d', keyid)

                challenge = random.read(32)
                self.ser.writeBytes(challenge)
                self.log.debug('Challenge sent')
                response = self.ser.readBytes(32)
                self.log.debug('Received response')

                key = self.db.getKey(keyid)

                if (key != None):
                    key_and_challenge = bytearray()
                    for i in range(0,32):
                        a = struct.unpack('B', key[i])[0]
                        b = struct.unpack('B', challenge[i])[0]
                        key_and_challenge.append( struct.pack('B', (a & b)) )

                    cipher.update(key_and_challenge)
                    key_hash = cipher.digest()

                    if (response == key_hash):
                        self.log.info('Key for id ' + keyid + ' accepted')
                        self.ser.openDoor()
                    else:
                        self.log.info('Key for id ' + keyid + ' rejected')

            elif (command == 0x02): # Door bell
                self.ser.relayDoorBell()

            cipher = None
            self.ser.timeout_dis()
Пример #17
0
def upload_contact(fname, fcontent, input_format, fname_alerts, session_id):
    trigger = dash.callback_context.triggered[0]
    cache = keydb.KeyDB(connection_pool=keydb_pool)

    if session_utils.is_expired_session(session_id, cache, app.logger):
        return no_update, None, components.SessionTimedOutModal()
    elif not callback_utils.ensure_triggered(trigger):
        return callback_utils.retrieve_contact_fnames(session_id,
                                                      cache), None, None
    elif not cache_utils.is_valid_fname(fname):
        return no_update, no_update, components.InvalidFnameModal(fname)

    return data_utils.upload_dataset(
        fname,
        fcontent,
        input_format,
        fname_alerts,
        session_id,
        cache,
        app.logger,
        dataset=loaders.DatasetReference.CONTACT_MAP.value)
Пример #18
0
 def setUpClass(cls):
     keydb_pool = keydb_utils.create_pool('redis://127.0.0.1:6379')
     cls.cache = keydb.KeyDB(connection_pool=keydb_pool)
     cls.session_id = session_utils.initiate_session(
         cls.cache, logging.getLogger())
Пример #19
0
 def test_2(self):
     cache = keydb.KeyDB(connection_pool=self.keydb_pool)
     cache.ping()