예제 #1
0
def _update_redis_backends(name, action):
    redis_backend_config = "{}/lib/redis_backends.json".format(get_homedir())
    with open(redis_backend_config, 'rt', encoding='utf-8') as f:
        config = json.loads(f.read())
    redis_backends = globals()['_update_config_{}'.format(action)](config, name)
    REDIS_BACKENDS = redis_backends
    config['redis_backends'] = redis_backends
    with open(redis_backend_config, 'wt', encoding='utf-8') as f:
        f.write(json.dumps(config, indent=2))
예제 #2
0
def _check_backends(names):
    redis_path = (get_homedir() / 'redis_backends')
    if names is None:
        redis_backends = os.listdir(redis_path)
        if len(redis_backends) == len(REDIS_BACKENDS) and sorted(redis_backends) == sorted(REDIS_BACKENDS):
            _check_backend(redis_backends, redis_path)
        else:
            _check_differences(redis_backends, redis_path)
    else:
        _check_backend(names, redis_path)
    sys.exit(0)
예제 #3
0
def _create_redis(names):
    if names is None:
        sys.exit('Please specify a name for the redis instance(s) you want to create.')
    potiron_path = get_homedir()
    for name in names:
        if name in REDIS_BACKENDS:
            print("{}: This redis backend already exists.".format(name))
            continue
        for to_read, to_write, permission in zip(_to_read_files, _to_write_files, _permissions):
            _create_file(potiron_path, to_read, to_write, name, permission)
        _update_redis_backends(name, 'creation')
        print("Successfully created {}".format(name))
예제 #4
0
def process_storage(red, files, ck, logconsole):
    potiron.logconsole = logconsole
    for key, value in red.hgetall('PARAMETERS').items():
        globals()[f"_{key.upper()}"] = value
    globals()['_RED'] = red
    if _FORMAT == 'standard':
        _check_ck(red, ck)
        globals()['_JSON_FIELDS'] = red.lrange("JSON_FIELDS", 0, -1)
        if ck == 'True':
            globals()['_PROTOCOLS'] = potiron.define_protocols(get_homedir() / "doc/protocols")
        globals()['_KEY_FUNCTION'] = globals()[_ck_mapping[str(ck)]]
    with ProcessPoolExecutor() as executor:
        for to_return in executor.map(_store_file, files):
            potiron.infomsg(to_return)
예제 #5
0
def process_storage(red, files, ck, logconsole):
    potiron.logconsole = logconsole
    for key, value in red.hgetall('PARAMETERS').items():
        globals()[f"_{key.upper()}"] = value
    globals()['_RED'] = red
    if _FORMAT == 'standard':
        _check_ck(red, ck)
        globals()['_JSON_FIELDS'] = red.lrange("JSON_FIELDS", 0, -1)
        if ck == 'True':
            globals()['_PROTOCOLS'] = potiron.define_protocols(get_homedir() /
                                                               "doc/protocols")
        globals()['_KEY_FUNCTION'] = globals()[_ck_mapping[str(ck)]]
    with ProcessPoolExecutor() as executor:
        for to_return in executor.map(_store_file, files):
            potiron.infomsg(to_return)
예제 #6
0
def standard_process(red, files, logconsole):
    potiron.logconsole = logconsole
    globals()["_FIELDS"] = red.lrange('FIELDS', 0, -1)
    globals()["_JSON_FIELDS"] = extract_json_fields(_FIELDS)
    for key, value in red.hgetall('PARAMETERS').items():
        globals()[f"_{key.upper()}"] = value
    if _ENABLE_JSON:
        globals()["_FIRST_PACKET"] = {feature[1:].lower(): globals()[feature] for feature in ("_FORMAT", "_TSHARK_FILTER", "_JSON_FIELDS")}
    if _CK:
        globals()["_PROTOCOLS"] = potiron.define_protocols(get_homedir() / "doc/protocols")
    globals()["_KEY_FUNCTION"] = globals()[_ck_mapping[_CK]]
    globals()["_RED"] = red
    with ProcessPoolExecutor() as executor:
        for to_return in executor.map(globals()[_to_process[_ENABLE_JSON]], files):
            potiron.infomsg(to_return)
