Initial commit

master
root 3 years ago
commit c3a7ef3780
  1. 7
      certbot-webroot
  2. 72
      certbot-webroot.js
  3. 14
      certbot-webroot.service
  4. 5
      debian/changelog
  5. 1
      debian/compat
  6. 17
      debian/control
  7. 0
      debian/copyright
  8. 28
      debian/postinst
  9. 9
      debian/rules
  10. 1
      debian/source/format

@ -0,0 +1,7 @@
# Port nodejs will use
# default 9000
#NODE_PORT=
# IP nodes will listen
# default 127.0.0.1
#NODE_LISTEN_IP=

@ -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}`);

@ -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

@ -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

@ -0,0 +1 @@
10

17
debian/control vendored

@ -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

28
debian/postinst vendored

@ -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

@ -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

@ -0,0 +1 @@
3.0 (quilt)
Loading…
Cancel
Save