Mercurial Hosting > chat
changeset 1:b116b6ef07bf
add config
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 23 Oct 2024 21:18:04 -0600 |
parents | fddd11ae516c |
children | ee1f91e67509 |
files | .hgignore src/lib/Shared.luan src/private/tools/config.html.luan src/private/tools/index.html.luan src/private/tools/save_config.txt.luan |
diffstat | 5 files changed, 86 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
diff -r fddd11ae516c -r b116b6ef07bf .hgignore --- a/.hgignore Wed Oct 23 13:13:07 2024 -0600 +++ b/.hgignore Wed Oct 23 21:18:04 2024 -0600 @@ -1,3 +1,4 @@ syntax: glob err +local/
diff -r fddd11ae516c -r b116b6ef07bf src/lib/Shared.luan --- a/src/lib/Shared.luan Wed Oct 23 13:13:07 2024 -0600 +++ b/src/lib/Shared.luan Wed Oct 23 21:18:04 2024 -0600 @@ -1,6 +1,9 @@ local Luan = require "luan:Luan.luan" local error = Luan.error local ipairs = Luan.ipairs or error() +local parse = Luan.parse or error() +local Io = require "luan:Io.luan" +local uri = Io.uri or error() local Shared = {} @@ -33,4 +36,22 @@ } end +local config_file = uri("site:/private/local/config.luano") +Shared.config_file = config_file + +do + if config_file.exists() then + Shared.config = parse( config_file.read_text() ) + else + Shared.config = { + mail_server = { + host = "smtpcorp.com" + port = 465 + username = "xxx" + password = "xxx" + } + } + end +end + return Shared
diff -r fddd11ae516c -r b116b6ef07bf src/private/tools/config.html.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/private/tools/config.html.luan Wed Oct 23 21:18:04 2024 -0600 @@ -0,0 +1,43 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local stringify = Luan.stringify or error() +local Io = require "luan:Io.luan" +local Http = require "luan:http/Http.luan" +local Shared = require "site:/lib/Shared.luan" +local head = Shared.head or error() +local header = Shared.private_header or error() +local config = Shared.config or error() + + +return function() + Io.stdout = Http.response.text_writer() +%> +<!doctype html> +<html> + <head> +<% head() %> + <title>Chat Private Tools</title> + <style> + textarea { + width: 90%; + height: 20em; + } + </style> + </head> + <body> +<% header() %> + <div content> + <h1>Configure</h1> + <form method=post action="save_config.txt"> + <p> + <textarea name=config autofocus><%= stringify(config) %></textarea> + </p> + <p> + <input type=submit value="Update"> + </p> + </form> + </div> + </body> +</html> +<% +end
diff -r fddd11ae516c -r b116b6ef07bf src/private/tools/index.html.luan --- a/src/private/tools/index.html.luan Wed Oct 23 13:13:07 2024 -0600 +++ b/src/private/tools/index.html.luan Wed Oct 23 21:18:04 2024 -0600 @@ -20,11 +20,7 @@ <% header() %> <div content> <h1>Private Tools</h1> - <p><a href="private_users.html">edit private users</a></p> - <p><a href="backup.html">edit backup</a></p> - <p><a href="all_users.html">all users</a></p> - <p><a href="configure_mail.html">configure mail</a></p> - <p><a href="links.txt">links.txt</a></p> + <p><a href="config.html">configure</a></p> </div> </body> </html>
diff -r fddd11ae516c -r b116b6ef07bf src/private/tools/save_config.txt.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/private/tools/save_config.txt.luan Wed Oct 23 21:18:04 2024 -0600 @@ -0,0 +1,20 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local parse = Luan.parse or error() +local stringify = Luan.stringify or error() +local Io = require "luan:Io.luan" +local uri = Io.uri or error() +local Http = require "luan:http/Http.luan" +local Shared = require "site:/lib/Shared.luan" +local config_file = Shared.config_file or error() + + +return function() + local config = Http.request.parameters.config or error() + config = parse(config) + uri("site:/private/local/").mkdir() + config_file.write_text(stringify(config).."\n") + Http.reset_luan() + Io.stdout = Http.response.text_writer() + %>saved<% +end