Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
0e1a5d7314 | |||
5d1c11d42d | |||
d461290730 | |||
38261bb0a2 | |||
01c158db6d | |||
7f7c562455 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1 +1,4 @@
|
|||||||
list_alias.py
|
list_alias.py
|
||||||
|
malias.zip
|
||||||
|
malias_local.py
|
||||||
|
.DS_Store
|
51
malias.py
51
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.1'
|
app_version = '0.2.1'
|
||||||
|
|
||||||
|
|
||||||
def connect_database():
|
def connect_database():
|
||||||
@@ -164,8 +164,6 @@ def delete_alias(alias):
|
|||||||
response = requests.post('https://'+server+'/api/v1/delete/alias',
|
response = requests.post('https://'+server+'/api/v1/delete/alias',
|
||||||
data=json.dumps(data), headers=headers)
|
data=json.dumps(data), headers=headers)
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
print(response_data)
|
|
||||||
exit(0)
|
|
||||||
if response_data[0]['type'] == 'success':
|
if response_data[0]['type'] == 'success':
|
||||||
if check_local_db(the_alias_id) == 1:
|
if check_local_db(the_alias_id) == 1:
|
||||||
now = datetime.now().strftime("%m-%d-%Y %H:%M")
|
now = datetime.now().strftime("%m-%d-%Y %H:%M")
|
||||||
@@ -212,6 +210,7 @@ def copy_data():
|
|||||||
|
|
||||||
|
|
||||||
def checklist(alias):
|
def checklist(alias):
|
||||||
|
alias_exist = None
|
||||||
apikey = get_api()
|
apikey = get_api()
|
||||||
mail_server = get_settings('mail_server')
|
mail_server = get_settings('mail_server')
|
||||||
req = urllib.request.Request('https://'+mail_server+'/api/v1/get/alias/all')
|
req = urllib.request.Request('https://'+mail_server+'/api/v1/get/alias/all')
|
||||||
@@ -222,10 +221,16 @@ def checklist(alias):
|
|||||||
remoteData = json.loads(remote)
|
remoteData = json.loads(remote)
|
||||||
i = 0
|
i = 0
|
||||||
for search in remoteData:
|
for search in remoteData:
|
||||||
if alias in remoteData[i]['address']:
|
if alias in remoteData[i]['address'] or alias in remoteData[i]['goto']:
|
||||||
return True
|
alias_exist = True
|
||||||
i=i+1
|
i=i+1
|
||||||
return None
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('SELECT count(*) FROM aliases where alias like ? or goto like ?', (alias,alias,))
|
||||||
|
count = cursor.fetchone()[0]
|
||||||
|
if count >= 1 :
|
||||||
|
alias_exist = True
|
||||||
|
|
||||||
|
return alias_exist
|
||||||
|
|
||||||
|
|
||||||
def list_alias():
|
def list_alias():
|
||||||
@@ -294,12 +299,38 @@ def check_local_db(alias_id):
|
|||||||
|
|
||||||
|
|
||||||
def search(alias):
|
def search(alias):
|
||||||
results = checklist(alias)
|
apikey = get_api()
|
||||||
mail_server = get_settings('mail_server')
|
mail_server = get_settings('mail_server')
|
||||||
if results == True:
|
cursor = conn.cursor()
|
||||||
print('\n\nThe mail address %s exists. Using the mailcow instance : %s\n\n'%(alias,mail_server))
|
cursor.execute('SELECT data_copy FROM settings where id = 1')
|
||||||
|
result = cursor.fetchone()[0]
|
||||||
|
if result == 1:
|
||||||
|
search_term = '%'+alias+'%'
|
||||||
|
cursor.execute('SELECT * from aliases where alias like ? or goto like ?',(search_term,search_term,))
|
||||||
|
remoteData = cursor.fetchall()
|
||||||
|
i = 0
|
||||||
|
print('\nAliases on %s that contains %s' %(mail_server,alias))
|
||||||
|
print('=================================================================')
|
||||||
|
for search in remoteData:
|
||||||
|
the_alias = remoteData[i][1].ljust(20,' ')
|
||||||
|
print(the_alias + '\tgoes to\t\t' + remoteData[i][2])
|
||||||
|
i=i+1
|
||||||
|
print('\n\nData from local DB')
|
||||||
else:
|
else:
|
||||||
print('\n\nThe mail address %s [b]does not[/b] exists. Using the mailcow instance : %s\n\n'%(alias,mail_server))
|
req = urllib.request.Request('https://'+mail_server+'/api/v1/get/alias/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)
|
||||||
|
i = 0
|
||||||
|
print('\nAliases on %s that contains %s' %(mail_server,alias))
|
||||||
|
print('=================================================')
|
||||||
|
for search in remoteData:
|
||||||
|
if alias in remoteData[i]['address'] or alias in remoteData[i]['goto']:
|
||||||
|
print(remoteData[i]['address'] + '\tgoes to\t\t' + remoteData[i]['goto'])
|
||||||
|
i=i+1
|
||||||
|
print('\n\nData from server')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user