added node project with auth_collector stub
This commit is contained in:
parent
0e41e93be6
commit
c06d689c2b
24
init.lua
24
init.lua
@ -7,5 +7,29 @@ dofile(MP .. "/persistence.lua")
|
||||
dofile(MP .. "/inbox.lua")
|
||||
dofile(MP .. "/ui.lua")
|
||||
|
||||
-- optional webmail stuff below
|
||||
|
||||
--[[ minetest.conf
|
||||
secure.http_mods = mail
|
||||
webmail.url = http://127.0.0.1:8080
|
||||
webmail.key = myserverkey
|
||||
--]]
|
||||
|
||||
local http = minetest.request_http_api()
|
||||
|
||||
if http then
|
||||
local webmail_url = minetest.settings:get("webmail.url")
|
||||
local webmail_key = minetest.settings:get("webmail.key")
|
||||
|
||||
if not webmail_url then error("webmail.url is not defined") end
|
||||
if not webmail_key then error("webmail.key is not defined") end
|
||||
|
||||
print("[mail] loading webmail-component with endpoint: " .. webmail_url)
|
||||
dofile(MP .. "/webmail.lua")
|
||||
mail.webmail_init(http, webmail_url, webmail_key)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
mail.load()
|
||||
|
63
webmail.lua
Normal file
63
webmail.lua
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
local url, key, http
|
||||
|
||||
local webmail = {}
|
||||
|
||||
-- polls the webmail server and processes the logins made there
|
||||
webmail.auth_collector = function()
|
||||
http.fetch({
|
||||
url=url .. "/api/auth_collector",
|
||||
extra_headers = { "webmailkey: " .. key },
|
||||
timeout=10
|
||||
}, function(res)
|
||||
|
||||
if res.code == 403 then
|
||||
-- unauthorized, abort
|
||||
minetest.log("error", "[webmail] invalid key specified!")
|
||||
return
|
||||
end
|
||||
|
||||
if res.succeeded and res.code == 200 then
|
||||
local data = minetest.parse_json(res.data)
|
||||
if data then
|
||||
local auth_response = {}
|
||||
local handler = minetest.get_auth_handler()
|
||||
|
||||
for _,auth in pairs(data) do
|
||||
local success = false
|
||||
local entry = handler.get_auth(auth.name)
|
||||
if entry and minetest.check_password_entry(auth.name, entry.password, auth.password) then
|
||||
success = true
|
||||
end
|
||||
|
||||
table.insert(auth_response, {
|
||||
name = auth.name,
|
||||
success = success
|
||||
})
|
||||
end
|
||||
|
||||
-- send back auth response data
|
||||
http.fetch({
|
||||
url=url .. "/api/auth_collector",
|
||||
extra_headers = { "Content-Type: application/json", "webmailkey: " .. key },
|
||||
post_data = minetest.write_json(auth_response)
|
||||
}, function(res)
|
||||
-- stub
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
-- execute again
|
||||
minetest.after(1, webmail.auth_collector)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
mail.webmail_init = function(_http, webmail_url, webmail_key)
|
||||
url = webmail_url
|
||||
key = webmail_key
|
||||
http = _http
|
||||
|
||||
-- start auth collector loop
|
||||
webmail.auth_collector()
|
||||
end
|
1
webmail/.gitignore
vendored
Normal file
1
webmail/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
19
webmail/Dockerfile
Executable file
19
webmail/Dockerfile
Executable file
@ -0,0 +1,19 @@
|
||||
FROM ubuntu:artful
|
||||
|
||||
RUN apt-get update
|
||||
|
||||
# node stuff
|
||||
RUN apt-get install -y nodejs npm
|
||||
|
||||
COPY package.json /data/
|
||||
COPY src /data/src
|
||||
COPY public /data/public
|
||||
|
||||
RUN cd /data && npm i
|
||||
|
||||
WORKDIR /data
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["node", "src/index.js"]
|
||||
|
8
webmail/Makefile
Normal file
8
webmail/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
TAG=registry.rudin.io/x86/minetest-webmail
|
||||
|
||||
build:
|
||||
docker build . -t $(TAG)
|
||||
|
||||
push:
|
||||
docker push $(TAG)
|
15
webmail/package.json
Normal file
15
webmail/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "webmail",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.18.3",
|
||||
"express": "^4.16.3"
|
||||
}
|
||||
}
|
0
webmail/public/.keep
Normal file
0
webmail/public/.keep
Normal file
35
webmail/src/api/auth_collector.js
Normal file
35
webmail/src/api/auth_collector.js
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
const app = require("../app");
|
||||
|
||||
const bodyParser = require('body-parser')
|
||||
const jsonParser = bodyParser.json()
|
||||
|
||||
function checkKey(req, res){
|
||||
|
||||
if (!req.headers["webmailkey"] || req.headers["webmailkey"] != process.env.WEBMAILKEY){
|
||||
console.error("Invalid key: " + req.headers["webmailkey"]);
|
||||
res.status(403).end();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
app.get('/api/auth_collector', function(req, res){
|
||||
if (!checkKey(req, res))
|
||||
return;
|
||||
|
||||
setTimeout(function(){
|
||||
res.json([{ name: "testuser", password: "enter" }]);
|
||||
}, 3000);
|
||||
});
|
||||
|
||||
|
||||
app.post('/api/auth_collector', jsonParser, function(req, res){
|
||||
if (!checkKey(req, res))
|
||||
return;
|
||||
|
||||
//TODO
|
||||
console.log(req.body);
|
||||
});
|
||||
|
1
webmail/src/api/index.js
Normal file
1
webmail/src/api/index.js
Normal file
@ -0,0 +1 @@
|
||||
require("./auth_collector");
|
7
webmail/src/app.js
Normal file
7
webmail/src/app.js
Normal file
@ -0,0 +1,7 @@
|
||||
const express = require('express')
|
||||
|
||||
const app = express()
|
||||
app.use(express.static('public'));
|
||||
app.disable('etag');
|
||||
|
||||
module.exports = app;
|
7
webmail/src/index.js
Normal file
7
webmail/src/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
const app = require("./app");
|
||||
require("./api");
|
||||
|
||||
|
||||
app.listen(8080, () => console.log('Listening on http://127.0.0.1:8080'))
|
||||
|
6
webmail/start.sh
Executable file
6
webmail/start.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
export WEBMAILKEY=myserverkey
|
||||
|
||||
node src/index.js
|
||||
|
Loading…
x
Reference in New Issue
Block a user