From b307b67f8a333ee01d4cb666b0bac3bf4e8ae577 Mon Sep 17 00:00:00 2001 From: deepend Date: Sun, 16 Jul 2023 14:53:59 +0000 Subject: [PATCH] add znccreate.py --- roles/shell/files/znccreate.py | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 roles/shell/files/znccreate.py diff --git a/roles/shell/files/znccreate.py b/roles/shell/files/znccreate.py new file mode 100644 index 0000000..b5858aa --- /dev/null +++ b/roles/shell/files/znccreate.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3.9 +# Script created/contributed by ~jmjl + +import socket, ssl, json, time, sys +# Takes the first argument as a username and the second as the password. +def loadconf(cfgfile): + with open(cfgfile, 'r') as f: + cfg = json.load(f) + return cfg +def send(msg): + s.send(f"{msg}\n".encode('utf-8')) + +cfg = loadconf("/root/.znc-conf/znc-config.json") + +readbuffer="" +s = socket.socket() +if cfg['tls'] == 'yes': + ctx = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH) + s = ctx.wrap_socket(s) +s.connect((cfg['srv'], int(cfg['port']))) +send("NICK bot") +send("USER bot 0 * :A bot to make users") + +while True: + readbuffer = readbuffer + s.recv(2048).decode('utf-8') + temp = str.split(readbuffer, "\n") + readbuffer = temp.pop() + + for line in temp: + line = str.rstrip(line) + line = str.split(line) + + #print(' '.join(line)) + if line[1] == '464': + send(f"PASS {cfg['user']}:{cfg['password']}") + if line[0][1:] == 'irc.znc.in' and line[1] == '001': + user = sys.argv[1] + pswd = sys.argv[2] + send(f"PRIVMSG *controlpanel :AddUser {user} {pswd}") + print(f"Maken znc user {user}") + sys.exit(0) \ No newline at end of file