first commit

main
ben 1 year ago
commit 6340489983

BIN
.DS_Store vendored

Binary file not shown.

@ -0,0 +1,16 @@
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI support for lxd
LUCI_PKGARCH:=all
LUCI_DEPENDS:=+lsblk +lxdc +luci-lib-taskd +docker
define Package/luci-app-lxdterm/conffiles
/etc/config/lxdterm
endef
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

@ -0,0 +1,15 @@
module("luci.controller.lxdterm", package.seeall)
function index()
entry({"admin", "apps"}, firstchild(), _("apps") , 45).dependent = false
if not nixio.fs.access("/etc/config/lxdterm") then
return
end
local page = entry({"admin", "apps", "lxdterm"}, cbi("lxdterm"), _("lxdterm"))
page.order = 10
page.dependent = true
page.acl_depends = { "luci-app-lxdterm" }
entry({"admin","lxc","lxdterm","status"},call("act_status")).leaf=true
end

@ -0,0 +1,29 @@
--[[
LuCI - Lua Configuration Interface
]]--
local taskd = require "luci.model.tasks"
local lxdterm_model = require "luci.model.lxdterm"
local m, s, o
m = taskd.docker_map("lxdterm", "lxdterm", "/usr/libexec/apps/lxdterm/lxdterm.sh",
translate("lxdterm"),
translate("Access your LXD containers in Luci Terminal")
.. translate("Official website:") .. ' <a href=\"https://lxd.com/\" target=\"_blank\">https://lxd.com/</a>')
s = m:section(SimpleSection, translate("Service Status"), translate("lxdterm status:"))
s:append(Template("lxdterm/status"))
s = m:section(TypedSection, "lxdterm", translate("Container"), translate("Enter the LXC container you want to access then click save."))
s.addremove=false
s.anonymous=true
o = s:option(Value, "container", translate("container").."<b>*</b>")
o.rmempty = false
o.default = "ubuntu" -- Changed default to "ubuntu"
o.datatype = "string" -- Changed datatype to "string"
local blocks = lxdterm_model.blocks()
local home = lxdterm_model.home()
return m

@ -0,0 +1,55 @@
local util = require "luci.util"
local jsonc = require "luci.jsonc"
local lxdterm = {}
lxdterm.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
lxdterm.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["Public"] = uci:get_first("quickstart", "main", "pub_dir", home_dirs["main_dir"].."/Public")
home_dirs["Downloads"] = uci:get_first("quickstart", "main", "dl_dir", home_dirs["Public"].."/Downloads")
home_dirs["Caches"] = uci:get_first("quickstart", "main", "tmp_dir", home_dirs["main_dir"].."/Caches")
return home_dirs
end
lxdterm.find_paths = function(blocks, home_dirs, path_name)
local default_path = ''
local configs = {}
default_path = home_dirs[path_name] .. "/lxdterm"
if #blocks == 0 then
table.insert(configs, default_path)
else
for _, val in pairs(blocks) do
table.insert(configs, val .. "/" .. path_name .. "/lxdterm")
end
local without_conf_dir = "/root/" .. path_name .. "/lxdterm"
if default_path == without_conf_dir then
default_path = configs[1]
end
end
return configs, default_path
end
return simplex

@ -0,0 +1,31 @@
<%
local util = require "luci.util"
local container_status = util.trim(util.exec("/usr/libexec/apps/simplex/simplex.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"><%:simplex is running%></button>
<% else %>
<button class="cbi-button cbi-button-negative" disabled="true"><%:simplex is not running%></button>
<% end %>
</div>
</div>
<%
if container_running then
local port=util.trim(util.exec("/usr/libexec/apps/simplex/simplex.sh port"))
if port == "" then
port="5223"
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 simplex%>" onclick="window.open('http://'+location.hostname+':<%=port%>/', '_blank')">
</div>
</div>
<% end %>

@ -0,0 +1,4 @@
config lxdterm
option 'container' 'ubuntu'
option 'config_path' '/mnt/sda1/lxc

@ -0,0 +1,14 @@
#!/bin/sh
config_dir=`uci -q get simplex.@simplex[0].config_path`
data_dir=`docker inspect --format '{{.Mounts}}' simplex | grep -Eom1 '[^ ]+/_data /var/www/html local true ' | cut -d' ' -f1`
if [ -n "$data_dir" -a "$data_dir" != "$config_dir" ]; then
uci -q batch <<-EOF >/dev/null
set simplex.@simplex[0].config_path="$data_dir"
commit simplex
EOF
fi
exit 0

@ -0,0 +1,64 @@
#!/bin/sh
ACTION=${1}
shift 1
get_image() {
GEN_PASS=$(< /dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c14; echo)
}
do_install_detail() {
local config=`uci get lxdterm.@lxdterm[0].container 2>/dev/null`
#Generate the generic environment variables for the docker-compose
# Get our local LAN IP Address
LAN_IP=$(uci get network.lan.ipaddr)
# Strip trailing network mask
LAN_IP="${LAN_IP%/*}"
echo "Entering LXC container"
lxc-attach -n "$config"
}
usage() {
echo "usage: $0 sub-command"
echo "where sub-command is one of:"
echo " install Install lxdterm"
echo " upgrade Upgrade lxdterm"
echo " rm/start/stop/restart Remove/Start/Stop/Restart lxdterm"
echo " status lxdterm status"
echo " port lxdterm port"
}
case ${ACTION} in
"install")
get_image
do_install_detail
;;
"upgrade")
get_image
do_install_detail
;;
"rm")
docker rm -f lxdterm
;;
"start" | "stop" | "restart")
docker ${ACTION} lxdterm
;;
"status")
docker ps --all -f 'name=lxdterm' --format '{{.State}}'
;;
"port")
docker ps --all -f 'name=lxdterm' --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-lxdterm": {
"description": "Grant UCI access for luci-app-lxdterm",
"read": {
"uci": [ "lxdterm" ]
},
"write": {
"uci": [ "lxdterm" ]
}
}
}
Loading…
Cancel
Save