mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-03 12:53:56 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_VERSION:=1.0.2-20240822
|
||||
PKG_RELEASE:=1
|
||||
|
||||
LUCI_TITLE:=LuCI support for UnifiController
|
||||
LUCI_PKGARCH:=all
|
||||
LUCI_DEPENDS:=+lsblk +docker +dockerd +luci-lib-taskd
|
||||
|
||||
define Package/luci-app-unifi/conffiles
|
||||
/etc/config/unifi
|
||||
endef
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
|
||||
module("luci.controller.unifi", package.seeall)
|
||||
|
||||
function index()
|
||||
entry({"admin", "services", "unifi"}, alias("admin", "services", "unifi", "config"), _("UnifiController"), 30).dependent = true
|
||||
entry({"admin", "services", "unifi", "config"}, cbi("unifi"))
|
||||
end
|
||||
@@ -0,0 +1,49 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
]]--
|
||||
|
||||
local taskd = require "luci.model.tasks"
|
||||
local unifi_model = require "luci.model.unifi"
|
||||
local m, s, o
|
||||
|
||||
m = taskd.docker_map("unifi", "unifi", "/usr/libexec/istorec/unifi.sh",
|
||||
translate("UnifiController"),
|
||||
translate("UnifiController ubnt.")
|
||||
.. translate("Official website:") .. ' <a href=\"https://www.ui.com/\" target=\"_blank\">https://www.ui.com/</a>')
|
||||
|
||||
s = m:section(SimpleSection, translate("Service Status"), translate("UnifiController status:"))
|
||||
s:append(Template("unifi/status"))
|
||||
|
||||
s = m:section(TypedSection, "main", translate("Setup"), translate("The following parameters will only take effect during installation or upgrade:"))
|
||||
s.addremove=false
|
||||
s.anonymous=true
|
||||
|
||||
o = s:option(Flag, "hostnet", translate("Host network"), translate("UnifiController running in host network, port is always 8443 if enabled"))
|
||||
o.default = 0
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "http_port", translate("HTTPS Port").."<b>*</b>")
|
||||
o.default = "8083"
|
||||
o.datatype = "string"
|
||||
o:depends("hostnet", 0)
|
||||
|
||||
o = s:option(Value, "image_name", translate("Image").."<b>*</b>")
|
||||
o.rmempty = false
|
||||
o.datatype = "string"
|
||||
o:value("lscr.io/linuxserver/unifi-controller:latest", "lscr.io/linuxserver/unifi-controller:latest")
|
||||
o.default = "lscr.io/linuxserver/unifi-controller:latest"
|
||||
|
||||
local blocks = unifi_model.blocks()
|
||||
local home = unifi_model.home()
|
||||
|
||||
o = s:option(Value, "config_path", translate("Config path").."<b>*</b>")
|
||||
o.rmempty = false
|
||||
o.datatype = "string"
|
||||
|
||||
local paths, default_path = unifi_model.find_paths(blocks, home, "Configs")
|
||||
for _, val in pairs(paths) do
|
||||
o:value(val, val)
|
||||
end
|
||||
o.default = default_path
|
||||
|
||||
return m
|
||||
@@ -0,0 +1,53 @@
|
||||
local util = require "luci.util"
|
||||
local jsonc = require "luci.jsonc"
|
||||
|
||||
local unifi = {}
|
||||
|
||||
unifi.blocks = function()
|
||||
local f = io.popen("lsblk -s -f -b -o NAME,FSSIZE,MOUNTPOINT --json", "r")
|
||||
local vals = {}
|
||||
if f then
|
||||
local ret = f:read("*all")
|
||||
f:close()
|
||||
local obj = jsonc.parse(ret)
|
||||
for _, val in pairs(obj["blockdevices"]) do
|
||||
local fsize = val["fssize"]
|
||||
if fsize ~= nil and string.len(fsize) > 10 and val["mountpoint"] then
|
||||
-- fsize > 1G
|
||||
vals[#vals+1] = val["mountpoint"]
|
||||
end
|
||||
end
|
||||
end
|
||||
return vals
|
||||
end
|
||||
|
||||
unifi.home = function()
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local home_dirs = {}
|
||||
home_dirs["main_dir"] = uci:get_first("quickstart", "main", "main_dir", "/root")
|
||||
home_dirs["Configs"] = uci:get_first("quickstart", "main", "conf_dir", home_dirs["main_dir"].."/Configs")
|
||||
home_dirs["Caches"] = uci:get_first("quickstart", "main", "tmp_dir", home_dirs["main_dir"].."/Caches")
|
||||
return home_dirs
|
||||
end
|
||||
|
||||
unifi.find_paths = function(blocks, home_dirs, path_name)
|
||||
local default_path = ''
|
||||
local configs = {}
|
||||
|
||||
default_path = home_dirs[path_name] .. "/UnifiController"
|
||||
if #blocks == 0 then
|
||||
table.insert(configs, default_path)
|
||||
else
|
||||
for _, val in pairs(blocks) do
|
||||
table.insert(configs, val .. "/" .. path_name .. "/UnifiController")
|
||||
end
|
||||
local without_conf_dir = "/root/" .. path_name .. "/UnifiController"
|
||||
if default_path == without_conf_dir then
|
||||
default_path = configs[1]
|
||||
end
|
||||
end
|
||||
|
||||
return configs, default_path
|
||||
end
|
||||
|
||||
return unifi
|
||||
@@ -0,0 +1,31 @@
|
||||
<%
|
||||
local util = require "luci.util"
|
||||
local container_status = util.trim(util.exec("/usr/libexec/istorec/unifi.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"><%:UnifiController is running%></button>
|
||||
<% else %>
|
||||
<button class="cbi-button cbi-button-negative" disabled="true"><%:UnifiController is not running%></button>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<%
|
||||
if container_running then
|
||||
local port=util.trim(util.exec("/usr/libexec/istorec/unifi.sh port"))
|
||||
if port == "" then
|
||||
port="8443"
|
||||
end
|
||||
-%>
|
||||
<div class="cbi-value cbi-value-last">
|
||||
<label class="cbi-value-title"> </label>
|
||||
<div class="cbi-value-field">
|
||||
|
||||
<input type="button" class="btn cbi-button cbi-button-apply" name="start" value="<%:Open UnifiController%>" onclick="window.open('https://'+location.hostname+':<%=port%>', '_blank')">
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -0,0 +1,41 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8"
|
||||
|
||||
msgid "Official website:"
|
||||
msgstr "官方网站:"
|
||||
|
||||
msgid "UnifiController ubnt."
|
||||
msgstr "Ubnt AC 控制器。"
|
||||
|
||||
msgid "Config path"
|
||||
msgstr "配置文件路径"
|
||||
|
||||
msgid "HTTPS Port"
|
||||
msgstr "HTTPS 端口"
|
||||
|
||||
msgid "Service Status"
|
||||
msgstr "服务状态"
|
||||
|
||||
msgid "UnifiController status:"
|
||||
msgstr "UnifiController 的状态信息如下:"
|
||||
|
||||
msgid "Setup"
|
||||
msgstr "安装配置"
|
||||
|
||||
msgid "The following parameters will only take effect during installation or upgrade:"
|
||||
msgstr "以下参数只在安装或者升级时才会生效:"
|
||||
|
||||
msgid "Status"
|
||||
msgstr "状态"
|
||||
|
||||
msgid "UnifiController is running"
|
||||
msgstr "UnifiController 运行中"
|
||||
|
||||
msgid "UnifiController is not running"
|
||||
msgstr "UnifiController 未运行"
|
||||
|
||||
msgid "Open UnifiController"
|
||||
msgstr "打开 UnifiController"
|
||||
|
||||
msgid "UnifiController running in host network, port is always 8443 if enabled"
|
||||
msgstr "在宿主网络运行 UnifiController,如果启用则端口固定为8443,注意此端口可能与其他应用冲突"
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
zh-cn
|
||||
@@ -0,0 +1,6 @@
|
||||
config main
|
||||
option 'hostnet' '0'
|
||||
option 'http_port' '8083'
|
||||
option 'image_name' 'lscr.io/linuxserver/unifi-controller:latest'
|
||||
option 'config_path' ''
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
#!/bin/sh
|
||||
# Author Xiaobao(xiaobao@linkease.com)
|
||||
|
||||
ACTION=${1}
|
||||
shift 1
|
||||
|
||||
do_install() {
|
||||
local hostnet=`uci get unifi.@main[0].hostnet 2>/dev/null`
|
||||
local http_port=`uci get unifi.@main[0].http_port 2>/dev/null`
|
||||
local image_name=`uci get unifi.@main[0].image_name 2>/dev/null`
|
||||
local config=`uci get unifi.@main[0].config_path 2>/dev/null`
|
||||
|
||||
[ -z "$image_name" ] && image_name="lscr.io/linuxserver/unifi-controller:latest"
|
||||
echo "docker pull ${image_name}"
|
||||
docker pull ${image_name}
|
||||
docker rm -f unifi
|
||||
|
||||
if [ -z "$config" ]; then
|
||||
echo "config path is empty!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[ -z "$http_port" ] && http_port=8083
|
||||
|
||||
local cmd="docker run --restart=unless-stopped -d -v \"$config:/config\" "
|
||||
|
||||
if [ "$hostnet" = 1 ]; then
|
||||
cmd="$cmd\
|
||||
--dns=127.0.0.1 \
|
||||
--network=host "
|
||||
else
|
||||
cmd="$cmd\
|
||||
--dns=172.17.0.1 \
|
||||
-p 3478:3478/udp \
|
||||
-p 10001:10001/udp \
|
||||
-p 8080:8080 \
|
||||
-p $http_port:8443 "
|
||||
fi
|
||||
|
||||
local tz="`uci get system.@system[0].zonename | sed 's/ /_/g'`"
|
||||
[ -z "$tz" ] || cmd="$cmd -e TZ=$tz"
|
||||
|
||||
cmd="$cmd -v /mnt:/mnt"
|
||||
mountpoint -q /mnt && cmd="$cmd:rslave"
|
||||
cmd="$cmd --name unifi \"$image_name\""
|
||||
|
||||
echo "$cmd"
|
||||
eval "$cmd"
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 sub-command"
|
||||
echo "where sub-command is one of:"
|
||||
echo " install Install the unifi"
|
||||
echo " upgrade Upgrade the unifi"
|
||||
echo " rm/start/stop/restart Remove/Start/Stop/Restart the unifi"
|
||||
echo " status UnifiController status"
|
||||
echo " port UnifiController port"
|
||||
}
|
||||
|
||||
case ${ACTION} in
|
||||
"install")
|
||||
do_install
|
||||
;;
|
||||
"upgrade")
|
||||
do_install
|
||||
;;
|
||||
"rm")
|
||||
docker rm -f unifi
|
||||
;;
|
||||
"start" | "stop" | "restart")
|
||||
docker ${ACTION} unifi
|
||||
;;
|
||||
"status")
|
||||
docker ps --all -f 'name=^/unifi$' --format '{{.State}}'
|
||||
;;
|
||||
"port")
|
||||
docker ps --all -f 'name=^/unifi$' --format '{{.Ports}}' | grep -om1 '0.0.0.0:[0-9]*->8443/tcp' | sed 's/0.0.0.0:\([0-9]*\)->.*/\1/'
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-unifi": {
|
||||
"description": "Grant UCI access for luci-app-unifi",
|
||||
"read": {
|
||||
"uci": [ "unifi" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "unifi" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user