Ejemplo n.º 1
0
def execute_action():
    action = request.form["action"]
    if action == "reboot":
        pi_reboot()
    elif action == "shutdown":
        pi_shutdown()
    elif action == "start_vpn":
        start_vpn()
        flash("VPN Started!", "notice")
    elif action == "stop_vpn":
        stop_vpn()
        flash("VPN Stopped!", "notice")
    elif action == "restart_vpn":
        restart_vpn()
        flash("VPN Restarted!", "notice")
    elif action == "ssh_service":
        start_ssh_service()
        flash("SSH Service Started! It will be turned off on reboot.")
    elif action == "update_client":
        update_client()
        flash("Client will reboot... please reload this page in 1 minute.")
    else:
        form = initialSetupForm()
        flash("Error! Invalid Action!", "error")
        
    return redirect(url_for("status"))
Ejemplo n.º 2
0
def initial_setup():
    form = initialSetupForm()

    if request.method == "GET":
        return render_template("initial_setup.html", form=form) 

    elif request.method == "POST":
        if form.validate():
            ssid = form.ssid.data.rsplit("-", 1)[0]
            psk = form.psk.data
            add_wifi(ssid, psk)
            
            if internet_status() is True:
                vpn_server = form.vpn_server.data
                user_id = form.user_id.data
                user_psk = form.user_psk.data
                set_vpn_params(vpn_server, user_id, user_psk)
                restart_vpn()
            
                flash("Wifi and VPN settings saved!", "success")
                return redirect(url_for("status"))
            else:
                flash("Error! Cannot reach the internet...", "error")
                return render_template("initial_setup.html", form=form)
            
        else:
            flash("Error! " + str(form.data), "error")
            return render_template("initial_setup.html", form=form)
Ejemplo n.º 3
0
def wifi():
    form = wifiForm()

    if request.method == "GET":
        return render_template("wifi.html", form=form)
    
    elif request.method == "POST":
        if form.validate():
            ssid = form.ssid.data.rsplit("-", 1)[0]
            psk = form.psk.data
            add_wifi(ssid, psk)
            time.sleep(5)
            
            if internet_status() is True:
                restart_vpn()
                time.sleep(5)
                flash("Wifi settings saved! VPN Restarted!", "success")
                return redirect(url_for("status"))
            else:
                flash("Error! Cannot reach the internet...", "error")
                return render_template("wifi.html", form=form)

        else:
            flash("Error! " + str(form.data), "error")
            return render_template("wifi.html", form=form)
Ejemplo n.º 4
0
def wifi():
    form = wifiForm()

    if(request.method == "GET"):
        return render_template("wifi.html", form=form)
    
    elif(request.method == "POST"):
        if(form.validate()):
            ssid = (form.ssid.data).rsplit("-", 1)[0]
            psk = form.psk.data
            add_wifi(ssid, psk)
            time.sleep(5)
            
            if(internet_status() == True):
                restart_vpn()
                time.sleep(5)
                flash("Wifi settings saved! VPN Restarted!", "success")
                return redirect(url_for("status"))
            else:
                flash("Error! Cannot reach the internet...", "error")
                return render_template("wifi.html", form=form)

        else:
            flash("Error! " + str(form.data), "error")
            return render_template("wifi.html", form=form)
Ejemplo n.º 5
0
def initial_setup():
    form = initialSetupForm()

    if(request.method == "GET"):
        return render_template("initial_setup.html", form=form) 

    elif(request.method == "POST"):
        if(form.validate()):
            ssid = (form.ssid.data).rsplit("-", 1)[0]
            psk = form.psk.data
            add_wifi(ssid, psk)
            
            if(internet_status() == True):
                vpn_server = form.vpn_server.data
                user_id = form.user_id.data
                user_psk = form.user_psk.data
                set_vpn_params(vpn_server, user_id, user_psk)
                restart_vpn()
            
                flash("Wifi and VPN settings saved!", "success")
                return redirect(url_for("status"))
            else:
                flash("Error! Cannot reach the internet...", "error")
                return render_template("initial_setup.html", form=form)
            
        else:
            flash("Error! " + str(form.data), "error")
            return render_template("initial_setup.html", form=form)
Ejemplo n.º 6
0
def vpn_psk():
    form = vpnPskForm()

    if request.method == "GET":
        return render_template("vpn_psk.html", form=form)

    elif request.method == "POST":
        if form.validate():
            vpn_server = form.vpn_server.data
            user_id = form.user_id.data
            user_psk = form.user_psk.data
            set_vpn_params(vpn_server, user_id, user_psk)
            restart_vpn()

            if vpn_status():
                flash("VPN settings saved and VPN restarted!", "success")
                return redirect(url_for("status"))
            else:
                flash(
                    "VPN settings saved and VPN restarted! Unable to establish VPN connection.",
                    "error")
                return render_template("vpn_psk.html", form=form)
        else:
            flash("Error! " + str(form.data), "error")
            return render_template("vpn_psk.html", form=form)
