aboutsummaryrefslogtreecommitdiffstats
path: root/filter_plugins
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-03-17 13:50:11 +0800
committerAaron LI <aly@aaronly.me>2018-03-17 13:50:11 +0800
commitca8703974ede3950eaed0589dc55b7e606224f98 (patch)
tree257b282c2f3e871b0e8a1fe2ceff9705060e9970 /filter_plugins
parent097cb80499bbed7148fa3b77a555a43d915d39c5 (diff)
downloadansible-dfly-vps-ca8703974ede3950eaed0589dc55b7e606224f98.tar.bz2
znc: Add filter znc_makepass, improve templating with ipv4+ipv6
Diffstat (limited to 'filter_plugins')
-rw-r--r--filter_plugins/znc.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/filter_plugins/znc.py b/filter_plugins/znc.py
new file mode 100644
index 0000000..243cdd5
--- /dev/null
+++ b/filter_plugins/znc.py
@@ -0,0 +1,32 @@
+# Copyright (c) 2018 Aaron LI <aly@aaronly.me>
+# MIT License
+
+"""
+Custom Ansible template filters for "znc" role.
+"""
+
+import os
+import base64
+import hashlib
+
+
+def znc_makepass(p, method="sha256", saltlen=20):
+ """
+ Generate the salted hashed password for ZNC configuration.
+
+ Implement the "znc --makepass" command.
+
+ ZNC password format: <method>#<hash>#<salt>
+ """
+ salt = os.urandom(saltlen)
+ salt = base64.b64encode(salt)[:saltlen]
+ s = p + salt
+ h = getattr(hashlib, method)(s)
+ return "%s#%s#%s" % (method, h.hexdigest(), salt)
+
+
+class FilterModule(object):
+ def filters(self):
+ return {
+ "znc_makepass": znc_makepass,
+ }