Added function for listing mail domains
This commit is contained in:
parent
8a6eceb9a5
commit
7f12bd3743
31
malias.py
31
malias.py
@ -29,7 +29,7 @@ database = filepath.joinpath('malias.db')
|
|||||||
logfile = filepath.joinpath('malias.log')
|
logfile = filepath.joinpath('malias.log')
|
||||||
Path(filepath).mkdir(parents=True, exist_ok=True)
|
Path(filepath).mkdir(parents=True, exist_ok=True)
|
||||||
logging.basicConfig(filename=logfile,level=logging.INFO,format='%(message)s')
|
logging.basicConfig(filename=logfile,level=logging.INFO,format='%(message)s')
|
||||||
app_version = '0.2.2'
|
app_version = '0.2.3'
|
||||||
|
|
||||||
|
|
||||||
def connect_database():
|
def connect_database():
|
||||||
@ -128,6 +128,30 @@ def apikey(key):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def get_mail_domains():
|
||||||
|
apikey = get_api()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
mail_server = get_settings('mail_server')
|
||||||
|
req = urllib.request.Request('https://'+mail_server+'/api/v1/get/domain/all')
|
||||||
|
req.add_header('Content-Type', 'application/json')
|
||||||
|
req.add_header('X-API-Key', apikey)
|
||||||
|
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)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create(alias,to_address):
|
def create(alias,to_address):
|
||||||
now = datetime.now().strftime("%m-%d-%Y %H:%M")
|
now = datetime.now().strftime("%m-%d-%Y %H:%M")
|
||||||
server = get_settings('mail_server')
|
server = get_settings('mail_server')
|
||||||
@ -431,6 +455,9 @@ parser.add_argument('-c', '--copy', help='Copy alias data from mailcow server to
|
|||||||
parser.add_argument('-l', '--list', help='List all aliases on the Mailcow instance.\n\n',
|
parser.add_argument('-l', '--list', help='List all aliases on the Mailcow instance.\n\n',
|
||||||
required=False, action='store_true')
|
required=False, action='store_true')
|
||||||
|
|
||||||
|
parser.add_argument('-o', '--domains', help='List all mail domains on the Mailcow instance.\n\n',
|
||||||
|
required=False, action='store_true')
|
||||||
|
|
||||||
|
|
||||||
args = vars(parser.parse_args())
|
args = vars(parser.parse_args())
|
||||||
|
|
||||||
@ -450,6 +477,8 @@ elif args['copy']:
|
|||||||
copy_data()
|
copy_data()
|
||||||
elif args['list']:
|
elif args['list']:
|
||||||
list_alias()
|
list_alias()
|
||||||
|
elif args['domains']:
|
||||||
|
get_mail_domains()
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user