Ejemplo n.º 7
0
def execute_action():
    action = request.form["action"]
    if action == "reboot":
        pi_reboot()
    elif action == "shutdown":
        pi_shutdown()
    elif action == "start_vpn":
        start_vpn()
        flash("VPN Started!", "notice")
    elif action == "stop_vpn":
        stop_vpn()
        flash("VPN Stopped!", "notice")
    elif action == "restart_vpn":
        restart_vpn()
        flash("VPN Restarted!", "notice")
    elif action == "ssh_service":
        start_ssh_service()
        flash("SSH Service Started! It will be turned off on reboot.")
    elif action == "update_client":
        update_client()
        flash("Client will reboot... please reload this page in 1 minute.")
    else:
        form = initialSetupForm()
        flash("Error! Invalid Action!", "error")
        
    return redirect(url_for("status"))
Ejemplo n.º 8
0
def api_vpn_actions():
    if request.method == "POST":
        if request.headers['Content-Type'] == 'application/json':
            action = request.json["action"]
            if action == "start_vpn":
                if start_vpn():
                    return "VPN service started, VPN is ESTABLISHED"
                else:
                    return "VPN service started, VPN is NOT ESTABLISHED"
                
            elif action == "stop_vpn":
                stop_vpn()
                return "VPN service stopped, VPN is NOT ESTABLISHED"
            
            elif action == "restart_vpn":
                if restart_vpn():
                    return "VPN service restarted, VPN is ESTABLISHED"
                else:
                    return "VPN service restarted, VPN is NOT ESTABLISHED"
            else:
                return "Error! Invalid Action!"

        else:
            return "415 Unsupported Media Type - Use application/json"
    else:
        return "Only POST method is supported. Refer to the API Documentation"
Ejemplo n.º 9
0
def api_vpn_actions():
    if(request.method == "POST"):
        if(request.headers['Content-Type'] == 'application/json'):
            action = request.json["action"]
            if(action == "start_vpn"):
                if(start_vpn()):
                    return "VPN service started, VPN is ESTABLISHED"
                else:
                    return "VPN service started, VPN is NOT ESTABLISHED"
                
            elif(action == "stop_vpn"):
                stop_vpn()
                return "VPN service stopped, VPN is NOT ESTABLISHED"
            
            elif(action == "restart_vpn"):
                if(restart_vpn()):
                    return "VPN service restarted, VPN is ESTABLISHED"
                else:
                    return "VPN service restarted, VPN is NOT ESTABLISHED"
            else:
                return "Error! Invalid Action!"

        else:
            return "415 Unsupported Media Type - Use application/json"
    else:
        return "Only POST method is supported. Refer to the API Documentation"
Ejemplo n.º 10
0
def execute_action():
    action = request.form["action"]
    if(action == "reboot"):
        pi_reboot()
    elif(action == "shutdown"):
        pi_shutdown()
    elif(action == "start_vpn"):
        start_vpn()
        flash("VPN Started!", "notice")
    elif(action == "stop_vpn"):
        stop_vpn()
        flash("VPN Stopped!", "notice")
    elif(action == "restart_vpn"):
        restart_vpn()
        flash("VPN Restarted!", "notice")
    elif(action == "ssh_service"):
        start_ssh_service()
        flash("SSH Service Started! It will be turned off on reboot.")
    else:
        form = initialSetupForm()
        flash("Error! Invalid Action!", "error")
        
    return redirect(url_for("status"))
Ejemplo n.º 11
0
def vpn_psk():
    form = vpnPskForm()

    if(request.method == "GET"):
        return render_template("vpn_psk.html", form=form)
    
    elif(request.method == "POST"):
        if(form.validate()):
            vpn_server = form.vpn_server.data
            user_id = form.user_id.data
            user_psk = form.user_psk.data
            set_vpn_params(vpn_server, user_id, user_psk)
            restart_vpn()

            if(vpn_status()):
                flash("VPN settings saved and VPN restarted!", "success")
                return redirect(url_for("status"))
            else:
                flash("VPN settings saved and VPN restarted! Unable to establish VPN connection.", "error")
                return render_template("vpn_psk.html", form=form)
        else:
            flash("Error! " + str(form.data), "error")
            return render_template("vpn_psk.html", form=form)