first commit

main
ben 1 year ago
commit aa5ba474fe

@ -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

@ -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

@ -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:") .. ' <a href=\"https://github.com/linuxserver/Heimdall\" target=\"_blank\">https://github.com/linuxserver/Heimdall</a>')
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").."<b>*</b>")
o.rmempty = false
o.default = "8088"
o.datatype = "port"
o = s:option(Value, "https_port", translate("HTTPS Port").."<b>*</b>")
o.rmempty = false
o.default = "8089"
o.datatype = "port"
o = s:option(Value, "config_path", translate("Config path").."<b>*</b>")
o.rmempty = false
o.default = "/root/heimdall/config"
o.datatype = "string"
return m

@ -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"
-%>
<div class="cbi-value">
<label class="cbi-value-title"><%:Status%></label>
<div class="cbi-value-field">
<% if container_running then %>
<button class="cbi-button cbi-button-success" disabled="true"><%:Heimdall is running%></button>
<% else %>
<button class="cbi-button cbi-button-negative" disabled="true"><%:Heimdall is not running%></button>
<% end %>
</div>
</div>
<%
if container_running then
local port=util.trim(util.exec("/usr/libexec/apps/heimdall.sh port"))
if port == "" then
port="8088"
end
-%>
<div class="cbi-value cbi-value-last">
<label class="cbi-value-title">&nbsp;</label>
<div class="cbi-value-field">
<input type="button" class="btn cbi-button cbi-button-apply" name="start" value="<%:Open Heimdall%>" onclick="window.open('http://'+location.hostname+':<%=port%>/', '_blank')">
</div>
</div>
<% end %>

@ -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"

@ -0,0 +1 @@
zh-cn

@ -0,0 +1,4 @@
config heimdall
option 'http_port' '8088'
option 'https_port' '8089'
option 'config_path' '/root/heimdall/config'

@ -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

@ -0,0 +1,11 @@
{
"luci-app-heimdall": {
"description": "Grant UCI access for luci-app-heimdall",
"read": {
"uci": [ "heimdall" ]
},
"write": {
"uci": [ "heimdall" ]
}
}
}
Loading…
Cancel
Save