first commit

main
Ben 1 year ago
commit 59056e9032

@ -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

@ -0,0 +1,4 @@
module("luci.controller.admin.tganyconnect", package.seeall)
function index()
entry({"admin", "vpn", "tganyconnect"}, cbi("torguard/tganyconnect"), _("TorGuard AnyConnect"), 102)
end

@ -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

@ -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 ''

@ -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"
}

@ -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

@ -0,0 +1,4 @@
module("luci.controller.admin.tganyconnect", package.seeall)
function index()
entry({"admin", "vpn", "tganyconnect"}, cbi("torguard/tganyconnect"), _("TorGuard AnyConnect"), 102)
end

@ -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
Loading…
Cancel
Save