From 137227389a2c4ec2dfb7cef85d95424127d2a196 Mon Sep 17 00:00:00 2001 From: kzolotarev95 Date: Sun, 28 Jun 2026 17:04:35 +0400 Subject: [PATCH] Add LuCI services menu entry --- .gitattributes | 1 + README.md | 9 ++++++++ .../lua/luci/controller/owrt_full_backup.lua | 23 +++++++++++++++++++ install.sh | 4 ++++ uninstall.sh | 3 +++ 5 files changed, 40 insertions(+) create mode 100644 files/usr/lib/lua/luci/controller/owrt_full_backup.lua diff --git a/.gitattributes b/.gitattributes index 33aca80..88d5837 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11,3 +11,4 @@ uninstall.sh text eol=lf files/usr/sbin/owrt-full-backup text eol=lf files/etc/config/fullbackup text eol=lf files/www/cgi-bin/owrt-full-backup text eol=lf +files/usr/lib/lua/luci/controller/owrt_full_backup.lua text eol=lf diff --git a/README.md b/README.md index 65670d4..a53c689 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ - `/usr/sbin/owrt-full-backup` - консольная команда; - `/www/cgi-bin/owrt-full-backup` - веб-панель; +- `/usr/lib/lua/luci/controller/owrt_full_backup.lua` - пункт меню LuCI; - `/etc/config/fullbackup` - настройки по умолчанию; - `/etc/owrt-full-backup/web.key` - секретный ключ для входа в панель. @@ -35,6 +36,14 @@ http://192.168.1.1/cgi-bin/owrt-full-backup?key=SECRET Эту ссылку никому не отдавай: ключ в URL дает доступ к созданию и восстановлению бэкапов. +Также появится пункт меню LuCI: + +```text +Службы -> OpenWrt Full Backup +``` + +Если пункт не появился сразу, обнови страницу LuCI или выйди и зайди снова. + ## Возможности веб-панели - создать полный архив бэкапа; diff --git a/files/usr/lib/lua/luci/controller/owrt_full_backup.lua b/files/usr/lib/lua/luci/controller/owrt_full_backup.lua new file mode 100644 index 0000000..7dca09d --- /dev/null +++ b/files/usr/lib/lua/luci/controller/owrt_full_backup.lua @@ -0,0 +1,23 @@ +module("luci.controller.owrt_full_backup", package.seeall) + +function index() + entry({"admin", "services", "owrt-full-backup"}, call("action_open"), "OpenWrt Full Backup", 90).dependent = false +end + +function action_open() + local http = require "luci.http" + local fs = require "nixio.fs" + local key = fs.readfile("/etc/owrt-full-backup/web.key") or "" + + key = key:gsub("%s+", "") + if key == "" then + http.prepare_content("text/html; charset=utf-8") + http.write("OpenWrt Full Backup") + http.write("

OpenWrt Full Backup

") + http.write("

Веб-ключ не найден. Переустанови модуль командой sh install.sh.

") + http.write("") + return + end + + http.redirect("/cgi-bin/owrt-full-backup?key=" .. key) +end diff --git a/install.sh b/install.sh index 9485379..a85fb47 100644 --- a/install.sh +++ b/install.sh @@ -103,6 +103,9 @@ install_file "usr/sbin/owrt-full-backup" 0755 ln -sf owrt-full-backup "$(target_path usr/sbin/owrt-backup)" install_config install_file "www/cgi-bin/owrt-full-backup" 0755 +install_file "usr/lib/lua/luci/controller/owrt_full_backup.lua" 0644 + +rm -rf "$(target_path tmp/luci-indexcache)" "$(target_path tmp/luci-modulecache)" 2>/dev/null || true if [ -x "$(target_path etc/init.d/uhttpd)" ]; then "$(target_path etc/init.d/uhttpd)" reload >/dev/null 2>&1 || "$(target_path etc/init.d/uhttpd)" restart >/dev/null 2>&1 || true @@ -112,5 +115,6 @@ key="$(make_key)" ip="$(router_ip)" info "Веб-панель OpenWrt Full Backup установлена." +info "LuCI: Службы -> OpenWrt Full Backup" info "Открыть: http://$ip/cgi-bin/owrt-full-backup?key=$key" info "CLI: owrt-full-backup create -o /mnt/usb" diff --git a/uninstall.sh b/uninstall.sh index b12c75a..7d6e127 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -16,6 +16,7 @@ rmf() { rmf usr/sbin/owrt-full-backup rmf usr/sbin/owrt-backup rmf www/cgi-bin/owrt-full-backup +rmf usr/lib/lua/luci/controller/owrt_full_backup.lua if [ "$PURGE" = "1" ]; then rmf etc/config/fullbackup @@ -23,6 +24,8 @@ if [ "$PURGE" = "1" ]; then rmdir "$(target_path etc/owrt-full-backup)" 2>/dev/null || true fi +rm -rf "$(target_path tmp/luci-indexcache)" "$(target_path tmp/luci-modulecache)" 2>/dev/null || true + if [ -x "$(target_path etc/init.d/uhttpd)" ]; then "$(target_path etc/init.d/uhttpd)" reload >/dev/null 2>&1 || "$(target_path etc/init.d/uhttpd)" restart >/dev/null 2>&1 || true fi