mirror of
https://github.com/lxsang/antd-web-apps
synced 2025-01-16 01:38:25 +01:00
Compare commits
No commits in common. "8e02d3f6ba08b75b9922ccd9ebc5d0758a2c0a9b" and "7ede87e962d71859d49b64af8c1003ceb362609f" have entirely different histories.
8e02d3f6ba
...
7ede87e962
@ -19,66 +19,24 @@ end
|
|||||||
function ServiceController:sendmail()
|
function ServiceController:sendmail()
|
||||||
if not REQUEST.json then
|
if not REQUEST.json then
|
||||||
fail("unknown request")
|
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
|
end
|
||||||
local rq = (JSON.decodeString(REQUEST.json))
|
local rq = (JSON.decodeString(REQUEST.json))
|
||||||
local to = "contact@iohub.dev"
|
local to = "mrsang@iohub.dev"
|
||||||
|
local from = "From: " .. rq.email .. "\n"
|
||||||
local msg = {
|
local suject = "Subject: " .. rq.subject .. "\n"
|
||||||
headers = {
|
local content = "Contact request from:" .. rq.name .. "\n Email: " .. rq.email .. "\n" .. rq.content .. "\n"
|
||||||
from = string.format("%s <%s>", rq.name, rq.email),
|
|
||||||
to = string.format("Contact <%s>",to),
|
local cmd = 'echo "' .. utils.escape(from .. suject .. content) .. '"| sendmail ' .. to
|
||||||
subject = rq.subject
|
|
||||||
},
|
--print(cmd)
|
||||||
body = rq.content
|
local r = os.execute(cmd)
|
||||||
}
|
|
||||||
LOG_INFO("Send mail on server %s user %s port %d: %s", setting.server, setting.user, setting.port, JSON.encode(msg))
|
if r then
|
||||||
local ok, err = smtp.send {
|
result(r)
|
||||||
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)
|
|
||||||
else
|
else
|
||||||
result("Email sent")
|
fail("Cannot send email at the moment, the service may be down")
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function ServiceController:subscribe()
|
function ServiceController:subscribe()
|
||||||
|
@ -9,7 +9,6 @@ enc = require("enc")
|
|||||||
WWW_ROOT = __ROOT__.."/blog"
|
WWW_ROOT = __ROOT__.."/blog"
|
||||||
DB_LOC="/opt/www/databases"
|
DB_LOC="/opt/www/databases"
|
||||||
DB_FILE = DB_LOC.."/mrsang.db"
|
DB_FILE = DB_LOC.."/mrsang.db"
|
||||||
SMTP_SETTING=DB_LOC.."/smtp.json"
|
|
||||||
-- add aditional paths
|
-- add aditional paths
|
||||||
package.path = package.path..";"..WWW_ROOT .. '/?.lua'
|
package.path = package.path..";"..WWW_ROOT .. '/?.lua'
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?lua if not HEADER.mobile then ?>
|
<?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 end ?>
|
||||||
<?lua
|
<?lua
|
||||||
local datas = posts
|
local datas = posts
|
||||||
|
@ -11,64 +11,15 @@ end
|
|||||||
|
|
||||||
local function sendmail(to, subject, content)
|
local function sendmail(to, subject, content)
|
||||||
LOG_DEBUG("Sending email to %s", to)
|
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 cmd = 'echo "' .. utils.escape(from .. suject .. content) ..
|
||||||
|
'"| sendmail ' .. to
|
||||||
local socket = require 'socket'
|
local r = os.execute(cmd)
|
||||||
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
|
|
||||||
|
|
||||||
|
if r then return true end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
function CommentController:index(...)
|
function CommentController:index(...)
|
||||||
if (REQUEST.method == "OPTIONS") then
|
if (REQUEST.method == "OPTIONS") then
|
||||||
|
@ -9,7 +9,6 @@ enc = require("enc")
|
|||||||
WWW_ROOT = __ROOT__.."/talk"
|
WWW_ROOT = __ROOT__.."/talk"
|
||||||
DB_LOC="/opt/www/databases"
|
DB_LOC="/opt/www/databases"
|
||||||
DB_FILE = DB_LOC.."/quicktalk.db"
|
DB_FILE = DB_LOC.."/quicktalk.db"
|
||||||
SMTP_SETTING=DB_LOC.."/smtp.json"
|
|
||||||
function fail(msg)
|
function fail(msg)
|
||||||
std.json()
|
std.json()
|
||||||
std.t(JSON.encode({error = msg}))
|
std.t(JSON.encode({error = msg}))
|
||||||
|
Loading…
Reference in New Issue
Block a user