mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-02 21:03:56 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
+98
@@ -0,0 +1,98 @@
|
||||
#!/bin/sh
|
||||
|
||||
######################################################
|
||||
# smartvpn dnsmasq domain configuration file generator
|
||||
# create by Daniel Yang 2021-07-22
|
||||
######################################################
|
||||
|
||||
domain_file_formated="/tmp/smartvpn_domain_format.tmp"
|
||||
domain_file_sorted="/tmp/smartvpn_domain_sort.tmp"
|
||||
#domain_file_smartvpn="/etc/smartvpn/smartdns.conf"
|
||||
|
||||
#ipset_name="smartvpn"
|
||||
|
||||
rule_file=$1
|
||||
domain_file=$2
|
||||
ip_file=$3
|
||||
ipset_name=$4
|
||||
dnsserver=$5
|
||||
append=$6
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "gensmartdns.sh rule_file domain_file ip_file ipset_name [dnsserver] [append]"
|
||||
echo "-- rule_file : must specify"
|
||||
echo "-- domain_file : must specify, writable, domain list output"
|
||||
echo "-- ip_file : must specify, writable, ip list output"
|
||||
echo "-- ipset_name : must specify"
|
||||
echo "-- dnsserver : optional, default is 8.8.8.8"
|
||||
echo ""
|
||||
}
|
||||
|
||||
|
||||
# echo "gen arg list: "$*" "
|
||||
|
||||
[ -z $rule_file ] && {
|
||||
usage
|
||||
return 1
|
||||
}
|
||||
|
||||
[ -z $ip_file ] && {
|
||||
usage
|
||||
return 1
|
||||
}
|
||||
|
||||
[ -z $dnsserver ] && {
|
||||
dnsserver="8.8.8.8"
|
||||
}
|
||||
|
||||
[ -z $ipset_name ] && {
|
||||
ipset_name="smartvpn"
|
||||
}
|
||||
|
||||
echo "gensmartdns: domain_file=$rule_file, ip_file=$ip_file, dnsserver=$dnsserver"
|
||||
|
||||
format2domain()
|
||||
{
|
||||
local _rule=$1
|
||||
local _dmf=$2
|
||||
local _ipf=$3
|
||||
|
||||
[ -z $append ] && {
|
||||
echo "" > $_dmf
|
||||
echo "" > $_ipf
|
||||
}
|
||||
|
||||
cat $_rule | while read line || [ -n "$line" ]
|
||||
do
|
||||
if [ -n "$line" ]; then
|
||||
if [[ "${line:0:1}" = "." ]]; then
|
||||
echo "${line:1}" >> $_dmf
|
||||
elif [[ "${line:0:1}" = "#" ]]; then
|
||||
line=""
|
||||
else
|
||||
echo "$line" >> $_ipf
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
format2domain $rule_file $domain_file_formated $ip_file
|
||||
[ $? -ne 0 ] && {
|
||||
echo "format2domain error!"
|
||||
return 1
|
||||
}
|
||||
|
||||
sort $domain_file_formated | uniq > $domain_file_sorted
|
||||
cat $domain_file_sorted | while read line
|
||||
do
|
||||
if [ -n "$line" ]; then
|
||||
echo "server=/$line/$dnsserver"
|
||||
echo "ipset=/$line/$ipset_name"
|
||||
fi
|
||||
done > $domain_file
|
||||
|
||||
# rm $domain_file_formated
|
||||
# rm $domain_file_sorted
|
||||
echo "Gen smartdns conf done!"
|
||||
|
||||
Executable
+411
@@ -0,0 +1,411 @@
|
||||
#!/bin/sh
|
||||
|
||||
############################################
|
||||
# smartvpn control scrip for OpenWRT
|
||||
# create by Daniel Yang 2021-06-18
|
||||
############################################
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/network.sh
|
||||
|
||||
SMARTVPN_VER='v1.1.4'
|
||||
|
||||
smartvpn_logger()
|
||||
{
|
||||
logger -s -t smartvpn "$1"
|
||||
}
|
||||
|
||||
# do not destroy ipset(mwan3 firewall rule still need it)
|
||||
smartvpn_ipset_delete()
|
||||
{
|
||||
|
||||
if [[ "$SOFT" != "soft" ]]; then
|
||||
|
||||
smartvpn_logger "Flush ipset for host and network segment..."
|
||||
|
||||
ipset flush ip_oversea
|
||||
ipset flush net_oversea
|
||||
|
||||
ipset flush ip_hongkong
|
||||
ipset flush net_hongkong
|
||||
|
||||
ipset flush ip_mainland
|
||||
ipset flush net_mainland
|
||||
fi
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ipset_create(){
|
||||
local _ipset=$1
|
||||
local _type=$2
|
||||
|
||||
ipset list | grep $_ipset > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
ipset create $_ipset hash:$_type >/dev/null 2>&1
|
||||
else
|
||||
[[ "$3" == "hard" ]] && ipset flush $_ipset
|
||||
fi
|
||||
}
|
||||
|
||||
smartvpn_ipset_create()
|
||||
{
|
||||
|
||||
smartvpn_logger "creating ipset for host..."
|
||||
if [[ "$SOFT" = "soft" ]]; then
|
||||
smartvpn_logger "soft mode: keep ipset for host"
|
||||
fi
|
||||
|
||||
if [[ $vpn_status == "on" && "$SOFT" != "hard" ]];
|
||||
then
|
||||
smartvpn_logger "SmartVPN already on, try a soft restart..."
|
||||
fi
|
||||
|
||||
ipset_create ip_oversea ip $SOFT
|
||||
ipset_create ip_hongkong ip $SOFT
|
||||
ipset_create ip_mainland ip $SOFT
|
||||
|
||||
ipset_create net_oversea net
|
||||
ipset_create net_hongkong net
|
||||
ipset_create net_mainland net
|
||||
}
|
||||
|
||||
smartvpn_ipset_add_by_file()
|
||||
{
|
||||
local _ipfile=$1
|
||||
local _ipset_name=$2
|
||||
|
||||
smartvpn_logger "add network segments to ipset $_ipset_name."
|
||||
cat $_ipfile | while read line
|
||||
do
|
||||
if [ -n "$line" ]; then
|
||||
ipset add $_ipset_name $line >/dev/null 2>&1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
dnsmasq_conf_path="/etc/dnsmasq.d/"
|
||||
smartdns_conf_path="/etc/smartvpn/"
|
||||
|
||||
smartvpn_enable()
|
||||
{
|
||||
|
||||
# 根据proxy.txt生成dnsmasq配置
|
||||
gensmartdns.sh "/etc/smartvpn/proxy_oversea.txt" "/tmp/dm_oversea.conf" "/tmp/smartvpn_ip.txt" "ip_oversea" "8.8.8.8" > /dev/null 2>&1
|
||||
if [ -f /etc/smartvpn/user_oversea.txt ]; then
|
||||
gensmartdns.sh "/etc/smartvpn/user_oversea.txt" "/tmp/dm_oversea.conf" "/tmp/smartvpn_ip.txt" "ip_oversea" "8.8.8.8" append > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
|
||||
[ -f /tmp/smartvpn_ip.txt ] && {
|
||||
smartvpn_ipset_add_by_file /tmp/smartvpn_ip.txt net_oversea
|
||||
hostlist_not_null=1
|
||||
rm /tmp/smartvpn_ip.txt
|
||||
}
|
||||
|
||||
gensmartdns.sh "/etc/smartvpn/proxy_hongkong.txt" "/tmp/dm_hongkong.conf" "/tmp/smartvpn_ip.txt" "ip_hongkong" "1.1.1.1" > /dev/null 2>&1
|
||||
if [ -f /etc/smartvpn/user_hongkong.txt ]; then
|
||||
gensmartdns.sh "/etc/smartvpn/user_hongkong.txt" "/tmp/dm_hongkong.conf" "/tmp/smartvpn_ip.txt" "ip_hongkong" "1.1.1.1" append > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
[ -f /tmp/smartvpn_ip.txt ] && {
|
||||
smartvpn_ipset_add_by_file /tmp/smartvpn_ip.txt net_hongkong
|
||||
hostlist_not_null=1
|
||||
rm /tmp/smartvpn_ip.txt
|
||||
}
|
||||
|
||||
gensmartdns.sh "/etc/smartvpn/proxy_mainland.txt" "/tmp/dm_mainland.conf" "/tmp/smartvpn_ip.txt" "ip_mainland" $DNS_MAINLAND > /dev/null 2>&1
|
||||
if [ -f /etc/smartvpn/user_mainland.txt ]; then
|
||||
gensmartdns.sh "/etc/smartvpn/user_mainland.txt" "/tmp/dm_mainland.conf" "/tmp/smartvpn_ip.txt" "ip_mainland" $DNS_MAINLAND append > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
[ -f /tmp/smartvpn_ip.txt ] && {
|
||||
smartvpn_ipset_add_by_file /tmp/smartvpn_ip.txt net_mainland
|
||||
hostlist_not_null=1
|
||||
rm /tmp/smartvpn_ip.txt
|
||||
}
|
||||
|
||||
smartvpn_ipset_create # 创建ipset
|
||||
|
||||
# 把dnsmasq配置文件拷贝到 /etc/dnsmasq.d 目录下
|
||||
cp -p /tmp/dm_oversea.conf /tmp/dnsmasq.d
|
||||
cp -p /tmp/dm_hongkong.conf /tmp/dnsmasq.d
|
||||
cp -p /tmp/dm_mainland.conf /tmp/dnsmasq.d
|
||||
rm /tmp/dm_oversea.conf
|
||||
rm /tmp/dm_hongkong.conf
|
||||
rm /tmp/dm_mainland.conf
|
||||
|
||||
smartvpn_logger "Restarting dnsmasq..."
|
||||
/etc/init.d/dnsmasq restart # 重启nsmasq
|
||||
|
||||
sleep 3
|
||||
|
||||
smartvpn_logger "Restarting mwan3..."
|
||||
/etc/init.d/mwan3 restart > /dev/null 2>&1
|
||||
}
|
||||
|
||||
smartvpn_open()
|
||||
{
|
||||
if [ $softether_status == "stop" ];
|
||||
then
|
||||
smartvpn_logger "softether not start! can not enable smartvpn."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# ifdown lanman
|
||||
# ifdown vpnhub01
|
||||
# ifdown vpnhub02
|
||||
|
||||
ifup lanman
|
||||
ifup vpnhub01
|
||||
ifup vpnhub02
|
||||
|
||||
network_is_up lanman
|
||||
if [ $? -ne 0 ]; then
|
||||
smartvpn_logger "softether tap interface is missing."
|
||||
return 2
|
||||
fi
|
||||
|
||||
smartvpn_enable
|
||||
|
||||
smartvpn_logger "SmartVPN is on!"
|
||||
echo
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
smartvpn_close()
|
||||
{
|
||||
# smartvpn_logger "Stoping mwan3..."
|
||||
# /etc/init.d/mwan3 stop > /dev/null 2>&1
|
||||
|
||||
smartvpn_ipset_delete
|
||||
rm /tmp/dnsmasq.d/dm_oversea.conf >/dev/null 2>&1
|
||||
rm /tmp/dnsmasq.d/dm_hongkong.conf >/dev/null 2>&1
|
||||
rm /tmp/dnsmasq.d/dm_mainland.conf >/dev/null 2>&1
|
||||
|
||||
smartvpn_logger "Restarting dnsmasq..."
|
||||
/etc/init.d/dnsmasq restart # 重启nsmasq
|
||||
|
||||
sleep 3
|
||||
|
||||
smartvpn_logger "Restarting mwan3..."
|
||||
/etc/init.d/mwan3 restart > /dev/null 2>&1
|
||||
|
||||
smartvpn_logger "SmartVPN is off!"
|
||||
echo
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
smartvpn_status()
|
||||
{
|
||||
local _savefile="/etc/smartvpn/user_ipset.sav"
|
||||
|
||||
if [ $softether_status == "stop" ]; then
|
||||
echo "VPN service is missing"
|
||||
else
|
||||
network_is_up lanman
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "VPN tunnel is missing ($SMARTVPN_VER)"
|
||||
else
|
||||
if [ $vpn_status == "on" ]; then
|
||||
echo "SmartVPN is ON ($SMARTVPN_VER)"
|
||||
else
|
||||
echo "SmartVPN is OFF ($SMARTVPN_VER)"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $vpn_status == "on" ]; then
|
||||
|
||||
mlip=`ipset list ip_mainland | grep "Number of entries" | awk '{print $4}'`
|
||||
hkip=`ipset list ip_hongkong | grep "Number of entries" | awk '{print $4}'`
|
||||
osip=`ipset list ip_oversea | grep "Number of entries" | awk '{print $4}'`
|
||||
|
||||
saved_mlip=0
|
||||
saved_hkip=0
|
||||
saved_osip=0
|
||||
|
||||
if [ -f $_savefile ]; then
|
||||
saved_mlip=`grep "add ip_mainland" $_savefile | wc -l`
|
||||
saved_hkip=`grep "add ip_hongkong" $_savefile | wc -l`
|
||||
saved_osip=`grep "add ip_oversea" $_savefile | wc -l`
|
||||
fi
|
||||
|
||||
if [[ "$SHORT" == "short" ]]; then
|
||||
echo "match $mlip (snapshot: $saved_mlip)"
|
||||
echo "match $hkip (snapshot: $saved_hkip)"
|
||||
echo "match $osip (snapshot: $saved_osip)"
|
||||
else
|
||||
echo "Mainland ip match $mlip (snapshot: $saved_mlip)"
|
||||
echo "Hongkong ip match $hkip (snapshot: $saved_hkip)"
|
||||
echo "Oversea ip macth $osip (snapshot: $saved_osip)"
|
||||
fi
|
||||
|
||||
else
|
||||
echo "-"
|
||||
echo "-"
|
||||
echo "-"
|
||||
fi
|
||||
|
||||
cd /usr/share/smartvpn
|
||||
. ./conf/network.conf
|
||||
echo "${SMARTVPN_USERID:-NoUser} (netid=${SMARTVPN_NETID:-null})"
|
||||
}
|
||||
|
||||
smartvpn_saveipset()
|
||||
{
|
||||
local _savefile="/etc/smartvpn/user_ipset.sav"
|
||||
|
||||
echo "Saving ipset to $_savefile"
|
||||
ipset save net_hongkong > $_savefile
|
||||
ipset save ip_hongkong >> $_savefile
|
||||
ipset save net_oversea >> $_savefile
|
||||
ipset save ip_oversea >> $_savefile
|
||||
ipset save ip_mainland >> $_savefile
|
||||
ipset save net_mainland >> $_savefile
|
||||
}
|
||||
|
||||
smartvpn_restoreipset()
|
||||
{
|
||||
|
||||
local _savefile="/etc/smartvpn/user_ipset.sav"
|
||||
|
||||
echo "Restoring ipset from $_savefile"
|
||||
ipset restore -! < $_savefile
|
||||
}
|
||||
|
||||
|
||||
|
||||
vpn_status_get()
|
||||
{
|
||||
if [ -f /tmp/dnsmasq.d/dm_oversea.conf ]; then
|
||||
vpn_status="on"
|
||||
else
|
||||
vpn_status="off"
|
||||
fi
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
softether_status_get()
|
||||
{
|
||||
__tmpPID=$(ps | grep "vpnserver" | grep -v "grep vpnserver" | awk '{print $1}' 2>/dev/null)
|
||||
|
||||
if [[ -n "$__tmpPID" ]]; then
|
||||
softether_status="start"
|
||||
else
|
||||
softether_status="stop"
|
||||
fi
|
||||
return
|
||||
}
|
||||
|
||||
smartvpn_usage()
|
||||
{
|
||||
echo "usage: smartvpn.sh status"
|
||||
echo " smartvpn.sh on [hard] # hard -- start with clean ipset"
|
||||
echo " smartvpn.sh off [soft] # soft -- keep ipset in memory"
|
||||
echo " smartvpn.sh save|restore"
|
||||
echo ""
|
||||
echo "softether status = $softether_status"
|
||||
echo "smartvpn status = $vpn_status"
|
||||
echo ""
|
||||
return
|
||||
}
|
||||
|
||||
# main
|
||||
|
||||
vpn_status_get
|
||||
softether_status_get
|
||||
|
||||
config_load "smartvpn"
|
||||
config_get VPN_ENABLE global vpn_enable 0
|
||||
config_get DNS_MAINLAND global dns_mainland 119.29.29.29
|
||||
|
||||
OPT=$1
|
||||
SOFT=$2
|
||||
SHORT=$2
|
||||
|
||||
case $OPT in
|
||||
on)
|
||||
if [[ ! -z "$SOFT" && "$SOFT" != "hard" ]]; then
|
||||
echo "***Error*** second parameter only support 'hard'"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
on|off)
|
||||
if [[ ! -z "$SOFT" && "$SOFT" != "soft" ]]; then
|
||||
echo "***Error*** second parameter only support 'soft'"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
smartvpn_lock="/var/run/smartvpn.lock"
|
||||
smartvpn_work="/var/run/smartvpn.work"
|
||||
trap "lock -u $smartvpn_lock; rm ${smartvpn_work}; exit 2" SIGHUP SIGINT SIGTERM
|
||||
lock $smartvpn_lock
|
||||
echo $$ > ${smartvpn_work}
|
||||
|
||||
retval=0
|
||||
|
||||
case $OPT in
|
||||
on)
|
||||
grep 'declare Cascade0' /usr/libexec/softethervpn/vpn_server.config > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "***Error*** The vpnserver dose not setup with upstream connection"
|
||||
retval=3
|
||||
else
|
||||
smartvpn_open
|
||||
retval=$?
|
||||
fi
|
||||
;;
|
||||
|
||||
off)
|
||||
smartvpn_close
|
||||
retval=$?
|
||||
;;
|
||||
|
||||
status)
|
||||
smartvpn_status
|
||||
retval=$?
|
||||
;;
|
||||
|
||||
save)
|
||||
if [ $vpn_status == "on" ]; then
|
||||
smartvpn_saveipset
|
||||
retval=$?
|
||||
else
|
||||
echo "***Error*** SmartVPN service is not enabled"
|
||||
retval=2
|
||||
fi
|
||||
;;
|
||||
|
||||
restore)
|
||||
if [ $vpn_status == "on" ]; then
|
||||
smartvpn_restoreipset
|
||||
retval=$?
|
||||
else
|
||||
echo "***Error*** SmartVPN service is not enabled"
|
||||
retval=2
|
||||
fi
|
||||
;;
|
||||
|
||||
status)
|
||||
smartvpn_status
|
||||
retval=$?
|
||||
;;
|
||||
|
||||
*)
|
||||
smartvpn_usage
|
||||
retval=$?
|
||||
;;
|
||||
esac
|
||||
|
||||
rm ${smartvpn_work}
|
||||
lock -u $smartvpn_lock
|
||||
|
||||
exit $retval
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"admin/network/smartvpn": {
|
||||
"title": "SmartVPN",
|
||||
"order": "500",
|
||||
"action": {
|
||||
"type": "alias",
|
||||
"path": "admin/network/smartvpn/overview"
|
||||
},
|
||||
"depends": {
|
||||
"fs": {
|
||||
"/usr/sbin/smartvpn.sh": "executable",
|
||||
"/etc/init.d/smartvpn": "executable"
|
||||
},
|
||||
"uci": { "smartvpn": true }
|
||||
}
|
||||
},
|
||||
"admin/services/smartvpn/overview": {
|
||||
"title": "Overview",
|
||||
"order": 10,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "smartvpn/overview"
|
||||
}
|
||||
},
|
||||
"admin/services/smartvpn/mainland": {
|
||||
"title": "Mainland hosts",
|
||||
"order": 20,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "smartvpn/mainland"
|
||||
}
|
||||
},
|
||||
"admin/services/smartvpn/hongkong": {
|
||||
"title": "Hongkong hosts",
|
||||
"order": 30,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "smartvpn/hongkong"
|
||||
}
|
||||
},
|
||||
"admin/services/smartvpn/oversea": {
|
||||
"title": "Oversea hosts",
|
||||
"order": 40,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "smartvpn/oversea"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"luci-app-smartvpn": {
|
||||
"description": "Grant access to LuCI app smartvpn",
|
||||
"write": {
|
||||
"uci": [ "smartvpn" ],
|
||||
"cgi-io": [ "upload" ],
|
||||
"file": {
|
||||
"/etc/smartvpn/user*": [ "write" ],
|
||||
"/tmp/smartvpn.userconf": [ "write" ]
|
||||
}
|
||||
},
|
||||
"read": {
|
||||
"uci": [ "smartvpn" ],
|
||||
"cgi-io": [ "download", "exec" ],
|
||||
"file": {
|
||||
"/etc/smartvpn/user*": [ "read" ],
|
||||
"/usr/sbin/smartvpn.sh *": [ "exec" ],
|
||||
"/etc/init.d/smartvpn *" : [ "exec" ],
|
||||
"/usr/share/smartvpn/userconfig *" : [ "exec" ],
|
||||
"/var/run/smartvpn.work" : [ "read" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
# SmartVPN firewall configuration
|
||||
|
||||
# defaults(确认defaults存在,属性覆盖设置,否则提示错误)
|
||||
SMARTVPN_FW_DEFAULT_INPUT='REJECT'
|
||||
SMARTVPN_FW_DEFAULT_OUTPUT='ACCEPT'
|
||||
SMARTVPN_FW_DEFAULT_FORWARD='REJECT'
|
||||
SMARTVPN_FW_DEFAULT_SYNFLOOD='1'
|
||||
|
||||
# zone
|
||||
# zone lan(确认lan区域存在, 属性覆盖,否则不更新,否则提示错误)
|
||||
SMARTVPN_FW_LAN_NAME='lan'
|
||||
SMARTVPN_FW_LAN_IF='lan'
|
||||
SMARTVPN_FW_LAN_INPUT='ACCEPT'
|
||||
SMARTVPN_FW_LAN_OUTPUT='ACCEPT'
|
||||
SMARTVPN_FW_LAN_FORWARD='ACCEPT'
|
||||
# zone wan(需确认wan区域存在,属性覆盖,否则提示错误)
|
||||
SMARTVPN_FW_WAN_NAME='wan'
|
||||
SMARTVPN_FW_WAN_IF='wan wan6 vpnhub01 vpnhub02'
|
||||
SMARTVPN_FW_WAN_INPUT='REJECT'
|
||||
SMARTVPN_FW_WAN_OUTPUT='ACCEPT'
|
||||
SMARTVPN_FW_WAN_FORWARD='ACCEPT'
|
||||
SMARTVPN_FW_WAN_MASQ='1'
|
||||
SMARTVPN_FW_WAN_MTU='1'
|
||||
# zone lanman(删除后添加)
|
||||
SMARTVPN_FW_LANMAN_NAME='lanman'
|
||||
SMARTVPN_FW_LANMAN_IF='lanman'
|
||||
SMARTVPN_FW_LANMAN_INPUT='ACCEPT'
|
||||
SMARTVPN_FW_LANMAN_OUTPUT='ACCEPT'
|
||||
SMARTVPN_FW_LANMAN_FORWARD='ACCEPT'
|
||||
|
||||
# forwarding
|
||||
# lan转发(删除后添加)
|
||||
SMARTVPN_FW_LAN_WAN_FORWARD_SRC='lan'
|
||||
SMARTVPN_FW_LAN_WAN_FORWARD_DEST='wan'
|
||||
# lanman转发(删除后添加)
|
||||
SMARTVPN_FW_LAN_LANMAN_FORWARD_SRC='lan'
|
||||
SMARTVPN_FW_LAN_LANMAN_FORWARD_DEST='lanman'
|
||||
SMARTVPN_FW_LANMAN_LAN_FORWARD_SRC='lanman'
|
||||
SMARTVPN_FW_LANMAN_LAN_FORWARD_DEST='lan'
|
||||
# wan转发(删除后添加)
|
||||
SMARTVPN_FW_WAN_LANMAN_FORWARD_SRC='wan'
|
||||
SMARTVPN_FW_WAN_LANMAN_FORWARD_DEST='lanman'
|
||||
SMARTVPN_FW_LANMAN_WAN_FORWARD_SRC='lanman'
|
||||
SMARTVPN_FW_LANMAN_WAN_FORWARD_DEST='wan'
|
||||
|
||||
# rule
|
||||
# 允许VPN接入(删除后添加)
|
||||
SMARTVPN_FW_IPSEC_NAME='Allow-IPSec-ESP'
|
||||
SMARTVPN_FW_IPSEC_SRC='wan'
|
||||
SMARTVPN_FW_IPSEC_DEST='lan'
|
||||
SMARTVPN_FW_IPSEC_PROTO='esp'
|
||||
SMARTVPN_FW_IPSEC_TARGET='ACCEPT'
|
||||
# 允许VPN接入(删除后添加)
|
||||
SMARTVPN_FW_ISAKMP_NAME='Allow-ISAKMP'
|
||||
SMARTVPN_FW_ISAKMP_SRC='wan'
|
||||
SMARTVPN_FW_ISAKMP_DEST='lan'
|
||||
SMARTVPN_FW_ISAKMP_PROTO='udp'
|
||||
SMARTVPN_FW_ISAKMP_DEST_PORT='500'
|
||||
SMARTVPN_FW_ISAKMP_TARGET='ACCEPT'
|
||||
# 允许局域网访问WAN(删除后添加)
|
||||
SMARTVPN_FW_PRIVATE_NAME='Allow-PrivateNet'
|
||||
SMARTVPN_FW_PRIVATE_SRC='wan'
|
||||
SMARTVPN_FW_PRIVATE_SRC_IP='192.168.0.0/16'
|
||||
SMARTVPN_FW_PRIVATE_TARGET='ACCEPT'
|
||||
# 允许访问SoftEther(删除后添加)
|
||||
SMARTVPN_FW_SEMAN_NAME='Allow-SEMAN'
|
||||
SMARTVPN_FW_SEMAN_SRC='wan'
|
||||
SMARTVPN_FW_SEMAN_DEST_PORT='1193-1197'
|
||||
SMARTVPN_FW_SEMAN_TARGET='ACCEPT'
|
||||
# 允许UDP加速(删除后添加)
|
||||
SMARTVPN_FW_SEUDP_NAME='Allow-SEUDP'
|
||||
SMARTVPN_FW_SEUDP_SRC='wan'
|
||||
SMARTVPN_FW_SEUDP_PROTO='udp'
|
||||
SMARTVPN_FW_SEUDP_DEST_PORT='40000-40015'
|
||||
SMARTVPN_FW_SEUDP_TARGET='ACCEPT'
|
||||
@@ -0,0 +1,77 @@
|
||||
# SmartVPN network configuration
|
||||
|
||||
SMARTVPN_USERID='test-user'
|
||||
SMARTVPN_NETID= # 为空时无论如何都不修改lan的ip
|
||||
SMARTVPN_SECONFIG='/etc/smartvpn/myvpn.config'
|
||||
|
||||
[[ -f ./conf/user.conf ]] && source ./conf/user.conf
|
||||
[[ -f /etc/smartvpn/user.conf ]] && source /etc/smartvpn/user.conf
|
||||
|
||||
# network common
|
||||
SMARTVPN_NETSEG='192.168'
|
||||
SMARTVPN_NETMASK='255.255.255.0'
|
||||
SMARTVPN_MANSEG='28'
|
||||
SMARTVPN_HUB01SEG='27'
|
||||
SMARTVPN_HUB01GW='192.168.27.2' # 香港加速出口
|
||||
SMARTVPN_HUB02SEG='29'
|
||||
SMARTVPN_HUB02GW='192.168.29.1' # 默认海外出口
|
||||
|
||||
# interface name for R2S/R4S
|
||||
SMARTVPN_WAN_IF='eth0'
|
||||
SMARTVPN_LAN_IF='eth1'
|
||||
|
||||
# interface name defination
|
||||
SMARTVPN_MAN_IF='tap_manhub'
|
||||
SMARTVPN_MY_IF='tap_myhub'
|
||||
SMARTVPN_HUB01_IF='tap_hub01'
|
||||
SMARTVPN_HUB02_IF='tap_hub02'
|
||||
|
||||
# 修改lan(需确lan存在,且认类型为bridge,否则不更新,提示错误)
|
||||
# 提供用户保护局域网ip的选项?
|
||||
SMARTVPN_LAN_NAME='lan'
|
||||
SMARTVPN_LAN_ADDR_IP4="$SMARTVPN_NETSEG.$SMARTVPN_NETID.1"
|
||||
SMARTVPN_LAN_DNS_IP4="$SMARTVPN_LAN_ADDR_IP4"
|
||||
SMARTVPN_LAN_MASK_IP4="$SMARTVPN_NETMASK"
|
||||
SMARTVPN_LAN_IFNAME="$SMARTVPN_LAN_IF $SMARTVPN_MY_IF"
|
||||
SMARTVPN_LAN_METRIC='0'
|
||||
|
||||
# 增加lanman(先删除后增加)
|
||||
SMARTVPN_LANMAN_NAME='lanman'
|
||||
SMARTVPN_LANMAN_IF="$SMARTVPN_MAN_IF"
|
||||
[[ -n "$SMARTVPN_NETID" ]] && SMARTVPN_LANMAN_PROTO='static' || SMARTVPN_LANMAN_PROTO='none'
|
||||
SMARTVPN_LANMAN_AUTO='0'
|
||||
SMARTVPN_LANMAN_FOURCE_LINK='0'
|
||||
SMARTVPN_LANMAN_ADDR_IP4=${SMARTVPN_NETID:+$SMARTVPN_NETSEG.$SMARTVPN_MANSEG.$SMARTVPN_NETID}
|
||||
SMARTVPN_LANMAN_MASK_IP4=${SMARTVPN_NETID:+$SMARTVPN_NETMASK}
|
||||
|
||||
# 增加vpnhub01(先删除后增加)
|
||||
SMARTVPN_HUB01_NAME='vpnhub01'
|
||||
SMARTVPN_HUB01_IF="$SMARTVPN_HUB01_IF"
|
||||
[[ -n "$SMARTVPN_NETID" ]] && SMARTVPN_HUB01_PROTO='static' || SMARTVPN_HUB01_PROTO='none'
|
||||
SMARTVPN_HUB01_AUTO='0'
|
||||
SMARTVPN_HUB01_FOURCE_LINK='0'
|
||||
SMARTVPN_HUB01_ADDR_IP4=${SMARTVPN_NETID:+$SMARTVPN_NETSEG.$SMARTVPN_HUB01SEG.$SMARTVPN_NETID}
|
||||
SMARTVPN_HUB01_MASK_IP4=${SMARTVPN_NETID:+$SMARTVPN_NETMASK}
|
||||
SMARTVPN_HUB01_GATEWAY_IP4="$SMARTVPN_HUB01GW"
|
||||
SMARTVPN_HUB01_METRIC='200'
|
||||
|
||||
# 增加vpnhub02(先删除后增加)
|
||||
SMARTVPN_HUB02_NAME='vpnhub02'
|
||||
SMARTVPN_HUB02_IF="$SMARTVPN_HUB02_IF"
|
||||
[[ -n "$SMARTVPN_NETID" ]] && SMARTVPN_HUB02_PROTO='static' || SMARTVPN_HUB02_PROTO='none'
|
||||
SMARTVPN_HUB02_AUTO='0'
|
||||
SMARTVPN_HUB02_FOURCE_LINK='0'
|
||||
SMARTVPN_HUB02_ADDR_IP4=${SMARTVPN_NETID:+$SMARTVPN_NETSEG.$SMARTVPN_HUB02SEG.$SMARTVPN_NETID}
|
||||
SMARTVPN_HUB02_MASK_IP4=${SMARTVPN_NETID:+$SMARTVPN_NETMASK}
|
||||
SMARTVPN_HUB02_GATEWAY_IP4="$SMARTVPN_HUB02GW"
|
||||
SMARTVPN_HUB02_METRIC='300'
|
||||
|
||||
# 增加vpnhub01静态路由(先删除后增加,接口和目的IP一直)
|
||||
SMARTVPN_ROUTE_DNS01_IF="$SMARTVPN_HUB01_NAME"
|
||||
SMARTVPN_ROUTE_DNS01_TG='1.1.1.1'
|
||||
SMARTVPN_ROUTE_DNS01_GW="$SMARTVPN_HUB01_GATEWAY_IP4"
|
||||
|
||||
# 增加vpnhub02静态路由(先删除后增加,接口和目的IP一直)
|
||||
SMARTVPN_ROUTE_DNS02_IF="$SMARTVPN_HUB02_NAME"
|
||||
SMARTVPN_ROUTE_DNS02_TG='8.8.8.8'
|
||||
SMARTVPN_ROUTE_DNS02_GW="$SMARTVPN_HUB02_GATEWAY_IP4"
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,2 @@
|
||||
# net 网段格式: xxx.xxx.xxx.xxx/yy
|
||||
# domain 域名格式: 必须以点开头
|
||||
@@ -0,0 +1,2 @@
|
||||
#netxxx.xxx.xxx.xxxyy
|
||||
#domain
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,175 @@
|
||||
|
||||
config statistics 'collectd'
|
||||
option BaseDir '/var/run/collectd'
|
||||
option Include '/etc/collectd/conf.d'
|
||||
option PIDFile '/var/run/collectd.pid'
|
||||
option PluginDir '/usr/lib/collectd'
|
||||
option TypesDB '/usr/share/collectd/types.db'
|
||||
option Interval '30'
|
||||
option ReadThreads '2'
|
||||
|
||||
config statistics 'rrdtool'
|
||||
option default_timespan '1hour'
|
||||
option image_width '600'
|
||||
option image_path '/tmp/rrdimg'
|
||||
|
||||
config statistics 'collectd_rrdtool'
|
||||
option enable '1'
|
||||
option RRASingle '1'
|
||||
option DataDir '/opt/rrd'
|
||||
option RRATimespans '1hour 1day 1week 1month 1year'
|
||||
option RRARows '144'
|
||||
|
||||
config statistics 'collectd_cpu'
|
||||
option enable '1'
|
||||
option ReportByCpu '1'
|
||||
option ReportByState '1'
|
||||
option ValuesPercentage '1'
|
||||
|
||||
config statistics 'collectd_load'
|
||||
option enable '1'
|
||||
|
||||
config statistics 'collectd_memory'
|
||||
option enable '1'
|
||||
option ValuesAbsolute '1'
|
||||
option ValuesPercentage '0'
|
||||
|
||||
config statistics 'collectd_thermal'
|
||||
option enable '1'
|
||||
option IgnoreSelected '0'
|
||||
option Device 'thermal_zone0'
|
||||
|
||||
config statistics 'collectd_interface'
|
||||
option enable '1'
|
||||
option IgnoreSelected '0'
|
||||
option Interfaces 'eth0 tap_myhub tap_hub01 tap_hub02'
|
||||
|
||||
config statistics 'collectd_uptime'
|
||||
option enable '0'
|
||||
|
||||
config statistics 'collectd_csv'
|
||||
option enable '0'
|
||||
option StoreRates '0'
|
||||
option DataDir '/tmp'
|
||||
|
||||
config statistics 'collectd_email'
|
||||
option enable '0'
|
||||
option SocketFile '/var/run/collectd/email.sock'
|
||||
option SocketGroup 'nogroup'
|
||||
|
||||
config statistics 'collectd_logfile'
|
||||
option enable '0'
|
||||
option LogLevel 'notice'
|
||||
option File '/var/log/collectd.log'
|
||||
option Timestamp '1'
|
||||
|
||||
config statistics 'collectd_network'
|
||||
option enable '0'
|
||||
|
||||
config statistics 'collectd_unixsock'
|
||||
option enable '0'
|
||||
option SocketFile '/var/run/collectd/query.sock'
|
||||
option SocketGroup 'nogroup'
|
||||
|
||||
config statistics 'collectd_apcups'
|
||||
option enable '0'
|
||||
option Host 'localhost'
|
||||
option Port '3551'
|
||||
|
||||
config statistics 'collectd_conntrack'
|
||||
option enable '0'
|
||||
|
||||
config statistics 'collectd_contextswitch'
|
||||
option enable '0'
|
||||
|
||||
config statistics 'collectd_cpufreq'
|
||||
option enable '0'
|
||||
|
||||
config statistics 'collectd_curl'
|
||||
option enable '0'
|
||||
|
||||
config statistics 'collectd_df'
|
||||
option enable '0'
|
||||
option Devices '/dev/mtdblock/4'
|
||||
option MountPoints '/jffs'
|
||||
option FSTypes 'tmpfs'
|
||||
option IgnoreSelected '0'
|
||||
|
||||
config statistics 'collectd_disk'
|
||||
option enable '0'
|
||||
option Disks 'hda1 hdb'
|
||||
option IgnoreSelected '0'
|
||||
|
||||
config statistics 'collectd_dns'
|
||||
option enable '0'
|
||||
option Interfaces 'br-lan'
|
||||
option IgnoreSources '127.0.0.1'
|
||||
|
||||
config statistics 'collectd_entropy'
|
||||
option enable '0'
|
||||
|
||||
config statistics 'collectd_exec'
|
||||
option enable '0'
|
||||
|
||||
config statistics 'collectd_iptables'
|
||||
option enable '0'
|
||||
|
||||
config collectd_iptables_match
|
||||
option table 'nat'
|
||||
option chain 'luci_fw_postrouting'
|
||||
option target 'MASQUERADE'
|
||||
option source '192.168.1.0/24'
|
||||
option outputif 'br-ff'
|
||||
option name 'LAN-Clients traffic'
|
||||
|
||||
config collectd_iptables_match
|
||||
option chain 'luci_fw_postrouting'
|
||||
option table 'nat'
|
||||
option target 'MASQUERADE'
|
||||
option source '10.61.230.0/24'
|
||||
option outputif 'br-ff'
|
||||
option name 'WLAN-Clients traffic'
|
||||
|
||||
config statistics 'collectd_irq'
|
||||
option enable '0'
|
||||
option Irqs '2 3 4 7'
|
||||
|
||||
config statistics 'collectd_iwinfo'
|
||||
option enable '1'
|
||||
|
||||
config statistics 'collectd_netlink'
|
||||
option enable '0'
|
||||
option IgnoreSelected '0'
|
||||
option VerboseInterfaces 'br-lan'
|
||||
option QDiscs 'br-lan'
|
||||
|
||||
config statistics 'collectd_nut'
|
||||
option enable '0'
|
||||
list UPS 'myupsname'
|
||||
|
||||
config statistics 'collectd_olsrd'
|
||||
option enable '0'
|
||||
option Port '2006'
|
||||
option Host '127.0.0.1'
|
||||
|
||||
config statistics 'collectd_ping'
|
||||
option enable '0'
|
||||
option TTL '127'
|
||||
option Interval '30'
|
||||
option Hosts '127.0.0.1'
|
||||
|
||||
config statistics 'collectd_processes'
|
||||
option enable '0'
|
||||
option Processes 'uhttpd dnsmasq dropbear'
|
||||
|
||||
config statistics 'collectd_sensors'
|
||||
option enable '0'
|
||||
|
||||
config statistics 'collectd_splash_leases'
|
||||
option enable '0'
|
||||
|
||||
config statistics 'collectd_tcpconns'
|
||||
option enable '0'
|
||||
option ListeningPorts '0'
|
||||
option LocalPorts '22 80'
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
|
||||
config rule 'mainland_ip'
|
||||
option proto 'all'
|
||||
option sticky '0'
|
||||
option ipset 'ip_mainland'
|
||||
option use_policy 'default'
|
||||
|
||||
config rule 'mainland_net'
|
||||
option proto 'all'
|
||||
option sticky '0'
|
||||
option ipset 'net_mainland'
|
||||
option use_policy 'default'
|
||||
|
||||
config rule 'hongkong_ip'
|
||||
option proto 'all'
|
||||
option sticky '0'
|
||||
option ipset 'ip_hongkong'
|
||||
option use_policy 'hongkong'
|
||||
|
||||
config rule 'hongkong_net'
|
||||
option proto 'all'
|
||||
option sticky '0'
|
||||
option ipset 'net_hongkong'
|
||||
option use_policy 'hongkong'
|
||||
|
||||
config rule 'oversea_ip'
|
||||
option proto 'all'
|
||||
option sticky '0'
|
||||
option ipset 'ip_oversea'
|
||||
option use_policy 'oversea'
|
||||
|
||||
config rule 'oversea_net'
|
||||
option proto 'all'
|
||||
option sticky '0'
|
||||
option ipset 'net_oversea'
|
||||
option use_policy 'oversea'
|
||||
|
||||
config globals 'globals'
|
||||
option mmx_mask '0x3F00'
|
||||
option rtmon_interval '5'
|
||||
|
||||
config interface 'vpnhub01'
|
||||
option initial_state 'online'
|
||||
option family 'ipv4'
|
||||
option track_method 'ping'
|
||||
option reliability '1'
|
||||
option count '1'
|
||||
option size '56'
|
||||
option max_ttl '60'
|
||||
option check_quality '0'
|
||||
option timeout '2'
|
||||
option interval '5'
|
||||
option failure_interval '5'
|
||||
option recovery_interval '5'
|
||||
option down '3'
|
||||
option up '3'
|
||||
option enabled '1'
|
||||
|
||||
config interface 'vpnhub02'
|
||||
option initial_state 'online'
|
||||
option family 'ipv4'
|
||||
option track_method 'ping'
|
||||
option reliability '1'
|
||||
option count '1'
|
||||
option size '56'
|
||||
option max_ttl '60'
|
||||
option check_quality '0'
|
||||
option timeout '2'
|
||||
option interval '5'
|
||||
option failure_interval '5'
|
||||
option recovery_interval '5'
|
||||
option down '3'
|
||||
option up '3'
|
||||
option enabled '1'
|
||||
|
||||
config member 'hub01'
|
||||
option interface 'vpnhub01'
|
||||
|
||||
config member 'hub02'
|
||||
option interface 'vpnhub02'
|
||||
|
||||
config policy 'hongkong'
|
||||
list use_member 'hub01'
|
||||
option last_resort 'unreachable'
|
||||
|
||||
config policy 'oversea'
|
||||
list use_member 'hub02'
|
||||
option last_resort 'unreachable'
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
config nlbwmon
|
||||
option netlink_buffer_size '524288'
|
||||
option commit_interval '24h'
|
||||
option refresh_interval '30s'
|
||||
option database_generations '10'
|
||||
option database_interval '1'
|
||||
option database_limit '10000'
|
||||
option protocol_database '/usr/share/nlbwmon/protocols'
|
||||
option database_directory '/opt/nlbwmon'
|
||||
list local_network 'lan'
|
||||
list local_network 'wan'
|
||||
@@ -0,0 +1,68 @@
|
||||
1 0 ICMP
|
||||
2 0 IGMP
|
||||
4 0 IP-in-IP
|
||||
6 20 FTP
|
||||
6 21 FTP
|
||||
6 22 SSH
|
||||
6 23 Telnet
|
||||
6 25 SMTP
|
||||
6 53 DNS
|
||||
17 53 DNS
|
||||
6 80 HTTP
|
||||
17 80 QUIC
|
||||
6 109 POP2
|
||||
6 110 POP3
|
||||
6 123 NTP
|
||||
6 137 NetBIOS
|
||||
6 138 NetBIOS
|
||||
6 139 NetBIOS
|
||||
17 137 NetBIOS
|
||||
17 138 NetBIOS
|
||||
6 143 IMAP
|
||||
6 220 IMAP3
|
||||
6 443 HTTPS
|
||||
17 443 QUIC
|
||||
6 445 SMB-over-TCP
|
||||
6 853 DNS-over-TLS
|
||||
17 853 DNS-over-TLS
|
||||
6 989 FTPS
|
||||
6 990 FTPS
|
||||
6 993 IMAPS
|
||||
6 995 POP3S
|
||||
6 3389 Microsoft RDP
|
||||
17 3389 Microsoft RDP
|
||||
6 5222 XMPP
|
||||
6 5223 Apple Push Service
|
||||
6 5228 Google Cloud Messaging
|
||||
17 5353 mDNS
|
||||
6 5355 LLMNR
|
||||
17 5355 LLMNR
|
||||
41 0 IPv6-in-IP
|
||||
47 0 GRE
|
||||
50 0 ESP
|
||||
51 0 AH
|
||||
58 0 IPv6-ICMP
|
||||
94 0 IPIP
|
||||
115 0 L2TPv3
|
||||
6 1193 seVPN
|
||||
6 1194 seVPN
|
||||
6 1197 seVPN
|
||||
17 1193 seVPN-UDP
|
||||
17 1194 seVPN-UDP
|
||||
17 1197 seVPN-UDP
|
||||
17 40000 seVPN-UDP
|
||||
17 40001 seVPN-UDP
|
||||
17 40002 seVPN-UDP
|
||||
17 40003 seVPN-UDP
|
||||
17 40004 seVPN-UDP
|
||||
17 40005 seVPN-UDP
|
||||
17 40006 seVPN-UDP
|
||||
17 40007 seVPN-UDP
|
||||
17 40008 seVPN-UDP
|
||||
17 40009 seVPN-UDP
|
||||
17 40010 seVPN-UDP
|
||||
17 40011 seVPN-UDP
|
||||
17 40012 seVPN-UDP
|
||||
17 40013 seVPN-UDP
|
||||
17 40014 seVPN-UDP
|
||||
17 40015 seVPN-UDP
|
||||
File diff suppressed because it is too large.
Load diff
+594
@@ -0,0 +1,594 @@
|
||||
#!/bin/sh
|
||||
|
||||
############################################
|
||||
# smartvpn configuration scrip
|
||||
# create by Daniel Yang 2021-07-22
|
||||
############################################
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/network.sh
|
||||
|
||||
cd "$( dirname $0 )"
|
||||
|
||||
. ./conf/network.conf
|
||||
. ./conf/firewall.conf
|
||||
|
||||
smartvpn_logger()
|
||||
{
|
||||
logger -s -t smartvpn "$1"
|
||||
}
|
||||
|
||||
process_network_firewall() {
|
||||
|
||||
# processing network lan interface(modify only)
|
||||
config_cb() {
|
||||
local stype="$1"
|
||||
local sname="$2"
|
||||
if [[ "$stype" == "interface" && "$sname" == "$SMARTVPN_LAN_NAME" ]]; then
|
||||
|
||||
echo
|
||||
smartvpn_logger "Processing: network lan interface"
|
||||
|
||||
if [[ "$SET_LOCALIP" == 1 && -n "$SMARTVPN_NETID" ]]; then
|
||||
smartvpn_logger " -- setting lan ip by config"
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.$sname.ipaddr="$SMARTVPN_LAN_ADDR_IP4"
|
||||
set network.$sname.netmask="$SMARTVPN_LAN_MASK_IP4"
|
||||
set network.$sname.dns="$SMARTVPN_LAN_DNS_IP4"
|
||||
set network.$sname.device="$SMARTVPN_LAN_IFNAME"
|
||||
commit network
|
||||
EOF
|
||||
else
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set network.$sname.device="$SMARTVPN_LAN_IFNAME"
|
||||
commit network
|
||||
EOF
|
||||
fi
|
||||
uci show network.$sname
|
||||
|
||||
fi
|
||||
}
|
||||
config_load network
|
||||
reset_cb
|
||||
|
||||
# process vpn tap interface (replace if already exists)
|
||||
echo
|
||||
smartvpn_logger "Processing: vpn tap interface"
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete network.$SMARTVPN_LANMAN_NAME
|
||||
set network.$SMARTVPN_LANMAN_NAME=interface
|
||||
set network.$SMARTVPN_LANMAN_NAME.device="$SMARTVPN_LANMAN_IF"
|
||||
set network.$SMARTVPN_LANMAN_NAME.proto="$SMARTVPN_LANMAN_PROTO"
|
||||
set network.$SMARTVPN_LANMAN_NAME.auto="$SMARTVPN_LANMAN_AUTO"
|
||||
set network.$SMARTVPN_LANMAN_NAME.netmask="$SMARTVPN_LANMAN_MASK_IP4"
|
||||
set network.$SMARTVPN_LANMAN_NAME.force_link="$SMARTVPN_LANMAN_FOURCE_LINK"
|
||||
set network.$SMARTVPN_LANMAN_NAME.ipaddr="$SMARTVPN_LANMAN_ADDR_IP4"
|
||||
commit network
|
||||
EOF
|
||||
#smartvpn_logger "seting tap interface: $SMARTVPN_LANMAN_NAME"
|
||||
uci show network.$SMARTVPN_LANMAN_NAME
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete network.$SMARTVPN_HUB01_NAME
|
||||
set network.$SMARTVPN_HUB01_NAME=interface
|
||||
set network.$SMARTVPN_HUB01_NAME.device="$SMARTVPN_HUB01_IF"
|
||||
set network.$SMARTVPN_HUB01_NAME.proto="$SMARTVPN_HUB01_PROTO"
|
||||
set network.$SMARTVPN_HUB01_NAME.auto="$SMARTVPN_HUB01_AUTO"
|
||||
set network.$SMARTVPN_HUB01_NAME.netmask="$SMARTVPN_HUB01_MASK_IP4"
|
||||
set network.$SMARTVPN_HUB01_NAME.force_link="$SMARTVPN_HUB01_FOURCE_LINK"
|
||||
set network.$SMARTVPN_HUB01_NAME.ipaddr="$SMARTVPN_HUB01_ADDR_IP4"
|
||||
set network.$SMARTVPN_HUB01_NAME.metric="$SMARTVPN_HUB01_METRIC"
|
||||
set network.$SMARTVPN_HUB01_NAME.gateway="$SMARTVPN_HUB01_GATEWAY_IP4"
|
||||
commit network
|
||||
EOF
|
||||
#smartvpn_logger "seting tap interface: $SMARTVPN_HUB01_NAME"
|
||||
uci show network.$SMARTVPN_HUB01_NAME
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete network.$SMARTVPN_HUB02_NAME
|
||||
set network.$SMARTVPN_HUB02_NAME=interface
|
||||
set network.$SMARTVPN_HUB02_NAME.device="$SMARTVPN_HUB02_IF"
|
||||
set network.$SMARTVPN_HUB02_NAME.proto="$SMARTVPN_HUB02_PROTO"
|
||||
set network.$SMARTVPN_HUB02_NAME.auto="$SMARTVPN_HUB02_AUTO"
|
||||
set network.$SMARTVPN_HUB02_NAME.netmask="$SMARTVPN_HUB02_MASK_IP4"
|
||||
set network.$SMARTVPN_HUB02_NAME.force_link="$SMARTVPN_HUB02_FOURCE_LINK"
|
||||
set network.$SMARTVPN_HUB02_NAME.ipaddr="$SMARTVPN_HUB02_ADDR_IP4"
|
||||
set network.$SMARTVPN_HUB02_NAME.metric="$SMARTVPN_HUB02_METRIC"
|
||||
set network.$SMARTVPN_HUB02_NAME.gateway="$SMARTVPN_HUB02_GATEWAY_IP4"
|
||||
commit network
|
||||
EOF
|
||||
#smartvpn_logger "seting tap interface: $SMARTVPN_HUB02_NAME"
|
||||
uci show network.$SMARTVPN_HUB02_NAME
|
||||
|
||||
# processing network static route(replace if already exist)
|
||||
delete_route() {
|
||||
local config="$1"
|
||||
local rttarget
|
||||
|
||||
config_get rttarget "$config" target
|
||||
if [[ "$rttarget" == "1.1.1.1" || "$rttarget" == "8.8.8.8" ]]; then
|
||||
smartvpn_logger "Old route target $rttarget found, deleting..."
|
||||
uci delete network.$config
|
||||
#smartvpn_logger "session: $config"
|
||||
fi
|
||||
}
|
||||
echo
|
||||
smartvpn_logger "Processing: network static route"
|
||||
config_load network
|
||||
config_foreach delete_route route
|
||||
uci commit network
|
||||
smartvpn_logger "Adding static route for 1.1.1.1 and 8.8.8.8"
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
add network route
|
||||
set network.@route[-1].target=$SMARTVPN_ROUTE_DNS01_TG
|
||||
set network.@route[-1].gateway=$SMARTVPN_ROUTE_DNS01_GW
|
||||
set network.@route[-1].interface=$SMARTVPN_ROUTE_DNS01_IF
|
||||
add network route
|
||||
set network.@route[-1].target=$SMARTVPN_ROUTE_DNS02_TG
|
||||
set network.@route[-1].gateway=$SMARTVPN_ROUTE_DNS02_GW
|
||||
set network.@route[-1].interface=$SMARTVPN_ROUTE_DNS02_IF
|
||||
commit network
|
||||
EOF
|
||||
|
||||
# process firewall defauls
|
||||
config_cb() {
|
||||
local stype="$1"
|
||||
local sname="$2"
|
||||
if [[ "$stype" == "defaults" ]]; then
|
||||
echo
|
||||
smartvpn_logger "Processing: firewall zone defaults"
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set firewall.$sname.input="$SMARTVPN_FW_DEFAULT_INPUT"
|
||||
set firewall.$sname.output="$SMARTVPN_FW_DEFAULT_OUTPUT"
|
||||
set firewall.$sname.forward="$SMARTVPN_FW_DEFAULT_FORWARD"
|
||||
set firewall.$sname.synflood_protect="$SMARTVPN_FW_DEFAULT_SYNFLOOD"
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$sname
|
||||
fi
|
||||
}
|
||||
config_load firewall
|
||||
reset_cb
|
||||
|
||||
# processing firewall zones
|
||||
handle_zone() {
|
||||
local config="$1"
|
||||
local zname
|
||||
config_get zname "$config" name
|
||||
|
||||
if [[ "$zname" == "$SMARTVPN_FW_LAN_NAME" ]]; then
|
||||
smartvpn_logger "Updating zone $zname($config) setting"
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set firewall.$config.network="$SMARTVPN_FW_LAN_IF"
|
||||
set firewall.$config.input="$SMARTVPN_FW_LAN_INPUT"
|
||||
set firewall.$config.output="$SMARTVPN_FW_LAN_OUTPUT"
|
||||
set firewall.$config.forward="$SMARTVPN_FW_LAN_FORWARD"
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
elif [[ "$zname" == "$SMARTVPN_FW_WAN_NAME" ]]; then
|
||||
smartvpn_logger "Updating zone $zname($config) setting"
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set firewall.$config.network="$SMARTVPN_FW_WAN_IF"
|
||||
set firewall.$config.input="$SMARTVPN_FW_WAN_INPUT"
|
||||
set firewall.$config.output="$SMARTVPN_FW_WAN_OUTPUT"
|
||||
set firewall.$config.forward="$SMARTVPN_FW_WAN_FORWARD"
|
||||
set firewall.$config.masq="$SMARTVPN_FW_WAN_MASQ"
|
||||
set firewall.$config.mtu_fix="$SMARTVPN_FW_WAN_MTU"
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
elif [[ "$zname" == "$SMARTVPN_FW_LANMAN_NAME" ]]; then
|
||||
smartvpn_logger "Old zone $zname($config) found, delete..."
|
||||
uci delete firewall.$config
|
||||
fi
|
||||
}
|
||||
echo
|
||||
smartvpn_logger "Processing: firewall zones"
|
||||
config_load firewall
|
||||
config_foreach handle_zone zone
|
||||
uci commit firewall
|
||||
smartvpn_logger "Adding zone $SMARTVPN_FW_LANMAN_NAME"
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall zone
|
||||
set firewall.@zone[-1].name=$SMARTVPN_FW_LANMAN_NAME
|
||||
set firewall.@zone[-1].network=$SMARTVPN_FW_LANMAN_IF
|
||||
set firewall.@zone[-1].input=$SMARTVPN_FW_LANMAN_INPUT
|
||||
set firewall.@zone[-1].output=$SMARTVPN_FW_LANMAN_OUTPUT
|
||||
set firewall.@zone[-1].forward=$SMARTVPN_FW_LANMAN_FORWARD
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
|
||||
# processing firewall forwarding rule
|
||||
handle_forwarding() {
|
||||
local config="$1"
|
||||
local dest
|
||||
local src
|
||||
config_get dest "$config" dest
|
||||
config_get src "$config" src
|
||||
|
||||
if [[ "$dest" == "$SMARTVPN_FW_LAN_WAN_FORWARD_DEST" && "$src" == "$SMARTVPN_FW_LAN_WAN_FORWARD_SRC" ]]; then
|
||||
smartvpn_logger "Old forwarding rule $src->$dest found, deleting"
|
||||
uci delete firewall.$config
|
||||
elif [[ "$dest" == "$SMARTVPN_FW_LAN_LANMAN_FORWARD_DEST" && "$src" == "$SMARTVPN_FW_LAN_LANMAN_FORWARD_SRC" ]]; then
|
||||
smartvpn_logger "Old forwarding rule $src->$dest found, deleting"
|
||||
uci delete firewall.$config
|
||||
elif [[ "$dest" == "$SMARTVPN_FW_LANMAN_LAN_FORWARD_DEST" && "$src" == "$SMARTVPN_FW_LANMAN_LAN_FORWARD_SRC" ]]; then
|
||||
smartvpn_logger "Old forwarding rule $src->$dest found, deleting"
|
||||
uci delete firewall.$config
|
||||
elif [[ "$dest" == "$SMARTVPN_FW_WAN_LANMAN_FORWARD_DEST" && "$src" == "$SMARTVPN_FW_WAN_LANMAN_FORWARD_SRC" ]]; then
|
||||
smartvpn_logger "Old forwarding rule $src->$dest found, deleting"
|
||||
uci delete firewall.$config
|
||||
elif [[ "$dest" == "$SMARTVPN_FW_LANMAN_WAN_FORWARD_DEST" && "$src" == "$SMARTVPN_FW_LANMAN_WAN_FORWARD_SRC" ]]; then
|
||||
smartvpn_logger "Old forwarding rule $src->$dest found, deleting"
|
||||
uci delete firewall.$config
|
||||
fi
|
||||
}
|
||||
echo
|
||||
smartvpn_logger "Processing: firewall forwarding rule"
|
||||
config_load firewall
|
||||
config_foreach handle_forwarding forwarding
|
||||
uci commit firewall
|
||||
smartvpn_logger "Adding forwarding rule for lan->wan and lan<->lanman"
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall forwarding
|
||||
set firewall.@forwarding[-1].dest=$SMARTVPN_FW_LAN_WAN_FORWARD_DEST
|
||||
set firewall.@forwarding[-1].src=$SMARTVPN_FW_LAN_WAN_FORWARD_SRC
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall forwarding
|
||||
set firewall.@forwarding[-1].dest=$SMARTVPN_FW_LAN_LANMAN_FORWARD_DEST
|
||||
set firewall.@forwarding[-1].src=$SMARTVPN_FW_LAN_LANMAN_FORWARD_SRC
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall forwarding
|
||||
set firewall.@forwarding[-1].dest=$SMARTVPN_FW_LANMAN_LAN_FORWARD_DEST
|
||||
set firewall.@forwarding[-1].src=$SMARTVPN_FW_LANMAN_LAN_FORWARD_SRC
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall forwarding
|
||||
set firewall.@forwarding[-1].dest=$SMARTVPN_FW_WAN_LANMAN_FORWARD_DEST
|
||||
set firewall.@forwarding[-1].src=$SMARTVPN_FW_WAN_LANMAN_FORWARD_SRC
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall forwarding
|
||||
set firewall.@forwarding[-1].dest=$SMARTVPN_FW_LANMAN_WAN_FORWARD_DEST
|
||||
set firewall.@forwarding[-1].src=$SMARTVPN_FW_LANMAN_WAN_FORWARD_SRC
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
|
||||
# processing firewall wan access rule
|
||||
handle_rule() {
|
||||
local config="$1"
|
||||
local src
|
||||
local dest
|
||||
local dest_port
|
||||
local proto
|
||||
local name
|
||||
|
||||
config_get src "$config" src "x"
|
||||
config_get dest "$config" dest "x"
|
||||
config_get dest_port "$config" dest_port "x"
|
||||
config_get proto "$config" proto "x"
|
||||
config_get name "$config" name "x"
|
||||
|
||||
if [[ "$name" == "$SMARTVPN_FW_SEMAN_NAME" ]]; then
|
||||
smartvpn_logger "Old $SMARTVPN_FW_SEMAN_NAME($config) rule found, deleting"
|
||||
uci delete firewall.$config
|
||||
elif [[ "$name" == "$SMARTVPN_FW_SEUDP_NAME" ]]; then
|
||||
smartvpn_logger "Old $SMARTVPN_FW_SEUDP_NAME($config) rule found, deleting"
|
||||
uci delete firewall.$config
|
||||
elif [[ "$name" == "$SMARTVPN_FW_PRIVATE_NAME" ]]; then
|
||||
smartvpn_logger "Old $SMARTVPN_FW_PRIVATE_NAME($config) rule found, deleting"
|
||||
uci delete firewall.$config
|
||||
elif [[ "$dest" == "$SMARTVPN_FW_IPSEC_DEST" && "$src" == "$SMARTVPN_FW_IPSEC_SRC" && "$proto" == "$SMARTVPN_FW_IPSEC_PROTO" ]]; then
|
||||
smartvpn_logger "Old $SMARTVPN_FW_IPSEC_NAME($config) rulefound, deleting"
|
||||
uci delete firewall.$config
|
||||
elif [[ "$dest" == "$SMARTVPN_FW_ISAKMP_DEST" && "$src" == "$SMARTVPN_FW_ISAKMP_SRC" && "$dest_port" == "$SMARTVPN_FW_ISAKMP_DEST_PORT" ]]; then
|
||||
smartvpn_logger "Old $SMARTVPN_FW_ISAKMP_NAME($config) rule found, deleting"
|
||||
uci delete firewall.$config
|
||||
fi
|
||||
}
|
||||
echo
|
||||
smartvpn_logger "Processing: firewall wan access rule"
|
||||
config_load firewall
|
||||
config_foreach handle_rule rule
|
||||
uci commit firewall
|
||||
smartvpn_logger "Adding new $SMARTVPN_FW_IPSEC_NAME rule"
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall rule
|
||||
set firewall.@rule[-1].name="$SMARTVPN_FW_IPSEC_NAME"
|
||||
set firewall.@rule[-1].src="$SMARTVPN_FW_IPSEC_SRC"
|
||||
set firewall.@rule[-1].dest="$SMARTVPN_FW_IPSEC_DEST"
|
||||
set firewall.@rule[-1].proto="$SMARTVPN_FW_IPSEC_PROTO"
|
||||
set firewall.@rule[-1].target="$SMARTVPN_FW_IPSEC_TARGET"
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
smartvpn_logger "Adding new $SMARTVPN_FW_ISAKMP_NAME rule"
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall rule
|
||||
set firewall.@rule[-1].name="$SMARTVPN_FW_ISAKMP_NAME"
|
||||
set firewall.@rule[-1].src="$SMARTVPN_FW_ISAKMP_SRC"
|
||||
set firewall.@rule[-1].dest="$SMARTVPN_FW_ISAKMP_DEST"
|
||||
set firewall.@rule[-1].proto="$SMARTVPN_FW_ISAKMP_PROTO"
|
||||
set firewall.@rule[-1].dest_port="$SMARTVPN_FW_ISAKMP_DEST_PORT"
|
||||
set firewall.@rule[-1].target="$SMARTVPN_FW_ISAKMP_TARGET"
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
smartvpn_logger "Adding new $SMARTVPN_FW_PRIVATE_NAME rule"
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall rule
|
||||
set firewall.@rule[-1].name="$SMARTVPN_FW_PRIVATE_NAME"
|
||||
set firewall.@rule[-1].src="$SMARTVPN_FW_PRIVATE_SRC"
|
||||
set firewall.@rule[-1].src_ip="$SMARTVPN_FW_PRIVATE_SRC_IP"
|
||||
set firewall.@rule[-1].target="$SMARTVPN_FW_PRIVATE_TARGET"
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
smartvpn_logger "Adding new $SMARTVPN_FW_SEMAN_NAME rule"
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall rule
|
||||
set firewall.@rule[-1].name="$SMARTVPN_FW_SEMAN_NAME"
|
||||
set firewall.@rule[-1].src="$SMARTVPN_FW_SEMAN_SRC"
|
||||
set firewall.@rule[-1].dest_port="$SMARTVPN_FW_SEMAN_DEST_PORT"
|
||||
set firewall.@rule[-1].target="$SMARTVPN_FW_SEMAN_TARGET"
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
smartvpn_logger "Adding new $SMARTVPN_FW_SEUDP_NAME rule"
|
||||
config=`uci -q batch` <<-EOF
|
||||
add firewall rule
|
||||
set firewall.@rule[-1].name="$SMARTVPN_FW_SEUDP_NAME"
|
||||
set firewall.@rule[-1].src="$SMARTVPN_FW_SEUDP_SRC"
|
||||
set firewall.@rule[-1].proto="$SMARTVPN_FW_SEUDP_PROTO"
|
||||
set firewall.@rule[-1].dest_port="$SMARTVPN_FW_SEUDP_DEST_PORT"
|
||||
set firewall.@rule[-1].target="$SMARTVPN_FW_SEUDP_TARGET"
|
||||
commit firewall
|
||||
EOF
|
||||
uci show firewall.$config
|
||||
|
||||
}
|
||||
|
||||
check_installed_package(){
|
||||
local _packagename=$1
|
||||
_tmpPackage=$(opkg list-installed | grep "$_packagename" | awk '{print $1}' 2>/dev/null)
|
||||
if [[ -z "$_tmpPackage" ]]; then
|
||||
smartvpn_logger "package $_packagename is missing"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
check_env(){
|
||||
check_installed_package dnsmasq-full && check_installed_package softethervpn-server \
|
||||
&& check_installed_package mwan3 && check_installed_package luci-app-smartvpn
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
smartvpn_logger "Error: required package is missing. Config abort!"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
SMARTVPN_BACKUP_DIR=/etc/smartvpn/backup
|
||||
backup_file(){
|
||||
local ifname=$1
|
||||
local bfname=$( basename $ifname )
|
||||
local today=$( date +%Y%m%d )
|
||||
local num=0
|
||||
local prefix=''
|
||||
local ofname
|
||||
|
||||
[[ ! -d $SMARTVPN_BACKUP_DIR ]] && mkdir $SMARTVPN_BACKUP_DIR
|
||||
|
||||
ofname=$SMARTVPN_BACKUP_DIR/$bfname
|
||||
while [ -e $ofname ]; do
|
||||
num=$(( $num + 1 ))
|
||||
prefix=$( printf '%s-%03d-' $today $num )
|
||||
ofname=$SMARTVPN_BACKUP_DIR/$prefix$bfname
|
||||
done
|
||||
[[ -e $SMARTVPN_BACKUP_DIR/$bfname ]] && mv $SMARTVPN_BACKUP_DIR/$bfname $ofname
|
||||
cp -p $ifname $SMARTVPN_BACKUP_DIR/$bfname
|
||||
}
|
||||
|
||||
config_vpnserver(){
|
||||
local new_config_file=$1
|
||||
smartvpn_logger "Stoping vpnserver"
|
||||
/etc/init.d/softethervpnserver stop
|
||||
sleep 2
|
||||
backup_file /usr/libexec/softethervpn/vpn_server.config
|
||||
cp -p $new_config_file /usr/libexec/softethervpn/vpn_server.config
|
||||
smartvpn_logger "Starting vpnserver"
|
||||
/etc/init.d/softethervpnserver start
|
||||
sleep 3
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
echo
|
||||
echo "Usage: smartvpnconfig.sh --norestart --lanip [all] [network] [mwan3] [nlbwmon] [statistics] [vpnserver] [domain]"
|
||||
echo
|
||||
echo "command:"
|
||||
echo " all: config all settings (use --localip)"
|
||||
echo " network: resotre network setting (use --localip)"
|
||||
echo " mwan3: restore mwan3 setting"
|
||||
echo " nlbwmon: restore nlbwmon setting"
|
||||
echo " statistics: restore luci-statisitics setting"
|
||||
echo " vpnserver: restore vpnserver setting"
|
||||
echo " domain: restore system domain setting(mainland/hongkong/oversea)"
|
||||
echo "optionn:"
|
||||
echo " --lanip: set route's LAN by user config file (works with 'network' command)"
|
||||
echo " --norestart: do not restart SmartVPN when config is done"
|
||||
echo
|
||||
return
|
||||
}
|
||||
|
||||
action=""
|
||||
SET_LOCALIP=0
|
||||
DO_NOT_RESTART=0
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
case $1 in
|
||||
network|mwan3|nlbwmon|statistics|vpnserver|domain)
|
||||
action="$action $1"
|
||||
;;
|
||||
|
||||
all)
|
||||
action="network mwan3 nlbwmon statistics vpnserver domain"
|
||||
;;
|
||||
|
||||
--lanip)
|
||||
SET_LOCALIP=1
|
||||
;;
|
||||
|
||||
--norestart)
|
||||
DO_NOT_RESTART=1
|
||||
;;
|
||||
|
||||
*)
|
||||
echo
|
||||
smartvpn_logger "Error: unrecognized command or option"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ -z "$action" ]]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# echo "Action: $action"
|
||||
|
||||
# 检查安装环境
|
||||
check_env
|
||||
|
||||
smartvpn_lock="/var/run/smartvpn.lock"
|
||||
smartvpn_work="/var/run/smartvpn.work"
|
||||
trap "lock -u $smartvpn_lock; rm $smartvpn_work; exit 2" SIGHUP SIGINT SIGTERM
|
||||
lock $smartvpn_lock
|
||||
echo $$ > ${smartvpn_work}
|
||||
|
||||
case $action in
|
||||
*vpnserver*)
|
||||
if [[ -f ./service/vpn_server.config || -f $SMARTVPN_SECONFIG ]]; then
|
||||
|
||||
echo
|
||||
if [[ -f $SMARTVPN_SECONFIG ]]; then
|
||||
smartvpn_logger "Setting vpnserver with user specific config..."
|
||||
config_vpnserver $SMARTVPN_SECONFIG
|
||||
else
|
||||
grep 'declare Cascade0' /usr/libexec/softethervpn/vpn_server.config > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
smartvpn_logger "Current vpnserver has upstream connection defined, can not be replace with system dufault config!"
|
||||
action=${action//vpnserver/}
|
||||
else
|
||||
smartvpn_logger "Setting vpnserver with system default config(no upstream connection)..."
|
||||
config_vpnserver ./service/vpn_server.config
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo
|
||||
smartvpn_logger "Can not find config file for vpnserver!!!"
|
||||
action=${action//vpnserver/}
|
||||
fi
|
||||
esac
|
||||
|
||||
case $action in
|
||||
*network*)
|
||||
config_load network
|
||||
config_get lan2rt_ifname lan2rt ifname
|
||||
echo
|
||||
if [[ -n "$lan2rt_ifname" ]]; then
|
||||
smartvpn_logger "This is a side router, network config skipped!!!"
|
||||
action=${action//network/}
|
||||
else
|
||||
backup_file /etc/config/network
|
||||
backup_file /etc/config/firewall
|
||||
process_network_firewall
|
||||
smartvpn_logger "Restarting network..."
|
||||
/etc/init.d/network restart
|
||||
sleep 2
|
||||
fi
|
||||
esac
|
||||
|
||||
case $action in
|
||||
*nlbwmon*)
|
||||
echo
|
||||
smartvpn_logger "Updating nlbwmon config..."
|
||||
backup_file /etc/config/nlbwmon
|
||||
backup_file /usr/share/nlbwmon/protocols
|
||||
cp -p ./service/nlbwmon /etc/config/nlbwmon
|
||||
cp -p ./service/protocols /usr/share/nlbwmon/protocols
|
||||
smartvpn_logger "Restarting nlbwmon service..."
|
||||
/etc/init.d/nlbwmon restart
|
||||
esac
|
||||
|
||||
case $action in
|
||||
*statistics*)
|
||||
echo
|
||||
smartvpn_logger "Updating luci_statistics config..."
|
||||
backup_file /etc/config/luci_statistics
|
||||
cp -p ./service/luci_statistics /etc/config/luci_statistics
|
||||
smartvpn_logger "Restarting luci_statistics service..."
|
||||
/etc/init.d/collectd restart
|
||||
/etc/init.d/luci_statistics restart
|
||||
rm -f /tmp/luci-indexcache*
|
||||
rm -rf /tmp/luci-modulecache/
|
||||
esac
|
||||
|
||||
case $action in
|
||||
*mwan3*)
|
||||
echo
|
||||
smartvpn_logger "Updating mwan3 to config..."
|
||||
backup_file /etc/config/mwan3
|
||||
cp -p ./service/mwan3 /etc/config/mwan3
|
||||
esac
|
||||
|
||||
case $action in
|
||||
*domain*)
|
||||
echo
|
||||
smartvpn_logger "Updating system mainland domain..."
|
||||
backup_file /etc/smartvpn/proxy_mainland.txt
|
||||
cp -p ./proxy/proxy_mainland.txt /etc/smartvpn/proxy_mainland.txt
|
||||
|
||||
echo
|
||||
smartvpn_logger "Updating system hongkong domain..."
|
||||
backup_file /etc/smartvpn/proxy_hongkong.txt
|
||||
cp -p ./proxy/proxy_hongkong.txt /etc/smartvpn/proxy_hongkong.txt
|
||||
|
||||
echo
|
||||
smartvpn_logger "Updating system oversea domain..."
|
||||
backup_file /etc/smartvpn/proxy_oversea.txt
|
||||
cp -p ./proxy/proxy_oversea.txt /etc/smartvpn/proxy_oversea.txt
|
||||
;;
|
||||
esac
|
||||
|
||||
rm ${smartvpn_work}
|
||||
lock -u $smartvpn_lock
|
||||
|
||||
if [[ "$DO_NOT_RESTART" == 0 ]]; then
|
||||
case $action in
|
||||
*mwan3*|*domain*|*network*|*vpnserver*)
|
||||
echo
|
||||
smartvpn_logger "Restarting SmartVPN..."
|
||||
/etc/init.d/smartvpn restart
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "--- Config is done ---"
|
||||
exit 0
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"config": "smartvpn",
|
||||
"init": "smartvpn"
|
||||
}
|
||||
Reference in new issue
Block a user