from liberouterapi import auth, config from bson import json_util from bson.objectid import ObjectId from flask import request from datetime import datetime from time import mktime from liberouterapi.dbConnector import dbConnector nemea = dbConnector("nemea") nemea = nemea.db[config['nemea']['collection']] #@auth.required() def aggregate(): req = request.args.to_dict() match = { "$match" : { "$and" : [ { "DetectTime" : { "$gte" : datetime.utcfromtimestamp(int(req["begintime"])), "$lte" : datetime.utcfromtimestamp(int(req["endtime"])) }} ] } } tmp = list()
from liberouterapi import config from liberouterapi.dbConnector import dbConnector from liberouterapi.modules.module import Module # Load Alerts configuration file if Alerts section is not present in current config if 'alerts' not in config.config.sections(): config.load(path=__path__[0] + '/config.ini') conf_path = config['alerts'] # Alerts and filters collection set up alerts_conn = dbConnector('alerts', provider='mongodb', config={'database': config['alerts']['database']}) alerts_coll = alerts_conn.db[config['alerts']['collection']] filters_coll = alerts_conn.db[config['alerts']['collection2']] # Register a blueprint alerts_bp = Module('alerts', __name__, url_prefix='/alerts', no_version=True) from .fill_db import * from .alerts import * from .filters import * # Some testing functions to fill database with random alerts and delete all records in database # fill_db_with_n(1000000) # print(format_datetime("2019-11-28 14:34:33.373067")) # delete_data_from_db() # Get limited number of records for one page alerts_bp.add_url_rule('/alert-page', view_func=get_limited_number_of_records, methods=['GET']) # Set array of alerts status to confirmed alerts_bp.add_url_rule('/set-confirmed', view_func=set_confirmed, methods=['POST'])
# Own classes to connect and work with database from liberouterapi import db, auth, config from liberouterapi.dbConnector import dbConnector import random from random import getrandbits from ipaddress import IPv4Address from datetime import datetime, timedelta import uuid import sys # Connect and select alerts collection alerts_db = dbConnector("alerts") alerts_coll = alerts_db.db[config['alerts']['collection']] categories = [ "Attempt.Login", "Anomaly.Connection", "Recon.Scanning", "Availibility.DDoS", "Intrusion.Botnet" ] def delete_data_from_db(): x = alerts_coll.delete_many({}) print(x.deleted_count, " documents deleted.") def fill_db_with_n(n): gen = alert_data_generator() print("Inserting documents") i = 0 for y in range(100):
from liberouterapi import db, auth, config from liberouterapi.dbConnector import dbConnector import json from flask import request from .dashboards import * from .alert_data import * dashboard_db = dbConnector( 'dashboard', provider='mongodb', config={'database': config['dashboard']['database']}) dashboards_coll = dashboard_db.db[config['dashboard']['collectionDashboards']] data_coll = dashboard_db.db[config['dashboard']['collectionData']] @auth.required() def load_users_dashboard_list(): return get_all_dashboards(get_username_from_session(), dashboards_coll) @auth.required() def add_users_dashboard(): data = request.json name = data['dashboard'] return add_dashboard(get_username_from_session(), name, dashboards_coll) @auth.required() def get_grid(grid_name): return get_dashboard_data(get_username_from_session(), grid_name, dashboards_coll)
from liberouterapi import app, config from liberouterapi.dbConnector import dbConnector from liberouterapi.modules.module import Module # Load NEMEA configuration file if nemea section is not present in current config if "nemea" not in config.config.sections(): config.load(path = __path__[0] + '/config.ini') conf_path = config['nemea'] # We need collection for NEMEA Events and Dashboard to be set up nemea_conn = dbConnector("nemea", provider = "mongodb", config = { 'database' : config['nemea']['database'] }) nemea = nemea_conn.db[config['nemea']['collection']] # Register a blueprint nemea_bp = Module('nemea', __name__, url_prefix='/nemea', no_version=True) from .events import * from .Query import query from .Stats import aggregate, top, count from .Reporters import * from .Status import * from .supervisor.controllers import * # Create index for DetectTime nemea_bp.add_url_rule('/indexes', view_func=indexes, methods=['GET'])
import json from flask import request import logging from liberouterapi import auth, db from liberouterapi.dbConnector import dbConnector from liberouterapi.modules.module import Module from liberouterapi.user import User, UserException from liberouterapi.role import Role log = logging.getLogger(__name__) user_db = dbConnector() users = Module('users', __name__, url_prefix='/users', no_version=True) def user_exists(user): if db.get("users", "username", user.username): return True elif db.get("users", "email", user.email): return True return False @auth.required() def get_users(): res = list(db.getAll("users")) # Remove password hash from the resulting query for user in res:
import json from eventlet.timeout import Timeout from flask import request import logging from .sockets import * import os import yang from .schemas import get_schema from .devices import * from .data import * import pprint sessions = {} log = logging.getLogger(__name__) netconf_db = dbConnector('netconf', provider='mongodb', config={'database': config['netconf']['database']}) netconf_coll = netconf_db.db[config['netconf']['collection']] """ netconf session (ncs) static PyGetSetDef ncSessionGetSetters[] = { {"id", (getter)ncSessionGetId, NULL, "NETCONF Session id.", NULL}, {"host", (getter)ncSessionGetHost, NULL, "Host where the NETCONF Session is connected.", NULL}, {"port", (getter)ncSessionGetPort, NULL, "Port number where the NETCONF Session is connected.", NULL}, {"user", (getter)ncSessionGetUser, NULL, "Username of the user connected with the NETCONF Session.", NULL}, {"transport", (getter)ncSessionGetTransport, NULL, "Transport protocol used for the NETCONF Session.", NULL}, {"version", (getter)ncSessionGetVersion, NULL, "NETCONF Protocol version used for the NETCONF Session.", NULL}, {"capabilities", (getter)ncSessionGetCapabilities, NULL, "Capabilities of the NETCONF Session.", NULL}, {"context", (getter)ncSessionGetContext, NULL, "libyang context of the NETCONF Session.", NULL}, {NULL} /* Sentinel */ };
# Own classes to connect and work with database from liberouterapi import db, auth, config from liberouterapi.dbConnector import dbConnector # MongoDB data manipulation import json from flask import request # Connect and select filters collection filters_db = dbConnector('alerts') filters_coll = filters_db.db[config['alerts']['collection2']] @auth.required() def save_filter(): data = request.json name = data['name'] received_filter = data['filter'] session = auth.lookup(request.headers.get('lgui-Authorization', None)) user = session['user'].username filter_doc = {"name": name, "user": user, "filter": received_filter} try: if not received_filter: filters_coll.delete_one({'name': name, 'user': user}) return json.dumps({"success": True, "errCode": 200}) filters_coll.update_one({'name': name}, {'$set': filter_doc}, upsert=True)
# Own classes to connect and work with database from liberouterapi import db, auth, config from liberouterapi.dbConnector import dbConnector # Data manipulation import json from flask import request import re import dateutil.parser # Connect and select alerts collection alerts_db = dbConnector('alerts') alerts_coll = alerts_db.db[config['alerts']['collection']] @auth.required() def set_confirmed(): data = request.json ids = data['ids'] return set_status(ids, 0) @auth.required() def set_false_positive(): data = request.json ids = data['ids'] return set_status(ids, 1) def set_status(ids, status): try: