aboutsummaryrefslogtreecommitdiff
path: root/cheat/.cheat/mkcert
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-02-14 12:49:30 +0100
committerneodarz <neodarz@neodarz.net>2019-02-14 12:49:30 +0100
commitc57807815e7b2183b766d5f2b52222c30a116475 (patch)
treedfd5fba005e14e3fabb3baa22da12ebb04e9e2d2 /cheat/.cheat/mkcert
parentbc3f5659576aa0d2803a4cd933079b1393537be5 (diff)
downloaddotfiles_ascii-c57807815e7b2183b766d5f2b52222c30a116475.tar.xz
dotfiles_ascii-c57807815e7b2183b766d5f2b52222c30a116475.zip
Add more good cheats
Diffstat (limited to 'cheat/.cheat/mkcert')
-rw-r--r--cheat/.cheat/mkcert38
1 files changed, 38 insertions, 0 deletions
diff --git a/cheat/.cheat/mkcert b/cheat/.cheat/mkcert
new file mode 100644
index 0000000..2b673c8
--- /dev/null
+++ b/cheat/.cheat/mkcert
@@ -0,0 +1,38 @@
+# Generate certs for localhost + some addresses
+mkcert -cert-file localhost.pem -key-file localhost.key.pem localhost $(/sbin/ip -4 -o addr | /usr/bin/awk '{gsub(/\/.*/,"",$4); print $4}' | /usr/bin/sed ':a;N;$!ba;s/\n/ /g') <addresses>
+
+# Auto generate cert from current apache conf and current ip addresses
+
+#!/usr/bin/python3
+import re
+from subprocess import call
+import netifaces as ni
+import shutil
+
+url = []
+
+# Search for all servername enable in apache conf
+file = open("/etc/httpd/conf/httpd.conf")
+for line in file:
+ if re.search("^Include", line):
+ conf = open("/etc/httpd/"+line.split()[1])
+ for conf_line in conf:
+ if re.search("^ ServerName", conf_line):
+ if conf_line.split()[1] not in url:
+ url.append(conf_line.split()[1])
+ conf.close()
+file.close()
+
+# Add localhost
+if "localhost" not in url:
+ url.append("localhost")
+
+# Get all current ip
+for interfaces in ni.interfaces():
+ ip = ni.ifaddresses(interfaces)[ni.AF_INET][0]['addr']
+ if ip not in url:
+ url.append(ip)
+
+call(["mkcert", "-cert-file", "localhost.pem", "-key-file", "localhost.key.pem"] + url)
+shutil.move("localhost.pem", "/etc/ssl/certs/localhost.pem")
+shutil.move("localhost.key.pem", "/etc/ssl/certs/localhost.key.pem")