Added some functionality

This commit is contained in:
rune 2023-09-05 11:36:39 +02:00
parent f653a20d35
commit 8814127cf8

View File

@ -128,7 +128,7 @@ def apikey(key):
conn.commit() conn.commit()
def get_mail_domains(): def get_mail_domains(info):
apikey = get_api() apikey = get_api()
cursor = conn.cursor() cursor = conn.cursor()
mail_server = get_settings('mail_server') mail_server = get_settings('mail_server')
@ -138,6 +138,7 @@ def get_mail_domains():
current = urllib.request.urlopen(req) current = urllib.request.urlopen(req)
remote = current.read().decode('utf-8') remote = current.read().decode('utf-8')
remoteData = json.loads(remote) remoteData = json.loads(remote)
if info:
total_aliases = 0 total_aliases = 0
i=0 i=0
print('\n[b]malias[/b] - All email domains on %s' %(mail_server)) print('\n[b]malias[/b] - All email domains on %s' %(mail_server))
@ -149,7 +150,8 @@ def get_mail_domains():
print('%s \t\twith %s aliases' %(remoteData[i]['domain_name'],count)) print('%s \t\twith %s aliases' %(remoteData[i]['domain_name'],count))
i+=1 i+=1
print('\n\nThere is a total of %s domains with %s aliases.' %(str(i),str(total_aliases))) print('\n\nThere is a total of %s domains with %s aliases.' %(str(i),str(total_aliases)))
else:
return(remoteData)
def create(alias,to_address): def create(alias,to_address):
@ -440,18 +442,27 @@ def show_current_info():
aliases_server = number_of_aliases_on_server() aliases_server = number_of_aliases_on_server()
alias_db = number_of_aliases_in_db() alias_db = number_of_aliases_in_db()
mailcow_version = get_mailcow_version() mailcow_version = get_mailcow_version()
mail_domains = get_mail_domains(False)
domain = ""
i=0
for domains in mail_domains:
if i!=0:
domain = domain + ', ' + str(mail_domains[i]['domain_name'])
else:
domain = domain + str(mail_domains[i]['domain_name'])
i+=1
print('\n[b]malias[/b] - Manage aliases on mailcow Instance.') print('\n[b]malias[/b] - Manage aliases on mailcow Instance.')
print('===================================================') print('===================================================')
print('API key : [b]%s[/b]' % (API)) print('API key : [b]%s[/b]' % (API))
print('mailcow Instance : [b]%s[/b]' % (mail_server)) print('Mailcow Instance : [b]%s[/b]' % (mail_server))
print('Active domains : [b]%s[/b]' % (domain))
print('Mailcow version : [b]%s[/b]' % (mailcow_version)) print('Mailcow version : [b]%s[/b]' % (mailcow_version))
print('Logfile : [b]%s[/b]' % (logfile)) print('Logfile : [b]%s[/b]' % (logfile))
print('Databse : [b]%s[b]' % (database)) print('Databse : [b]%s[b]' % (database))
print('Aliases on server : [b]%s[/b]' % (aliases_server)) print('Aliases on server : [b]%s[/b]' % (aliases_server))
print('Aliases in DB : [b]%s[/b]' % (alias_db)) print('Aliases in DB : [b]%s[/b]' % (alias_db))
print('') print('')
print('App version : [b]%s[/b] (https://iurl.no/malias)' % (app_version)) print('App version : [b]%s[/b] (https://gitlab.pm/rune/malias)' % (app_version))
print('') print('')
@ -512,7 +523,7 @@ elif args['copy']:
elif args['list']: elif args['list']:
list_alias() list_alias()
elif args['domains']: elif args['domains']:
get_mail_domains() get_mail_domains(True)
else: else: