1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2025-01-15 17:28:25 +01:00

Compare commits

..

No commits in common. "8e02d3f6ba08b75b9922ccd9ebc5d0758a2c0a9b" and "7ede87e962d71859d49b64af8c1003ceb362609f" have entirely different histories.

5 changed files with 22 additions and 115 deletions

View File

@ -19,66 +19,24 @@ end
function ServiceController:sendmail()
if not REQUEST.json then
fail("unknown request")
return
end
local setting = JSON.decodeFile(SMTP_SETTING)
local socket = require 'socket'
local smtp = require 'socket.smtp'
local ssl = require 'ssl'
local https = require 'ssl.https'
local ltn12 = require 'ltn12'
local sslCreate = function()
local sock = socket.tcp()
return setmetatable({
connect = function(_, host, port)
local r, e = sock:connect(host, port)
if not r then return r, e end
sock = ssl.wrap(sock, {mode='client', protocol='tlsv1_2'})
return sock:dohandshake()
end
}, {
__index = function(t,n)
return function(_, ...)
return sock[n](sock, ...)
end
end
})
end
if not setting then
fail("Dont know how to connect to SMTP server")
return
end
local rq = (JSON.decodeString(REQUEST.json))
local to = "contact@iohub.dev"
local msg = {
headers = {
from = string.format("%s <%s>", rq.name, rq.email),
to = string.format("Contact <%s>",to),
subject = rq.subject
},
body = rq.content
}
LOG_INFO("Send mail on server %s user %s port %d: %s", setting.server, setting.user, setting.port, JSON.encode(msg))
local ok, err = smtp.send {
from = string.format("<%s>",rq.email),
rcpt = string.format('<%s>', to),
source = smtp.message(msg),
user = setting.user,
password = setting.password,
server = setting.server,
port = math.floor(setting.port),
create = sslCreate
}
if not ok then
fail(err)
local to = "mrsang@iohub.dev"
local from = "From: " .. rq.email .. "\n"
local suject = "Subject: " .. rq.subject .. "\n"
local content = "Contact request from:" .. rq.name .. "\n Email: " .. rq.email .. "\n" .. rq.content .. "\n"
local cmd = 'echo "' .. utils.escape(from .. suject .. content) .. '"| sendmail ' .. to
--print(cmd)
local r = os.execute(cmd)
if r then
result(r)
else
result("Email sent")
fail("Cannot send email at the moment, the service may be down")
end
return false
end
function ServiceController:subscribe()

View File

@ -9,7 +9,6 @@ enc = require("enc")
WWW_ROOT = __ROOT__.."/blog"
DB_LOC="/opt/www/databases"
DB_FILE = DB_LOC.."/mrsang.db"
SMTP_SETTING=DB_LOC.."/smtp.json"
-- add aditional paths
package.path = package.path..";"..WWW_ROOT .. '/?.lua'

View File

@ -1,5 +1,5 @@
<?lua if not HEADER.mobile then ?>
<!--iframe width="980" height="410" src="https://mars.nasa.gov/layout/embed/send-your-name/future/certificate/?cn=792789419260" frameborder="0"></iframe-->
<iframe width="980" height="410" src="https://mars.nasa.gov/layout/embed/send-your-name/future/certificate/?cn=792789419260" frameborder="0"></iframe>
<?lua end ?>
<?lua
local datas = posts

View File

@ -11,64 +11,15 @@ end
local function sendmail(to, subject, content)
LOG_DEBUG("Sending email to %s", to)
local from = "From: contact@iohub.dev\nTo: " .. to .. "\n"
local suject = "Subject: " .. subject .. "\n"
local setting = JSON.decodeFile(SMTP_SETTING)
local socket = require 'socket'
local smtp = require 'socket.smtp'
local ssl = require 'ssl'
local https = require 'ssl.https'
local ltn12 = require 'ltn12'
local sslCreate = function()
local sock = socket.tcp()
return setmetatable({
connect = function(_, host, port)
local r, e = sock:connect(host, port)
if not r then return r, e end
sock = ssl.wrap(sock, {mode='client', protocol='tlsv1_2'})
return sock:dohandshake()
end
}, {
__index = function(t,n)
return function(_, ...)
return sock[n](sock, ...)
end
end
})
end
local setting = JSON.decodeFile(SMTP_SETTING)
if not setting then
return false
end
local from = "contact@iohub.dev"
local msg = {
headers = {
from = string.format("QuickTalk <%s>", from),
to = string.format("%s <%s>",to,to),
subject = subject
},
body = content
}
LOG_INFO("Send mail on server %s user %s port %d: %s", setting.server, setting.user, setting.port, JSON.encode(msg))
local ok, err = smtp.send {
from = string.format("<%s>",from),
rcpt = string.format('<%s>', to),
source = smtp.message(msg),
user = setting.user,
password = setting.password,
server = setting.server,
port = math.floor(setting.port),
create = sslCreate
}
if not ok then return false end
return true
local cmd = 'echo "' .. utils.escape(from .. suject .. content) ..
'"| sendmail ' .. to
local r = os.execute(cmd)
if r then return true end
return false
end
function CommentController:index(...)
if (REQUEST.method == "OPTIONS") then

View File

@ -9,7 +9,6 @@ enc = require("enc")
WWW_ROOT = __ROOT__.."/talk"
DB_LOC="/opt/www/databases"
DB_FILE = DB_LOC.."/quicktalk.db"
SMTP_SETTING=DB_LOC.."/smtp.json"
function fail(msg)
std.json()
std.t(JSON.encode({error = msg}))