2021-12-28 22:07:03 +00:00
|
|
|
#!/usr/bin/python3.8
|
2021-12-29 00:21:12 +00:00
|
|
|
# Script created/contributed by ~jmjl
|
|
|
|
|
2021-12-28 22:07:03 +00:00
|
|
|
import socket, ssl, json, time, sys
|
2025-09-10 17:00:04 +00:00
|
|
|
|
2021-12-28 22:07:03 +00:00
|
|
|
def loadconf(cfgfile):
|
|
|
|
with open(cfgfile, 'r') as f:
|
2025-09-10 17:00:04 +00:00
|
|
|
return json.load(f)
|
|
|
|
|
2021-12-28 22:07:03 +00:00
|
|
|
def send(msg):
|
|
|
|
s.send(f"{msg}\n".encode('utf-8'))
|
|
|
|
|
2021-12-28 22:24:36 +00:00
|
|
|
cfg = loadconf("/root/.znc-conf/znc-config.json")
|
2021-12-28 22:07:03 +00:00
|
|
|
|
2025-09-10 17:00:04 +00:00
|
|
|
readbuffer = ""
|
2021-12-28 22:07:03 +00:00
|
|
|
s = socket.socket()
|
2025-09-10 17:00:04 +00:00
|
|
|
if cfg.get('tls') == 'yes':
|
2021-12-28 22:07:03 +00:00
|
|
|
ctx = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
|
|
|
|
s = ctx.wrap_socket(s)
|
2025-09-10 17:00:04 +00:00
|
|
|
|
2021-12-28 22:07:03 +00:00
|
|
|
s.connect((cfg['srv'], int(cfg['port'])))
|
|
|
|
send("NICK bot")
|
|
|
|
send("USER bot 0 * :A bot to make users")
|
|
|
|
|
2025-09-10 17:00:04 +00:00
|
|
|
# Parse optional key=value settings after username/password.
|
|
|
|
# Example: MaxNetworks=3 MaxClients=5
|
|
|
|
cli_settings = {}
|
|
|
|
for arg in sys.argv[3:]:
|
|
|
|
if '=' in arg:
|
|
|
|
k, v = arg.split('=', 1)
|
|
|
|
k = k.strip()
|
|
|
|
v = v.strip()
|
|
|
|
if k:
|
|
|
|
cli_settings[k] = v
|
|
|
|
|
|
|
|
# Also allow defaults from config, but CLI wins.
|
|
|
|
# In /root/.znc-conf/znc-config.json you may add:
|
|
|
|
# { ..., "default_user_settings": { "MaxNetworks": "3" } }
|
|
|
|
default_settings = cfg.get("default_user_settings", {}) or {}
|
|
|
|
|
2021-12-28 22:07:03 +00:00
|
|
|
while True:
|
2025-09-10 17:00:04 +00:00
|
|
|
readbuffer += s.recv(2048).decode('utf-8', errors='ignore')
|
2021-12-28 22:07:03 +00:00
|
|
|
temp = str.split(readbuffer, "\n")
|
|
|
|
readbuffer = temp.pop()
|
|
|
|
|
|
|
|
for line in temp:
|
2025-09-10 17:00:04 +00:00
|
|
|
line = line.rstrip("\r")
|
|
|
|
parts = line.split()
|
|
|
|
|
|
|
|
if len(parts) < 2:
|
|
|
|
continue
|
2021-12-28 22:07:03 +00:00
|
|
|
|
2025-09-10 17:00:04 +00:00
|
|
|
# Authenticate when ZNC asks for PASS (ERR_PASSWDMISMATCH 464).
|
|
|
|
if parts[1] == '464':
|
2021-12-28 22:07:03 +00:00
|
|
|
send(f"PASS {cfg['user']}:{cfg['password']}")
|
2025-09-10 17:00:04 +00:00
|
|
|
|
|
|
|
# On welcome (001), create user and apply settings.
|
|
|
|
# (Preserves your original hostname check.)
|
|
|
|
if parts[0][1:] == 'irc.znc.in' and parts[1] == '001':
|
2021-12-28 22:07:03 +00:00
|
|
|
user = sys.argv[1]
|
|
|
|
pswd = sys.argv[2]
|
2025-09-10 17:00:04 +00:00
|
|
|
|
|
|
|
# Create user (unchanged)
|
2021-12-28 22:07:03 +00:00
|
|
|
send(f"PRIVMSG *controlpanel :AddUser {user} {pswd}")
|
2025-09-10 17:00:04 +00:00
|
|
|
|
|
|
|
# Merge defaults + CLI, CLI overrides
|
|
|
|
effective = dict(default_settings)
|
|
|
|
effective.update(cli_settings)
|
|
|
|
|
|
|
|
# Apply settings like: set MaxNetworks <user> <val>
|
|
|
|
for key, val in effective.items():
|
|
|
|
send(f"PRIVMSG *controlpanel :set {key} {user} {val}")
|
|
|
|
|
2021-12-28 22:07:03 +00:00
|
|
|
print(f"Maken znc user {user}")
|
|
|
|
sys.exit(0)
|