def add_inbound(): port = int(request.form['port']) print("进来了") if Inbound.query.filter_by(port=port).count() > 0: return jsonify(Msg(False, gettext('port exists'))) listen = request.form['listen'] protocol = request.form['protocol'] settings = request.form['settings'] email = random_email() remail = '"email":"' + email + '",' str_list = list(settings) str_list.insert(13, remail) # 插入堆积 newsettings = ''.join(str_list) stream_settings = request.form['stream_settings'] sniffing = request.form['sniffing'] remark = request.form['remark'] # 当前用户等级 user_level = request.form['level'] # 是否更新所有服务器 allvps = request.form['allvps'] inbound = Inbound(port, listen, protocol, newsettings, stream_settings, sniffing, remark, user_level) local_ip = get_ip() if allvps == 'true': print("更新所有vps") devices = mysqlsesson.query(VpsDevice).filter(VpsDevice.level <= int(user_level), VpsDevice.status == 1).all() inbound.allvps = 'false' for device in devices: if local_ip != device.ip: try: inbound.remark = device.country_code requests.post("http://" + device.ip + ":"+str(config.get_port())+"/v2ray/inbound/add", inbound.to_json_vps(), timeout=13) except: print("Failed http") mysqlsesson.add(FailedNodeJob(local_ip,device.ip,"http://" + device.ip + ":"+str(config.get_port())+"/v2ray/inbound/add", str(inbound.to_json_vps()))) # requests.post("http://127.0.0.1:5000/v2ray/inbound/add", inbound.to_json_vps(), timeout=3) # 插入mysql 用户表,生成订阅 userSubscribe = UserSubscribe(base64.b64encode(email.encode('utf-8')), port, user_level, 1) mysqlsesson.add(userSubscribe) db.session.add(inbound) # 插入mysql inbound #查询自己服务器重新赋值 device = mysqlsesson.query(VpsDevice).filter(VpsDevice.server==local_ip).first() inboundMysql = InboundMysql(local_ip, port, listen, protocol, newsettings, stream_settings, sniffing, device.country_code) mysqlsesson.add(inboundMysql) # 插入mysql 节点表 Node = VpsNode(protocol, local_ip, json.loads(settings)['clients'][0]['id'], json.loads(settings)['clients'][0]['alterId'], port, json.loads(stream_settings)['wsSettings']['path'], device.country_code, json.loads(stream_settings)['network']) mysqlsesson.add(Node) mysqlsesson.commit() db.session.commit() return jsonify( Msg(True, gettext(u'Successfully added, will take effect within %(seconds)d seconds', seconds=__check_interval) ) )
def update_inbound(in_id): update = {} port = request.form.get('port') add_if_not_none(update, 'port', port) if port: if Inbound.query.filter(Inbound.port == port).count() > 1: return jsonify(Msg(False, gettext('port exists'))) add_if_not_none(update, 'tag', 'inbound-' + port) add_if_not_none(update, 'listen', request.form.get('listen')) add_if_not_none(update, 'protocol', request.form.get('protocol')) add_if_not_none(update, 'settings', request.form.get('settings')) add_if_not_none(update, 'stream_settings', request.form.get('stream_settings')) add_if_not_none(update, 'sniffing', request.form.get('sniffing')) add_if_not_none(update, 'remark', request.form.get('remark')) add_if_not_none(update, 'enable', request.form.get('enable') == 'true') add_if_not_none(update, 'level', request.form.get('level')) listen = request.form['listen'] protocol = request.form['protocol'] settings = request.form['settings'] email = random_email() remail = '"email":"' + email + '",' str_list = list(settings) str_list.insert(13, remail) # 插入堆积 newsettings = ''.join(str_list) stream_settings = request.form['stream_settings'] sniffing = request.form['sniffing'] remark = request.form['remark'] # 当前用户等级 user_level = request.form['level'] # 是否更新所有服务器 allvps = request.form['allvps'] local_ip = get_ip() if allvps == "true": inbound = Inbound(int(port), listen, protocol, newsettings, stream_settings, sniffing, remark, user_level) inbound.allvps = 'false' devices = mysqlsesson.query(VpsDevice).filter(VpsDevice.level <= int(user_level), VpsDevice.status == 1).all() for device in devices: if local_ip != device.ip: requests.post("http://" + device.ip + ":"+str(config.get_port())+"/v2ray/inbound/update/" + str(in_id), inbound.to_json_vps(), timeout=3) # requests.post("http://127.0.0.1:5000/v2ray/inbound/add", inbound.to_json_vps(), timeout=3) print("vps更新") Inbound.query.filter_by(port=in_id).update(update) db.session.commit() return jsonify( Msg(True, gettext(u'Successfully updated, will take effect within %(seconds)d seconds', seconds=__check_interval) ) )
def add_inbound(): user_id = int(request.form["user_id"]) port = int(request.form["port"]) listen = request.form["listen"] protocol = request.form["protocol"] if (Inbound.query.filter_by(port=port).count() > 0 and Inbound.query.filter_by(port=port, protocol=protocol).count() == 0): return jsonify(Msg(False, gettext("Port exists."))) settings = request.form["settings"] stream_settings = request.form["stream_settings"] sniffing = request.form["sniffing"] remark = request.form["remark"] enable = request.form["enable"] == "true" inbound = Inbound( user_id, port, listen, protocol, settings, stream_settings, sniffing, remark, enable, ) db.session.add(inbound) db.session.commit() return jsonify( Msg( True, gettext( u"Successfully added, will take effect within %(seconds)d seconds.", seconds=__check_interval, ), ))
def add_inbound(): port = int(request.form['port']) if Inbound.query.filter_by(port=port).count() > 0: return jsonify(Msg(False, '端口已存在')) listen = request.form['listen'] protocol = request.form['protocol'] settings = request.form['settings'] stream_settings = request.form['stream_settings'] remark = request.form['remark'] inbound = Inbound(port, listen, protocol, settings, stream_settings, remark) db.session.add(inbound) db.session.commit() return jsonify(Msg(True, '添加成功,将在 %d 秒内自动生效' % __check_interval))
def add_inbound(): port = int(request.form['port']) if Inbound.query.filter_by(port=port).count() > 0: return jsonify(Msg(False, gettext('port exists'))) listen = request.form['listen'] protocol = request.form['protocol'] settings = request.form['settings'] stream_settings = request.form['stream_settings'] sniffing = request.form['sniffing'] remark = request.form['remark'] inbound = Inbound(port, listen, protocol, settings, stream_settings, sniffing, remark) # add the host host_setting = Setting.query.filter_by(key='host').first() host = host_setting.value inbound.host = host db.session.add(inbound) db.session.commit() return jsonify( Msg( True, gettext( u'Successfully added, will take effect within %(seconds)d seconds', seconds=__check_interval)))
def add_inbound(): port = int(request.form['port']) user = session_util.get_user() if Inbound.query.filter_by(port=port).count() > 0: return jsonify(Msg(False, gettext('port exists'))) listen = request.form['listen'] protocol = request.form['protocol'] settings = request.form['settings'] stream_settings = request.form['stream_settings'] sniffing = request.form['sniffing'] remark = request.form['remark'] inbound = Inbound(user['id'], port, listen, protocol, settings, stream_settings, sniffing, remark) db.session.add(inbound) db.session.commit() return jsonify( Msg(True, gettext(u'Successfully added, will take effect within %(seconds)d seconds', seconds=__check_interval) ) )