# Path: lib/settings.py
# def get_top_domains(dbname):


from flask import Flask
from flask import request
from flask import abort
from flask import Response
from lib.logger import *
from lib.settings import homenet, lock, country_stats
import threading
import json
import lib.utils as utils
        if not request.json:
            abort(400)

        action = str(request.json['action'])
        target = request.json['target']
        if action == 'blacklist':
            utils.flush_ipset_list('blacklist-user')
            for ip in target:
                with lock:
                    if (len(ip) >= 7) and (ip not in homenet.user_blacklist) and (ip not in homenet.user_whitelist):
                        homenet.user_blacklist.append(ip)
                        utils.add_ip_ipset_blacklist(ip, 'blacklist-user')
                        log.debug('FG-INFO: IP ' + ip + 'added to user blacklist')

            resp = Response()
            resp.status_code = 200
            return resp
        elif action == 'unblock':
            for ip in target:
                with lock:
                    if (len(ip) >= 7) and (ip in homenet.user_blacklist):
                        utils.del_ip_ipset_blacklist(ip, 'blacklist-user')
            resp = Response()
            resp.status_code = 200
            return resp
        elif action == 'whitelist':
            for ip in target:
                if len(ip) >= 7:
                    utils.del_ip_ipset_blacklist(ip, 'blacklist')
                    utils.del_ip_ipset_blacklist(ip, 'blacklist-user')

# Path: lib/settings.py
# def get_top_domains(dbname):


# Path: api/api.py
from flask import Flask
from flask import request
from flask import abort
from flask import Response
from lib.logger import *
from lib.settings import homenet, lock, country_stats
import threading
import json
import lib.utils as utils

        if not request.json:
            abort(400)

        action = str(request.json['action'])
        target = request.json['target']
        if action == 'blacklist':
            utils.flush_ipset_list('blacklist-user')
            for ip in target:
                with lock:
                    if (len(ip) >= 7) and (ip not in homenet.user_blacklist) and (ip not in homenet.user_whitelist):
                        homenet.user_blacklist.append(ip)
                        utils.add_ip_ipset_blacklist(ip, 'blacklist-user')
                        log.debug('FG-INFO: IP ' + ip + 'added to user blacklist')

            resp = Response()
            resp.status_code = 200
            return resp
        elif action == 'unblock':
            for ip in target:
                with lock:
                    if (len(ip) >= 7) and (ip in homenet.user_blacklist):
                        utils.del_ip_ipset_blacklist(ip, 'blacklist-user')
            resp = Response()
            resp.status_code = 200
            return resp
        elif action == 'whitelist':
            for ip in target:
                if len(ip) >= 7:
                    utils.del_ip_ipset_blacklist(ip, 'blacklist')
                    utils.del_ip_ipset_blacklist(ip, 'blacklist-user')

                    with lock: