diff host/admin/src/private/tools/sites.html.luan @ 1995:301a6561fb6b

add host/admin
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 04 Jul 2025 10:25:38 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/host/admin/src/private/tools/sites.html.luan	Fri Jul 04 10:25:38 2025 -0600
@@ -0,0 +1,95 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local ipairs = Luan.ipairs or error()
+local Io = require "luan:Io.luan"
+local String = require "luan:String.luan"
+local split = String.split or error()
+local Table = require "luan:Table.luan"
+local concat = Table.concat or error()
+local insert = Table.insert or error()
+local sort = Table.sort or error()
+local Time = require "luan:Time.luan"
+local format_time = Time.format or error()
+local Http = require "luan:http/Http.luan"
+local Utils = require "site:/private/lib/Utils.luan"
+local Logging = require "luan:logging/Logging.luan"
+local logger = Logging.logger "sites.html"
+
+
+local function remove()
+	local site = Http.request.parameters.site or error()
+	local site_dir = Utils.sites_dir.child(site)
+	site_dir.exists() or error()
+	site_dir.delete()
+end
+
+
+return function()
+	local action = Http.request.parameters.action
+	if action == "remove" then
+		remove()
+		Http.response.send_redirect "sites.html"
+		return
+	end
+
+	Io.stdout = Http.response.text_writer()
+	local dirs = Utils.sites_dir.children()
+	for _, dir in ipairs(dirs) do
+		local t = {}
+		for _, s in ipairs{split(dir.name(),".")} do
+			insert(t,1,s)
+		end
+		dir.sort = concat(t,".")
+	end
+	sort(dirs,function(d1,d2)
+		return d1.sort < d2.sort
+	end)
+%>
+<!doctype html>
+<html lang="en">
+	<body>
+		<table>
+			<tr><th></th><th>site</th><th>logs/web</th><th>DNS</th><th></th><th>password</th></tr>
+<%
+	local my_ips = Io.my_ips()
+	for i, site_dir in ipairs(dirs) do
+		local site = site_dir.name()
+		if site_dir.is_directory() then
+			local url = "http://"..site
+			local port = Http.request.port
+			if port ~= nil and port ~= 80 then
+				url = url..":"..port
+			end
+			url = url.."/"
+			local password = Luan.do_file(site_dir.to_string().."/info.luan").password or error()
+			local web_log = site_dir.child("site/private/local/logs/web")
+			local date = web_log.last_modified()
+
+			local dns = ""
+			local ip = Io.ip(site)
+			if my_ips[ip] ~= true then
+				dns = ip or "not found"
+			end
+%>
+			<tr>
+				<td><%=i%></td>
+				<td><a href="<%=url%>"><%=site%></a></td>
+				<td nowrap><%=format_time(date,"yyyy-MM-dd")%></td>
+				<td><%=dns%></td>
+				<td><a href="sites.html?action=remove&site=<%=site%>" onclick="return confirm('Delete <%=site%>?')">remove</a></td>
+				<td><%=password%></td>
+			</tr>
+<%
+		else
+%>
+			<tr><td><%=site%></td></tr>
+<%
+		end
+	end
+%>
+		<table>
+
+	</body>
+</html>
+<%
+end