mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-02-12 10:31:51 +00:00
Add backup to VPS interface and simplify IPv6 enable/disable
This commit is contained in:
parent
e9556c107c
commit
88706de9b2
9 changed files with 142 additions and 116 deletions
|
@ -19,6 +19,8 @@ function index()
|
|||
entry({"admin", "system", "openmptcprouter", "settings"}, template("openmptcprouter/settings"), _("Advanced Settings"), 3).leaf = true
|
||||
entry({"admin", "system", "openmptcprouter", "settings_add"}, post("settings_add")).leaf = true
|
||||
entry({"admin", "system", "openmptcprouter", "update_vps"}, post("update_vps")).leaf = true
|
||||
entry({"admin", "system", "openmptcprouter", "backup"}, template("openmptcprouter/backup"), _("Backup on server"), 3).leaf = true
|
||||
entry({"admin", "system", "openmptcprouter", "backupgr"}, post("backupgr")).leaf = true
|
||||
entry({"admin", "system", "openmptcprouter", "debug"}, template("openmptcprouter/debug"), _("Show all settings"), 5).leaf = true
|
||||
end
|
||||
|
||||
|
@ -263,9 +265,10 @@ function wizard_add()
|
|||
ucic:commit("network")
|
||||
|
||||
-- Enable/disable IPv6
|
||||
local disable_ipv6 = luci.http.formvalue("enableipv6") or "1"
|
||||
local ut = require "luci.util"
|
||||
local result = ut.ubus("openmptcprouter", "set_ipv6_state", { disable_ipv6 = disable_ipv6 })
|
||||
local disableipv6 = luci.http.formvalue("enableipv6") or "1"
|
||||
ucic:set("openmptcprouter","settings","disable_ipv6",disable_ipv6)
|
||||
--local ut = require "luci.util"
|
||||
--local result = ut.ubus("openmptcprouter", "set_ipv6_state", { disable_ipv6 = disableipv6 })
|
||||
|
||||
-- Get VPN set by default
|
||||
local default_vpn = luci.http.formvalue("default_vpn") or "glorytun_tcp"
|
||||
|
@ -699,6 +702,17 @@ function update_vps()
|
|||
end
|
||||
end
|
||||
|
||||
function backupgr()
|
||||
local get_backup = luci.http.formvalue("restore") or ""
|
||||
if get_backup ~= "" then
|
||||
luci.sys.call("/etc/init.d/openmptcprouter-vps backup_get >/dev/null 2>/dev/null")
|
||||
end
|
||||
local send_backup = luci.http.formvalue("save") or ""
|
||||
if send_backup ~= "" then
|
||||
luci.sys.call("/etc/init.d/openmptcprouter-vps backup_send >/dev/null 2>/dev/null")
|
||||
end
|
||||
end
|
||||
|
||||
function get_device(interface)
|
||||
local dump = require("luci.util").ubus("network.interface.%s" % interface, "status", {})
|
||||
return dump['l3_device']
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<%+header%>
|
||||
|
||||
<% if stderr and #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
|
||||
<form class="inline" method="post" action="<%=url('admin/system/openmptcprouter/backupgr')%>">
|
||||
<div class="cbi-map">
|
||||
<h2 name="content"><%:Backup on server%></h2>
|
||||
<fieldset class="cbi-section" id="networks">
|
||||
<%
|
||||
uci:foreach("openmptcprouter","server", function(s)
|
||||
servername = s[".name"]
|
||||
%>
|
||||
<h3><%=servername%></h3>
|
||||
<%
|
||||
if luci.model.uci.cursor():get("openmptcprouter",servername,"lastbackup") ~= "" then
|
||||
%>
|
||||
<div class="cbi-section-node">
|
||||
<%:Last available backup on server:%> <%=os.date('%d-%b-%Y', luci.model.uci.cursor():get("openmptcprouter",servername,"lastbackup"))%>
|
||||
</div>
|
||||
<input type="hidden" name="token" value="<%=token%>" />
|
||||
<input type="submit" class="cbi-button cbi-button-action important" name="restore" value="<%:Restore backup%>"/>
|
||||
<input type="submit" class="cbi-button cbi-button-action important" name="save" value="<%:Send backup%>"/>
|
||||
<% else %>
|
||||
<div class="cbi-section-node">
|
||||
<%:No available backup on server.%>
|
||||
</div>
|
||||
<input type="hidden" name="token" value="<%=token%>" />
|
||||
<input type="submit" class="cbi-button cbi-button-action important" name="save" value="<%:Send backup%>"/>
|
||||
<% end %>
|
||||
<%
|
||||
end)
|
||||
%>
|
||||
</fieldset>
|
||||
</div>
|
||||
</form>
|
||||
<%+footer%>
|
|
@ -1,12 +1,10 @@
|
|||
<%+header%>
|
||||
|
||||
<% if stderr and #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
|
||||
<form class="inline" method="post" action="<%=url('admin/system/openmptcprouter/update_vps')%>">
|
||||
<div class="cbi-map">
|
||||
<h2 name="content"><%:All router settings%></h2>
|
||||
<div class="cbi-section">
|
||||
<pre><%=luci.sys.exec("uci show")%></pre>
|
||||
</div>
|
||||
<div class="cbi-map">
|
||||
<h2 name="content"><%:All router settings%></h2>
|
||||
<div class="cbi-section">
|
||||
<pre><%=luci.sys.exec("uci show")%></pre>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<%+footer%>
|
||||
|
|
|
@ -33,40 +33,6 @@ omr_intf_set() {
|
|||
fi
|
||||
}
|
||||
|
||||
set_ipv6_state() {
|
||||
local disable_ipv6=$1
|
||||
local sysctl_ipv6=0
|
||||
sysctl -w net.ipv6.conf.all.disable_ipv6=$sysctl_ipv6
|
||||
sed -i 's:^net.ipv6.conf.all.disable_ipv6=[0-9]*:net.ipv6.conf.all.disable_ipv6=$sysctl_ipv6:' /etc/sysctl.d/zzz_openmptcprouter.conf
|
||||
|
||||
uci -q set firewall.@defaults[0].disable_ipv6=$disable_ipv6
|
||||
uci -q commit firewall
|
||||
|
||||
if [ "$disable_ipv6" == "1" ]; then
|
||||
uci -q set dhcp.lan.ra_default="0"
|
||||
uci -q set network.lan.ipv6="0"
|
||||
uci -q delete network.lan.ipv6
|
||||
uci -q delete dhcp.lan.dhcpv6
|
||||
uci -q delete dhcp.lan.ra
|
||||
uci -q delete dhcp.lan.ra_default
|
||||
uci -q delete dhcp.lan.ra_preference
|
||||
uci -q set shadowsocks-libev.hi.local_address="0.0.0.0"
|
||||
else
|
||||
uci -q set dhcp.lan.ra_default="1"
|
||||
uci -q set dhcp.lan.ra_preference="high"
|
||||
uci -q set network.lan.ipv6="1"
|
||||
uci -q set network.lan.delegate="0"
|
||||
uci -q set shadowsocks-libev.hi.local_address="::"
|
||||
fi
|
||||
uci -q commit shadowsocks-libev
|
||||
uci -q commit dhcp
|
||||
uci -q commit network
|
||||
#if [ "$disable_ipv6" == "1" ]; then
|
||||
# /etc/init.d/odhcpd stop >/dev/null 2>&1
|
||||
# /etc/init.d/odhcpd disable >/dev/null 2>&1
|
||||
#fi
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local scaling_min_freq scaling_max_freq
|
||||
|
||||
|
@ -94,11 +60,6 @@ start_service() {
|
|||
echo $scaling_governor > $c/scaling_governor
|
||||
done
|
||||
}
|
||||
config_get disable_ipv6 settings disable_ipv6 "0"
|
||||
if [ "$(uci -q get firewall.@defaults[0].disable_ipv6)" != "$disable_ipv6" ]; then
|
||||
set_ipv6_state $disable_ipv6
|
||||
fi
|
||||
|
||||
# remove sysctl already defined in /etc/sysctl.d/
|
||||
sed -i -e '/tcp_fin_timeout/d' -e '/tcp_keepalive_time/d' -e '/nf_conntrack_max/d' -e '/tcp_syn_retries/d' -e '/tcp_fastopen/d' /etc/sysctl.conf
|
||||
sed -i -e '/tcp_fin_timeout/d' -e '/tcp_keepalive_time/d' -e '/nf_conntrack_max/d' -e '/tcp_syn_retries/d' -e '/tcp_fastopen/d' /etc/sysctl.d/10-default.conf
|
||||
|
|
|
@ -449,7 +449,10 @@ end
|
|||
|
||||
function disableipv6(disable_ipv6)
|
||||
-- Disable IPv6
|
||||
set_ipv6_state(disable_ipv6)
|
||||
ucic:set("openmptcprouter","settings","disable_ipv6",disable_ipv6)
|
||||
ucic:save("openmptcprouter")
|
||||
ucic:commit("openmptcprouter")
|
||||
luci.sys.call("/etc/init.d/omr-6in4 restart >/dev/null 2>/dev/null")
|
||||
end
|
||||
|
||||
function externalcheck(externalcheck)
|
||||
|
@ -1042,7 +1045,7 @@ function interfaces_status()
|
|||
local ipv6_discover = "NONE"
|
||||
if ifname ~= "" and ifname ~= nil and mArray.openmptcprouter["ipv6"] == "enabled" then
|
||||
local ipv6_result = ""
|
||||
--local ipv6_result = _ipv6_discover(ifname)
|
||||
local ipv6_result = _ipv6_discover(ifname)
|
||||
if type(ipv6_result) == "table" and #ipv6_result > 0 then
|
||||
local ipv6_addr_test
|
||||
for k,v in ipairs(ipv6_result) do
|
||||
|
@ -1051,9 +1054,9 @@ function interfaces_status()
|
|||
ipv6_addr_test = sys.exec("ip -6 addr | grep " .. v.RecursiveDnsServer)
|
||||
if ipv6_addr_test == "" then
|
||||
ipv6_discover = "DETECTED"
|
||||
if connectivity == "OK" then
|
||||
connectivity = "WARNING"
|
||||
end
|
||||
--if connectivity == "OK" then
|
||||
-- connectivity = "WARNING"
|
||||
--end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1183,67 +1186,6 @@ function _ipv6_discover(interface)
|
|||
return ra6_result
|
||||
end
|
||||
|
||||
function set_ipv6_state(disable_ipv6)
|
||||
-- Disable/Enable IPv6 support
|
||||
luci.sys.exec("sysctl -qw net.ipv6.conf.all.disable_ipv6=%s" % disable_ipv6)
|
||||
luci.sys.exec("sed -i 's:^net.ipv6.conf.all.disable_ipv6=[0-9]*:net.ipv6.conf.all.disable_ipv6=%s:' /etc/sysctl.d/zzz_openmptcprouter.conf" % disable_ipv6)
|
||||
--luci.sys.exec("sysctl -qw net.ipv6.conf.all.disable_ipv6=" % disable_ipv6)
|
||||
--luci.sys.exec("sed -i 's:^net.ipv6.conf.all.disable_ipv6=[0-9]*:net.ipv6.conf.all.disable_ipv6=0:' /etc/sysctl.d/zzz_openmptcprouter.conf" % disable_ipv6)
|
||||
|
||||
-- Disable/Enable IPv6 for firewall
|
||||
ucic:set("firewall",ucic:get_first("firewall","defaults"),"disable_ipv6",disable_ipv6)
|
||||
ucic:save("firewall")
|
||||
ucic:commit("firewall")
|
||||
|
||||
-- Disable/Enable IPv6 in OpenMPTCProuter settings
|
||||
ucic:set("openmptcprouter","settings","disable_ipv6",disable_ipv6)
|
||||
ucic:save("openmptcprouter")
|
||||
ucic:commit("openmptcprouter")
|
||||
|
||||
-- Disable/Enable route announce of IPv6
|
||||
if disable_ipv6 == "1" then
|
||||
ucic:set("dhcp","lan","ra_default","0")
|
||||
ucic:set("network","lan","ipv6","0")
|
||||
--luci.sys.call("uci -q del network.lan.ipifaceid")
|
||||
else
|
||||
-- ucic:set("dhcp","lan","ra_default","1")
|
||||
ucic:set("network","lan","ipv6","1")
|
||||
ucic:set("network","lan","delegate","0")
|
||||
--ucic:set("network","lan","ipifaceid","random")
|
||||
end
|
||||
ucic:save("network")
|
||||
ucic:commit("network")
|
||||
|
||||
-- Disable/Enable IPv6 DHCP and change Shadowsocks listen address
|
||||
if disable_ipv6 == "1" then
|
||||
luci.sys.call("uci -q del dhcp.lan.dhcpv6")
|
||||
luci.sys.call("uci -q del dhcp.lan.ra")
|
||||
luci.sys.call("uci -q del dhcp.lan.ra_default")
|
||||
luci.sys.call("uci -q del dhcp.lan.ra_management")
|
||||
luci.sys.call("uci -q del dhcp.lan.ra_preference")
|
||||
ucic:set("shadowsocks-libev","hi","local_address","0.0.0.0")
|
||||
else
|
||||
ucic:set("dhcp","lan","dhcpv6","server")
|
||||
ucic:set("dhcp","lan","ra","server")
|
||||
ucic:set("dhcp","lan","ra_default","1")
|
||||
ucic:set("dhcp","lan","ra_preference","high")
|
||||
ucic:set("dhcp","lan","ra_management","1")
|
||||
ucic:set("shadowsocks-libev","hi","local_address","::")
|
||||
end
|
||||
ucic:save("shadowsocks-libev")
|
||||
ucic:commit("shadowsocks-libev")
|
||||
ucic:save("dhcp")
|
||||
ucic:commit("dhcp")
|
||||
luci.sys.exec("/etc/init.d/omr-6in4 restart >/dev/null 2>&1")
|
||||
--if disable_ipv6 == "1" then
|
||||
-- luci.sys.exec("/etc/init.d/odhcpd stop >/dev/null 2>&1")
|
||||
-- luci.sys.exec("/etc/init.d/odhcpd disable >/dev/null 2>&1")
|
||||
--else
|
||||
-- luci.sys.exec("/etc/init.d/odhcpd start >/dev/null 2>&1")
|
||||
-- luci.sys.exec("/etc/init.d/odhcpd enable >/dev/null 2>&1")
|
||||
--end
|
||||
end
|
||||
|
||||
local methods = {
|
||||
status = {
|
||||
call = function()
|
||||
|
|
|
@ -10,8 +10,51 @@
|
|||
USE_PROCD=1
|
||||
}
|
||||
|
||||
set_ipv6_state() {
|
||||
local disable_ipv6="$(uci -q get openmptcprouter.settings.disable_ipv6)"
|
||||
[ -z "$disable_ipv6" ] && disable_ipv6="1"
|
||||
sysctl -w net.ipv6.conf.all.disable_ipv6=$disable_ipv6
|
||||
sed -i 's:^net.ipv6.conf.all.disable_ipv6=[0-9]*:net.ipv6.conf.all.disable_ipv6=$disable_ipv6:' /etc/sysctl.d/zzz_openmptcprouter.conf
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set firewall.@defaults[0].disable_ipv6=$disable_ipv6
|
||||
commit firewall
|
||||
EOF
|
||||
|
||||
if [ "$disable_ipv6" == "1" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set dhcp.lan.ra_default="0"
|
||||
set network.lan.ipv6="0"
|
||||
delete network.lan.ipv6
|
||||
delete dhcp.lan.dhcpv6
|
||||
delete dhcp.lan.ra
|
||||
delete dhcp.lan.ra_default
|
||||
delete dhcp.lan.ra_management
|
||||
delete dhcp.lan.ra_preference
|
||||
set shadowsocks-libev.hi.local_address="0.0.0.0"
|
||||
EOF
|
||||
else
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set dhcp.lan.dhcpv6="server1"
|
||||
set dhcp.lan.ra="server"
|
||||
set dhcp.lan.ra_default="1"
|
||||
set dhcp.lan.ra_preference="high"
|
||||
set dhcp.lan.ra_management="1"
|
||||
set network.lan.ipv6="1"
|
||||
set network.lan.delegate="0"
|
||||
set shadowsocks-libev.hi.local_address="::"
|
||||
EOF
|
||||
fi
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
commit network
|
||||
commit dhcp
|
||||
commit shadowsocks-libev
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
start_service() {
|
||||
[ "$(uci -q get openmptcprouter.settings.disable_ipv6)" != "$(sysctl -w net.ipv6.conf.all.disable_ipv6)" ] && set_ipv6_state
|
||||
[ "$(uci -q get openmptcprouter.settings.disable_ipv6)" = "1" ] && return
|
||||
procd_open_instance
|
||||
# shellcheck disable=SC2086
|
||||
|
|
|
@ -12,6 +12,7 @@ if [ "$(uci -q show network | grep omr6in4)" = "" ]; then
|
|||
set network.omr6in4.peeraddr=10.255.255.1
|
||||
set network.omr6in4.gateway=fe80::a00:1
|
||||
set network.omr6in4.ip6addr=fe80::a00:2
|
||||
set network.omr6in4.auto='0'
|
||||
commit network
|
||||
EOF
|
||||
fi
|
||||
|
|
|
@ -854,7 +854,7 @@ _backup_get() {
|
|||
EOF
|
||||
return
|
||||
}
|
||||
vps_backup=$(_get_json "backup")
|
||||
vps_backup=$(_get_json "backupget")
|
||||
[ -z "$vps_backup" ] && return
|
||||
backup_data="$(echo "$vps_backup" | jsonfilter -q -e '@.data')"
|
||||
backup_sha256sum="$(echo "$vps_backup" | jsonfilter -q -e '@.sha256sum')"
|
||||
|
@ -869,6 +869,36 @@ backup_get() {
|
|||
config_foreach _backup_get server
|
||||
}
|
||||
|
||||
_backup_list() {
|
||||
servername=$1
|
||||
[ -z "$(uci -q get openmptcprouter.${servername}.username)" ] && return
|
||||
[ -z "$(uci -q get openmptcprouter.${servername}.password)" ] && return
|
||||
[ -z "$(uci -q get openmptcprouter.${servername}.port)" ] && return
|
||||
token=""
|
||||
vps_config=""
|
||||
_login
|
||||
[ -z "$token" ] && {
|
||||
logger -t "OMR-VPS" "Can't get token, try later"
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
set openmptcprouter.${servername}.admin_error=1
|
||||
EOF
|
||||
return
|
||||
}
|
||||
vps_backup=$(_get_json "backuplist")
|
||||
[ -z "$vps_backup" ] && return
|
||||
backup_lastmodif="$(echo "$vps_backup" | jsonfilter -q -e '@.modif')"
|
||||
[ -n "$backup_lastmodif" ] && {
|
||||
uci -q set openmptcprouter.$servername.lastbackup=$backup_lastmodif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
backup_list() {
|
||||
config_load openmptcprouter
|
||||
config_foreach _backup_list server
|
||||
}
|
||||
|
||||
|
||||
_count_server() {
|
||||
local servername=$1
|
||||
|
@ -919,6 +949,7 @@ _config_service() {
|
|||
[ -z "$(_set_glorytun_vps)" ] && error=1
|
||||
[ -z "$(_set_openvpn_vps)" ] && error=1
|
||||
_set_vps_firewall
|
||||
_backup_list
|
||||
redirect_port="0"
|
||||
if [ "$(uci -q get openmptcprouter.${servername}.redirect_ports)" = "1" ] || [ "$(uci -q get upnpd.config.enabled)" = "1" ]; then
|
||||
redirect_port="1"
|
||||
|
|
|
@ -96,6 +96,7 @@ set network.lan.ipaddr=192.168.100.1
|
|||
set network.lan.netmask=255.255.255.0
|
||||
set network.lan.ifname=${lanif}
|
||||
set network.lan.metric=2048
|
||||
set network.lan.ipv6=0
|
||||
set network.lan.delegate=0
|
||||
EOF
|
||||
|
||||
|
|
Loading…
Reference in a new issue