2019-01-30 15:47:03 +00:00
|
|
|
import Bluebird = require("bluebird");
|
|
|
|
import Fs = require("fs");
|
|
|
|
import Request = require("request-promise");
|
|
|
|
|
|
|
|
export async function GetLinkFromFile() {
|
|
|
|
const data = await Bluebird.promisify(Fs.readFile)("/tmp/authelia/notification.txt")
|
|
|
|
const regexp = new RegExp(/Link: (.+)/);
|
|
|
|
const match = regexp.exec(data.toLocaleString());
|
|
|
|
if (match == null) {
|
|
|
|
throw new Error('No match');
|
|
|
|
}
|
|
|
|
return match[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
export async function GetLinkFromEmail() {
|
|
|
|
const data = await Request({
|
|
|
|
method: "GET",
|
2019-03-03 22:51:52 +00:00
|
|
|
uri: "https://mail.example.com:8080/messages",
|
|
|
|
json: true,
|
|
|
|
rejectUnauthorized: false,
|
2019-01-30 15:47:03 +00:00
|
|
|
});
|
|
|
|
const messageId = data[data.length - 1].id;
|
|
|
|
const data2 = await Request({
|
|
|
|
method: "GET",
|
2019-03-03 22:51:52 +00:00
|
|
|
rejectUnauthorized: false,
|
|
|
|
uri: `https://mail.example.com:8080/messages/${messageId}.html`
|
2019-01-30 15:47:03 +00:00
|
|
|
});
|
|
|
|
const regexp = new RegExp(/<a href="(.+)" class="button">Continue<\/a>/);
|
|
|
|
const match = regexp.exec(data2);
|
|
|
|
if (match == null) {
|
|
|
|
throw new Error('No match');
|
|
|
|
}
|
|
|
|
return match[1];
|
|
|
|
};
|