Browse Source

added pre/post hook event

tags/v2.0.0
Robin Thoni 8 years ago
parent
commit
16ac85729b

+ 5
- 0
TODO View File

@@ -0,0 +1,5 @@
1
+letsencrypt web root
2
+bash completion
3
+site create
4
+site remove
5
+letsencrypt command arguments

+ 1
- 10
apache/letsencrypt.conf View File

@@ -1,10 +1 @@
1
-<IfModule mod_proxy.c>
2
-<Location "/.well-known/acme-challenge/">
3
-    ProxyPass "http://127.0.0.1:9999/.well-known/acme-challenge/" retry=1
4
-    ProxyPassReverse "http://127.0.0.1:9999/.well-known/acme-challenge/"
5
-    ProxyPreserveHost On
6
-    Order allow,deny
7
-    Allow from all
8
-    Require all granted
9
-  </Location>
10
-</IfModule>
1
+Alias "/.well-known/acme-challenge/" "/tmp/acme-challenge/"

+ 1
- 1
cron/sitegen-cert-renew View File

@@ -1,3 +1,3 @@
1 1
 SHELL=/bin/sh
2 2
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
3
-12 00  * * 1   root    sitegen --cert-renew
3
+12 12  * * 1   root    sitegen --cert-renew

+ 1
- 0
install View File

@@ -17,6 +17,7 @@ service apache2 reload &&
17 17
 
18 18
 if [ ! -e /etc/cron.d/sitegen-cert-renew ]
19 19
 then
20
+  rm -f  /etc/cron.d/cert-renew &&
20 21
   cp "${dir}/cron/sitegen-cert-renew" /etc/cron.d/sitegen-cert-renew
21 22
 fi &&
22 23
 service cron reload

+ 7
- 5
sitegen.py View File

@@ -84,7 +84,8 @@ class SiteGen:
84 84
         out = proc.communicate()
85 85
         return proc.returncode, out[0]
86 86
 
87
-    def execute_hooks(self, hook_type, args):
87
+    def execute_hooks(self, hook_type, hook_event, args):
88
+        args.insert(0, hook_event)
88 89
         for hook_name in self.get_hook_files(hook_type, True):
89 90
             self.execute(self.get_hook_file(hook_type, hook_name, True), args, False)
90 91
 
@@ -117,7 +118,10 @@ class SiteGen:
117 118
         return domains
118 119
 
119 120
     def cert_request(self, domain, logger):
120
-        logger("Requesting: %s" % domain)
121
+
122
+        cert_files = self.get_cert_files(domain)
123
+        cert_files.insert(0, domain)
124
+        self.execute_hooks("cert", "pre", cert_files)
121 125
 
122 126
         res, out = self.execute(self.letsencryptCommand, [domain], False)
123 127
         if res != 0:
@@ -127,9 +131,7 @@ class SiteGen:
127 131
         self.symlink_letsencrypt_file(domain, "privkey.pem", domain + ".key")
128 132
         self.symlink_letsencrypt_file(domain, "chain.pem", domain + "-chain.crt")
129 133
 
130
-        cert_files = self.get_cert_files(domain)
131
-        cert_files.insert(0, domain)
132
-        self.execute_hooks("cert", cert_files)
134
+        self.execute_hooks("cert", "post", cert_files)
133 135
 
134 136
     def certs_request(self, domains, logger):
135 137
         for domain in domains:

+ 11
- 4
sitegen/hooks-available/cert/000-print View File

@@ -1,8 +1,15 @@
1 1
 #! /usr/bin/env sh
2
-host="${1}"
3
-cert_file="${2}"
4
-key_file="${3}"
5
-chain_file="${4}"
2
+
3
+event="${1}"
4
+host="${2}"
5
+cert_file="${3}"
6
+key_file="${4}"
7
+chain_file="${5}"
8
+
9
+if [ "${event}" != "pre" ]
10
+then
11
+    exit 0
12
+fi
6 13
 
7 14
 echo "Host: ${host}"
8 15
 echo "Certificate File: ${cert_file}"

+ 13
- 6
sitegen/hooks-available/site/000-print View File

@@ -1,10 +1,17 @@
1 1
 #! /usr/bin/env sh
2
-host="${1}"
3
-root_dir="${2}"
4
-conf_conf="${3}"
5
-conf_include="${4}"
6
-site_conf="${5}"
7
-site_include="${6}"
2
+
3
+event="${1}"
4
+host="${2}"
5
+root_dir="${3}"
6
+conf_conf="${4}"
7
+conf_include="${5}"
8
+site_conf="${6}"
9
+site_include="${7}"
10
+
11
+if [ "${event}" != "pre" ]
12
+then
13
+    exit 0
14
+fi
8 15
 
9 16
 echo "Host: ${host}"
10 17
 echo "Root Document: ${root_dir}"

