From 8814127cf8079da15166d541e0a0524e5ddfe632 Mon Sep 17 00:00:00 2001 From: rune Date: Tue, 5 Sep 2023 11:36:39 +0200 Subject: [PATCH] Added some functionality --- malias.py | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/malias.py b/malias.py index 0500b59..52db715 100755 --- a/malias.py +++ b/malias.py @@ -128,7 +128,7 @@ def apikey(key): conn.commit() -def get_mail_domains(): +def get_mail_domains(info): apikey = get_api() cursor = conn.cursor() mail_server = get_settings('mail_server') @@ -138,18 +138,20 @@ def get_mail_domains(): current = urllib.request.urlopen(req) remote = current.read().decode('utf-8') remoteData = json.loads(remote) - total_aliases = 0 - i=0 - print('\n[b]malias[/b] - All email domains on %s' %(mail_server)) - print('==================================================================') - for domains in remoteData: - cursor.execute('SELECT count(*) FROM aliases where alias like ? or goto like ?', ('%'+remoteData[i]['domain_name']+'%','%'+remoteData[i]['domain_name']+'%',)) - count = cursor.fetchone()[0] - total_aliases += count - print('%s \t\twith %s aliases' %(remoteData[i]['domain_name'],count)) - i+=1 - print('\n\nThere is a total of %s domains with %s aliases.' %(str(i),str(total_aliases))) - + if info: + total_aliases = 0 + i=0 + print('\n[b]malias[/b] - All email domains on %s' %(mail_server)) + print('==================================================================') + for domains in remoteData: + cursor.execute('SELECT count(*) FROM aliases where alias like ? or goto like ?', ('%'+remoteData[i]['domain_name']+'%','%'+remoteData[i]['domain_name']+'%',)) + count = cursor.fetchone()[0] + total_aliases += count + print('%s \t\twith %s aliases' %(remoteData[i]['domain_name'],count)) + i+=1 + 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): @@ -440,18 +442,27 @@ def show_current_info(): aliases_server = number_of_aliases_on_server() alias_db = number_of_aliases_in_db() 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('===================================================') 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('Logfile : [b]%s[/b]' % (logfile)) print('Databse : [b]%s[b]' % (database)) print('Aliases on server : [b]%s[/b]' % (aliases_server)) print('Aliases in DB : [b]%s[/b]' % (alias_db)) 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('') @@ -512,7 +523,7 @@ elif args['copy']: elif args['list']: list_alias() elif args['domains']: - get_mail_domains() + get_mail_domains(True) else: