Version 1
- Added basic error handling - Decided to keep Debug block: - moved it to the bottom - hardcoded my hostmask - Changed server config variable to Private - Changed access config variable's help text
This commit is contained in:
parent
eda43f1d3c
commit
491452f326
Binary file not shown.
@ -68,7 +68,7 @@ registry.String('',
|
|||||||
"""
|
"""
|
||||||
Your Mailcow server \(https://example.com\)
|
Your Mailcow server \(https://example.com\)
|
||||||
"""
|
"""
|
||||||
, private=False
|
, private=True
|
||||||
))
|
))
|
||||||
|
|
||||||
conf.registerGroup(Mailcow, 'access')
|
conf.registerGroup(Mailcow, 'access')
|
||||||
@ -76,7 +76,7 @@ conf.registerGroup(Mailcow, 'access')
|
|||||||
conf.registerGlobalValue(Mailcow.access, 'read',
|
conf.registerGlobalValue(Mailcow.access, 'read',
|
||||||
registry.CommaSeparatedListOfStrings('',
|
registry.CommaSeparatedListOfStrings('',
|
||||||
"""
|
"""
|
||||||
Nicknames to grant Read-Only access
|
Hostmasks to grant Read-Only access
|
||||||
"""
|
"""
|
||||||
, private=True
|
, private=True
|
||||||
))
|
))
|
||||||
@ -84,7 +84,7 @@ Nicknames to grant Read-Only access
|
|||||||
conf.registerGlobalValue(Mailcow.access, 'write',
|
conf.registerGlobalValue(Mailcow.access, 'write',
|
||||||
registry.CommaSeparatedListOfStrings('',
|
registry.CommaSeparatedListOfStrings('',
|
||||||
"""
|
"""
|
||||||
Nicknames to grant Write access
|
Hostmasks to grant Write access
|
||||||
"""
|
"""
|
||||||
, private=True
|
, private=True
|
||||||
))
|
))
|
||||||
|
120
plugin.py
120
plugin.py
@ -60,10 +60,11 @@ class Mailcow(callbacks.Plugin):
|
|||||||
hostmask = irc.state.nickToHostmask(msg.nick)
|
hostmask = irc.state.nickToHostmask(msg.nick)
|
||||||
|
|
||||||
#Read-Functions: Summary
|
#Read-Functions: Summary
|
||||||
|
try:
|
||||||
if 'summary' in variant:
|
if 'summary' in variant:
|
||||||
if hostmask in read or write:
|
if hostmask in read or write:
|
||||||
URL = server + get + '/domain/' + id
|
URL = server + get + '/domain/' + id
|
||||||
|
try:
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
URL,
|
URL,
|
||||||
headers = {'accept': 'application/json', 'X-API-Key': api_key},
|
headers = {'accept': 'application/json', 'X-API-Key': api_key},
|
||||||
@ -72,16 +73,20 @@ class Mailcow(callbacks.Plugin):
|
|||||||
domain = data['domain_name']
|
domain = data['domain_name']
|
||||||
description = data['description']
|
description = data['description']
|
||||||
bytes_total = data['bytes_total']
|
bytes_total = data['bytes_total']
|
||||||
|
#response.raise_for_status()
|
||||||
irc.reply(f"Domain: {domain} | Description: {description} | Bytes Total: {bytes_total} ")
|
irc.reply(f"Domain: {domain} | Description: {description} | Bytes Total: {bytes_total} ")
|
||||||
|
except requests.exceptions.ConnectionError as err:
|
||||||
|
irc.error("Connection failed.")
|
||||||
|
except requests.exceptions.HTTPError as err:
|
||||||
|
irc.error(err)
|
||||||
else:
|
else:
|
||||||
irc.reply("Thou shall not pass.")
|
irc.reply("Thou shalt not pass.")
|
||||||
print("Intrusion attempt: " + hostmask)
|
print("Intrusion attempt: " + hostmask)
|
||||||
|
|
||||||
#Write-Functions: Create/Delete
|
#Write-Functions: Create/Delete
|
||||||
elif 'create' in variant:
|
elif 'create' in variant:
|
||||||
if hostmask in write:
|
if hostmask in write:
|
||||||
URL = server + api + '/add/domain'
|
URL = server + api + '/add/domain'
|
||||||
#domain = id['domain']
|
|
||||||
payload = {
|
payload = {
|
||||||
"active": "1",
|
"active": "1",
|
||||||
"aliases": "20",
|
"aliases": "20",
|
||||||
@ -140,52 +145,16 @@ class Mailcow(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
irc.reply("Unknown option.")
|
irc.reply("Unknown option.")
|
||||||
|
|
||||||
|
except KeyError as err:
|
||||||
|
key = err.args[0]
|
||||||
|
if key == 'domain_name':
|
||||||
|
irc.error("Invalid domain.")
|
||||||
|
else:
|
||||||
|
irc.error("Unhandled " + str(err))
|
||||||
|
|
||||||
|
|
||||||
maildomain = wrap(maildomain, ['anything', 'anything'])
|
maildomain = wrap(maildomain, ['anything', 'anything'])
|
||||||
|
|
||||||
####################
|
|
||||||
#FOR DEBUGGING / REMOVE BEFORE RELEASE
|
|
||||||
####################
|
|
||||||
def mcdebug(self, irc, msg, args, variant):
|
|
||||||
"""Prints values."""
|
|
||||||
|
|
||||||
server = self.registryValue('api.server')
|
|
||||||
api_key = self.registryValue('api.key')
|
|
||||||
read = self.registryValue('access.read')
|
|
||||||
write = self.registryValue('access.write')
|
|
||||||
nick = msg.nick
|
|
||||||
hostmask = irc.state.nickToHostmask(msg.nick)
|
|
||||||
|
|
||||||
|
|
||||||
if hostmask in read or hostmask in write:
|
|
||||||
|
|
||||||
if 'key' in variant:
|
|
||||||
irc.reply('> ' + api_key + ' <')
|
|
||||||
|
|
||||||
elif 'server' in variant:
|
|
||||||
irc.reply('> ' + server + ' <')
|
|
||||||
|
|
||||||
elif 'user' in variant:
|
|
||||||
u = ircdb.users.getUser(msg.prefix)
|
|
||||||
nick = msg.nick
|
|
||||||
hm = irc.state.nickToHostmask(nick)
|
|
||||||
print(hm)
|
|
||||||
irc.reply('> ' + u.name + ' ' + hm + ' <')
|
|
||||||
|
|
||||||
elif 'read' in variant:
|
|
||||||
irc.reply('> ' + str(read) + ' <')
|
|
||||||
|
|
||||||
elif 'write' in variant:
|
|
||||||
irc.reply('> ' + str(write) + ' <')
|
|
||||||
|
|
||||||
else:
|
|
||||||
irc.reply('What?')
|
|
||||||
else:
|
|
||||||
irc.reply('Go home')
|
|
||||||
|
|
||||||
mcdebug = wrap(mcdebug, ['anything'])
|
|
||||||
####################
|
|
||||||
|
|
||||||
def mailbox(self, irc, msg, args, variant, id):
|
def mailbox(self, irc, msg, args, variant, id):
|
||||||
"""<option> <id>
|
"""<option> <id>
|
||||||
i.e. 'summary cranberrry@liberta.casa' will print some details about his mailbox"""
|
i.e. 'summary cranberrry@liberta.casa' will print some details about his mailbox"""
|
||||||
@ -198,9 +167,11 @@ class Mailcow(callbacks.Plugin):
|
|||||||
hostmask = irc.state.nickToHostmask(msg.nick)
|
hostmask = irc.state.nickToHostmask(msg.nick)
|
||||||
|
|
||||||
#Read-Functions: Summary
|
#Read-Functions: Summary
|
||||||
|
try:
|
||||||
if 'summary' in variant:
|
if 'summary' in variant:
|
||||||
if hostmask in read or write:
|
if hostmask in read or write:
|
||||||
URL = server + get + '/mailbox/' + id
|
URL = server + get + '/mailbox/' + id
|
||||||
|
try:
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
URL,
|
URL,
|
||||||
params={'q': 'requests'},
|
params={'q': 'requests'},
|
||||||
@ -209,6 +180,10 @@ class Mailcow(callbacks.Plugin):
|
|||||||
data = response.json()
|
data = response.json()
|
||||||
#return(print(data))
|
#return(print(data))
|
||||||
irc.reply('Username: ' + data['username'] + ' | Quota: ' + str(data['quota']) + ' | Messages: ' + str(data['messages']) + ' | Mail Active: ' + str(data['active']) + ' | XMPP Active: ' + str(data['domain_xmpp']))
|
irc.reply('Username: ' + data['username'] + ' | Quota: ' + str(data['quota']) + ' | Messages: ' + str(data['messages']) + ' | Mail Active: ' + str(data['active']) + ' | XMPP Active: ' + str(data['domain_xmpp']))
|
||||||
|
except requests.exceptions.ConnectionError as err:
|
||||||
|
irc.error("Connection failed.")
|
||||||
|
except requests.exceptions.HTTPError as err:
|
||||||
|
irc.error(err)
|
||||||
else:
|
else:
|
||||||
irc.reply("Thou shall not pass.")
|
irc.reply("Thou shall not pass.")
|
||||||
print("Intrusion attempt: " + hostmask)
|
print("Intrusion attempt: " + hostmask)
|
||||||
@ -265,11 +240,64 @@ class Mailcow(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
irc.reply("Thou shall not delete.")
|
irc.reply("Thou shall not delete.")
|
||||||
print("Intrusion attempt: " + hostmask)
|
print("Intrusion attempt: " + hostmask)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
irc.reply('Unknown function.')
|
irc.reply('Unknown function.')
|
||||||
|
|
||||||
|
except KeyError as err:
|
||||||
|
key = err.args[0]
|
||||||
|
if key == 'username':
|
||||||
|
irc.error("Invalid mailbox.")
|
||||||
|
else:
|
||||||
|
irc.error("Unhandled " + str(err))
|
||||||
|
|
||||||
mailbox = wrap(mailbox, ['anything', 'anything'])
|
mailbox = wrap(mailbox, ['anything', 'anything'])
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
#FOR DEBUGGING / REMOVE BEFORE RELEASE (or don't, developers hostmask is hardcoded)
|
||||||
|
############################################################
|
||||||
|
def mcdebug(self, irc, msg, args, variant):
|
||||||
|
"""Prints values. If you were supposed to use this, you would know how."""
|
||||||
|
|
||||||
|
server = self.registryValue('api.server')
|
||||||
|
api_key = self.registryValue('api.key')
|
||||||
|
read = self.registryValue('access.read')
|
||||||
|
write = self.registryValue('access.write')
|
||||||
|
nick = msg.nick
|
||||||
|
hostmask = irc.state.nickToHostmask(msg.nick)
|
||||||
|
|
||||||
|
|
||||||
|
if hostmask in read or hostmask in write:
|
||||||
|
if hostmask == 'cranberry!~u@cranberry.juice':
|
||||||
|
if 'key' in variant:
|
||||||
|
irc.reply('> ' + api_key + ' <')
|
||||||
|
|
||||||
|
elif 'server' in variant:
|
||||||
|
irc.reply('> ' + server + ' <')
|
||||||
|
|
||||||
|
elif 'user' in variant:
|
||||||
|
u = ircdb.users.getUser(msg.prefix)
|
||||||
|
nick = msg.nick
|
||||||
|
hm = irc.state.nickToHostmask(nick)
|
||||||
|
print(hm)
|
||||||
|
irc.reply('> ' + u.name + ' ' + hm + ' <')
|
||||||
|
|
||||||
|
elif 'read' in variant:
|
||||||
|
irc.reply('> ' + str(read) + ' <')
|
||||||
|
|
||||||
|
elif 'write' in variant:
|
||||||
|
irc.reply('> ' + str(write) + ' <')
|
||||||
|
|
||||||
|
else:
|
||||||
|
irc.reply("What?")
|
||||||
|
else:
|
||||||
|
irc.error("You're not a dev. Firstly, install Arch Linux.")
|
||||||
|
else:
|
||||||
|
irc.reply("Go home")
|
||||||
|
|
||||||
|
mcdebug = wrap(mcdebug, ['anything'])
|
||||||
|
############################################################
|
||||||
|
|
||||||
Class = Mailcow
|
Class = Mailcow
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user