first commit
commit
4966d0458a
@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
|
||||
LUCI_TITLE:=LuCI support for TorGuard SSTP VPN
|
||||
LUCI_PKGARCH:=all
|
||||
LUCI_DEPENDS:=+sstp-client +luci-proto-sstp
|
||||
|
||||
define Package/tgsstp/conffiles
|
||||
/etc/config/tgsstp_cfg
|
||||
endef
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
@ -0,0 +1,4 @@
|
||||
module("luci.controller.admin.tgsstp", package.seeall)
|
||||
function index()
|
||||
entry({"admin", "vpn", "tgsstp"}, cbi("torguard/tgsstp"), _("TorGuard SSTP"), 102)
|
||||
end
|
@ -0,0 +1,75 @@
|
||||
-- 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("tgsstp_cfg", "TorGuard SSTP VPN Setup")
|
||||
|
||||
-- Define the section for the SSTP settings
|
||||
s = m:section(TypedSection, "sstpconfig", "SSTP VPN Settings")
|
||||
s.anonymous = true
|
||||
s.addremove = false
|
||||
|
||||
-- Define the input fields for the SSTP 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("ar.torguard.org", "Argentina")
|
||||
svr:value("au.torguard.org", "Australia Sydney")
|
||||
svr:value("br.torguard.org", "Brazil Sau Paulo")
|
||||
svr:value("br2.torguard.org", "Brazil Sau Paulo 2")
|
||||
svr:value("us-la.torguard.org", "USA LA")
|
||||
svr:value("us-fl.torguard.org", "USA Miami")
|
||||
svr:value("us-ny.torguard.org", "USA NY")
|
||||
svr:value("us-lv.torguard.org", "USA Las Vegas")
|
||||
svr:value("us-sa.torguard.org", "USA Seattle")
|
||||
svr:value("us-slc.torguard.org", "USA Salt Lake City")
|
||||
svr:value("dn.torguard.org", "Denmark Copenhagen")
|
||||
svr:value("fn.torguard.org", "Finland Helsinki")
|
||||
svr:value("dn.torguard.org", "Denmark Copenhagen")
|
||||
svr:value("fr.torguard.org", "France Paris")
|
||||
svr:value("ger.torguard.org", "Germany Frankfurt")
|
||||
svr:value("ice.torguard.org", "Iceland Reykjavik")
|
||||
svr:value("ire.torguard.org", "Ireland Dublin")
|
||||
svr:value("it.torguard.org", "Italy Milan")
|
||||
svr:value("nl.torguard.org", "Netherlands Amsterdam")
|
||||
svr:value("ru.torguard.org", "Russia Moscow")
|
||||
svr:value("swe.torguard.org", "Sweden Stockholm")
|
||||
svr:value("tk.torguard.org", "Turkey Istanbul")
|
||||
svr:value("uk.man.torguard.org", "United Kingdom Manchester")
|
||||
svr:value("hk.torguard.org", "Hong Kong")
|
||||
svr:value("id.torguard.org", "Indonesia Jakarta")
|
||||
svr:value("sk.torguard.org", "South Korea Seoul")
|
||||
svr:value("nz.torguard.org", "New Zealand Auckland")
|
||||
svr:value("sg.torguard.org", "Singapore")
|
||||
svr:value("tw.torguard.org", "Taiwan Taipei")
|
||||
svr:value("th.torguard.org", "Thailand Bangkok")
|
||||
svr:value("bh.torguard.org", "Bahrain Manama")
|
||||
svr:value("in.torguard.org", "India Mumbai")
|
||||
svr:value("isr-loc1.torguard.org", "Israel Tel Aviv")
|
||||
svr:value("isr-loc2.torguard.org", "Israel Petah Tikva")
|
||||
svr:value("sa.torguard.org", "South Africa Johannesburg")
|
||||
|
||||
|
||||
|
||||
-- VPN Control: Start/Stop SSTP VPN
|
||||
ctrl = m:section(TypedSection, "sstpconfig", "VPN Control: Start/Stop SSTP")
|
||||
ctrl.anonymous = true
|
||||
ctrl.addremove = false
|
||||
|
||||
btnStop = ctrl:option(Button, "_btn_start", translate("Click to Stop SSTP"))
|
||||
function btnStop.write()
|
||||
io.popen("/etc/init.d/tgsstp stop")
|
||||
end
|
||||
|
||||
btnStart = ctrl:option(Button, "_btn_stop", translate("Click to Start SSTP"))
|
||||
function btnStart.write()
|
||||
io.popen("/etc/init.d/tgsstp start")
|
||||
end
|
||||
|
||||
-- Return the configuration page
|
||||
return m
|
@ -0,0 +1,4 @@
|
||||
config sstpconfig 'settings'
|
||||
option server 'fr.torguard.org'
|
||||
option username ''
|
||||
option password ''
|
@ -0,0 +1,76 @@
|
||||
#!/bin/bash /etc/rc.common
|
||||
# TorGuard SSTP init script
|
||||
|
||||
START=10
|
||||
STOP=15
|
||||
|
||||
USE_PROCD=0
|
||||
|
||||
NAME=tgsstp
|
||||
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 sstpc
|
||||
ifdown sstp
|
||||
uci commit network
|
||||
/etc/init.d/network reload
|
||||
ifdown wan
|
||||
ifup wan
|
||||
ifdown wwan
|
||||
ifup wwan
|
||||
log "sstp service stopped"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
log "Starting sstp service"
|
||||
config_load tgsstp_cfg
|
||||
|
||||
local server
|
||||
local username
|
||||
local password
|
||||
|
||||
config_get server settings server
|
||||
config_get username settings username
|
||||
config_get password settings password
|
||||
|
||||
#add sstp script with custom port
|
||||
rm /lib/netifd/proto/sstp.sh
|
||||
cp /etc/sstp/sstp.sh /lib/netifd/proto/sstp.sh
|
||||
|
||||
#copy missing plugin path
|
||||
cp /usr/lib/sstp-pppd-plugin.so /usr/lib/pppd/2.4.9/sstp-pppd-plugin.so
|
||||
|
||||
|
||||
# check if the sstp entry already exists in the firewall
|
||||
local sstp_exists=$(uci show firewall | grep -wc " 'sstp'")
|
||||
if [ "$sstp_exists" -eq 0 ]; then
|
||||
uci add_list firewall.wan.network="sstp"
|
||||
uci commit firewall
|
||||
reload_config
|
||||
fi
|
||||
|
||||
uci -q delete network.sstp
|
||||
uci set network.sstp="interface"
|
||||
uci set network.sstp.proto="sstp"
|
||||
uci set network.sstp.server="${server}"
|
||||
uci set network.sstp.username="${username}"
|
||||
uci set network.sstp.password="${password}"
|
||||
uci commit network
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command /usr/sbin/sstpc "$server:9443" --user "$username" --pass "$password"
|
||||
procd_set_param stdout 1 # forward stdout of the command to logd
|
||||
procd_set_param stderr 1 # same for stderr
|
||||
procd_set_param respawn # automatically restart the service if it dies
|
||||
procd_close_instance
|
||||
/etc/init.d/network reload
|
||||
ifdown sstp
|
||||
ifup sstp
|
||||
log "sstp service started"
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ -x /usr/bin/sstpc ] || exit 0
|
||||
|
||||
[ -n "$INCLUDE_ONLY" ] || {
|
||||
. /lib/functions.sh
|
||||
. ../netifd-proto.sh
|
||||
init_proto "$@"
|
||||
}
|
||||
|
||||
proto_sstp_init_config() {
|
||||
proto_config_add_string "server"
|
||||
proto_config_add_string "username"
|
||||
proto_config_add_string "password"
|
||||
proto_config_add_string "pppd_options"
|
||||
proto_config_add_string "sstp_options"
|
||||
proto_config_add_int "log_level"
|
||||
proto_config_add_int "mtu"
|
||||
proto_config_add_boolean "ipv6"
|
||||
proto_config_add_boolean "defaultroute"
|
||||
proto_config_add_boolean "peerdns"
|
||||
available=1
|
||||
no_device=1
|
||||
}
|
||||
|
||||
proto_sstp_setup() {
|
||||
local config="$1"; shift
|
||||
local iface="$2"
|
||||
local ifname="sstp-$config"
|
||||
|
||||
local ip serv_addr server ipv6 defaultroute peerdns
|
||||
json_get_var server server && {
|
||||
for ip in $(resolveip -t 5 "$server"); do
|
||||
( proto_add_host_dependency "$config" "$ip" )
|
||||
serv_addr=1
|
||||
done
|
||||
}
|
||||
[ -n "$serv_addr" ] || {
|
||||
echo "Could not resolve server address"
|
||||
sleep 5
|
||||
proto_setup_failed "$config"
|
||||
exit 1
|
||||
}
|
||||
|
||||
json_get_vars username password pppd_options sstp_options log_level ipv6 defaultroute peerdns
|
||||
if [ "$ipv6" = 1 ]; then
|
||||
ipv6=1
|
||||
else
|
||||
ipv6=""
|
||||
fi
|
||||
if [ "$defaultroute" = 0 ]; then
|
||||
defaultroute=""
|
||||
else
|
||||
defaultroute=1
|
||||
fi
|
||||
|
||||
if [ "$peerdns" = 0 ]; then
|
||||
peerdns=""
|
||||
else
|
||||
peerdns=1
|
||||
fi
|
||||
|
||||
[ -n "$mtu" ] || json_get_var mtu mtu
|
||||
[ -n "$log_level" ] || log_level=0
|
||||
|
||||
local load
|
||||
for module in slhc ppp_generic ppp_async ppp_mppe ip_gre gre pptp; do
|
||||
grep -q "^$module " /proc/modules && continue
|
||||
/sbin/insmod $module 2>&- >&-
|
||||
load=1
|
||||
done
|
||||
[ "$load" = "1" ] && sleep 1
|
||||
|
||||
proto_init_update "$ifname" 1
|
||||
proto_send_update "$config"
|
||||
|
||||
proto_run_command "$config" sstpc \
|
||||
--cert-warn \
|
||||
--password $password \
|
||||
--user $username \
|
||||
--log-level $log_level \
|
||||
--save-server-route \
|
||||
--ipparam $config \
|
||||
$sstp_options \
|
||||
$server:9443 \
|
||||
ifname $ifname \
|
||||
require-mschap-v2 \
|
||||
${ipv6:++ipv6} \
|
||||
refuse-pap \
|
||||
noauth \
|
||||
${defaultroute:+replacedefaultroute defaultroute} \
|
||||
${peerdns:+usepeerdns} \
|
||||
ip-up-script /lib/netifd/ppp-up \
|
||||
ipv6-up-script /lib/netifd/ppp-up \
|
||||
ip-down-script /lib/netifd/ppp-down \
|
||||
ipv6-down-script /lib/netifd/ppp-down \
|
||||
${mtu:+mtu $mtu mru $mtu} \
|
||||
$pppd_options
|
||||
|
||||
# WORKAROUND: Workaround to properly register the sstp interface (As seeen in: https://forum.archive.openwrt.org/viewtopic.php?id=58007)
|
||||
# WORKAROUND: Start
|
||||
sleep 10
|
||||
proto_init_update "$ifname" 1
|
||||
proto_send_update "$config"
|
||||
# WORKAROUND: End
|
||||
|
||||
# if use pppoe and sstp at same time , firewall need reload .
|
||||
# but don't konw why
|
||||
/etc/init.d/firewall reload 2>&- >&-
|
||||
}
|
||||
|
||||
proto_sstp_teardown() {
|
||||
local interface="$1"
|
||||
|
||||
case "$ERROR" in
|
||||
11|19)
|
||||
proto_notify_error "$interface" AUTH_FAILED
|
||||
proto_block_restart "$interface"
|
||||
;;
|
||||
2)
|
||||
proto_notify_error "$interface" INVALID_OPTIONS
|
||||
proto_block_restart "$interface"
|
||||
;;
|
||||
esac
|
||||
proto_kill_command "$interface"
|
||||
}
|
||||
|
||||
[ -n "$INCLUDE_ONLY" ] || {
|
||||
add_protocol sstp
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@tgsstp_def[-1]
|
||||
add ucitrack tgsstp
|
||||
set ucitrack.@tgsstp[-1].init=tgsstp
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
||||
|
@ -0,0 +1,4 @@
|
||||
module("luci.controller.admin.tgsstp", package.seeall)
|
||||
function index()
|
||||
entry({"admin", "vpn", "tgsstp"}, cbi("torguard/tgsstp"), _("TorGuard SSTP"), 102)
|
||||
end
|
@ -0,0 +1,75 @@
|
||||
-- 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("tgsstp_cfg", "TorGuard SSTP VPN Setup")
|
||||
|
||||
-- Define the section for the SSTP settings
|
||||
s = m:section(TypedSection, "sstpconfig", "SSTP VPN Settings")
|
||||
s.anonymous = true
|
||||
s.addremove = false
|
||||
|
||||
-- Define the input fields for the SSTP 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("ar.torguard.org", "Argentina")
|
||||
svr:value("au.torguard.org", "Australia Sydney")
|
||||
svr:value("br.torguard.org", "Brazil Sau Paulo")
|
||||
svr:value("br2.torguard.org", "Brazil Sau Paulo 2")
|
||||
svr:value("us-la.torguard.org", "USA LA")
|
||||
svr:value("us-fl.torguard.org", "USA Miami")
|
||||
svr:value("us-ny.torguard.org", "USA NY")
|
||||
svr:value("us-lv.torguard.org", "USA Las Vegas")
|
||||
svr:value("us-sa.torguard.org", "USA Seattle")
|
||||
svr:value("us-slc.torguard.org", "USA Salt Lake City")
|
||||
svr:value("dn.torguard.org", "Denmark Copenhagen")
|
||||
svr:value("fn.torguard.org", "Finland Helsinki")
|
||||
svr:value("dn.torguard.org", "Denmark Copenhagen")
|
||||
svr:value("fr.torguard.org", "France Paris")
|
||||
svr:value("ger.torguard.org", "Germany Frankfurt")
|
||||
svr:value("ice.torguard.org", "Iceland Reykjavik")
|
||||
svr:value("ire.torguard.org", "Ireland Dublin")
|
||||
svr:value("it.torguard.org", "Italy Milan")
|
||||
svr:value("nl.torguard.org", "Netherlands Amsterdam")
|
||||
svr:value("ru.torguard.org", "Russia Moscow")
|
||||
svr:value("swe.torguard.org", "Sweden Stockholm")
|
||||
svr:value("tk.torguard.org", "Turkey Istanbul")
|
||||
svr:value("uk.man.torguard.org", "United Kingdom Manchester")
|
||||
svr:value("hk.torguard.org", "Hong Kong")
|
||||
svr:value("id.torguard.org", "Indonesia Jakarta")
|
||||
svr:value("sk.torguard.org", "South Korea Seoul")
|
||||
svr:value("nz.torguard.org", "New Zealand Auckland")
|
||||
svr:value("sg.torguard.org", "Singapore")
|
||||
svr:value("tw.torguard.org", "Taiwan Taipei")
|
||||
svr:value("th.torguard.org", "Thailand Bangkok")
|
||||
svr:value("bh.torguard.org", "Bahrain Manama")
|
||||
svr:value("in.torguard.org", "India Mumbai")
|
||||
svr:value("isr-loc1.torguard.org", "Israel Tel Aviv")
|
||||
svr:value("isr-loc2.torguard.org", "Israel Petah Tikva")
|
||||
svr:value("sa.torguard.org", "South Africa Johannesburg")
|
||||
|
||||
|
||||
|
||||
-- VPN Control: Start/Stop SSTP VPN
|
||||
ctrl = m:section(TypedSection, "sstpconfig", "VPN Control: Start/Stop SSTP")
|
||||
ctrl.anonymous = true
|
||||
ctrl.addremove = false
|
||||
|
||||
btnStop = ctrl:option(Button, "_btn_start", translate("Click to Stop SSTP"))
|
||||
function btnStop.write()
|
||||
io.popen("/etc/init.d/tgsstp stop")
|
||||
end
|
||||
|
||||
btnStart = ctrl:option(Button, "_btn_stop", translate("Click to Start SSTP"))
|
||||
function btnStart.write()
|
||||
io.popen("/etc/init.d/tgsstp start")
|
||||
end
|
||||
|
||||
-- Return the configuration page
|
||||
return m
|
Binary file not shown.
Loading…
Reference in New Issue