annotate src/private/admin/mail_config.html.luan @ 61:389e5d8e5f8a default tip

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Dec 2022 13:37:25 -0700
parents a17e400ddaa1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local stringify = Luan.stringify or error()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local String = require "luan:String.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local trim = String.trim or error()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Html = require "luan:Html.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local html_encode = Html.encode or error()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Parsers = require "luan:Parsers.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local json_string = Parsers.json_string or error()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Io = require "luan:Io.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Http = require "luan:http/Http.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local Mail = require "site:/lib/Mail.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local Shared = require "site:/lib/Shared.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local head = Shared.head or error()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local header = Shared.admin_header or error()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local Logging = require "luan:logging/Logging.luan"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 local logger = Logging.logger "admin/mail_config.html"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 --[[
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local default = stringify{
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 host = "smtpcorp.com"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 username = "xxx"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 password = "xxx"
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 port = 2525
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 }
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 ]]
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 return function()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 Io.stdout = Http.response.text_writer()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 local updated = false
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 if Http.request.method == "POST" then
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 local config = Http.request.parameters.config or error()
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 if trim(config) == "" then
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 config = nil
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 end
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 Mail.set(config)
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 updated = true
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 end
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 %>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 <!doctype html>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 <html>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 <head>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 <% head() %>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 <title>FreedIt - Configure Mail</title>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <style>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 textarea {
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 width: 20em;
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 height: 10em;
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 }
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 </style>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 </head>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 <body>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 <% header() %>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 <div content>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 <h1>Configure Mail</h1>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 <% if updated then %>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 <p>Updated</p>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 <% else %>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 <form method=post>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 <p><textarea name=config autofocus><%= html_encode(Mail.get() or "") %></textarea></p>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 <p><input type=submit><p>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 </form>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 <% end %>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 </div>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 </body>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 </html>
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 <%
a17e400ddaa1 add email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 end