mynode/rootfs/standard/var/www/mynode/vpn.py
Abhishek Shandilya b09d322331 Dark mode feature (#16)
* added toggle dark mode button on settings page, new logo and CSS file for dark mode

* change colors of settings_input for dark mode

* added the dark_mode flag in every templateData (very painfully)

* Using ui.json to store all UI settings, darkmode implementation is cleaner

* moved all CSS and JS links to head.html; imported ui_settigns appropriately; created dark version of bitcoind CSS

* subheader color on lnd page

* save ui.json on both HDD and mynode for redundancy

* use head and logo template in new config and login pages

* add ui_settings to templateData for new login and config pages

* avoid repeating CSS for dark theme

* change colors of config textarea

* wrap ui setting hdd write in TRY/except

* group similar CSS commands
2019-11-09 11:17:52 -06:00

86 lines
2.4 KiB
Python

from flask import Blueprint, render_template, session, abort, Markup, request, redirect, send_from_directory, url_for, flash
from thread_functions import get_public_ip
from device_info import is_community_edition
from settings import read_ui_settings
from user_management import check_logged_in
import subprocess
import pam
import os
import json
mynode_vpn = Blueprint('mynode_vpn',__name__)
# Helper functions
# Flask Pages
@mynode_vpn.route("/vpn-info")
def page_vpn_info():
check_logged_in()
# Check if we are premium
if is_community_edition():
return redirect("/")
# 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,
"vpn_file_exists": vpn_file_exists,
"port_forwarded": port_forwarded,
"public_ip": ip,
"port": "51194",
"ui_settings": read_ui_settings()
}
return render_template('vpn_info.html', **templateData)
@mynode_vpn.route("/regen-vpn", methods=["POST"])
def page_regen_vpn():
check_logged_in()
p = pam.pam()
pw = request.form.get('password_regen_ovpn')
if pw == None or p.authenticate("admin", pw) == False:
flash("Invalid Password", category="error")
return redirect(url_for(".page_vpn_info"))
# Stop
#os.system("rm /home/pivpn/ovpns/mynode_vpn.ovpn")
os.system("pivpn -r mynode_vpn")
os.system("systemctl stop openvpn")
os.system("systemctl stop vpn")
# Clean up files
os.system("rm -rf /mnt/hdd/mynode/vpn/*")
# Restart
os.system("systemctl start vpn")
# Download ovpn
flash("Regenerating VPN files...", category="message")
return redirect(url_for(".page_vpn_info"))
@mynode_vpn.route("/mynode.ovpn", methods=["POST"])
def page_download_ovpn():
check_logged_in()
p = pam.pam()
pw = request.form.get('password_download_ovpn')
if pw == None or p.authenticate("admin", pw) == False:
flash("Invalid Password", category="error")
return redirect(url_for(".page_vpn_info"))
# Download ovpn
return send_from_directory(directory="/home/pivpn/ovpns/", filename="mynode_vpn.ovpn")