update 2022-07-25 20:19:04

This commit is contained in:
github-actions[bot]
2022-07-25 20:19:04 +08:00
parent c9dfdcccc3
commit 55b16270a2
7 changed files with 108 additions and 7 deletions

View File

@ -44,6 +44,7 @@ function index()
entry({ "admin", "system", "amlogic", "start_openwrt_author" }, call("action_openwrt_author")).leaf = true
entry({ "admin", "system", "amlogic", "state" }, call("action_state")).leaf = true
entry({ "admin", "system", "amlogic", "start_poweroff" }, call("action_poweroff")).leaf = true
entry({ "admin", "system", "amlogic", "start_switch" }, call("action_switch")).leaf = true
end
--Remove the spaces in the string
@ -450,3 +451,10 @@ end
function action_poweroff()
luci.sys.exec("/sbin/poweroff")
end
--Switching dual partition
function action_switch()
luci.sys.exec("[ -f /boot/efi/EFI/BOOT/grub.cfg.prev ] && (cd /boot/efi/EFI/BOOT/ && mv -f grub.cfg grub.cfg.bak && mv -f grub.cfg.prev grub.cfg && mv -f grub.cfg.bak grub.cfg.prev)")
luci.sys.exec("sync && reboot")
end

View File

@ -5,13 +5,20 @@
local io = require "io"
local os = require "os"
local fs = require "nixio.fs"
local b, c
local b, c, x
-- Checks wheather the given path exists and points to a directory.
function isdirectory(dirname)
return fs.stat(dirname, "type") == "dir"
end
-- Check if a file or directory exists
function file_exists(path)
local file = io.open(path, "rb")
if file then file:close() end
return file ~= nil
end
--SimpleForm for Backup Config
b = SimpleForm("backup", nil)
b.title = translate("Backup Firmware Config")
@ -90,10 +97,22 @@ w.render = function(self, section, scope)
end
w.write = function(self, section, scope)
local x = luci.sys.exec("btrfs subvolume snapshot -r /etc /.snapshots/etc-" .. os.date("%m.%d.%H%M%S") .. " 2>/dev/null && sync")
local x = luci.sys.exec("btrfs subvolume snapshot -r /etc /.snapshots/etc-" ..
os.date("%m.%d.%H%M%S") .. " 2>/dev/null && sync")
luci.http.redirect(luci.dispatcher.build_url("admin", "system", "amlogic", "backup"))
end
w = d:option(TextValue, "snapshot_list", nil)
w.template = "amlogic/other_snapshot"
return b, c
--KVM virtual machine switching dual partition
if file_exists("/boot/efi/EFI/BOOT/grub.cfg.prev") then
x = SimpleForm("kvm", nil)
x.title = translate("KVM dual system switching")
x.description = translate("You can freely switch between KVM dual partitions, using OpenWrt systems in different partitions.")
x.reset = false
x.submit = false
x:section(SimpleSection).template = "amlogic/other_kvm"
end
return b, c, x

View File

@ -0,0 +1,48 @@
<style>
.NewsTdHeight{ line-height:32px; }
.imgLeft{ float:left; margin-right:10px; vertical-align:middle; }
.contentRight{ align-items: center; }
</style>
<fieldset class="cbi-section">
<table width="100%" class="NewsTdHeight">
<tr><td width="100%" align="left">
<input class="cbi-button cbi-button-save" type="button" value="<%:Switch System%>" onclick="switchopenwrt(this)" />
<p style="display:none">
<img id="img_loading" style="display:block" src="<%=resource%>/amlogic/loading.gif" alt="<%:Loading%>" class="imgLeft" />
<img id="img_switch" style="display:none" src="<%=resource%>/amlogic/switch.png" alt="<%:PowerOff%>" class="imgLeft" />
<span id="msg_switch" class="contentRight"><%:System is switching...%></span>
</p>
</td></tr>
</table>
</fieldset>
<script type="text/javascript">//<![CDATA[
function status_check() {
var time = 5;
var img_loading = document.getElementById("img_loading");
var img_switch = document.getElementById("img_switch");
var msg = document.getElementById("msg_switch");
var set = setInterval(function() {
time--;
msg.innerHTML = "<%:Waiting for system switching...%>";
if(time === 0) {
img_loading.style.display = 'none';
img_switch.style.display = 'block';
msg.innerHTML = "<%:System switchover succeeded, restarting...%>";
clearInterval(set);
}
}, 1000);
}
function switchopenwrt(btn) {
if (confirm('<%:Are you sure you want to switch systems?%>') != true) { return false; }
btn.style.display = 'none';
document.getElementById('msg_switch').parentNode.style.display = 'block';
(new XHR()).post('<%=luci.dispatcher.build_url("admin", "system", "amlogic", "start_switch")%>', { token: '<%=token%>' }, status_check);
}
//]]></script>