From 59056e9032be2e68209b0da596ae200d3361c919 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 2 Sep 2023 17:15:10 +0000 Subject: [PATCH] first commit --- Makefile | 16 +++++ README.md | 0 luasrc/controller/admin/tganyconnect.lua | 4 ++ luasrc/model/cbi/torguard/tganyconnect.lua | 62 ++++++++++++++++ root/etc/config/tganyconnect_cfg | 5 ++ root/etc/init.d/tganyconnect | 70 +++++++++++++++++++ root/etc/uci-defaults/tganyconnect_def | 12 ++++ .../luci/controller/admin/tganyconnect.lua | 4 ++ .../luci/model/cbi/torguard/tganyconnect.lua | 62 ++++++++++++++++ 9 files changed, 235 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 luasrc/controller/admin/tganyconnect.lua create mode 100644 luasrc/model/cbi/torguard/tganyconnect.lua create mode 100644 root/etc/config/tganyconnect_cfg create mode 100755 root/etc/init.d/tganyconnect create mode 100644 root/etc/uci-defaults/tganyconnect_def create mode 100644 root/usr/lib/lua/luci/controller/admin/tganyconnect.lua create mode 100644 root/usr/lib/lua/luci/model/cbi/torguard/tganyconnect.lua diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..78854c7 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ + + +include $(TOPDIR)/rules.mk + + +LUCI_TITLE:=LuCI support for TorGuard AnyConnect VPN +LUCI_PKGARCH:=all +LUCI_DEPENDS:=+openconnect +luci-proto-openconnect + +define Package/tganyconnect/conffiles +/etc/config/tganyconnect_cfg +endef + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/luasrc/controller/admin/tganyconnect.lua b/luasrc/controller/admin/tganyconnect.lua new file mode 100644 index 0000000..4906b58 --- /dev/null +++ b/luasrc/controller/admin/tganyconnect.lua @@ -0,0 +1,4 @@ +module("luci.controller.admin.tganyconnect", package.seeall) +function index() + entry({"admin", "vpn", "tganyconnect"}, cbi("torguard/tganyconnect"), _("TorGuard AnyConnect"), 102) +end \ No newline at end of file diff --git a/luasrc/model/cbi/torguard/tganyconnect.lua b/luasrc/model/cbi/torguard/tganyconnect.lua new file mode 100644 index 0000000..aa4ea98 --- /dev/null +++ b/luasrc/model/cbi/torguard/tganyconnect.lua @@ -0,0 +1,62 @@ +-- Import the necessary LuCI modules +local uci = require("luci.model.uci").cursor() +local sys = require("luci.sys") +local util = require("luci.util") + +-- Define the model +m = Map("tganyconnect_cfg", "TorGuard AnyConnect VPN Setup") + +-- Define the section for the AnyConnect settings +s = m:section(TypedSection, "anyconnectconfig", "AnyConnect VPN Settings") +s.anonymous = true +s.addremove = false + +-- Define the input fields for the AnyConnect settings +user = s:option(Value, "username", translate("VPN Username")) +pass = s:option(Value, "password", translate("VPN Password")) +pass.password = true + +svr = s:option(ListValue, "server", translate("VPN Server")) +-- Add all servers here +svr:value("fr.anyconnect.host", "France Strasbourg") +svr:value("ger.anyconnect.host", "Germany Frankfurt") +svr:value("ger2.anyconnect.host", "Germany - Frankfurt 2") +svr:value("hk.anyconnect.host", "Hong Kong") +svr:value("nl.anyconnect.host", "Netherlands") +svr:value("pl.anyconnect.host", "Poland") +svr:value("sg.anyconnect.host", "Singapore") +svr:value("uk.anyconnect.host", "United Kingdom") +svr:value("la.usa.anyconnect.host", "USA LA") +svr:value("ny.usa.anyconnect.host", "USA NY") + +dns = s:option(ListValue, "dns", translate("DNS")) +-- Add all ports here +dns:value("8.8.8.8 8.8.4.4", "Google") +dns:value("1.1.1.1 1.0.0.1", "Cloudflare") +dns:value("9.9.9.9 149.112.112.112", "Quad9") +dns:value("208.67.222.222 208.67.220.220", "OpenDNS") +dns:value("84.200.69.80 84.200.70.40", "DNS.WATCH") +dns:value("8.26.56.26 8.20.247.2", "Comodo Secure DNS") +dns:value("64.6.64.6 64.6.65.6", "Verisign DNS") +dns:value("185.228.168.9 185.228.169.9", "CleanBrowsing") +dns:value("77.88.8.8 77.88.8.1", "Yandex.DNS") +dns:value("91.239.100.100 89.233.43.71", "UncensoredDNS") + + +-- VPN Control: Start/Stop AnyConnect VPN +ctrl = m:section(TypedSection, "anyconnectconfig", "VPN Control: Start/Stop AnyConnect") +ctrl.anonymous = true +ctrl.addremove = false + +btnStop = ctrl:option(Button, "_btn_start", translate("Click to Stop AnyConnect")) +function btnStop.write() + io.popen("/etc/init.d/tganyconnect stop") +end + +btnStart = ctrl:option(Button, "_btn_stop", translate("Click to Start AnyConnect")) +function btnStart.write() + io.popen("/etc/init.d/tganyconnect start") +end + +-- Return the configuration page +return m diff --git a/root/etc/config/tganyconnect_cfg b/root/etc/config/tganyconnect_cfg new file mode 100644 index 0000000..6b90e94 --- /dev/null +++ b/root/etc/config/tganyconnect_cfg @@ -0,0 +1,5 @@ +config anyconnectconfig 'settings' + option server 'ar.torguard.org' + option dns '8.8.8.8 8.8.4.4' + option username '' + option password '' diff --git a/root/etc/init.d/tganyconnect b/root/etc/init.d/tganyconnect new file mode 100755 index 0000000..d8f696b --- /dev/null +++ b/root/etc/init.d/tganyconnect @@ -0,0 +1,70 @@ +#!/bin/bash /etc/rc.common +# TorGuard AnyConnectVPN init script + +START=10 +STOP=15 + +USE_PROCD=1 + +NAME=tganyconnect +LOGFILE=/var/log/${NAME}.log + +log() { + local timestamp=$(date +"%Y-%m-%d %H:%M:%S") + echo "${timestamp} ${NAME}: $@" >> ${LOGFILE} +} + +stop_service() { + log "Stopping service" + procd_kill openconnect + ifdown vpn + uci commit network + /etc/init.d/network reload + ifdown wan + ifup wan + ifdown wwan + ifup wwan + log "Service stopped" +} + +start_service() { + log "Starting service" + config_load tganyconnect_cfg + + local server + local username + local password + local dns + + config_get server settings server + config_get dns settings dns + config_get username settings username + config_get password settings password + + uci rename firewall.@zone[0]="lan" + uci rename firewall.@zone[1]="wan" + + # check if the vpn entry already exists in the firewall + local vpn_exists=$(uci show firewall | grep -wc " 'vpn'") + if [ "$vpn_exists" -eq 0 ]; then + uci add_list firewall.wan.network="vpn" + uci commit firewall + reload_config + fi + + uci -q delete network.vpn + uci set network.vpn="interface" + uci set network.vpn.proto="openconnect" + uci set network.vpn.server="${server}" + uci set network.vpn.port="443" + uci set network.vpn.username="${username}" + uci set network.vpn.password="${password}" + uci set network.vpn.defaultroute="1" + uci set network.vpn.peerdns="0" + uci set network.vpn.dns="${dns}" + uci commit network + /etc/init.d/network reload + ifdown vpn + ifup vpn + log "Service started" +} diff --git a/root/etc/uci-defaults/tganyconnect_def b/root/etc/uci-defaults/tganyconnect_def new file mode 100644 index 0000000..c5d9959 --- /dev/null +++ b/root/etc/uci-defaults/tganyconnect_def @@ -0,0 +1,12 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@tganyconnect_def[-1] + add ucitrack tganyconnect + set ucitrack.@tganyconnect[-1].init=tganyconnect + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 + diff --git a/root/usr/lib/lua/luci/controller/admin/tganyconnect.lua b/root/usr/lib/lua/luci/controller/admin/tganyconnect.lua new file mode 100644 index 0000000..4906b58 --- /dev/null +++ b/root/usr/lib/lua/luci/controller/admin/tganyconnect.lua @@ -0,0 +1,4 @@ +module("luci.controller.admin.tganyconnect", package.seeall) +function index() + entry({"admin", "vpn", "tganyconnect"}, cbi("torguard/tganyconnect"), _("TorGuard AnyConnect"), 102) +end \ No newline at end of file diff --git a/root/usr/lib/lua/luci/model/cbi/torguard/tganyconnect.lua b/root/usr/lib/lua/luci/model/cbi/torguard/tganyconnect.lua new file mode 100644 index 0000000..aa4ea98 --- /dev/null +++ b/root/usr/lib/lua/luci/model/cbi/torguard/tganyconnect.lua @@ -0,0 +1,62 @@ +-- Import the necessary LuCI modules +local uci = require("luci.model.uci").cursor() +local sys = require("luci.sys") +local util = require("luci.util") + +-- Define the model +m = Map("tganyconnect_cfg", "TorGuard AnyConnect VPN Setup") + +-- Define the section for the AnyConnect settings +s = m:section(TypedSection, "anyconnectconfig", "AnyConnect VPN Settings") +s.anonymous = true +s.addremove = false + +-- Define the input fields for the AnyConnect settings +user = s:option(Value, "username", translate("VPN Username")) +pass = s:option(Value, "password", translate("VPN Password")) +pass.password = true + +svr = s:option(ListValue, "server", translate("VPN Server")) +-- Add all servers here +svr:value("fr.anyconnect.host", "France Strasbourg") +svr:value("ger.anyconnect.host", "Germany Frankfurt") +svr:value("ger2.anyconnect.host", "Germany - Frankfurt 2") +svr:value("hk.anyconnect.host", "Hong Kong") +svr:value("nl.anyconnect.host", "Netherlands") +svr:value("pl.anyconnect.host", "Poland") +svr:value("sg.anyconnect.host", "Singapore") +svr:value("uk.anyconnect.host", "United Kingdom") +svr:value("la.usa.anyconnect.host", "USA LA") +svr:value("ny.usa.anyconnect.host", "USA NY") + +dns = s:option(ListValue, "dns", translate("DNS")) +-- Add all ports here +dns:value("8.8.8.8 8.8.4.4", "Google") +dns:value("1.1.1.1 1.0.0.1", "Cloudflare") +dns:value("9.9.9.9 149.112.112.112", "Quad9") +dns:value("208.67.222.222 208.67.220.220", "OpenDNS") +dns:value("84.200.69.80 84.200.70.40", "DNS.WATCH") +dns:value("8.26.56.26 8.20.247.2", "Comodo Secure DNS") +dns:value("64.6.64.6 64.6.65.6", "Verisign DNS") +dns:value("185.228.168.9 185.228.169.9", "CleanBrowsing") +dns:value("77.88.8.8 77.88.8.1", "Yandex.DNS") +dns:value("91.239.100.100 89.233.43.71", "UncensoredDNS") + + +-- VPN Control: Start/Stop AnyConnect VPN +ctrl = m:section(TypedSection, "anyconnectconfig", "VPN Control: Start/Stop AnyConnect") +ctrl.anonymous = true +ctrl.addremove = false + +btnStop = ctrl:option(Button, "_btn_start", translate("Click to Stop AnyConnect")) +function btnStop.write() + io.popen("/etc/init.d/tganyconnect stop") +end + +btnStart = ctrl:option(Button, "_btn_stop", translate("Click to Start AnyConnect")) +function btnStart.write() + io.popen("/etc/init.d/tganyconnect start") +end + +-- Return the configuration page +return m