mirror of
https://github.com/mynodebtc/mynode.git
synced 2024-12-24 13:38:11 +00:00
More VPN enhancements
This commit is contained in:
parent
9d29e73de3
commit
93272c162d
|
@ -498,7 +498,7 @@ confOpenVPN() {
|
|||
# "384" "Use a 384-bit certificate" OFF \
|
||||
# "521" "Use a 521-bit certificate (paranoid level)" OFF 3>&1 1>&2 2>&3)
|
||||
#fi
|
||||
ENCRYPT="1024"
|
||||
ENCRYPT="2048"
|
||||
|
||||
#exitstatus=$?
|
||||
#if [ $exitstatus != 0 ]; then
|
||||
|
|
|
@ -3,6 +3,7 @@ from config import *
|
|||
from flask import Flask, render_template, Markup, send_from_directory, redirect, request, url_for
|
||||
from bitcoind import mynode_bitcoind
|
||||
from bitcoin_cli import mynode_bitcoin_cli
|
||||
from vpn import mynode_vpn
|
||||
if CONFIG["electrs_enabled"]:
|
||||
from electrum_server import *
|
||||
from lnd import mynode_lnd, lnd_wallet_exists, is_lnd_logged_in, lnd_get, get_lnd_status
|
||||
|
@ -36,6 +37,7 @@ app.register_blueprint(mynode_lnd)
|
|||
app.register_blueprint(mynode_bitcoin_cli)
|
||||
if CONFIG["electrs_enabled"]:
|
||||
app.register_blueprint(mynode_electrum_server)
|
||||
app.register_blueprint(mynode_vpn)
|
||||
app.register_blueprint(mynode_settings)
|
||||
|
||||
### Definitions
|
||||
|
@ -416,37 +418,6 @@ def page_product_key():
|
|||
|
||||
return "Error"
|
||||
|
||||
@app.route("/vpn-info")
|
||||
def page_vpn_info():
|
||||
|
||||
message = ""
|
||||
if request.args.get('error_message'):
|
||||
message = Markup("<div class='error_message'>"+request.args.get('error_message')+"</div>")
|
||||
if request.args.get('success_message'):
|
||||
message = Markup("<div class='success_message'>"+request.args.get('success_message')+"</div>")
|
||||
|
||||
status = "Setting up..."
|
||||
if os.path.isfile("/home/pivpn/ovpns/mynode_vpn.ovpn"):
|
||||
status = "Running"
|
||||
templateData = {
|
||||
"title": "myNode VPN Info",
|
||||
"status": status,
|
||||
"message": message,
|
||||
"port": "51194"
|
||||
}
|
||||
return render_template('vpn_info.html', **templateData)
|
||||
|
||||
@app.route("/mynode.ovpn", methods=["POST"])
|
||||
def page_download_ovpn():
|
||||
p = pam.pam()
|
||||
pw = request.form.get('password_download_ovpn')
|
||||
if pw == None or p.authenticate("admin", pw) == False:
|
||||
return redirect(url_for(".page_vpn_info", error_message="Invalid Password"))
|
||||
|
||||
# Download ovpn
|
||||
return send_from_directory(directory="/home/pivpn/ovpns/", filename="mynode_vpn.ovpn")
|
||||
|
||||
|
||||
@app.route("/toggle-lndhub")
|
||||
def page_toggle_lndhub():
|
||||
if is_lndhub_enabled():
|
||||
|
|
|
@ -377,4 +377,14 @@ a:active {
|
|||
padding-left: 12px;
|
||||
margin: auto;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.port_forwarded_icon {
|
||||
width: 26px;
|
||||
height: 24px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
border-radius: 50%;
|
||||
-moz-border-radius: 50%;
|
||||
-webkit-border-radius: 50%;
|
||||
}
|
|
@ -74,7 +74,7 @@
|
|||
openConfirmDialog("confirm-dialog",
|
||||
"Enable VPN",
|
||||
"Enabling VPN will set your IP to a static IP rather than a dynamic one via DHCP. \
|
||||
The initial setup may take a couple hours.<br/><br/> \
|
||||
The initial setup may take about an hour.<br/><br/> \
|
||||
Would you like to enable VPN?",
|
||||
okFunction)
|
||||
}
|
||||
|
|
|
@ -41,6 +41,34 @@
|
|||
$("#download_ovpn_form").on("submit", function() {
|
||||
download_ovpn_dialog.dialog( "close" );
|
||||
});
|
||||
|
||||
function regenOvpn() {
|
||||
$("#regen_ovpn_form").submit();
|
||||
download_ovpn_dialog.dialog( "close" );
|
||||
}
|
||||
regen_ovpn_dialog = $( "#regen-ovpn-dialog" ).dialog({
|
||||
autoOpen: false,
|
||||
resizable: false,
|
||||
height: "auto",
|
||||
width: 600,
|
||||
modal: true,
|
||||
position: { my: "center top", at: "center top", of: window, collision: "none" },
|
||||
buttons: {
|
||||
"Regnerate": regenOvpn,
|
||||
Cancel: function() {
|
||||
regen_ovpn_dialog.dialog( "close" );
|
||||
}
|
||||
},
|
||||
open: function() {
|
||||
$("#password_regen_ovpn").val("")
|
||||
}
|
||||
});
|
||||
$("#regen_ovpn").on("click", function() {
|
||||
regen_ovpn_dialog.dialog( "open" );
|
||||
});
|
||||
$("#regen_ovpn_form").on("submit", function() {
|
||||
regen_ovpn_dialog.dialog( "close" );
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
@ -67,10 +95,38 @@
|
|||
<div class="info_tile_header">VPN Port</div>
|
||||
<div class="info_tile_contents">{{port}}</div>
|
||||
</div>
|
||||
<div class="info_tile">
|
||||
<div class="info_tile_header">Port Forwarded</div>
|
||||
<div class="info_tile_contents">
|
||||
{% if port_forwarded %}
|
||||
<div class="port_forwarded_icon green"></div>
|
||||
{% else %}
|
||||
<div class="port_forwarded_icon red"></div>
|
||||
<p style="font-size: 10px;">Please forward port 51194 to your myNode's local IP address</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="info_tile">
|
||||
<div class="info_tile_header">Public IP Address</div>
|
||||
<div class="info_tile_contents">{{public_ip}}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="app_tile_row">
|
||||
<div class="info_tile">
|
||||
<div class="info_tile_header">Download OVPN File</div>
|
||||
<div class="info_tile_contents">
|
||||
{% if vpn_file_exists %}
|
||||
<a class="ui-button ui-widget ui-corner-all mynode_button_small" id="download_ovpn" style="width: 70%;" href="#">download</a>
|
||||
{% else %}
|
||||
Generating file...
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="info_tile">
|
||||
<div class="info_tile_header">Regenerate VPN Files</div>
|
||||
<div class="info_tile_contents">
|
||||
<a class="ui-button ui-widget ui-corner-all mynode_button_small" id="regen_ovpn" style="width: 70%;" href="#">regenerate</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -90,6 +146,19 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<div id="regen-ovpn-dialog" title="Regnerate VPN Files" style="display:none;">
|
||||
<form id="regen_ovpn_form" name="regen_ovpn_form" action="/regen-vpn" method="POST">
|
||||
<p>If you are having issues and want to regnerate your VPN files, please enter your password below.
|
||||
Be sure to re-download and re-import your OVPN files on any VPN clients.</p>
|
||||
<b>Password:</b>
|
||||
<br/>
|
||||
<input type="password" name="password_regen_ovpn" id="password_regen_ovpn" value="" class="text ui-widget-content ui-corner-all">
|
||||
|
||||
<!-- Allow form submission with keyboard without duplicating the dialog button -->
|
||||
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% include 'includes/footer.html' %}
|
||||
</body>
|
||||
</html>
|
72
rootfs/standard/var/www/mynode/vpn.py
Normal file
72
rootfs/standard/var/www/mynode/vpn.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, send_from_directory, url_for
|
||||
import subprocess
|
||||
from requests import get
|
||||
import pam
|
||||
import os
|
||||
|
||||
|
||||
mynode_vpn = Blueprint('mynode_vpn',__name__)
|
||||
|
||||
# Helper functions
|
||||
def get_public_ip():
|
||||
ip = get('https://api.ipify.org').text
|
||||
return ip
|
||||
|
||||
# Flask Pages
|
||||
@mynode_vpn.route("/vpn-info")
|
||||
def page_vpn_info():
|
||||
|
||||
message = ""
|
||||
if request.args.get('error_message'):
|
||||
message = Markup("<div class='error_message'>"+request.args.get('error_message')+"</div>")
|
||||
if request.args.get('success_message'):
|
||||
message = Markup("<div class='success_message'>"+request.args.get('success_message')+"</div>")
|
||||
|
||||
# Check if port is forwarded
|
||||
port_forwarded = False
|
||||
ip = get_public_ip()
|
||||
if subprocess.call(["nc", "-v", "-u", "-w", "1", ip, "51194"]) == 0:
|
||||
port_forwarded = True
|
||||
|
||||
# Get status
|
||||
status = "Setting up..."
|
||||
vpn_file_exists = False
|
||||
if os.path.isfile("/home/pivpn/ovpns/mynode_vpn.ovpn"):
|
||||
vpn_file_exists = True
|
||||
status = "Running"
|
||||
|
||||
templateData = {
|
||||
"title": "myNode VPN Info",
|
||||
"status": status,
|
||||
"message": message,
|
||||
"vpn_file_exists": vpn_file_exists,
|
||||
"port_forwarded": port_forwarded,
|
||||
"public_ip": ip,
|
||||
"port": "51194"
|
||||
}
|
||||
return render_template('vpn_info.html', **templateData)
|
||||
|
||||
@mynode_vpn.route("/regen-vpn", methods=["POST"])
|
||||
def page_regen_vpn():
|
||||
p = pam.pam()
|
||||
pw = request.form.get('password_regen_ovpn')
|
||||
if pw == None or p.authenticate("admin", pw) == False:
|
||||
return redirect(url_for(".page_vpn_info", error_message="Invalid Password"))
|
||||
|
||||
os.system("rm /home/pivpn/ovpns/mynode_vpn.ovpn")
|
||||
os.system("systemctl stop openvpn")
|
||||
os.system("systemctl stop vpn")
|
||||
os.system("systemctl start vpn")
|
||||
|
||||
# Download ovpn
|
||||
return redirect(url_for(".page_vpn_info", success_message="Regenerating VPN files..."))
|
||||
|
||||
@mynode_vpn.route("/mynode.ovpn", methods=["POST"])
|
||||
def page_download_ovpn():
|
||||
p = pam.pam()
|
||||
pw = request.form.get('password_download_ovpn')
|
||||
if pw == None or p.authenticate("admin", pw) == False:
|
||||
return redirect(url_for(".page_vpn_info", error_message="Invalid Password"))
|
||||
|
||||
# Download ovpn
|
||||
return send_from_directory(directory="/home/pivpn/ovpns/", filename="mynode_vpn.ovpn")
|
Loading…
Reference in New Issue
Block a user