+ 0
- 16
sitegen/hooks-available/site/050-letsencrypt View File

@@ -1,16 +0,0 @@
1
-#! /usr/bin/env sh
2
-host="${1}"
3
-root_dir="${2}"
4
-conf_conf="${3}"
5
-conf_include="${4}"
6
-site_conf="${5}"
7
-site_include="${6}"
8
-
9
-count=$(grep -ci SSLCertificateFile ${site_conf})
10
-if [ "${count}" -ge 1 ]
11
-then
12
-  echo "SSL found; generating certificate..."
13
-  sitegen --cert-request "${host}"
14
-else
15
-  echo "No SSL found; doing nothing"
16
-fi

+ 23
- 0
sitegen/hooks-available/site/050-sitegen-cert-request View File

@@ -0,0 +1,23 @@
1
+#! /usr/bin/env sh
2
+
3
+event="${1}"
4
+host="${2}"
5
+root_dir="${3}"
6
+conf_conf="${4}"
7
+conf_include="${5}"
8
+site_conf="${6}"
9
+site_include="${7}"
10
+
11
+if [ "${event}" != "post" ]
12
+then
13
+    exit 0
14
+fi
15
+
16
+count=$(grep -ci '^ *SSLCertificateFile' ${site_conf})
17
+if [ "${count}" -ge 1 ]
18
+then
19
+  echo "SSLCertificateFile directive found; generating certificate..."
20
+  sitegen --cert-request "${host}"
21
+else
22
+  echo "SSLCertificateFile directive not found; doing nothing"
23
+fi

+ 13
- 6
sitegen/hooks-available/site/100-chown View File

@@ -1,10 +1,17 @@
1 1
 #! /usr/bin/env sh
2
-host="${1}"
3
-root_dir="${2}"
4
-conf_conf="${3}"
5
-conf_include="${4}"
6
-site_conf="${5}"
7
-site_include="${6}"
2
+
3
+event="${1}"
4
+host="${2}"
5
+root_dir="${3}"
6
+conf_conf="${4}"
7
+conf_include="${5}"
8
+site_conf="${6}"
9
+site_include="${7}"
10
+
11
+if [ "${event}" != "post" ]
12
+then
13
+    exit 0
14
+fi
8 15
 
9 16
 user=$(logname)
10 17
 echo "chown to ${user}"

+ 13
- 6
sitegen/hooks-available/site/200-a2ensite View File

@@ -1,9 +1,16 @@
1 1
 #! /usr/bin/env sh
2
-host="${1}"
3
-root_dir="${2}"
4
-conf_conf="${3}"
5
-conf_include="${4}"
6
-site_conf="${5}"
7
-site_include="${6}"
2
+
3
+event="${1}"
4
+host="${2}"
5
+root_dir="${3}"
6
+conf_conf="${4}"
7
+conf_include="${5}"
8
+site_conf="${6}"
9
+site_include="${7}"
10
+
11
+if [ "${event}" != "post" ]
12
+then
13
+    exit 0
14
+fi
8 15
 
9 16
 a2ensite "${host}.conf"

+ 13
- 6
sitegen/hooks-available/site/300-reload View File

@@ -1,9 +1,16 @@
1 1
 #! /usr/bin/env sh
2
-host="${1}"
3
-root_dir="${2}"
4
-conf_conf="${3}"
5
-conf_include="${4}"
6
-site_conf="${5}"
7
-site_include="${6}"
2
+
3
+event="${1}"
4
+host="${2}"
5
+root_dir="${3}"
6
+conf_conf="${4}"
7
+conf_include="${5}"
8
+site_conf="${6}"
9
+site_include="${7}"
10
+
11
+if [ "${event}" != "post" ]
12
+then
13
+    exit 0
14
+fi
8 15
 
9 16
 service apache2 reload

+ 13
- 1
sitegen/sitegen.json View File

@@ -3,7 +3,19 @@
3 3
   "siteDir": "/var/",
4 4
   "confDir": "/etc/sitegen/",
5 5
   "certRenewTime": 5356800,
6
-  "letsencryptCommand": "letsencrypt --agree-tos --renew-by-default --standalone --standalone-supported-challenges http-01 --http-01-port 9999 --server https://acme-v01.api.letsencrypt.org/directory certonly",
6
+  "letsencryptCommand": "letsencrypt",
7
+  "letsencryptArgs": [
8
+    "--agree-tos",
9
+    "--renew-by-default",
10
+    "--standalone",
11
+    "--standalone-supported-challenges",
12
+    "http-01",
13
+    "--http-01-port",
14
+    "9999",
15
+    "--server",
16
+    "https://acme-v01.api.letsencrypt.org/directory",
17
+    "certonly"
18
+  ],
7 19
   "letsencryptDir": "/etc/letsencrypt/live/",
8 20
   "certDir": "/etc/ssl/private/"
9 21
 }

Loading…
Cancel
Save