Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
1994:035996323891 | 1995:301a6561fb6b |
---|---|
1 local Luan = require "luan:Luan.luan" | |
2 local error = Luan.error | |
3 local ipairs = Luan.ipairs or error() | |
4 local Io = require "luan:Io.luan" | |
5 local String = require "luan:String.luan" | |
6 local split = String.split or error() | |
7 local Table = require "luan:Table.luan" | |
8 local concat = Table.concat or error() | |
9 local insert = Table.insert or error() | |
10 local sort = Table.sort or error() | |
11 local Time = require "luan:Time.luan" | |
12 local format_time = Time.format or error() | |
13 local Http = require "luan:http/Http.luan" | |
14 local Utils = require "site:/private/lib/Utils.luan" | |
15 local Logging = require "luan:logging/Logging.luan" | |
16 local logger = Logging.logger "sites.html" | |
17 | |
18 | |
19 local function remove() | |
20 local site = Http.request.parameters.site or error() | |
21 local site_dir = Utils.sites_dir.child(site) | |
22 site_dir.exists() or error() | |
23 site_dir.delete() | |
24 end | |
25 | |
26 | |
27 return function() | |
28 local action = Http.request.parameters.action | |
29 if action == "remove" then | |
30 remove() | |
31 Http.response.send_redirect "sites.html" | |
32 return | |
33 end | |
34 | |
35 Io.stdout = Http.response.text_writer() | |
36 local dirs = Utils.sites_dir.children() | |
37 for _, dir in ipairs(dirs) do | |
38 local t = {} | |
39 for _, s in ipairs{split(dir.name(),".")} do | |
40 insert(t,1,s) | |
41 end | |
42 dir.sort = concat(t,".") | |
43 end | |
44 sort(dirs,function(d1,d2) | |
45 return d1.sort < d2.sort | |
46 end) | |
47 %> | |
48 <!doctype html> | |
49 <html lang="en"> | |
50 <body> | |
51 <table> | |
52 <tr><th></th><th>site</th><th>logs/web</th><th>DNS</th><th></th><th>password</th></tr> | |
53 <% | |
54 local my_ips = Io.my_ips() | |
55 for i, site_dir in ipairs(dirs) do | |
56 local site = site_dir.name() | |
57 if site_dir.is_directory() then | |
58 local url = "http://"..site | |
59 local port = Http.request.port | |
60 if port ~= nil and port ~= 80 then | |
61 url = url..":"..port | |
62 end | |
63 url = url.."/" | |
64 local password = Luan.do_file(site_dir.to_string().."/info.luan").password or error() | |
65 local web_log = site_dir.child("site/private/local/logs/web") | |
66 local date = web_log.last_modified() | |
67 | |
68 local dns = "" | |
69 local ip = Io.ip(site) | |
70 if my_ips[ip] ~= true then | |
71 dns = ip or "not found" | |
72 end | |
73 %> | |
74 <tr> | |
75 <td><%=i%></td> | |
76 <td><a href="<%=url%>"><%=site%></a></td> | |
77 <td nowrap><%=format_time(date,"yyyy-MM-dd")%></td> | |
78 <td><%=dns%></td> | |
79 <td><a href="sites.html?action=remove&site=<%=site%>" onclick="return confirm('Delete <%=site%>?')">remove</a></td> | |
80 <td><%=password%></td> | |
81 </tr> | |
82 <% | |
83 else | |
84 %> | |
85 <tr><td><%=site%></td></tr> | |
86 <% | |
87 end | |
88 end | |
89 %> | |
90 <table> | |
91 | |
92 </body> | |
93 </html> | |
94 <% | |
95 end |