Exemple #1
0
def json2config(data, sub_url=""):
    v2 = v2rayConfig(
        add=data['add'],
        aid=data['aid'],
        host=data['host'],
        id=data['id'],
        net=data['net'],
        path=data['path'],
        port=data['port'],
        ps=data['ps'],
        tls=data['tls'],
        type=data['type'],
        encrypt='auto',  # 默认为auto
        mux='off',  # 默认关闭
        status="off",  # 默认关闭
        sub=sub_url)
    return v2
Exemple #2
0
def generate_config():
    data = json.loads(request.get_data(as_text=True))
    print(data)
    # 修改部分
    saveConfig = v2rayConfig.query.filter(
        v2rayConfig.num == data['num']).first()
    print(saveConfig.num)
    if saveConfig is not None:
        saveConfig.id = data['uuid']
        saveConfig.add = data['addr']
        saveConfig.port = data['port']
        saveConfig.aid = data['alterId']
        saveConfig.encrypt = data['encrypt']
        saveConfig.type = data['fake']
        saveConfig.path = data['path']
        saveConfig.tls = data['tls']
        saveConfig.mux = data['mux']
        saveConfig.ps = data['remarks']
        saveConfig.net = data['trans']
        saveConfig.host = data['host']
        saveConfig.status = data['status']
    else:
        # 手动添加部分
        v2 = v2rayConfig(id=data['uuid'],
                         add=data['addr'],
                         port=data['port'],
                         aid=data['alterId'],
                         encrypt=data['encrypt'],
                         type=data['fake'],
                         path=data['path'],
                         tls=data['tls'],
                         mux=data['mux'],
                         status=data['status'],
                         ps=data['remarks'],
                         net=data['trans'],
                         host=data['host'])
        db.session.add(v2)
    db.session.commit()
    return set_message(200, url_for('index'))