Ejemplo n.º 1
0
def update_all_subscribe_api():
    result = K.failed
    try:
        CoreService.update_all_subscribe()
        result = K.ok
    except:
        pass
    return jsonify({K.result: result})
Ejemplo n.º 2
0
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})
Ejemplo n.º 3
0
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})
Ejemplo n.º 4
0
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')
Ejemplo n.º 5
0
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})
Ejemplo n.º 6
0
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})
Ejemplo n.º 7
0
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})
Ejemplo n.º 8
0
def get_performance_api():
    performance = CoreService.performance()
    performance.update({K.result: K.ok})
    return jsonify(performance)
Ejemplo n.º 9
0
def get_status_api():
    status = CoreService.status()
    status.update({K.result: K.ok})
    return jsonify(status)
Ejemplo n.º 10
0
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})
Ejemplo n.º 11
0
def subscribe_list_api():
    list = CoreService.node_manager.dump()
    status = CoreService.status()
    list.update(status)
    list.update({K.result: K.ok})
    return jsonify(list)
Ejemplo n.º 12
0
#! /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")
Ejemplo n.º 13
0
def reset_advance_config_api():
    code = K.failed
    result = CoreService.reset_advance_config()
    if result:
        code = K.ok
    return jsonify({K.result: code})
Ejemplo n.º 14
0
def restart_service_api():
    result = K.failed
    if CoreService.re_apply_node():
        result = K.ok
    return jsonify({K.result: result})
Ejemplo n.º 15
0
def stop_service_api():
    result = K.failed
    if CoreService.stop_v2ray():
        result = K.ok
    return jsonify({K.result: result})
Ejemplo n.º 16
0
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})