예제 #7
0
def _delete_redis(names):
    if names is None:
        _deal_with_user_input('delete', 'existing')
        names = REDIS_BACKENDS
    for name in names:
        if name not in REDIS_BACKENDS:
            print("{}: This redis backend does not exist.".format(name))
            continue
        if check_running(name):
            shutdown_redis(name)
        redis_path = "{}/redis_backends/{}".format(get_homedir(), name)
        try:
            for filename in glob("{}/*".format(redis_path)):
                os.remove(filename)
            os.rmdir(redis_path)
            _update_redis_backends(name, 'deletion')
            print('Successfully deleted {}.'.format(name))
        except Exception:
            print('Can not delete {}, please check if the directory actually exists.'.format(name))
예제 #8
0
def shutdown_redis(redis_name, storage_directory: Path = None):
    if not storage_directory:
        storage_directory = (get_homedir() / 'redis_backends')
    s = Popen(["./shutdown_redis.sh"], cwd=(storage_directory / redis_name))
    s.wait()
예제 #9
0
def launch_redis(redis_name, storage_directory: Path = None):
    if not storage_directory:
        storage_directory = (get_homedir() / 'redis_backends')
    if not check_running(redis_name):
        Popen(["./run_redis.sh"], cwd=(storage_directory / redis_name))
예제 #10
0
            for f in json_fields:
                if (f in vfields) is False:
                    # Found a field that was not selected but is marked as being set
                    # in a previous iteration
                    if red.sismember("ENFIELDS", f):
                        red.srem("ENFIELDS", f)

        fields = load_selected_fields()
        return render_template('settings.html', fields=fields,
                               desc=create_program_meta(),
                               params=build_params())
    except redis.ConnectionError as err:
        errormsg("Cannot connect to redis. " + str(err))
        return render_template('offline.html', prefix=prefix)


if __name__ == '__main__':
    potiron_config = get_homedir() / 'var/www/potiron.cfg.json'
    with open(potiron_config, 'rt', encoding='utf-8') as f:
        config = json.loads(f.read())
    features = ('version', 'sensorname', 'interface', 'port', 'prefix',
                'debug', 'coverage', 'shortcoverage', 'unix_socket_path')
    for feature in features:
        if feature not in config:
            sys.exit("[ERROR] Config corrupted, %s missing." % feature)
    for key, value in config.items():
        globals()[key] = value
    unix_socket_path = str(get_homedir() / 'redis_backends' / unix_socket_path)
    red = redis.Redis(unix_socket_path=unix_socket_path, decode_responses=True)
    app.run()
예제 #11
0
                if (f in vfields) is False:
                    # Found a field that was not selected but is marked as being set
                    # in a previous iteration
                    if red.sismember("ENFIELDS", f):
                        red.srem("ENFIELDS", f)

        fields = load_selected_fields()
        return render_template('settings.html',
                               fields=fields,
                               desc=create_program_meta(),
                               params=build_params())
    except redis.ConnectionError as err:
        errormsg("Cannot connect to redis. " + str(err))
        return render_template('offline.html', prefix=prefix)


if __name__ == '__main__':
    potiron_config = get_homedir() / 'var/www/potiron.cfg.json'
    with open(potiron_config, 'rt', encoding='utf-8') as f:
        config = json.loads(f.read())
    features = ('version', 'sensorname', 'interface', 'port', 'prefix',
                'debug', 'coverage', 'shortcoverage', 'unix_socket_path')
    for feature in features:
        if feature not in config:
            sys.exit("[ERROR] Config corrupted, %s missing." % feature)
    for key, value in config.items():
        globals()[key] = value
    unix_socket_path = str(get_homedir() / 'redis_backends' / unix_socket_path)
    red = redis.Redis(unix_socket_path=unix_socket_path, decode_responses=True)
    app.run()
예제 #12
0
파일: run_redis.py 프로젝트: CIRCL/potiron
def shutdown_redis(redis_name, storage_directory: Path=None):
    if not storage_directory:
        storage_directory = (get_homedir() / 'redis_backends')
    s = Popen(["./shutdown_redis.sh"], cwd=(storage_directory / redis_name))
    s.wait()
예제 #13
0
파일: run_redis.py 프로젝트: CIRCL/potiron
def launch_redis(redis_name, storage_directory: Path=None):
    if not storage_directory:
        storage_directory = (get_homedir() / 'redis_backends')
    if not check_running(redis_name):
        Popen(["./run_redis.sh"], cwd=(storage_directory / redis_name))