diff options
34 files changed, 992 insertions, 385 deletions
diff --git a/applications/luci-app-advanced-reboot/Makefile b/applications/luci-app-advanced-reboot/Makefile index 329acece4f..a08d57fd8b 100644 --- a/applications/luci-app-advanced-reboot/Makefile +++ b/applications/luci-app-advanced-reboot/Makefile @@ -3,7 +3,7 @@ include $(TOPDIR)/rules.mk -PKG_LICENSE:=GPL-3.0+ +PKG_LICENSE:=GPL-3.0-or-later PKG_MAINTAINER:=Stan Grishin <stangri@melmac.net> LUCI_TITLE:=Advanced Linksys Reboot Web UI @@ -11,9 +11,9 @@ LUCI_DESCRIPTION:=Provides Web UI (found under System/Advanced Reboot) to reboot an alternative partition. Also provides Web UI to shut down (power off) your device. Supported dual-partition\ routers are listed at https://github.com/openwrt/luci/blob/master/applications/luci-app-advanced-reboot/README.md -LUCI_DEPENDS:=+luci-mod-admin-full +LUCI_DEPENDS:=+luci-compat +luci-mod-admin-full LUCI_PKGARCH:=all -PKG_RELEASE:=42 +PKG_RELEASE:=43 include ../../luci.mk diff --git a/applications/luci-app-advanced-reboot/README.md b/applications/luci-app-advanced-reboot/README.md index 61e43637d1..50ca1bc2d6 100644 --- a/applications/luci-app-advanced-reboot/README.md +++ b/applications/luci-app-advanced-reboot/README.md @@ -22,11 +22,11 @@ Currently supported dual-partition devices include: - Linksys WRT32X - ZyXEL NBG6817 -If you're interested in having your device supported, please post in [OpenWrt Forum Support Thread](https://forum.openwrt.org/t/web-ui-to-reboot-to-another-partition-dual-partition-routers/3423). +If your device is not in the list above, however it is a [dual-firmware device](https://openwrt.org/tag/dual_firmware?do=showtag&tag=dual_firmware) and you're interested in having your device supported, please post in [OpenWrt Forum Support Thread](https://forum.openwrt.org/t/web-ui-to-reboot-to-another-partition-dual-partition-routers/3423). ## Screenshot (luci-app-advanced-reboot) -![screenshot](https://raw.githubusercontent.com/stangri/openwrt_packages/master/screenshots/luci-app-advanced-reboot/screenshot01.png "screenshot") +![screenshot](https://raw.githubusercontent.com/stangri/openwrt_packages/master/screenshots/luci-app-advanced-reboot/screenshot02.png "screenshot") ## How to install diff --git a/applications/luci-app-advanced-reboot/luasrc/controller/advanced_reboot.lua b/applications/luci-app-advanced-reboot/luasrc/controller/advanced_reboot.lua index 6b8cba4c40..8b97f2e560 100644 --- a/applications/luci-app-advanced-reboot/luasrc/controller/advanced_reboot.lua +++ b/applications/luci-app-advanced-reboot/luasrc/controller/advanced_reboot.lua @@ -3,203 +3,282 @@ module("luci.controller.advanced_reboot", package.seeall) +local util = require "luci.util" +local fs = require "nixio.fs" +local sys = require "luci.sys" +local http = require "luci.http" +local dispatcher = require "luci.dispatcher" +local i18n = require "luci.i18n" +local ltemplate = require "luci.template" +local ip = require "luci.ip" +local http = require "luci.http" +local sys = require "luci.sys" +local dispatcher = require "luci.dispatcher" +local uci = require "luci.model.uci".cursor() + +function is_alt_mountable(p1_mtd, p2_mtd) + if p1_mtd:sub(1,3) == "mtd" and + p2_mtd:sub(1,3) == "mtd" and + fs.access("/usr/sbin/ubiattach") and + fs.access("/usr/sbin/ubiblock") and + fs.access("/bin/mount") then + return true + else + return false + end +end + +function get_partition_os_info(op_ubi) + local cp_info, ap_info + if fs.access("/etc/os-release") then + cp_info = util.trim(util.exec('. /etc/os-release && echo "$PRETTY_NAME"')) + end + alt_partition_unmount(op_ubi) + alt_partition_mount(op_ubi) + if fs.access("/alt/rom/etc/os-release") then + ap_info = util.trim(util.exec('. /alt/rom/etc/os-release && echo "$PRETTY_NAME"')) + end + alt_partition_unmount(op_ubi) + return cp_info, ap_info +end + +function alt_partition_mount(op_ubi) + local ubi_dev + util.exec('for i in rom overlay firmware; do [ ! -d "$i" ] && mkdir -p "/alt/${i}"; done') + util.exec("ubidetach -m " .. tostring(op_ubi)) + ubi_dev = tostring(util.exec("ubiattach -m " .. tostring(op_ubi))) + _, _, ubi_dev = ubi_dev:find("UBI device number (%d+)") + if not ubi_dev then + util.exec("ubidetach -m " .. tostring(op_ubi)) + return + end + util.exec("ubiblock --create /dev/ubi" .. ubi_dev .. "_0") + util.exec("mount -t squashfs -o ro /dev/ubiblock" .. ubi_dev .. "_0 /alt/rom") + util.exec("mount -t ubifs /dev/ubi1_" .. ubi_dev .. " /alt/overlay") + util.exec("mount -t overlay overlay -o noatime,lowerdir=/alt/rom,upperdir=/alt/overlay/upper,workdir=/alt/overlay/work /alt/firmware") +end + +function alt_partition_unmount(op_ubi) + util.exec("umount /alt/firmware") + util.exec("umount /alt/overlay") + util.exec("umount /alt/rom") + util.exec("ubiblock --remove /dev/ubi1_0") + util.exec("ubidetach -m " .. tostring(op_ubi)) + util.exec('rm -rf /alt') +end + devices = { - -- deviceName, boardName, partition1, partition2, offset, envVar1, envVar1Value1, envVar1Value2, envVar2, envVar2Value1, envVar2Value2 - {"Linksys EA3500", "linksys-audi", "mtd3", "mtd5", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, - {"Linksys E4200v2/EA4500", "linksys-viper", "mtd3", "mtd5", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, - {"Linksys EA6350v3", "linksys-ea6350v3", "mtd10", "mtd12", 192, "boot_part", 1, 2}, - {"Linksys EA8300", "linksys-ea8300", "mtd10", "mtd12", 192, "boot_part", 1, 2}, - {"Linksys EA8500", "ea8500", "mtd13", "mtd15", 32, "boot_part", 1, 2}, + -- deviceName, boardName, part1MTD, part2MTD, offset, envVar1, envVar1Value1, envVar1Value2, envVar2, envVar2Value1, envVar2Value2 + {"Linksys EA3500", "linksys-audi", "mtd3", "mtd5", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, + {"Linksys E4200v2/EA4500", "linksys-viper", "mtd3", "mtd5", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, + {"Linksys EA6350v3", "linksys-ea6350v3", "mtd10", "mtd12", 192, "boot_part", 1, 2}, + {"Linksys EA8300", "linksys-ea8300", "mtd10", "mtd12", 192, "boot_part", 1, 2}, + {"Linksys EA8500", "ea8500", "mtd13", "mtd15", 32, "boot_part", 1, 2}, -- {"Linksys EA9500", "linksys-panamera", "mtd3", "mtd6", 28, "boot_part", 1, 2}, - {"Linksys WRT1200AC", "linksys-caiman", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, - {"Linksys WRT1900AC", "linksys-mamba", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, - {"Linksys WRT1900ACv2", "linksys-cobra", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, - {"Linksys WRT1900ACS", "linksys-shelby", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, - {"Linksys WRT3200ACM", "linksys-rango", "mtd5", "mtd7", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, - {"Linksys WRT32X", "linksys-venom", "mtd5", "mtd7", nil, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, - {"ZyXEL NBG6817","nbg6817","mmcblk0p4","mmcblk0p7", 32, nil, 255, 1} + {"Linksys WRT1200AC", "linksys-caiman", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, + {"Linksys WRT1900AC", "linksys-mamba", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, + {"Linksys WRT1900ACv2", "linksys-cobra", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, + {"Linksys WRT1900ACS", "linksys-shelby", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, + {"Linksys WRT3200ACM", "linksys-rango", "mtd5", "mtd7", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, + {"Linksys WRT32X", "linksys-venom", "mtd5", "mtd7", nil, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, + {"ZyXEL NBG6817", "nbg6817", "mmcblk0p4", "mmcblk0p7", 32, nil, 255, 1} } -errorMessage = nil -rom_board_name = luci.util.trim(luci.sys.exec("cat /tmp/sysinfo/board_name")) +-- local errorMessage, d +-- local device_name, p1_mtd, p2_mtd, offset, bev1, bev1p1, bev1p2, bev2, bev2p1, bev2p2 +romBoardName = util.trim(util.exec("cat /tmp/sysinfo/board_name")) + for i=1, #devices do - device_board_name = devices[i][2]:gsub('%p','') - if rom_board_name and rom_board_name:gsub('%p',''):match(device_board_name) then - device_name = devices[i][1] - partition_one_mtd = devices[i][3] or nil - partition_two_mtd = devices[i][4] or nil - partition_skip = devices[i][5] or nil - boot_envvar1 = devices[i][6] or nil - boot_envvar1_partition_one = tonumber(devices[i][7]) or nil - boot_envvar1_partition_two = tonumber(devices[i][8]) or nil - boot_envvar2 = devices[i][9] or nil - boot_envvar2_partition_one = devices[i][10] or nil - boot_envvar2_partition_two = devices[i][11] or nil - if partition_one_mtd and partition_skip then - partition_one_label = luci.util.trim(luci.sys.exec("dd if=/dev/" .. partition_one_mtd .. " bs=1 skip=" .. partition_skip .. " count=128" .. " 2>/dev/null")) - n, partition_one_version = string.match(partition_one_label, '(Linux)-([%d|.]+)') - end - if partition_two_mtd and partition_skip then - partition_two_label = luci.util.trim(luci.sys.exec("dd if=/dev/" .. partition_two_mtd .. " bs=1 skip=" .. partition_skip .. " count=128" .. " 2>/dev/null")) - n, partition_two_version = string.match(partition_two_label, '(Linux)-([%d|.]+)') - end - if partition_one_label and string.find(partition_one_label, "LEDE") then partition_one_os = "LEDE" end - if partition_one_label and string.find(partition_one_label, "OpenWrt") then partition_one_os = "OpenWrt" end - if partition_one_label and string.find(partition_one_label, "Linksys") then partition_one_os = "Linksys" end - if partition_two_label and string.find(partition_two_label, "LEDE") then partition_two_os = "LEDE" end - if partition_two_label and string.find(partition_two_label, "OpenWrt") then partition_two_os = "OpenWrt" end - if partition_two_label and string.find(partition_two_label, "Linksys") then partition_two_os = "Linksys" end - if device_name and device_name == "ZyXEL NBG6817" then - if not partition_one_os then partition_one_os = "ZyXEL" end - if not partition_two_os then partition_two_os = "ZyXEL" end - end - if device_name and device_name == "Linksys WRT32X" then - if not partition_one_os then partition_one_os = "Unknown/Compressed" end - if not partition_two_os then partition_two_os = "Unknown/Compressed" end - end - if not partition_one_os then partition_one_os = "Unknown" end - if not partition_two_os then partition_two_os = "Unknown" end - if partition_one_os and partition_one_version then partition_one_os = partition_one_os .. " (Linux " .. partition_one_version .. ")" end - if partition_two_os and partition_two_version then partition_two_os = partition_two_os .. " (Linux " .. partition_two_version .. ")" end + d = devices[i][2]:gsub('%p','') + if romBoardName and romBoardName:gsub('%p',''):match(d) then + device_name = devices[i][1] + p1_mtd = devices[i][3] or nil + p2_mtd = devices[i][4] or nil + offset = devices[i][5] or nil + bev1 = devices[i][6] or nil + bev1p1 = tonumber(devices[i][7]) or nil + bev1p2 = tonumber(devices[i][8]) or nil + bev2 = devices[i][9] or nil + bev2p1 = devices[i][10] or nil + bev2p2 = devices[i][11] or nil + if p1_mtd and offset then + p1_label = util.trim(util.exec("dd if=/dev/" .. p1_mtd .. " bs=1 skip=" .. offset .. " count=128" .. " 2>/dev/null")) + n, p1_version = p1_label:match('(Linux)-([%d|.]+)') + end + if p2_mtd and offset then + p2_label = util.trim(util.exec("dd if=/dev/" .. p2_mtd .. " bs=1 skip=" .. offset .. " count=128" .. " 2>/dev/null")) + n, p2_version = p2_label:match('(Linux)-([%d|.]+)') + end + if p1_label and p1_label:find("LEDE") then p1_os = "LEDE" end + if p1_label and p1_label:find("OpenWrt") then p1_os = "OpenWrt" end + if p1_label and p1_label:find("Linksys") then p1_os = "Linksys" end + if p2_label and p2_label:find("LEDE") then p2_os = "LEDE" end + if p2_label and p2_label:find("OpenWrt") then p2_os = "OpenWrt" end + if p2_label and p2_label:find("Linksys") then p2_os = "Linksys" end + if device_name == "ZyXEL NBG6817" then + if not p1_os then p1_os = "ZyXEL" end + if not p2_os then p2_os = "ZyXEL" end + end + if device_name == "Linksys WRT32X" then + if not p1_os then p1_os = "Unknown/Compressed" end + if not p2_os then p2_os = "Unknown/Compressed" end + end + if not p1_os then p1_os = "Unknown" end + if not p2_os then p2_os = "Unknown" end + if p1_os and p1_version then p1_os = p1_os .. " (Linux " .. p1_version .. ")" end + if p2_os and p2_version then p2_os = p2_os .. " (Linux " .. p2_version .. ")" end - if device_name and device_name == "ZyXEL NBG6817" then - if not zyxelFlagPartition then zyxelFlagPartition = luci.util.trim(luci.sys.exec("source /lib/functions.sh; find_mtd_part 0:DUAL_FLAG")) end - if not zyxelFlagPartition then - errorMessage = errorMessage or "" .. luci.i18n.translate("Unable to find Dual Boot Flag Partition." .. " ") - luci.util.perror(luci.i18n.translate("Unable to find Dual Boot Flag Partition.")) - else - current_partition = tonumber(luci.sys.exec("dd if=" .. zyxelFlagPartition .. " bs=1 count=1 2>/dev/null | hexdump -n 1 -e '1/1 \"%d\"'")) - end - else - if nixio.fs.access("/usr/sbin/fw_printenv") and nixio.fs.access("/usr/sbin/fw_setenv") then - current_partition = tonumber(luci.util.trim(luci.sys.exec("/usr/sbin/fw_printenv -n " .. boot_envvar1))) - end - end - other_partition = current_partition == boot_envvar1_partition_two and boot_envvar1_partition_one or boot_envvar1_partition_two - end + if device_name == "ZyXEL NBG6817" then + if not zyxelFlagPartition then zyxelFlagPartition = util.trim(util.exec(". /lib/functions.sh; find_mtd_part 0:DUAL_FLAG")) end + if not zyxelFlagPartition then + errorMessage = errorMessage or "" .. i18n.translate("Unable to find Dual Boot Flag Partition." .. " ") + util.perror(i18n.translate("Unable to find Dual Boot Flag Partition.")) + else + current_partition = tonumber(util.exec("dd if=" .. zyxelFlagPartition .. " bs=1 count=1 2>/dev/null | hexdump -n 1 -e '1/1 \"%d\"'")) + end + else + if fs.access("/usr/sbin/fw_printenv") and fs.access("/usr/sbin/fw_setenv") then + current_partition = tonumber(util.trim(util.exec("fw_printenv -n " .. bev1))) + end + end + other_partition = current_partition == bev1p2 and bev1p1 or bev1p2 + + if is_alt_mountable(p1_mtd, p2_mtd) then + if current_partition == bev1p1 then + op_ubi = tonumber(p2_mtd:sub(4)) + 1 + else + op_ubi = tonumber(p1_mtd:sub(4)) + 1 + end + local cp_info, ap_info = get_partition_os_info(op_ubi) + if current_partition == bev1p1 then + p1_os = cp_info or p1_os + p2_os = ap_info or p2_os + else + p1_os = ap_info or p1_os + p2_os = cp_info or p2_os + end + end + end end function index() - entry({"admin", "system", "advanced_reboot"}, template("advanced_reboot/advanced_reboot"), _("Advanced Reboot"), 90) - entry({"admin", "system", "advanced_reboot", "reboot"}, post("action_reboot")) - entry({"admin", "system", "advanced_reboot", "alternative_reboot"}, post("action_altreboot")) - entry({"admin", "system", "advanced_reboot", "power_off"}, post("action_poweroff")) + entry({"admin", "system", "advanced_reboot"}, template("advanced_reboot/advanced_reboot"), _("Advanced Reboot"), 90) + entry({"admin", "system", "advanced_reboot", "reboot"}, post("action_reboot")) + entry({"admin", "system", "advanced_reboot", "alternative_reboot"}, post("action_altreboot")) + entry({"admin", "system", "advanced_reboot", "power_off"}, post("action_poweroff")) end function action_reboot() - local uci = require "luci.model.uci".cursor() - local ip = uci:get("network", "lan", "ipaddr") - luci.template.render("advanced_reboot/applyreboot", { - title = luci.i18n.translate("Rebooting..."), - msg = luci.i18n.translate("The system is rebooting now.<br /> DO NOT POWER OFF THE DEVICE!<br /> Wait a few minutes before you try to reconnect. It might be necessary to renew the address of your computer to reach the device again, depending on your settings."), - addr = luci.ip.new(type(ip) == "string" and ip or "192.168.1.1") or "192.168.1.1" - }) - luci.sys.reboot() + ltemplate.render("admin_system/applyreboot", { + title = i18n.translate("Rebooting..."), + msg = i18n.translate("The system is rebooting now.<br /> DO NOT POWER OFF THE DEVICE!<br /> Wait a few minutes before you try to reconnect. It might be necessary to renew the address of your computer to reach the device again, depending on your settings."), + addr = ip.new(type(ip) == "string" and ip or "192.168.1.1") or "192.168.1.1" + }) + sys.reboot() end function action_altreboot() - local uci = require "luci.model.uci".cursor() - local zyxelFlagPartition, zyxelBootFlag, zyxelNewBootFlag, errorCode, curEnvSetting, newEnvSetting - errorMessage = nil - errorCode = 0 - if luci.http.formvalue("cancel") then - luci.http.redirect(luci.dispatcher.build_url('admin/system/advanced_reboot')) - return - end - local step = tonumber(luci.http.formvalue("step") or 1) - if step == 1 then - if device_name and nixio.fs.access("/usr/sbin/fw_printenv") and nixio.fs.access("/usr/sbin/fw_setenv") then - luci.template.render("advanced_reboot/alternative_reboot",{}) - else - luci.template.render("advanced_reboot/advanced_reboot",{errorMessage = luci.i18n.translate("No access to fw_printenv or fw_printenv!")}) - end - elseif step == 2 then - if boot_envvar1 or boot_envvar2 then -- Linksys devices - if boot_envvar1 then - curEnvSetting = tonumber(luci.util.trim(luci.sys.exec("/usr/sbin/fw_printenv -n " .. boot_envvar1))) - if not curEnvSetting then - errorMessage = errorMessage .. luci.i18n.translate("Unable to obtain firmware environment variable") .. ": " .. boot_envvar1 .. ". " - luci.util.perror(luci.i18n.translate("Unable to obtain firmware environment variable") .. ": " .. boot_envvar1 .. ".") - else - newEnvSetting = curEnvSetting == boot_envvar1_partition_one and boot_envvar1_partition_two or boot_envvar1_partition_one - errorCode = luci.sys.call("/usr/sbin/fw_setenv " .. boot_envvar1 .. " " .. newEnvSetting) - if errorCode ~= 0 then - errorMessage = errorMessage or "" .. luci.i18n.translate("Unable to set firmware environment variable") .. ": " .. boot_envvar1 .. " " .. luci.i18n.translate("to") .. " " .. newEnvSetting .. ". " - luci.util.perror(luci.i18n.translate("Unable to set firmware environment variable") .. ": " .. boot_envvar1 .. " " .. luci.i18n.translate("to") .. " " .. newEnvSetting .. ".") - end - end - end - if boot_envvar2 then - curEnvSetting = luci.util.trim(luci.sys.exec("/usr/sbin/fw_printenv -n " .. boot_envvar2)) - if not curEnvSetting then - errorMessage = errorMessage or "" .. luci.i18n.translate("Unable to obtain firmware environment variable") .. ": " .. boot_envvar2 .. ". " - luci.util.perror(luci.i18n.translate("Unable to obtain firmware environment variable") .. ": " .. boot_envvar2 .. ".") - else - newEnvSetting = curEnvSetting == boot_envvar2_partition_one and boot_envvar2_partition_two or boot_envvar2_partition_one - errorCode = luci.sys.call("/usr/sbin/fw_setenv " .. boot_envvar2 .. " '" .. newEnvSetting .. "'") - if errorCode ~= 0 then - errorMessage = errorMessage or "" .. luci.i18n.translate("Unable to set firmware environment variable") .. ": " .. boot_envvar2 .. " " .. luci.i18n.translate("to") .. " " .. newEnvSetting .. ". " - luci.util.perror(luci.i18n.translate("Unable to set firmware environment variable") .. ": " .. boot_envvar2 .. " " .. luci.i18n.translate("to") .. " " .. newEnvSetting .. ".") - end - end - end - else -- NetGear device - if not zyxelFlagPartition then zyxelFlagPartition = luci.util.trim(luci.sys.exec("source /lib/functions.sh; find_mtd_part 0:DUAL_FLAG")) end - if not zyxelFlagPartition then - errorMessage = errorMessage .. luci.i18n.translate("Unable to find Dual Boot Flag Partition." .. " ") - luci.util.perror(luci.i18n.translate("Unable to find Dual Boot Flag Partition.")) - else - zyxelBootFlag = tonumber(luci.sys.exec("dd if=" .. zyxelFlagPartition .. " bs=1 count=1 2>/dev/null | hexdump -n 1 -e '1/1 \"%d\"'")) - zyxelNewBootFlag = zyxelBootFlag and zyxelBootFlag == 1 and "\\xff" or "\\x01" - if zyxelNewBootFlag then - errorCode = luci.sys.call("printf \"" .. zyxelNewBootFlag .. "\" >" .. zyxelFlagPartition ) - if errorCode ~= 0 then - errorMessage = errorMessage or "" .. luci.i18n.translate("Unable to set Dual Boot Flag Partition entry for partition") .. ": " .. zyxelFlagPartition .. ". " - luci.util.perror(luci.i18n.translate("Unable to set Dual Boot Flag Partition entry for partition") .. ": " .. zyxelFlagPartition .. ".") - end - end - end - end - if not errorMessage then - luci.template.render("advanced_reboot/applyreboot", { - title = luci.i18n.translate("Rebooting..."), - msg = luci.i18n.translate("The system is rebooting to an alternative partition now.<br /> DO NOT POWER OFF THE DEVICE!<br /> Wait a few minutes before you try to reconnect. It might be necessary to renew the address of your computer to reach the device again, depending on your settings."), - addr = luci.ip.new(uci:get("network", "lan", "ipaddr")) or "192.168.1.1" - }) - luci.sys.reboot() - else - luci.template.render("advanced_reboot/advanced_reboot",{ - rom_board_name=rom_board_name, - device_name=device_name, - boot_envvar1_partition_one=boot_envvar1_partition_one, - partition_one_os=partition_one_os, - boot_envvar1_partition_two=boot_envvar1_partition_two, - partition_two_os=partition_two_os, - current_partition=current_partition, - errorMessage = errorMessage}) - end - end + local zyxelFlagPartition, zyxelBootFlag, zyxelNewBootFlag, errorCode, curEnvSetting, newEnvSetting + errorMessage = nil + errorCode = 0 + if http.formvalue("cancel") then + http.redirect(dispatcher.build_url('admin/system/advanced_reboot')) + return + end + local step = tonumber(http.formvalue("step") or 1) + if step == 1 then + if fs.access("/usr/sbin/fw_printenv") and fs.access("/usr/sbin/fw_setenv") then + ltemplate.render("advanced_reboot/alternative_reboot",{}) + else + ltemplate.render("advanced_reboot/advanced_reboot",{errorMessage = i18n.translate("No access to fw_printenv or fw_printenv!")}) + end + elseif step == 2 then + if bev1 or bev2 then -- Linksys devices + if bev1 then + curEnvSetting = tonumber(util.trim(util.exec("fw_printenv -n " .. bev1))) + if not curEnvSetting then + errorMessage = errorMessage .. i18n.translate("Unable to obtain firmware environment variable") .. ": " .. bev1 .. ". " + util.perror(i18n.translate("Unable to obtain firmware environment variable") .. ": " .. bev1 .. ".") + else + newEnvSetting = curEnvSetting == bev1p1 and bev1p2 or bev1p1 + errorCode = sys.call("fw_setenv " .. bev1 .. " " .. newEnvSetting) + if errorCode ~= 0 then + errorMessage = errorMessage or "" .. i18n.translate("Unable to set firmware environment variable") .. ": " .. bev1 .. " " .. i18n.translate("to") .. " " .. newEnvSetting .. ". " + util.perror(i18n.translate("Unable to set firmware environment variable") .. ": " .. bev1 .. " " .. i18n.translate("to") .. " " .. newEnvSetting .. ".") + end + end + end + if bev2 then + curEnvSetting = util.trim(util.exec("fw_printenv -n " .. bev2)) + if not curEnvSetting then + errorMessage = errorMessage or "" .. i18n.translate("Unable to obtain firmware environment variable") .. ": " .. bev2 .. ". " + util.perror(i18n.translate("Unable to obtain firmware environment variable") .. ": " .. bev2 .. ".") + else + newEnvSetting = curEnvSetting == bev2p1 and bev2p2 or bev2p1 + errorCode = sys.call("fw_setenv " .. bev2 .. " '" .. newEnvSetting .. "'") + if errorCode ~= 0 then + errorMessage = errorMessage or "" .. i18n.translate("Unable to set firmware environment variable") .. ": " .. bev2 .. " " .. i18n.translate("to") .. " " .. newEnvSetting .. ". " + util.perror(i18n.translate("Unable to set firmware environment variable") .. ": " .. bev2 .. " " .. i18n.translate("to") .. " " .. newEnvSetting .. ".") + end + end + end + else -- NetGear device + if not zyxelFlagPartition then zyxelFlagPartition = util.trim(util.exec(". /lib/functions.sh; find_mtd_part 0:DUAL_FLAG")) end + if not zyxelFlagPartition then + errorMessage = errorMessage .. i18n.translate("Unable to find Dual Boot Flag Partition." .. " ") + util.perror(i18n.translate("Unable to find Dual Boot Flag Partition.")) + else + zyxelBootFlag = tonumber(util.exec("dd if=" .. zyxelFlagPartition .. " bs=1 count=1 2>/dev/null | hexdump -n 1 -e '1/1 \"%d\"'")) + zyxelNewBootFlag = zyxelBootFlag and zyxelBootFlag == 1 and "\\xff" or "\\x01" + if zyxelNewBootFlag then + errorCode = sys.call("printf \"" .. zyxelNewBootFlag .. "\" >" .. zyxelFlagPartition ) + if errorCode ~= 0 then + errorMessage = errorMessage or "" .. i18n.translate("Unable to set Dual Boot Flag Partition entry for partition") .. ": " .. zyxelFlagPartition .. ". " + util.perror(i18n.translate("Unable to set Dual Boot Flag Partition entry for partition") .. ": " .. zyxelFlagPartition .. ".") + end + end + end + end + if not errorMessage then + ltemplate.render("admin_system/applyreboot", { + title = i18n.translate("Rebooting..."), + msg = i18n.translate("The system is rebooting to an alternative partition now.<br /> DO NOT POWER OFF THE DEVICE!<br /> Wait a few minutes before you try to reconnect. It might be necessary to renew the address of your computer to reach the device again, depending on your settings."), + addr = ip.new(uci:get("network", "lan", "ipaddr")) or "192.168.1.1" + }) + sys.reboot() + else + ltemplate.render("advanced_reboot/advanced_reboot",{ + romBoardName=romBoardName, + device_name=device_name, + bev1p1=bev1p1, + p1_os=p1_os, + bev1p2=bev1p2, + p2_os=p2_os, + current_partition=current_partition, + errorMessage = errorMessage}) + end + end end function action_poweroff() - local uci = require "luci.model.uci".cursor() - if luci.http.formvalue("cancel") then - luci.http.redirect(luci.dispatcher.build_url('admin/system/advanced_reboot')) - return - end - local step = tonumber(luci.http.formvalue("step") or 1) - if step == 1 then - if nixio.fs.access("/sbin/poweroff") then - luci.template.render("advanced_reboot/power_off",{}) - else - luci.template.render("advanced_reboot/advanced_reboot",{}) - end - elseif step == 2 then - luci.template.render("advanced_reboot/applyreboot", { - title = luci.i18n.translate("Shutting down..."), - msg = luci.i18n.translate("The system is shutting down now.<br /> DO NOT POWER OFF THE DEVICE!<br /> It might be necessary to renew the address of your computer to reach the device again, depending on your settings."), - addr = luci.ip.new(uci:get("network", "lan", "ipaddr")) or "192.168.1.1" - }) - luci.sys.call("/sbin/poweroff") - end + local uci = require "luci.model.uci".cursor() + if http.formvalue("cancel") then + http.redirect(dispatcher.build_url('admin/system/advanced_reboot')) + return + end + local step = tonumber(http.formvalue("step") or 1) + if step == 1 then + if fs.access("/sbin/poweroff") then + ltemplate.render("advanced_reboot/power_off",{}) + else + ltemplate.render("advanced_reboot/advanced_reboot",{}) + end + elseif step == 2 then + ltemplate.render("admin_system/applyreboot", { + title = i18n.translate("Shutting down..."), + msg = i18n.translate("The system is shutting down now.<br /> DO NOT POWER OFF THE DEVICE!<br /> It might be necessary to renew the address of your computer to reach the device again, depending on your settings."), + addr = ip.new(uci:get("network", "lan", "ipaddr")) or "192.168.1.1" + }) + sys.call("/sbin/poweroff") + end end diff --git a/applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/advanced_reboot.htm b/applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/advanced_reboot.htm index 5c14f52ff8..f3d8338c47 100644 --- a/applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/advanced_reboot.htm +++ b/applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/advanced_reboot.htm @@ -20,70 +20,70 @@ <%- if device_name then -%> <fieldset class="cbi-section"> - <legend><%=device_name%><%: Partitions%></legend> - <div class="table cbi-section-table" id="partitions"> - <div class="tr cbi-section-table-titles"> - <div class="th cbi-section-table-cell"><%:Partition%></div> - <div class="th cbi-section-table-cell"><%:Status%></div> - <div class="th cbi-section-table-cell"><%:Firmware/OS (Kernel)%></div> - <div class="th cbi-section-table-cell"><%:Action%></div> - </div> - <div class="tr cbi-section-table-row"> - <div class="td"> - <%=string.format("%X", boot_envvar1_partition_one)%> - </div> - <div class="td"> - <%- if boot_envvar1_partition_one == current_partition then -%><%:Current%><%- else -%><%:Alternative%><%- end -%> - </div> - <div class="td"> - <%=partition_one_os%> - </div> - <div class="td"> - <%- if boot_envvar1_partition_one == current_partition then -%> - <form method="post" action="<%=url('admin/system/advanced_reboot/reboot')%>"> - <input type="hidden" name="token" value="<%=token%>" /> - <input id="reboot-button" type="submit" class="cbi-button cbi-button-apply important" value="<%:Reboot to current partition%>" /> - </form> - <%- else -%> - <form method="post" action="<%=url('admin/system/advanced_reboot/alternative_reboot')%>"> - <input type="hidden" name="token" value="<%=token%>" /> - <input id="altreboot-button" type="submit" class="cbi-button cbi-button-apply important" value="<%:Reboot to alternative partition...%>" /> - </form> - <%- end -%> - </div> - </div> - <div class="tr cbi-section-table-row"> - <div class="td"> - <%=string.format("%X", boot_envvar1_partition_two)%> - </div> - <div class="td"> - <%- if boot_envvar1_partition_two == current_partition then -%><%:Current%><%- else -%><%:Alternative%><%- end -%> - </div> - <div class="td"> - <%=partition_two_os%> - </div> - <div class="td"> - <%- if boot_envvar1_partition_two == current_partition then -%> - <form method="post" action="<%=url('admin/system/advanced_reboot/reboot')%>"> - <input type="hidden" name="token" value="<%=token%>" /> - <input id="reboot-button" type="submit" class="cbi-button cbi-button-apply important" value="<%:Reboot to current partition%>" /> - </form> - <%- else -%> - <form method="post" action="<%=url('admin/system/advanced_reboot/alternative_reboot')%>"> - <input type="hidden" name="token" value="<%=token%>" /> - <input id="altreboot-button" type="submit" class="cbi-button cbi-button-apply important" value="<%:Reboot to alternative partition...%>" /> - </form> - <%- end -%> - </div> - </div> - </div> + <legend><%=device_name%><%: Partitions%></legend> + <div class="table cbi-section-table" id="partitions"> + <div class="tr cbi-section-table-titles"> + <div class="th cbi-section-table-cell"><%:Partition%></div> + <div class="th cbi-section-table-cell"><%:Status%></div> + <div class="th cbi-section-table-cell"><%:Firmware%></div> + <div class="th cbi-section-table-cell"><%:Reboot%></div> + </div> + <div class="tr cbi-section-table-row cbi-rowstyle-1"> + <div class="td"> + <%=string.format("%X", bev1p1)%> + </div> + <div class="td"> + <%- if bev1p1 == current_partition then -%><%:Current%><%- else -%><%:Alternative%><%- end -%> + </div> + <div class="td"> + <%=p1_os%> + </div> + <div class="td"> + <%- if bev1p1 == current_partition then -%> + <form method="post" action="<%=url('admin/system/advanced_reboot/reboot')%>"> + <input type="hidden" name="token" value="<%=token%>" /> + <input id="reboot-button" type="submit" class="cbi-button cbi-button-apply important" value="<%:Reboot to current partition%>" /> + </form> + <%- else -%> + <form method="post" action="<%=url('admin/system/advanced_reboot/alternative_reboot')%>"> + <input type="hidden" name="token" value="<%=token%>" /> + <input id="altreboot-button" type="submit" class="cbi-button cbi-button-apply important" value="<%:Reboot to alternative partition...%>" /> + </form> + <%- end -%> + </div> + </div> + <div class="tr cbi-section-table-row cbi-rowstyle-2"> + <div class="td"> + <%=string.format("%X", bev1p2)%> + </div> + <div class="td"> + <%- if bev1p2 == current_partition then -%><%:Current%><%- else -%><%:Alternative%><%- end -%> + </div> + <div class="td"> + <%=p2_os%> + </div> + <div class="td"> + <%- if bev1p2 == current_partition then -%> + <form method="post" action="<%=url('admin/system/advanced_reboot/reboot')%>"> + <input type="hidden" name="token" value="<%=token%>" /> + <input id="reboot-button" type="submit" class="cbi-button cbi-button-apply important" value="<%:Reboot to current partition%>" /> + </form> + <%- else -%> + <form method="post" action="<%=url('admin/system/advanced_reboot/alternative_reboot')%>"> + <input type="hidden" name="token" value="<%=token%>" /> + <input id="altreboot-button" type="submit" class="cbi-button cbi-button-apply important" value="<%:Reboot to alternative partition...%>" /> + </form> + <%- end -%> + </div> + </div> + </div> </fieldset> <%- else -%> - <%- if rom_board_name then -%> - <p class="alert-message warning"><%=pcdata(translatef("Warning: Device (%s) is unknown or isn't a dual-partition device!", rom_board_name))%></p> - <%- else -%> - <p class="alert-message warning"><%=pcdata(translatef("Warning: Unable to obtain device information!"))%></p> - <%- end -%> + <%- if rom_board_name then -%> + <p class="alert-message warning"><%=pcdata(translatef("Warning: Device (%s) is unknown or isn't a dual-partition device!", rom_board_name))%></p> + <%- else -%> + <p class="alert-message warning"><%=pcdata(translatef("Warning: Unable to obtain device information!"))%></p> + <%- end -%> <%- end -%> <hr /> @@ -91,10 +91,10 @@ <%- if nixio.fs.access("/sbin/poweroff") then -%> <form method="post" action="<%=url('admin/system/advanced_reboot/power_off')%>"> <input type="hidden" name="token" value="<%=token%>" /> - <input id="poweroff-button" type="submit" class="cbi-button cbi-button-apply important" value="<%:Perform power off...%>" /> + <input id="poweroff-button" type="submit" class="cbi-button cbi-button-apply important" value="<%:Perform power off...%>" /> </form> <%- else -%> - <p class="alert-message warning"><%:Warning: This system does not support powering off!%></p> + <p class="alert-message warning"><%:Warning: This system does not support powering off!%></p> <%- end -%> <%+footer%> diff --git a/applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/alternative_reboot.htm b/applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/alternative_reboot.htm index b15f16b0d5..db11020628 100644 --- a/applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/alternative_reboot.htm +++ b/applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/alternative_reboot.htm @@ -10,10 +10,10 @@ <h2 name="content"><%:Reboot Device to an Alternative Partition%> - <%:Confirm%></h2> <p> <%_ WARNING: An alternative partition might have its own settings and completely different firmware.<br /><br /> - As your network configuration and WiFi SSID/password on alternative partition might be different, - you might have to adjust your computer settings to be able to access your device once it reboots.<br /><br /> - Please also be aware that alternative partition firmware might not provide an easy way to switch active partition - and boot back to the currently active partition.<br /><br /> + As your network configuration and WiFi SSID/password on alternative partition might be different, + you might have to adjust your computer settings to be able to access your device once it reboots.<br /><br /> + Please also be aware that alternative partition firmware might not provide an easy way to switch active partition + and boot back to the currently active partition.<br /><br /> Click "Proceed" below to reboot device to an alternative partition. %> </p> diff --git a/applications/luci-app-advanced-reboot/root/etc/uci-defaults/40_luci-advanced-reboot b/applications/luci-app-advanced-reboot/root/etc/uci-defaults/40_luci-advanced-reboot new file mode 100644 index 0000000000..e1a8f1e307 --- /dev/null +++ b/applications/luci-app-advanced-reboot/root/etc/uci-defaults/40_luci-advanced-reboot @@ -0,0 +1,5 @@ +#!/bin/sh + +rm -rf /var/luci-modulecache/; rm -f /var/luci-indexcache; +exit 0 + diff --git a/applications/luci-app-https_dns_proxy/Makefile b/applications/luci-app-https_dns_proxy/Makefile index d08940e59f..bd6cf9bd1b 100644 --- a/applications/luci-app-https_dns_proxy/Makefile +++ b/applications/luci-app-https_dns_proxy/Makefile @@ -3,14 +3,14 @@ include $(TOPDIR)/rules.mk -PKG_LICENSE:=GPL-3.0+ +PKG_LICENSE:=GPL-3.0-or-later PKG_MAINTAINER:=Stan Grishin <stangri@melmac.net> LUCI_TITLE:=HTTPS DNS Proxy Web UI LUCI_DESCRIPTION:=Provides Web UI for HTTPS DNS Proxy LUCI_DEPENDS:=+luci-compat +luci-mod-admin-full +https_dns_proxy LUCI_PKGARCH:=all -PKG_RELEASE:=5 +PKG_RELEASE:=9 include ../../luci.mk diff --git a/applications/luci-app-https_dns_proxy/luasrc/controller/https_dns_proxy.lua b/applications/luci-app-https_dns_proxy/luasrc/controller/https_dns_proxy.lua index e1fd8fcb9b..826f3f691f 100644 --- a/applications/luci-app-https_dns_proxy/luasrc/controller/https_dns_proxy.lua +++ b/applications/luci-app-https_dns_proxy/luasrc/controller/https_dns_proxy.lua @@ -1,7 +1,25 @@ module("luci.controller.https_dns_proxy", package.seeall) function index() - if not nixio.fs.access("/etc/config/https_dns_proxy") then - return + if nixio.fs.access("/etc/config/https_dns_proxy") then + entry({"admin", "services", "https_dns_proxy"}, cbi("https_dns_proxy"), _("DNS over HTTPS Proxy")) + entry({"admin", "services", "https_dns_proxy", "action"}, call("https_dns_proxy_action"), nil).leaf = true end - entry({"admin", "services", "https_dns_proxy"}, cbi("https_dns_proxy"), _("HTTPS DNS Proxy")) +end + +function https_dns_proxy_action(name) + local packageName = "https_dns_proxy" + if name == "start" then + luci.sys.init.start(packageName) + elseif name == "action" then + luci.util.exec("/etc/init.d/" .. packageName .. " reload >/dev/null 2>&1") + luci.util.exec("/etc/init.d/dnsmasq restart >/dev/null 2>&1") + elseif name == "stop" then + luci.sys.init.stop(packageName) + elseif name == "enable" then + luci.sys.init.enable(packageName) + elseif name == "disable" then + luci.sys.init.disable(packageName) + end + luci.http.prepare_content("text/plain") + luci.http.write("0") end diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/ch.digitale-gesellschaft.dns.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/ch.digitale-gesellschaft.dns.lua new file mode 100644 index 0000000000..723ca894c3 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/ch.digitale-gesellschaft.dns.lua @@ -0,0 +1,6 @@ +return { + name = "Digitale-Gesellschaft", + label = _("Digitale Gesellschaft"), + url_prefix = "https://dns.digitale-gesellschaft.ch/dns-query?", + bootstrap_dns = "185.95.218.42,185.95.218.43" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/com.adguard.dns-family.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/com.adguard.dns-family.lua new file mode 100644 index 0000000000..050549bf8d --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/com.adguard.dns-family.lua @@ -0,0 +1,14 @@ +-- .. "</br>" +-- .. translate("For more information on different options check ") +-- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]] +-- .. "AdGuard.com" .. [[</a>]] .. ", " +-- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]] +-- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " " +-- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]] +-- .. "Quad9.net" .. [[</a>]] .. "." +return { + name = "AdGuard-Family", + label = _("AdGuard (Family Protection)"), + url_prefix = "https://dns-family.adguard.com/dns-query?ct&", + bootstrap_dns = "176.103.130.132,176.103.130.134" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/com.adguard.dns.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/com.adguard.dns.lua new file mode 100644 index 0000000000..67b7c12811 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/com.adguard.dns.lua @@ -0,0 +1,14 @@ +-- .. "</br>" +-- .. translate("For more information on different options check ") +-- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]] +-- .. "AdGuard.com" .. [[</a>]] .. ", " +-- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]] +-- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " " +-- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]] +-- .. "Quad9.net" .. [[</a>]] .. "." +return { + name = "AdGuard-Standard", + label = _("AdGuard (Standard)"), + url_prefix = "https://dns.adguard.com/dns-query?ct&", + bootstrap_dns = "176.103.130.130,176.103.130.131" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/cz.nic.odvr.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/cz.nic.odvr.lua new file mode 100644 index 0000000000..e47576be86 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/cz.nic.odvr.lua @@ -0,0 +1,6 @@ +return { + name = "odvr-nic-cz", + label = _("ODVR (nic.cz)"), + url_prefix = "https://odvr.nic.cz/doh?", + bootstrap_dns = "193.17.47.1,185.43.135.1" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns.lua new file mode 100644 index 0000000000..356921a97f --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns.lua @@ -0,0 +1,14 @@ +-- .. "</br>" +-- .. translate("For more information on different options check ") +-- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]] +-- .. "AdGuard.com" .. [[</a>]] .. ", " +-- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]] +-- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " " +-- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]] +-- .. "Quad9.net" .. [[</a>]] .. "." +return { + name = "Quad9-Recommended", + label = _("Quad 9 (Recommended)"), + url_prefix = "https://dns.quad9.net:5053/dns-query?", + bootstrap_dns = "9.9.9.9,149.112.112.112" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns10.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns10.lua new file mode 100644 index 0000000000..a031556e8d --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns10.lua @@ -0,0 +1,14 @@ +-- .. "</br>" +-- .. translate("For more information on different options check ") +-- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]] +-- .. "AdGuard.com" .. [[</a>]] .. ", " +-- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]] +-- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " " +-- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]] +-- .. "Quad9.net" .. [[</a>]] .. "." +return { + name = "Quad9-Unsecured", + label = _("Quad 9 (Unsecured)"), + url_prefix = "https://dns10.quad9.net:5053/dns-query?", + bootstrap_dns = "9.9.9.10,149.112.112.10" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns11.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns11.lua new file mode 100644 index 0000000000..3b51978d25 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns11.lua @@ -0,0 +1,14 @@ +-- .. "</br>" +-- .. translate("For more information on different options check ") +-- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]] +-- .. "AdGuard.com" .. [[</a>]] .. ", " +-- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]] +-- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " " +-- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]] +-- .. "Quad9.net" .. [[</a>]] .. "." +return { + name = "Quad9-ECS", + label = _("Quad 9 (Secured with ECS Support)"), + url_prefix = "https://dns11.quad9.net:5053/dns-query?", + bootstrap_dns = "9.9.9.11,149.112.112.11" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns9.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns9.lua new file mode 100644 index 0000000000..c456a8dcdc --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/net.quad9.dns9.lua @@ -0,0 +1,14 @@ +-- .. "</br>" +-- .. translate("For more information on different options check ") +-- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]] +-- .. "AdGuard.com" .. [[</a>]] .. ", " +-- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]] +-- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " " +-- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]] +-- .. "Quad9.net" .. [[</a>]] .. "." +return { + name = "Quad9-Secured", + label = _("Quad 9 (Secured)"), + url_prefix = "https://dns9.quad9.net:5053/dns-query?", + bootstrap_dns = "9.9.9.9,149.112.112.9" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/org.cleanbrowsing.doh-adult.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/org.cleanbrowsing.doh-adult.lua new file mode 100644 index 0000000000..708a39e958 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/org.cleanbrowsing.doh-adult.lua @@ -0,0 +1,14 @@ +-- .. "</br>" +-- .. translate("For more information on different options check ") +-- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]] +-- .. "AdGuard.com" .. [[</a>]] .. ", " +-- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]] +-- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " " +-- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]] +-- .. "Quad9.net" .. [[</a>]] .. "." +return { + name = "CleanBrowsing-Adult", + label = _("CleanBrowsing (Adult Filter)"), + url_prefix = "https://doh.cleanbrowsing.org/doh/adult-filter/?ct&", + bootstrap_dns = "185.228.168.168" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/org.cleanbrowsing.doh-family.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/org.cleanbrowsing.doh-family.lua new file mode 100644 index 0000000000..f44ed43305 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/org.cleanbrowsing.doh-family.lua @@ -0,0 +1,14 @@ +-- .. "</br>" +-- .. translate("For more information on different options check ") +-- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]] +-- .. "AdGuard.com" .. [[</a>]] .. ", " +-- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]] +-- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " " +-- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]] +-- .. "Quad9.net" .. [[</a>]] .. "." +return { + name = "CleanBrowsing-Family", + label = _("CleanBrowsing (Family Filter)"), + url_prefix = "https://doh.cleanbrowsing.org/doh/family-filter/?ct&", + bootstrap_dns = "185.228.168.168" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/org.cleanbrowsing.doh-security.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/org.cleanbrowsing.doh-security.lua new file mode 100644 index 0000000000..e4a3bf4ac4 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers.disabled/org.cleanbrowsing.doh-security.lua @@ -0,0 +1,14 @@ +-- .. "</br>" +-- .. translate("For more information on different options check ") +-- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]] +-- .. "AdGuard.com" .. [[</a>]] .. ", " +-- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]] +-- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " " +-- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]] +-- .. "Quad9.net" .. [[</a>]] .. "." +return { + name = "CleanBrowsing-Security", + label = _("CleanBrowsing (Security Filter)"), + url_prefix = "https://doh.cleanbrowsing.org/doh/security-filter/?ct&", + bootstrap_dns = "185.228.168.168" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers/com.cloudflare-dns.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers/com.cloudflare-dns.lua new file mode 100644 index 0000000000..74d9273bcd --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers/com.cloudflare-dns.lua @@ -0,0 +1,6 @@ +return { + name = "Cloudflare", + label = _("Cloudflare"), + url_prefix = "https://cloudflare-dns.com/dns-query?ct=application/dns-json&", + bootstrap_dns = "1.1.1.1,1.0.0.1" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers/com.google.dns.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers/com.google.dns.lua new file mode 100644 index 0000000000..168f3f7aa4 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers/com.google.dns.lua @@ -0,0 +1,7 @@ +return { + name = "Google", + label = _("Google"), + url_prefix = "https://dns.google.com/resolve?", + bootstrap_dns = "8.8.8.8,8.8.4.4", + default = true +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers/sb.dns.lua b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers/sb.dns.lua new file mode 100644 index 0000000000..50dc74288a --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/https_dns_proxy/providers/sb.dns.lua @@ -0,0 +1,6 @@ +return { + name = "DNS.SB", + label = _("DNS.SB"), + url_prefix = "https://doh.dns.sb/dns-query?", + bootstrap_dns = "185.222.222.222,185.184.222.222" +} diff --git a/applications/luci-app-https_dns_proxy/luasrc/model/cbi/https_dns_proxy.lua b/applications/luci-app-https_dns_proxy/luasrc/model/cbi/https_dns_proxy.lua index 17ce610eab..4e7e02524f 100644 --- a/applications/luci-app-https_dns_proxy/luasrc/model/cbi/https_dns_proxy.lua +++ b/applications/luci-app-https_dns_proxy/luasrc/model/cbi/https_dns_proxy.lua @@ -1,144 +1,118 @@ +local sys = require "luci.sys" +local util = require "luci.util" +local fs = require "nixio.fs" +local dispatcher = require "luci.dispatcher" +local i18n = require "luci.i18n" local uci = require("luci.model.uci").cursor() -local dispatcher = require("luci.dispatcher") -function uci_del_list(conf, sect, opt, value) - local lval = uci:get(conf, sect, opt) - if lval == nil or lval == "" then - lval = {} - elseif type(lval) ~= "table" then - lval = { lval } - end +local packageName = "https_dns_proxy" +local providers_dir = "/usr/lib/lua/luci/" .. packageName .. "/providers/" - local i - local changed = false - for i = #lval, 1 do - if lval[i] == value then - table.remove(lval, i) - changed = true - end - end - - if changed then - if #lval > 0 then - uci:set(conf, sect, opt, lval) - else - uci:delete(conf, sect, opt) - end - end +function get_provider_name(value) + for filename in fs.dir(providers_dir) do + local p_func = loadfile(providers_dir .. filename) + setfenv(p_func, { _ = i18n.translate }) + local p = p_func() + value = value:gsub('[%p%c%s]', '') + p.url_match = p.url_prefix:gsub('[%p%c%s]', '') + if value:match(p.url_match) then + return p.label + end + end + return translate("Uknown Provider") end -function uci_add_list(conf, sect, opt, value) - local lval = uci:get(conf, sect, opt) - if lval == nil or lval == "" then - lval = {} - elseif type(lval) ~= "table" then - lval = { lval } - end +local tmpfsStatus, tmpfsStatusCode +local ubusStatus = util.ubus("service", "list", { name = packageName }) +local tmpfsVersion = tostring(util.trim(sys.exec("opkg list-installed " .. packageName .. " | awk '{print $3}'"))) - lval[#lval+1] = value - uci:set(conf, sect, opt, lval) +if not tmpfsVersion or tmpfsVersion == "" then + tmpfsStatusCode = -1 + tmpfsVersion = "" + tmpfsStatus = packageName .. " " .. translate("is not installed or not found") +else + tmpfsVersion = " [" .. packageName .. " " .. tmpfsVersion .. "]" + if not ubusStatus or not ubusStatus[packageName] then + tmpfsStatusCode = 0 + tmpfsStatus = translate("Stopped") + else + tmpfsStatusCode, tmpfsStatus = 1, "" + for n = 1,1000 do + if ubusStatus and ubusStatus[packageName] and + ubusStatus[packageName]["instances"] and + ubusStatus[packageName]["instances"]["instance" .. n] and + ubusStatus[packageName]["instances"]["instance" .. n]["running"] then + local value, k, v, url, url_flag, la, la_flag, lp, lp_flag + for k, v in pairs(ubusStatus[packageName]["instances"]["instance" .. n]["command"]) do + if la_flag then la, la_flag = v, false end + if lp_flag then lp, lp_flag = v, false end + if url_flag then url, url_flag = v, false end + if v == "-a" then la_flag = true end + if v == "-p" then lp_flag = true end + if v == "-r" then url_flag = true end + end + la = la or "127.0.0.1" + lp = lp or n + 5053 + tmpfsStatus = tmpfsStatus .. translate("Running") .. ": " .. get_provider_name(url) .. " " .. translate("DoH") .. " " .. translate("at") .. " " .. la .. ":" .. lp .. "\n" + else + break + end + end + end end -m = Map("https_dns_proxy", translate("HTTPS DNS Proxy Settings")) -m.template="cbi/map" +m = Map("https_dns_proxy", translate("DNS over HTTPS Proxy Settings")) + +h = m:section(TypedSection, "_dummy", translate("Service Status") .. tmpfsVersion) +h.template = "cbi/nullsection" +ss = h:option(DummyValue, "_dummy", translate("Service Status")) +if tmpfsStatusCode == -1 then + ss.template = packageName .. "/status" + ss.value = tmpfsStatus +else + if tmpfsStatusCode == 0 then + ss.template = packageName .. "/status" + else + ss.template = packageName .. "/status-textarea" + end + ss.value = tmpfsStatus + buttons = h:option(DummyValue, "_dummy") + buttons.template = packageName .. "/buttons" +end s3 = m:section(TypedSection, "https_dns_proxy", translate("Instances"), translate("When you add/remove any instances below, they will be used to override the 'DNS forwardings' section of ") .. [[ <a href="]] .. dispatcher.build_url("admin/network/dhcp") .. [[">]] - .. translate("DHCP and DNS") .. [[</a>]] .. "." --- .. "</br>" --- .. translate("For more information on different options check ") --- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]] --- .. "AdGuard.com" .. [[</a>]] .. ", " --- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]] --- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " " --- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]] --- .. "Quad9.net" .. [[</a>]] .. "." - ) + .. translate("DHCP and DNS") .. [[</a>]] .. ".") s3.template = "cbi/tblsection" s3.sortable = false s3.anonymous = true s3.addremove = true prov = s3:option(ListValue, "url_prefix", translate("Provider")) --- prov:value("https://dns.adguard.com/dns-query?", "AdGuard (Standard)") --- prov:value("https://dns-family.adguard.com/dns-query?", "AdGuard (Family Protection)") --- prov:value("https://doh.cleanbrowsing.org/doh/security-filter/?ct&", "CleanBrowsing (Security Filter)") --- prov:value("https://doh.cleanbrowsing.org/doh/family-filter/?ct&", "CleanBrowsing (Family Filter)") --- prov:value("https://doh.cleanbrowsing.org/doh/adult-filter/?ct&", "CleanBrowsing (Adult Filter)") -prov:value("https://cloudflare-dns.com/dns-query?ct=application/dns-json&", "Cloudflare") --- prov:value("https://dns.digitale-gesellschaft.ch/dns-query?", "Digitale Gesellschaft (ch)") -prov:value("https://doh.dns.sb/dns-query?", "DNS.SB") -prov:value("https://dns.google.com/resolve?", "Google") --- prov:value("https://odvr.nic.cz/doh?", "ODVR (nic.cz)") --- prov:value("https://dns.quad9.net:5053/dns-query?", "Quad9 (Recommended)") --- prov:value("https://dns9.quad9.net:5053/dns-query?", "Quad9 (Secured)") --- prov:value("https://dns10.quad9.net:5053/dns-query?", "Quad9 (Unsecured)") --- prov:value("https://dns11.quad9.net:5053/dns-query?", "Quad9 (Secured with ECS Support)") -prov.default = "https://dns.google.com/resolve?" +for filename in fs.dir(providers_dir) do + local p_func = loadfile(providers_dir .. filename) + setfenv(p_func, { _ = i18n.translate }) + local p = p_func() + prov:value(p.url_prefix, p.label) + if p.default then + prov.default = p.url_prefix + end +end prov.forcewrite = true prov.write = function(self, section, value) - if not value then return end - local n = 0 - uci:foreach("https_dns_proxy", "https_dns_proxy", function(s) - if s[".name"] == section then - return false - end - n = n + 1 - end) - local la_val = la:formvalue(section) - local lp_val = lp:formvalue(section) - if not la_val or la_val == "" then la_val = "127.0.0.1" end - if not lp_val or lp_val == "" then lp_val = n + 5053 end - if value:match("dns\.adguard") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "176.103.130.130,176.103.130.131") - uci:set("https_dns_proxy", section, "url_prefix", "https://dns.adguard.com/dns-query?ct&") - elseif value:match("family\.adguard") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "176.103.130.132,176.103.130.134") - uci:set("https_dns_proxy", section, "url_prefix", "https://dns-family.adguard.com/dns-query?ct&") - elseif value:match("cleanbrowsing\.org/doh/security") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "185.228.168.168") - uci:set("https_dns_proxy", section, "url_prefix", "https://doh.cleanbrowsing.org/doh/security-filter/?ct&") - elseif value:match("cleanbrowsing\.org/doh/family") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "185.228.168.168") - uci:set("https_dns_proxy", section, "url_prefix", "https://doh.cleanbrowsing.org/doh/family-filter/?ct&") - elseif value:match("cleanbrowsing\.org/doh/adult") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "185.228.168.168") - uci:set("https_dns_proxy", section, "url_prefix", "https://doh.cleanbrowsing.org/doh/adult-filter/?ct&") - elseif value:match("cloudflare") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "1.1.1.1,1.0.0.1") - uci:set("https_dns_proxy", section, "url_prefix", "https://cloudflare-dns.com/dns-query?ct=application/dns-json&") - elseif value:match("gesellschaft\.ch") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "185.95.218.42,185.95.218.43") - uci:set("https_dns_proxy", section, "url_prefix", "https://dns.digitale-gesellschaft.ch/dns-query?") - elseif value:match("dns\.sb") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "185.222.222.222,185.184.222.222") - uci:set("https_dns_proxy", section, "url_prefix", "https://doh.dns.sb/dns-query?") - elseif value:match("google") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "8.8.8.8,8.8.4.4") - uci:set("https_dns_proxy", section, "url_prefix", "https://dns.google.com/resolve?") - elseif value:match("odvr\.nic\.cz") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "193.17.47.1,185.43.135.1") - uci:set("https_dns_proxy", section, "url_prefix", "https://odvr.nic.cz/doh?") - elseif value:match("dns\.quad9") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "9.9.9.9,149.112.112.112") - uci:set("https_dns_proxy", section, "url_prefix", "https://dns.quad9.net:5053/dns-query?") - elseif value:match("dns9\.quad9") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "9.9.9.9,149.112.112.9") - uci:set("https_dns_proxy", section, "url_prefix", "https://dns9.quad9.net:5053/dns-query?") - elseif value:match("dns10\.quad9") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "9.9.9.10,149.112.112.10") - uci:set("https_dns_proxy", section, "url_prefix", "https://dns10.quad9.net:5053/dns-query?") - elseif value:match("dns11\.quad9") then - uci:set("https_dns_proxy", section, "bootstrap_dns", "9.9.9.11,149.112.112.11") - uci:set("https_dns_proxy", section, "url_prefix", "https://dns11.quad9.net:5053/dns-query?") - end - uci:save("https_dns_proxy") - if n == 0 then - uci:delete("dhcp", "@dnsmasq[0]", "server") - end - uci_del_list("dhcp", "@dnsmasq[0]", "server", tostring(la_val) .. "#" .. tostring(lp_val)) - uci_add_list("dhcp", "@dnsmasq[0]", "server", tostring(la_val) .. "#" .. tostring(lp_val)) - uci:save("dhcp") + if not value then return end + for filename in fs.dir(providers_dir) do + local p_func = loadfile(providers_dir .. filename) + setfenv(p_func, { _ = i18n.translate }) + local p = p_func() + value = value:gsub('[%p%c%s]', '') + p.url_match = p.url_prefix:gsub('[%p%c%s]', '') + if value:match(p.url_match) then + uci:set("https_dns_proxy", section, "bootstrap_dns", p.bootstrap_dns) + uci:set("https_dns_proxy", section, "url_prefix", p.url_prefix) + end + end + uci:save("https_dns_proxy") end la = s3:option(Value, "listen_addr", translate("Listen address")) @@ -148,10 +122,10 @@ la.rmempty = true local n = 0 uci:foreach("https_dns_proxy", "https_dns_proxy", function(s) - if s[".name"] == section then - return false - end - n = n + 1 + if s[".name"] == section then + return false + end + n = n + 1 end) lp = s3:option(Value, "listen_port", translate("Listen port")) diff --git a/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/buttons.htm b/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/buttons.htm new file mode 100644 index 0000000000..84c5f608d2 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/buttons.htm @@ -0,0 +1,56 @@ +<%# + Copyright 2019 Stan Grishin <stangri@melmac.net> +-%> + +<%- + local packageName = "https_dns_proxy" + local enabledFlag = luci.sys.init.enabled(packageName) + local ubusStatus = luci.util.ubus("service", "list", { name = packageName }) + + if not ubusStatus or not ubusStatus[packageName] then + tmpfsStatusCode = 0 + else + tmpfsStatusCode = 1 + end + + if tmpfsStatusCode == 0 then + btn_start_style = "cbi-button cbi-button-apply important" + btn_action_style = "cbi-button cbi-button-apply important" + btn_stop_style = "cbi-button cbi-button-reset -disabled" + else + btn_start_style = "cbi-button cbi-button-apply -disabled" + btn_action_style = "cbi-button cbi-button-apply important" + btn_stop_style = "cbi-button cbi-button-reset important" + end + if not enabledFlag then + btn_start_style = "cbi-button cbi-button-apply -disabled" + btn_action_style = "cbi-button cbi-button-apply -disabled" + btn_enable_style = "cbi-button cbi-button-apply important" + btn_disable_style = "cbi-button cbi-button-reset -disabled" + else + btn_enable_style = "cbi-button cbi-button-apply -disabled" + btn_disable_style = "cbi-button cbi-button-reset important" + end +-%> + +<%+https_dns_proxy/css%> +<%+https_dns_proxy/js%> + +<div class="cbi-value"><label class="cbi-value-title">Service Control</label> + <div class="cbi-value-field"> + <input type="button" class="<%=btn_start_style%>" id="btn_start" name="start" value="<%:Start%>" onclick="button_action(this)" /> + <span id="btn_start_spinner" class="btn_spinner"></span> + <input type="button" class="<%=btn_action_style%>" id="btn_action" name="action" value="<%:Reload%>" onclick="button_action(this)" /> + <span id="btn_action_spinner" class="btn_spinner"></span> + <input type="button" class="<%=btn_stop_style%>" id="btn_stop" name="stop" value="<%:Stop%>" onclick="button_action(this)" /> + <span id="btn_stop_spinner" class="btn_spinner"></span> + + + + + <input type="button" class="<%=btn_enable_style%>" id="btn_enable" name="enable" value="<%:Enable%>" onclick="button_action(this)" /> + <span id="btn_enable_spinner" class="btn_spinner"></span> + <input type="button" class="<%=btn_disable_style%>" id="btn_disable" name="disable" value="<%:Disable%>" onclick="button_action(this)" /> + <span id="btn_disable_spinner" class="btn_spinner"></span> + </div> +</div> diff --git a/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/css.htm b/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/css.htm new file mode 100644 index 0000000000..6fb3d51d3b --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/css.htm @@ -0,0 +1,9 @@ +<style type="text/css"> + .btn_spinner + { + display: inline-block; + width: 0px; + height: 16px; + margin: 0 0px; + } +</style> diff --git a/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/js.htm b/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/js.htm new file mode 100644 index 0000000000..3b0daaa19a --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/js.htm @@ -0,0 +1,60 @@ + +<script type="text/javascript"> +//<![CDATA[ + function button_action(action) { + var xhr = new XHR(false); + var btn_start = document.getElementById("btn_start"); + var btn_action = document.getElementById("btn_action"); + var btn_stop = document.getElementById("btn_stop"); + var btn_enable = document.getElementById("btn_enable"); + var btn_disable = document.getElementById("btn_disable"); + var btn_spinner; + switch (action.name) { + case "start": + btn_spinner = document.getElementById("btn_start_spinner"); + break; + case "action": + btn_spinner = document.getElementById("btn_action_spinner"); + break; + case "stop": + btn_spinner = document.getElementById("btn_stop_spinner"); + break; + case "enable": + btn_spinner = document.getElementById("btn_enable_spinner"); + break; + case "disable": + btn_spinner = document.getElementById("btn_disable_spinner"); + break; + } + btn_start.disabled = true; + btn_action.disabled = true; + btn_stop.disabled = true; + btn_enable.disabled = true; + btn_disable.disabled = true; + spinner(btn_spinner, 1); + xhr.get('<%=luci.dispatcher.build_url("admin", "services", "https_dns_proxy", "action")%>/' + action.name, null, + function (x) { + if (!x) { + return; + } + btn_start.disabled = false; + btn_action.disabled = false; + btn_stop.disabled = false; + btn_enable.disabled = false; + btn_disable.disabled = false; + spinner(btn_spinner, 0); + location.reload(); + }); +} +function spinner(element, state) { + if (state === 1) { + element.style.width = "16px"; + element.innerHTML = '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" width="16" height="16" style="vertical-align:middle" />'; + } + else { + element.style.width = "0px"; + element.innerHTML = ''; + } +} +//]]> +</script> diff --git a/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/status-textarea.htm b/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/status-textarea.htm new file mode 100644 index 0000000000..3840cd19d4 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/status-textarea.htm @@ -0,0 +1,13 @@ +<%# +Copyright 2017-2019 Stan Grishin (stangri@melmac.net) +This is free software, licensed under the Apache License, Version 2.0 +-%> + +<%+cbi/valueheader%> + +<textarea rows="<%=select(2, self:cfgvalue(section):gsub('\n', ''))%>" + style="border:none;box-shadow:none;background:transparent;font-weight:bold;line-height:20px;width:50em;padding:none;margin:6px;resize:none;overflow:hidden;" + disabled="disabled"><%=self:cfgvalue(section)%> +</textarea> + +<%+cbi/valuefooter%> diff --git a/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/status.htm b/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/status.htm new file mode 100644 index 0000000000..c453428405 --- /dev/null +++ b/applications/luci-app-https_dns_proxy/luasrc/view/https_dns_proxy/status.htm @@ -0,0 +1,10 @@ +<%# +Copyright 2017-2018 Dirk Brenken (dev@brenken.org) +This is free software, licensed under the Apache License, Version 2.0 +-%> + +<%+cbi/valueheader%> + +<input name="status" id="status" type="text" class="cbi-input-text" style="outline:none;border:none;box-shadow:none;background:transparent;font-weight:bold;line-height:30px;height:30px;width:50em;" value="<%=self:cfgvalue(section)%>" disabled="disabled" /> + +<%+cbi/valuefooter%> diff --git a/applications/luci-app-nextdns/Makefile b/applications/luci-app-nextdns/Makefile new file mode 100644 index 0000000000..263b66e6a6 --- /dev/null +++ b/applications/luci-app-nextdns/Makefile @@ -0,0 +1,12 @@ +# Copyright 2019 Olivier Poitrey (rs@nextdns.io) +# This is free software, licensed under the Apache License, Version 2.0 + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI support for NextDNS +LUCI_DEPENDS:=+luci-compat +nextdns +LUCI_PKGARCH:=all + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/applications/luci-app-nextdns/luasrc/controller/nextdns.lua b/applications/luci-app-nextdns/luasrc/controller/nextdns.lua new file mode 100644 index 0000000000..0552981938 --- /dev/null +++ b/applications/luci-app-nextdns/luasrc/controller/nextdns.lua @@ -0,0 +1,32 @@ +-- Copyright 2019 Olivier Poitrey (rs@nextdns.io) +-- This is free software, licensed under the Apache License, Version 2.0 + +module("luci.controller.nextdns", package.seeall) + +local util = require("luci.util") +local i18n = require("luci.i18n") +local templ = require("luci.template") +local http = require("luci.http") + +function index() + if not nixio.fs.access("/etc/config/nextdns") then + return + end + + entry({"admin", "services", "nextdns"}, firstchild(), _("NextDNS"), 60).dependent = false + entry({"admin", "services", "nextdns", "overview"}, cbi("overview", {hideresetbtn=true, hidesavebtn=true}), _("Overview"), 10).leaf = true + entry({"admin", "services", "nextdns", "log"}, template("nextdns/logread"), _("Logs"), 30).leaf = true + + entry({"admin", "services", "nextdns", "logread"}, call("logread"), nil).leaf = true + +end + +function logread() + local content = util.trim(util.exec("logread -e 'nextdns'")) or "" + + if content == "" then + content = "No nextdns related logs yet!" + end + http.write(content) +end + diff --git a/applications/luci-app-nextdns/luasrc/model/cbi/overview.lua b/applications/luci-app-nextdns/luasrc/model/cbi/overview.lua new file mode 100644 index 0000000000..a932a85f89 --- /dev/null +++ b/applications/luci-app-nextdns/luasrc/model/cbi/overview.lua @@ -0,0 +1,41 @@ +local uci = require("luci.model.uci").cursor() + +nextdns = Map("nextdns", translate("NextDNS"), + translate("NextDNS Configuration.") + .. "<br>" + .. translatef("For further information, go to " + .. "<a href=\"https://nextdns.io\" target=\"_blank\">nextdns.io</a>")) + + +function nextdns.on_after_commit(self) + luci.sys.call("env -i /etc/init.d/nextdns restart >/dev/null 2>&1") +end + +s = nextdns:section(TypedSection, "nextdns", translate("General")) +s.anonymous = true + +enabled = s:option(Flag, "enabled", translate("Enabled"), + translate("Enable NextDNS.")) +enabled.rmempty = false + +conf = s:option(Value, "config", translate("Configuration ID"), + translate("The ID of your NextDNS configuration.") + .. "<br>" + .. translate("Go to nextdns.io to create a configuration.")) +conf.rmempty = false + +report_client_info = s:option(Flag, "report_client_info", translate("Report Client Info"), + translate("Expose LAN clients information in NextDNS analytics.")) +report_client_info.rmempty = false + +hardened_privacy = s:option(Flag, "hardened_privacy", translate("Hardened Privacy"), + translate("When enabled, use DNS servers located in jurisdictions with strong privacy laws.") + .. "<br>" + .. translate("Available locations are: Switzerland, Iceland, Finland, Panama and Hong Kong.")) +hardened_privacy.rmempty = false + +log_query = s:option(Flag, "log_query", translate("Log Queries"), + translate("Log individual queries to system log.")) +log_query.rmempty = false + +return nextdns diff --git a/applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm b/applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm new file mode 100644 index 0000000000..0a98b2704f --- /dev/null +++ b/applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm @@ -0,0 +1,46 @@ +<%+header%> + +<style type="text/css"> + select[readonly], + textarea[readonly] + { + width: 100% !important; + height: 450px !important; + border: 1px solid #cccccc; + padding: 5px; + font-size: 12px; + font-family: monospace; + resize: none; + pointer-events: auto; + cursor: auto; + } +</style> + +<script type="text/javascript"> +//<![CDATA[ + function log_update() + { + XHR.poll(-1, '<%=luci.dispatcher.build_url("admin", "services", "nextdns", "logread")%>', null, + function(x) + { + if (!x) + { + return; + } + var view = document.getElementById("view_id"); + view.value = x.responseText; + view.scrollTop = view.scrollHeight; + }); + } + window.onload = log_update(); +//]]> +</script> + +<div class="cbi-map"> + <div class="cbi-section"> + <div class="cbi-section-descr"><%:The syslog output, pre-filtered for nextdns related messages only.%></div> + <textarea id="view_id" readonly="readonly" wrap="off" value=""></textarea> + </div> +</div> + +<%+footer%> diff --git a/applications/luci-app-nextdns/po/templates/nextdns.pot b/applications/luci-app-nextdns/po/templates/nextdns.pot new file mode 100644 index 0000000000..6f943818b5 --- /dev/null +++ b/applications/luci-app-nextdns/po/templates/nextdns.pot @@ -0,0 +1,84 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:34 +msgid "" +"Available locations are: Switzerland, Iceland, Finland, Panama and Hong Kong." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:21 +msgid "Configuration ID" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:18 +msgid "Enable NextDNS." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:17 +msgid "Enabled" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:28 +msgid "Expose LAN clients information in NextDNS analytics." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:6 +msgid "" +"For further information, go to <a href=\"https://nextdns.io\" target=\"_blank" +"\">nextdns.io</a>" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:14 +msgid "General" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:24 +msgid "Go to nextdns.io to create a configuration." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:31 +msgid "Hardened Privacy" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:37 +msgid "Log Queries" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:38 +msgid "Log individual queries to system log." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:18 +msgid "Logs" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:16 +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:3 +msgid "NextDNS" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:4 +msgid "NextDNS Configuration." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:17 +msgid "Overview" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:27 +msgid "Report Client Info" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:22 +msgid "The ID of your NextDNS configuration." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm:41 +msgid "The syslog output, pre-filtered for nextdns related messages only." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:32 +msgid "" +"When enabled, use DNS servers located in jurisdictions with strong privacy " +"laws." +msgstr "" diff --git a/applications/luci-app-nextdns/root/etc/uci-defaults/60_luci-nextdns b/applications/luci-app-nextdns/root/etc/uci-defaults/60_luci-nextdns new file mode 100755 index 0000000000..95fc92280e --- /dev/null +++ b/applications/luci-app-nextdns/root/etc/uci-defaults/60_luci-nextdns @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@nextdns[-1] + add ucitrack nextdns + set ucitrack.@nextdns[-1].init=nextdns + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 |