def update_all_subscribe_api(): result = K.failed try: CoreService.update_all_subscribe() result = K.ok except: pass return jsonify({K.result: result})
def update_subscribe_api(): result = K.failed try: url = request.args.get(K.subscribe) CoreService.update_subscribe(url) result = K.ok except: pass return jsonify({K.result: result})
def add_manual_node_api(): result = K.failed try: url = request.args.get(K.url) CoreService.add_manual_node(url) result = K.ok except: pass return jsonify({K.result: result})
def make_policy_api(): contents: str = request.args.get(K.contents) content_list = contents.split('\n') type = request.args.get(K.type) outbound = request.args.get(K.outbound) policy = CoreService.make_policy(content_list, type, outbound) return Response(policy, mimetype='application/json')
def set_advance_config_api(): config = request.json code = K.failed result = CoreService.apply_advance_config(config) if result: code = K.ok return jsonify({K.result: code})
def switch_proxy_mode_api(): mode = request.args.get('mode') mode = int(mode) success = CoreService.switch_mode(mode) result = K.failed if success: result = K.ok return jsonify({K.result: result})
def apply_node_api(): url = request.args.get(K.subscribe) index = request.args.get(K.node_index) index = int(index) result = K.failed if CoreService.apply_node(url, index): result = K.ok return jsonify({K.result: result})
def get_performance_api(): performance = CoreService.performance() performance.update({K.result: K.ok}) return jsonify(performance)
def get_status_api(): status = CoreService.status() status.update({K.result: K.ok}) return jsonify(status)
def get_node_link_api(): url = request.args.get(K.subscribe) index = request.args.get(K.node_index) index = int(index) link = CoreService.node_link(url, index) return jsonify({K.result: K.ok, K.node_link: link})
def subscribe_list_api(): list = CoreService.node_manager.dump() status = CoreService.status() list.update(status) list.update({K.result: K.ok}) return jsonify(list)
#! /usr/bin/env python # -*- coding: utf-8 -*- import os from flask import Flask, render_template, jsonify, request from flask_basicauth import BasicAuth from core.keys import Keyword as K from core.core_service import CoreService CoreService.load() dir_path = os.path.dirname(os.path.realpath(__file__)) os.chdir(dir_path) app = Flask(__name__, static_url_path='/static') app.config['BASIC_AUTH_USERNAME'] = CoreService.app_config.user app.config['BASIC_AUTH_PASSWORD'] = CoreService.app_config.password app.config['BASIC_AUTH_FORCE'] = True app.config['TEMPLATES_AUTO_RELOAD'] = True app.jinja_env.auto_reload = True basic_auth = BasicAuth(app) @app.route('/') @app.route('/index.html') def index_page(): return render_template("index.html") @app.route('/status.html') def status_page(): return render_template("status.html")
def reset_advance_config_api(): code = K.failed result = CoreService.reset_advance_config() if result: code = K.ok return jsonify({K.result: code})
def restart_service_api(): result = K.failed if CoreService.re_apply_node(): result = K.ok return jsonify({K.result: result})
def stop_service_api(): result = K.failed if CoreService.stop_v2ray(): result = K.ok return jsonify({K.result: result})
def delete_node_api(): url = request.args.get(K.subscribe) index = request.args.get(K.node_index) index = int(index) CoreService.delete_node(url, index) return jsonify({K.result: K.ok})