From aa5ba474fe02bdbf6f0c657c19731adefcdbad20 Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 6 Sep 2023 19:28:56 -0400 Subject: [PATCH] first commit --- Makefile | 16 +++ README.md | 0 luasrc/controller/heimdall.lua | 7 ++ luasrc/model/cbi/heimdall.lua | 35 +++++++ luasrc/view/heimdall/status.htm | 31 ++++++ po/zh-cn/heimdall.po | 44 +++++++++ po/zh_Hans | 1 + root/etc/config/heimdall | 4 + root/usr/libexec/apps/heimdall.sh | 97 +++++++++++++++++++ .../share/rpcd/acl.d/luci-app-heimdall.json | 11 +++ 10 files changed, 246 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100755 luasrc/controller/heimdall.lua create mode 100644 luasrc/model/cbi/heimdall.lua create mode 100644 luasrc/view/heimdall/status.htm create mode 100644 po/zh-cn/heimdall.po create mode 100755 po/zh_Hans create mode 100644 root/etc/config/heimdall create mode 100755 root/usr/libexec/apps/heimdall.sh create mode 100644 root/usr/share/rpcd/acl.d/luci-app-heimdall.json diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4867815 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ + + +include $(TOPDIR)/rules.mk + + +LUCI_TITLE:=LuCI support for heimdall +LUCI_PKGARCH:=all +LUCI_DEPENDS:=+docker +luci-lib-taskd + +define Package/luci-app-heimdall/conffiles +/etc/config/heimdall +endef + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/luasrc/controller/heimdall.lua b/luasrc/controller/heimdall.lua new file mode 100755 index 0000000..e54b8c4 --- /dev/null +++ b/luasrc/controller/heimdall.lua @@ -0,0 +1,7 @@ + +module("luci.controller.heimdall", package.seeall) + +function index() + entry({"admin", "apps", "heimdall"}, alias("admin", "apps", "heimdall", "config"), _("Heimdall"), 30).dependent = true + entry({"admin", "apps", "heimdall", "config"}, cbi("heimdall")) +end diff --git a/luasrc/model/cbi/heimdall.lua b/luasrc/model/cbi/heimdall.lua new file mode 100644 index 0000000..d82c4a4 --- /dev/null +++ b/luasrc/model/cbi/heimdall.lua @@ -0,0 +1,35 @@ +--[[ +LuCI - Lua Configuration Interface +]]-- + +local taskd = require "luci.model.tasks" +local m, s, o + +m = taskd.docker_map("heimdall", "heimdall", "/usr/libexec/apps/heimdall.sh", + translate("Heimdall"), + translate("Heimdall is an elegant solution to organise all your web applications.") + .. translate("Official website:") .. ' https://github.com/linuxserver/Heimdall') + +s = m:section(SimpleSection, translate("Service Status"), translate("Heimdall status:")) +s:append(Template("heimdall/status")) + +s = m:section(TypedSection, "heimdall", translate("Setup"), translate("The following parameters will only take effect during installation or upgrade:")) +s.addremove=false +s.anonymous=true + +o = s:option(Value, "http_port", translate("HTTP Port").."*") +o.rmempty = false +o.default = "8088" +o.datatype = "port" + +o = s:option(Value, "https_port", translate("HTTPS Port").."*") +o.rmempty = false +o.default = "8089" +o.datatype = "port" + +o = s:option(Value, "config_path", translate("Config path").."*") +o.rmempty = false +o.default = "/root/heimdall/config" +o.datatype = "string" + +return m diff --git a/luasrc/view/heimdall/status.htm b/luasrc/view/heimdall/status.htm new file mode 100644 index 0000000..79cb97f --- /dev/null +++ b/luasrc/view/heimdall/status.htm @@ -0,0 +1,31 @@ +<% +local util = require "luci.util" +local container_status = util.trim(util.exec("/usr/libexec/apps/heimdall.sh status")) +local container_install = (string.len(container_status) > 0) +local container_running = container_status == "running" +-%> +
+ +
+ <% if container_running then %> + + <% else %> + + <% end %> +
+
+<% +if container_running then + local port=util.trim(util.exec("/usr/libexec/apps/heimdall.sh port")) + if port == "" then + port="8088" + end +-%> +
+ +
+ + +
+
+<% end %> diff --git a/po/zh-cn/heimdall.po b/po/zh-cn/heimdall.po new file mode 100644 index 0000000..544174b --- /dev/null +++ b/po/zh-cn/heimdall.po @@ -0,0 +1,44 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8" + +msgid "Official website:" +msgstr "官方网站:" + +msgid "Heimdall is an elegant solution to organise all your web applications." +msgstr "Heimdall 是组织所有 Web 应用程序的优雅解决方案。" + +msgid "Config path" +msgstr "配置文件路径" + +msgid "Port" +msgstr "端口" + +msgid "HTTP Port" +msgstr "HTTP 端口" + +msgid "HTTPS Port" +msgstr "HTTPS 端口" + +msgid "Service Status" +msgstr "服务状态" + +msgid "Heimdall status:" +msgstr "Heimdall 的状态信息如下:" + +msgid "Setup" +msgstr "安装配置" + +msgid "The following parameters will only take effect during installation or upgrade:" +msgstr "以下参数只在安装或者升级时才会生效:" + +msgid "Status" +msgstr "状态" + +msgid "Heimdall is running" +msgstr "Heimdall 运行中" + +msgid "Heimdall is not running" +msgstr "Heimdall 未运行" + +msgid "Open Heimdall" +msgstr "打开 Heimdall" diff --git a/po/zh_Hans b/po/zh_Hans new file mode 100755 index 0000000..41451e4 --- /dev/null +++ b/po/zh_Hans @@ -0,0 +1 @@ +zh-cn \ No newline at end of file diff --git a/root/etc/config/heimdall b/root/etc/config/heimdall new file mode 100644 index 0000000..554dbd2 --- /dev/null +++ b/root/etc/config/heimdall @@ -0,0 +1,4 @@ +config heimdall + option 'http_port' '8088' + option 'https_port' '8089' + option 'config_path' '/root/heimdall/config' diff --git a/root/usr/libexec/apps/heimdall.sh b/root/usr/libexec/apps/heimdall.sh new file mode 100755 index 0000000..5e600d0 --- /dev/null +++ b/root/usr/libexec/apps/heimdall.sh @@ -0,0 +1,97 @@ +#!/bin/sh + +ACTION=${1} +shift 1 + +get_image() { + IMAGE_NAME="lscr.io/linuxserver/heimdall:latest" +} + +do_install() { + get_image + echo "docker pull ${IMAGE_NAME}" + docker pull ${IMAGE_NAME} + docker rm -f heimdall + + do_install_detail +} + +do_install_detail() { + local config=`uci get heimdall.@heimdall[0].config_path 2>/dev/null` + local http_port=`uci get heimdall.@heimdall[0].http_port 2>/dev/null` + local https_port=`uci get heimdall.@heimdall[0].https_port 2>/dev/null` + + if [ -z "$config" ]; then + echo "config path is empty!" + exit 1 + fi + + [ -z "$http_port" ] && http_port=8088 + [ -z "$https_port" ] && http_port=8089 + + local cmd="docker run --restart=unless-stopped -d \ + -v \"$config:/config\" \ + --dns=172.17.0.1 \ + -p $http_port:80 \ + -p $https_port:443 " + + cmd="$cmd -v /mnt:/mnt" + mountpoint -q /mnt && cmd="$cmd:rslave" + + local tz="`uci get system.@system[0].zonename`" + [ -z "$tz" ] || cmd="$cmd -e TZ=$tz" + + cmd="$cmd --name heimdall \"$IMAGE_NAME\"" + + echo "$cmd" + eval "$cmd" + + #Add link to shortcutmenu + # Get our local LAN IP Address + LAN_IP=$(uci get network.lan.ipaddr) + # Strip trailing network mask + LAN_IP="${LAN_IP%/*}" + + # Add a new list option to the "shortcutmenu" configuration file + uci add shortcutmenu lists + uci set shortcutmenu.@lists[-1].webname="$IMAGE_NAME" + uci set shortcutmenu.@lists[-1].weburl="$LAN_IP:$http_port" + uci set shortcutmenu.@lists[-1].webpath="/" + uci commit shortcutmenu + +} + +usage() { + echo "usage: $0 sub-command" + echo "where sub-command is one of:" + echo " install Install the heimdall" + echo " upgrade Upgrade the heimdall" + echo " rm/start/stop/restart Remove/Start/Stop/Restart the heimdall" + echo " status Heimdall status" + echo " port Heimdall port" +} + +case ${ACTION} in + "install") + do_install + ;; + "upgrade") + do_install + ;; + "rm") + docker rm -f heimdall + ;; + "start" | "stop" | "restart") + docker ${ACTION} heimdall + ;; + "status") + docker ps --all -f 'name=heimdall' --format '{{.State}}' + ;; + "port") + docker ps --all -f 'name=heimdall' --format '{{.Ports}}' | grep -om1 '0.0.0.0:[0-9]*' | sed 's/0.0.0.0://' + ;; + *) + usage + exit 1 + ;; +esac diff --git a/root/usr/share/rpcd/acl.d/luci-app-heimdall.json b/root/usr/share/rpcd/acl.d/luci-app-heimdall.json new file mode 100644 index 0000000..2bf4f79 --- /dev/null +++ b/root/usr/share/rpcd/acl.d/luci-app-heimdall.json @@ -0,0 +1,11 @@ +{ + "luci-app-heimdall": { + "description": "Grant UCI access for luci-app-heimdall", + "read": { + "uci": [ "heimdall" ] + }, + "write": { + "uci": [ "heimdall" ] + } + } +}