def main(): print('Starting PfSense Parental Control App') print('Finding LAN devices') devices = find_devices() print('Finding Rule Overides') overrides = get_overrides() print('Finding blocked users') blocked = find_blocked(devices, overrides) print('Resolving IP addresses') blocked_ip = [[build_descr(b), devices.get(b['MAC'])] for b in blocked] print("Configuring Faux API") api = PfsenseFauxapi(PFSENSE_HOST, apikey, apisecret) api.proto = 'http' print("Requesting config") current_block_rules, default_rules = get_rules(api) current_block_ip = dict( (r['descr'], r['source']['address']) for r in current_block_rules) new_rules = build_new_rules(blocked_ip, current_block_ip) new_patch = create_filter_rule_patch(new_rules + default_rules) pprint.pprint(new_patch) print("patching") api.config_patch(new_patch) api.function_call({ 'function': 'filter_configure_sync', 'args': [False], 'includes': ['shaper.inc'], })
app = Flask(__name__) CORS(app) _, conf_file = sys.argv with open(conf_file, 'r') as infile: conf = json.load(infile) PFSENSE_HOST = conf['PFSENSE_HOST'] apikey = conf['FAUXAPI_APIKEY'] apisecret = conf['FAUXAPI_APISECRET'] api = PfsenseFauxapi(PFSENSE_HOST, apikey, apisecret) api.proto = 'http' # Serving the web site @app.route('/') def index(): return send_file(os.path.join('build', 'index.html')) @app.route('/<path:path>') def root_files(path): # send_static_file will guess the correct MIME type return send_file(os.path.join('build', path)) @app.route('/static/css/<path:path>') def css_files(path): # send_static_file will guess the correct MIME type return send_file(os.path.join('build', 'static', 'css', path))