diff --git a/plugin.py b/plugin.py index c2c752c..affc914 100644 --- a/plugin.py +++ b/plugin.py @@ -31,7 +31,7 @@ import requests import secrets import string -from supybot import utils, plugins, ircutils, callbacks, ircdb +from supybot import utils, plugins, ircutils, callbacks, ircdb, ircmsgs from supybot.commands import * from supybot.ircmsgs import nick try: @@ -61,8 +61,8 @@ class Mailcow(callbacks.Plugin): #Read-Functions: Summary try: - if 'summary' in variant: - if hostmask in read or write: + if 'summary' in variant: + if hostmask in read or hostmask in write: URL = server + get + '/domain/' + id try: response = requests.get( @@ -78,7 +78,7 @@ class Mailcow(callbacks.Plugin): except requests.exceptions.ConnectionError as err: irc.error("Connection failed.") except requests.exceptions.HTTPError as err: - irc.error(err) + irc.error(err) else: irc.reply("Thou shalt not pass.") print("Intrusion attempt: " + hostmask) @@ -122,7 +122,7 @@ class Mailcow(callbacks.Plugin): else: irc.reply("Thou shall not create.") print("Intrusion attempt: " + hostmask) - + elif 'delete' in variant: if hostmask in write: URL = server + api + '/delete/domain' @@ -137,7 +137,18 @@ class Mailcow(callbacks.Plugin): data = response.json() status = data[0]['type'] object = data[0]['msg'] - irc.reply(f"DELETION: {status} - {msg} - Hey, where's that backup again?") + if 'success' in status: + if 'domain_removed' in object: + usefulstatus = status.replace("success", "Attempted Removal - please manually confirm") + usefulobject = object + else: + usefulstatus = status.replace("success", "Transmitted") + usefulobject = object + else: + usefulstatus = status + usefulobject = object + + irc.reply(f"DELETION: {usefulstatus} - {usefulobject} - Hey, where's that backup again?") else: irc.reply("Thou shall not delete.") print("Intrusion attempt: " + hostmask) @@ -151,8 +162,8 @@ class Mailcow(callbacks.Plugin): irc.error("Invalid domain.") else: irc.error("Unhandled " + str(err)) - - + + maildomain = wrap(maildomain, ['anything', 'anything']) def mailbox(self, irc, msg, args, variant, id): @@ -169,7 +180,7 @@ class Mailcow(callbacks.Plugin): #Read-Functions: Summary try: if 'summary' in variant: - if hostmask in read or write: + if hostmask in read or hostmask in write: URL = server + get + '/mailbox/' + id try: response = requests.get( @@ -183,7 +194,7 @@ class Mailcow(callbacks.Plugin): except requests.exceptions.ConnectionError as err: irc.error("Connection failed.") except requests.exceptions.HTTPError as err: - irc.error(err) + irc.error(err) else: irc.reply("Thou shall not pass.") print("Intrusion attempt: " + hostmask) @@ -194,16 +205,18 @@ class Mailcow(callbacks.Plugin): URL = server + api + '/add/mailbox/' + id user = id.split('@')[0] domain = id.split('@')[1] - random = secrets.token_urlsafe(64) + alphabet = string.ascii_letters + string.digits + random = ''.join(secrets.choice(alphabet) for i in range(64)) + pw = random payload = { "active": "1", "domain": domain, "local_part": user, "name": user + '@' + domain, - "password": random, - "password2": random, + "password": pw, + "password2": pw, "quota": "512", - "force_pw_update": "1", + "force_pw_update": "0", "tls_enforce_in": "1", "tls_enforce_out": "1" } @@ -216,7 +229,12 @@ class Mailcow(callbacks.Plugin): status = data[0]['type'] msg = data[0]['msg'] - irc.reply(f"CREATION: {status} | {msg} | " + str(random) + server) + if 'success' in status: + irc.queueMsg(msg=ircmsgs.IrcMsg(command='PRIVMSG', args=(nick, f'{pw}'))) + irc.reply(f"CREATION OK: {status} | {msg}") + else: + irc.reply(f"CREATION: {status} | {msg}") + else: irc.reply("Thou shall not create.") print("Intrusion attempt: " + hostmask) @@ -235,12 +253,25 @@ class Mailcow(callbacks.Plugin): data = response.json() status = data[0]['type'] object = data[0]['msg'] + if 'danger' in status: + if 'access_denied' in object: + usefulstatus = status.replace("danger", "Error:") + usefulobject = object.replace("access_denied", "Access denied or Mailbox does not exist") + else: + usefulstatus = status.replace("danger", "Error:") + usefulobject = object + elif 'success' in status: + usefulstatus = status.replace("success", "Success:") + usefulobject = object + else: + usefulstatus = status + usefulobject = object - irc.reply(f"DELETION: {status} - {msg}") + irc.reply(f"DELETION: {usefulstatus} {usefulobject}") else: irc.reply("Thou shall not delete.") print("Intrusion attempt: " + hostmask) - + else: irc.reply('Unknown function.') @@ -253,6 +284,114 @@ class Mailcow(callbacks.Plugin): mailbox = wrap(mailbox, ['anything', 'anything']) + def mailalias(self, irc, msg, args, variant, id, id2): + """