1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-vps-admin.git synced 2025-03-09 15:40:05 +00:00

Add dsvpn support

This commit is contained in:
Ycarus 2019-08-02 15:22:43 +00:00
parent 172a026778
commit 295af2eef8

View file

@ -208,6 +208,14 @@ def config():
glorytun_udp_host_ip = '10.255.254.1' glorytun_udp_host_ip = '10.255.254.1'
glorytun_udp_client_ip = '10.255.254.2' glorytun_udp_client_ip = '10.255.254.2'
available_vpn = ["glorytun-tcp", "glorytun-udp"] available_vpn = ["glorytun-tcp", "glorytun-udp"]
if os.path.isfile('/etc/dsvpn/dsvpn.key'):
dsvpn_key = open('/etc/dsvpn/dsvpn.key').readline().rstrip()
available_vpn.append("dsvpn")
else:
dsvpn_key = ''
dsvpn_port = '65011'
dsvpn_tcp_host_ip = '10.255.251.1'
dsvpn_tcp_client_ip = '10.255.251.2'
if os.path.isfile('/etc/iperf3/public.pem'): if os.path.isfile('/etc/iperf3/public.pem'):
with open('/etc/iperf3/public.pem',"rb") as iperfkey_file: with open('/etc/iperf3/public.pem',"rb") as iperfkey_file:
@ -291,7 +299,7 @@ def config():
if '#DNAT net vpn:$OMR_ADDR tcp 1-64999' in line: if '#DNAT net vpn:$OMR_ADDR tcp 1-64999' in line:
shorewall_redirect = "disable" shorewall_redirect = "disable"
return jsonify({'vps': {'kernel': vps_kernel,'machine': vps_machine,'omr_version': vps_omr_version,'loadavg': vps_loadavg,'uptime': vps_uptime,'aes': vps_aes},'shadowsocks': {'key': shadowsocks_key,'port': shadowsocks_port,'method': shadowsocks_method,'fast_open': shadowsocks_fast_open,'reuse_port': shadowsocks_reuse_port,'no_delay': shadowsocks_no_delay,'mptcp': shadowsocks_mptcp,'ebpf': shadowsocks_ebpf,'obfs': shadowsocks_obfs,'obfs_plugin': shadowsocks_obfs_plugin,'obfs_type': shadowsocks_obfs_type},'glorytun': {'key': glorytun_key,'udp': {'host_ip': glorytun_udp_host_ip,'client_ip': glorytun_udp_client_ip},'tcp': {'host_ip': glorytun_tcp_host_ip,'client_ip': glorytun_tcp_client_ip},'port': glorytun_port,'chacha': glorytun_chacha},'openvpn': {'key': openvpn_key, 'host_ip': openvpn_host_ip, 'client_ip': openvpn_client_ip, 'port': openvpn_port},'mlvpn': {'key': mlvpn_key, 'host_ip': mlvpn_host_ip, 'client_ip': mlvpn_client_ip},'shorewall': {'redirect_ports': shorewall_redirect},'mptcp': {'enabled': mptcp_enabled,'checksum': mptcp_checksum,'path_manager': mptcp_path_manager,'scheduler': mptcp_scheduler, 'syn_retries': mptcp_syn_retries},'network': {'congestion_control': congestion_control,'ipv6_network': ipv6_network,'ipv6': ipv6_addr,'ipv4': ipv4_addr,'domain': vps_domain},'vpn': {'available': available_vpn,'current': vpn},'iperf': {'user': 'openmptcprouter','password': 'openmptcprouter', 'key': iperf3_key},'pihole': {'state': pihole}}), 200 return jsonify({'vps': {'kernel': vps_kernel,'machine': vps_machine,'omr_version': vps_omr_version,'loadavg': vps_loadavg,'uptime': vps_uptime,'aes': vps_aes},'shadowsocks': {'key': shadowsocks_key,'port': shadowsocks_port,'method': shadowsocks_method,'fast_open': shadowsocks_fast_open,'reuse_port': shadowsocks_reuse_port,'no_delay': shadowsocks_no_delay,'mptcp': shadowsocks_mptcp,'ebpf': shadowsocks_ebpf,'obfs': shadowsocks_obfs,'obfs_plugin': shadowsocks_obfs_plugin,'obfs_type': shadowsocks_obfs_type},'glorytun': {'key': glorytun_key,'udp': {'host_ip': glorytun_udp_host_ip,'client_ip': glorytun_udp_client_ip},'tcp': {'host_ip': glorytun_tcp_host_ip,'client_ip': glorytun_tcp_client_ip},'port': glorytun_port,'chacha': glorytun_chacha},'dsvpn': {'key': dsvpn_key, 'host_ip': dsvpn_host_ip, 'client_ip': dsvpn_client_ip, 'port': dsvpn_port},'openvpn': {'key': openvpn_key, 'host_ip': openvpn_host_ip, 'client_ip': openvpn_client_ip, 'port': openvpn_port},'mlvpn': {'key': mlvpn_key, 'host_ip': mlvpn_host_ip, 'client_ip': mlvpn_client_ip},'shorewall': {'redirect_ports': shorewall_redirect},'mptcp': {'enabled': mptcp_enabled,'checksum': mptcp_checksum,'path_manager': mptcp_path_manager,'scheduler': mptcp_scheduler, 'syn_retries': mptcp_syn_retries},'network': {'congestion_control': congestion_control,'ipv6_network': ipv6_network,'ipv6': ipv6_addr,'ipv4': ipv4_addr,'domain': vps_domain},'vpn': {'available': available_vpn,'current': vpn},'iperf': {'user': 'openmptcprouter','password': 'openmptcprouter', 'key': iperf3_key},'pihole': {'state': pihole}}), 200
# Set shadowsocks config # Set shadowsocks config
@app.route('/shadowsocks', methods=['POST']) @app.route('/shadowsocks', methods=['POST'])
@ -478,6 +486,24 @@ def glorytun():
shorewall_port(str(port),'tcp','glorytun') shorewall_port(str(port),'tcp','glorytun')
return jsonify({'result': 'done'}) return jsonify({'result': 'done'})
# Set A Dead Simple VPN config
@app.route('/dsvpn', methods=['POST'])
@jwt_required
def dsvpn():
params = request.get_json()
key = params.get('key', None)
port = params.get('port', None)
if not key or port is None:
return jsonify({'result': 'error','reason': 'Invalid parameters','route': 'dsvpn'})
initial_md5 = hashlib.md5(file_as_bytes(open('/etc/dsvpn/dsvpn.key', 'rb'))).hexdigest()
with open('/etc/dsvpn/dsvpn.key','w') as outfile:
outfile.write(key)
final_md5 = hashlib.md5(file_as_bytes(open('/etc/dsvpn/dsvpn.key', 'rb'))).hexdigest()
if not initial_md5 == final_md5:
os.system("systemctl -q restart dsvpn-server")
shorewall_port(str(port),'tcp','dsvpn')
return jsonify({'result': 'done'})
# Set OpenVPN config # Set OpenVPN config
@app.route('/openvpn', methods=['POST']) @app.route('/openvpn', methods=['POST'])
@jwt_required @jwt_required