Initial commit
This commit is contained in:
commit
c3a7ef3780
7
certbot-webroot
Normal file
7
certbot-webroot
Normal file
@ -0,0 +1,7 @@
|
||||
# Port nodejs will use
|
||||
# default 9000
|
||||
#NODE_PORT=
|
||||
|
||||
# IP nodes will listen
|
||||
# default 127.0.0.1
|
||||
#NODE_LISTEN_IP=
|
72
certbot-webroot.js
Normal file
72
certbot-webroot.js
Normal file
@ -0,0 +1,72 @@
|
||||
// certbot_webroot.js
|
||||
// writted by Benoit LORAND <benoit.lorand@blorand.org>
|
||||
//
|
||||
// webservice help certbot when using webroot
|
||||
// Could be behind a reverse proxy (Apache, Nginx, haproxy) who do basic authentication
|
||||
//
|
||||
// inspired from https://stackoverflow.com/questions/16333790/node-js-quick-file-server-static-files-over-http
|
||||
//
|
||||
"use strict";
|
||||
const http = require('http');
|
||||
const url = require('url');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const port = Number(process.env.NODE_PORT) || 9000;
|
||||
const listenip = process.env.NODE_LISTEN_IP || '127.0.0.1';
|
||||
const base_dir = './data';
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
|
||||
// parse URL
|
||||
const parsedUrl = url.parse(req.url);
|
||||
// extract URL path
|
||||
let pathname = `${parsedUrl.pathname}`;
|
||||
// based on the URL path, extract the file extention. e.g. .js, .doc, ...
|
||||
const ext = path.parse(pathname).ext;
|
||||
// maps file extention to MIME typere
|
||||
const map = {
|
||||
'.ico': 'image/x-icon',
|
||||
'.html': 'text/html',
|
||||
'.js': 'text/javascript',
|
||||
'.json': 'application/json',
|
||||
'.css': 'text/css',
|
||||
'.png': 'image/png',
|
||||
'.jpg': 'image/jpeg',
|
||||
'.wav': 'audio/wav',
|
||||
'.mp3': 'audio/mpeg',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.pdf': 'application/pdf',
|
||||
'.doc': 'application/msword'
|
||||
};
|
||||
|
||||
fs.exists(base_dir + pathname, function (exist) {
|
||||
if(!exist) {
|
||||
// if the file is not found, return 404
|
||||
console.log(`certbot_validation_fqdn : ${req.method} ${req.url} - 404`);
|
||||
res.statusCode = 404;
|
||||
res.end(`File ${pathname} not found!`);
|
||||
return;
|
||||
}
|
||||
|
||||
// if is a directory search for index file matching the extention
|
||||
if (fs.statSync(base_dir + pathname).isDirectory()) pathname += '/index' + ext;
|
||||
|
||||
// read file from file system
|
||||
fs.readFile(base_dir + pathname, function(err, data){
|
||||
if(err){
|
||||
console.log(`certbot_validation_fqdn : ${req.method} ${req.url} - 500`);
|
||||
res.statusCode = 500;
|
||||
res.end(`Error getting the file: ${err}.`);
|
||||
} else {
|
||||
// if the file is found, set Content-type and send data
|
||||
console.log(`certbot_validation_fqdn : ${req.method} ${req.url} - 200`);
|
||||
res.setHeader('Content-type', map[ext] || 'text/plain' );
|
||||
res.end(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}).listen(parseInt(port, listenip));
|
||||
|
||||
console.log(`Server listening on port ${listenip}:${port}`);
|
14
certbot-webroot.service
Normal file
14
certbot-webroot.service
Normal file
@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=certbot-webroot.js - webservice for helping certbot to validate FQDN
|
||||
Documentation=https://www.blorand.org
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=-/etc/default/certbot-webroot
|
||||
Type=simple
|
||||
User=www-data
|
||||
ExecStart=/usr/bin/node /opt/certbot-webbroot/certbot-webroot.js
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
5
debian/changelog
vendored
Normal file
5
debian/changelog
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
certbot-webroot (1.0) stable; urgency=medium
|
||||
|
||||
* Initial release.
|
||||
|
||||
-- Benoit LORAND <benoit.lorand@blorand.org> Tue, 24 Mar 2020 22:20:33 +0100
|
1
debian/compat
vendored
Normal file
1
debian/compat
vendored
Normal file
@ -0,0 +1 @@
|
||||
10
|
17
debian/control
vendored
Normal file
17
debian/control
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
Source: certbot-webroot
|
||||
Maintainer: Benoit LORAND <benoit.lorand@blorand.fr>
|
||||
Section: misc
|
||||
Priority: optional
|
||||
Standards-Version: 3.9.2
|
||||
Build-Depends: debhelper (>= 9)
|
||||
|
||||
Package: certbot-webroot
|
||||
Architecture: all
|
||||
Depends: ${shlibs:Depends},
|
||||
${misc:Depends},
|
||||
nodejs,
|
||||
npm
|
||||
Suggests: haproxy
|
||||
Section: BLORAND
|
||||
Priority: optional
|
||||
Description: WebService pour aider certbot à faire les validations de FQDN
|
0
debian/copyright
vendored
Normal file
0
debian/copyright
vendored
Normal file
28
debian/postinst
vendored
Executable file
28
debian/postinst
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
#! /bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
case "$1" in
|
||||
configure)
|
||||
mkdir -p /opt/certbot-webroot/data
|
||||
systemctl daemon-reload
|
||||
systemctl --now enable certbot-webroot.service
|
||||
|
||||
;;
|
||||
|
||||
abort-upgrade|abort-remove|abort-deconfigure)
|
||||
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "postinst called with unknown argument \`$1'" >&2
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# dh_installdeb will replace this with shell code automatically
|
||||
# generated by other debhelper scripts.
|
||||
|
||||
|
||||
|
||||
exit 0
|
9
debian/rules
vendored
Executable file
9
debian/rules
vendored
Executable file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/make -f
|
||||
%:
|
||||
dh $@
|
||||
|
||||
override_dh_auto_install:
|
||||
install -D -m 0644 certbot-webroot.js $$(pwd)/debian/certbot-webroot/opt/certbot-webroot/certbot-webroot.js
|
||||
install -D -m 0644 certbot-webroot $$(pwd)/debian/certbot-webroot/etc/default/certbot-webroot
|
||||
install -D -m 0644 certbot-webroot.service $$(pwd)/debian/certbot-webroot/lib/systemd/system/certbot-webroot.service
|
||||
|
1
debian/source/format
vendored
Normal file
1
debian/source/format
vendored
Normal file
@ -0,0 +1 @@
|
||||
3.0 (quilt)
|
Loading…
Reference in New Issue
Block a user