-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fasterFront' into 'development'
Faster front See merge request hosting/api!79
- Loading branch information
Showing
20 changed files
with
520 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,12 @@ | |
def add_user_dns(user_id, entry, ip): | ||
database.add_dns_entry(user_id, entry, ip, validated=False) | ||
logging.info("DNS entry added: " + str(user_id) + " " + str(entry) + "=> " + str(ip)) | ||
logging.info("send a notification to [email protected]") | ||
mailBody = util.mailHTMLBureau(user_id, entry, ip) | ||
try : | ||
util.sendMailBureau(mailBody, user_id) | ||
except Exception as e: | ||
print("ERROR : the mail to " + str(user_id) + " failed to be sent : " + str(e)) | ||
return {"dns": "added"}, 201 | ||
|
||
|
||
|
@@ -42,8 +48,21 @@ def accept_user_dns(user_id, entry, ip): | |
|
||
rep_msg, rep_code = ddns.create_entry(entry, ip) | ||
if rep_code == 201: | ||
|
||
database.validate_dns_entry(user_id, entry, ip) | ||
logging.info("DNS entry validated: " + str(user_id) + " " + str(entry) + "=> " + str(ip)) | ||
logging.info("send a notification to " + str(user_id)) | ||
print("send a notification to " + str(user_id)) | ||
mailBody = util.mailHTMLAdherent(user_id, entry, ip, "acceptée") | ||
account, status = util.get_adh6_account(user_id) | ||
if (account is None): | ||
return {"error": "Impossible to retrieve the user info"}, 404 | ||
try : | ||
util.sendMailAdherent(account["email"], mailBody, entry, True) | ||
except Exception as e: | ||
print("ERROR : the mail to " + str(user_id) + " failed to be sent : " + str(e)) | ||
return rep_msg, rep_code | ||
|
||
return rep_msg, rep_code | ||
|
||
def isDnsEntryExistingInDatabase(entry): | ||
|
@@ -63,7 +82,7 @@ def get_user_dns(user_id = ""): | |
|
||
|
||
|
||
def del_user_dns(dnsid): | ||
def del_user_dns(dnsid, sendMail:bool = False): | ||
db_result = database.get_entry_host_and_validation(dnsid) | ||
if db_result is None: | ||
return {"dns": "not found"}, 404 | ||
|
@@ -83,6 +102,14 @@ def del_user_dns(dnsid): | |
else: | ||
database.del_dns_entry(dnsid) | ||
logging.info("DNS entry deleted: " + str(dnsid)) | ||
if sendMail: | ||
user_id = db_result[0]['userId'] | ||
ip = db_result[0]['ip'] | ||
mailBody = util.mailHTMLAdherent(user_id, entry, ip, "refusée") | ||
try : | ||
util.sendMailAdherent(mailBody, user_id, entry, False) | ||
except Exception as e: | ||
print("ERROR : the mail to " + str(user_id) + " failed to be sent : " + str(e)) | ||
return {"dns": "entry deleted"}, 201 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,13 @@ | |
import connexion | ||
import tempfile | ||
import subprocess | ||
from flask_apscheduler import APScheduler | ||
from flask_cors import CORS | ||
import proxmox_api.config.configuration as config | ||
import proxmox_api.config.configuration as config | ||
from proxmox_api import encoder | ||
from proxmox_api.db.db_models import db | ||
from email.message import EmailMessage | ||
import smtplib | ||
|
||
|
||
if not bool(config.ADH6_API_KEY): | ||
raise Exception("NO ADH6 API KEY GIVEN") | ||
|
@@ -344,3 +345,88 @@ def subscribe_to_hosting_ML(username): | |
return status, response.status_code | ||
|
||
return {"error" : "the user " + username + " failed to be retrieved"}, 404 | ||
|
||
def sendMailBureau(htmlbody, username): | ||
msg = EmailMessage() | ||
msg['From'] = "[email protected]" | ||
msg['To'] = "[email protected]" | ||
# msg['Bcc'] = "[email protected]" | ||
msg['subject'] = f"[Hosting]" + {username} + " veut créer un nom de domaine !" | ||
msg.add_header('Content-Type','text/html') | ||
msg.set_payload(htmlbody.encode('utf-8')) | ||
server = smtplib.SMTP("192.168.102.18:25") | ||
server.send_message(msg) | ||
server.set_debuglevel(1) | ||
server.quit() | ||
print("OK email") | ||
return 0 | ||
|
||
def sendMailAdherent(usermail: str, htmlbody: str, entry: str, accepted: bool): | ||
msg = EmailMessage() | ||
msg['From'] = "[email protected]" | ||
print(usermail) | ||
msg['To'] = usermail | ||
# msg['Bcc'] = "[email protected]" | ||
if accepted: | ||
msg['subject'] = f"[Hosting] : {entry} a été accepté comme nom de domaine!" | ||
else: | ||
msg['subject'] = f"[Hosting] : {entry} a été refusé comme nom de domaine!" | ||
|
||
msg.add_header('Content-Type','text/html') | ||
msg.set_payload(htmlbody.encode('utf-8')) | ||
server = smtplib.SMTP("192.168.102.18:25") | ||
server.send_message(msg) | ||
server.set_debuglevel(1) | ||
server.quit() | ||
print("OK email") | ||
return 0 | ||
|
||
def mailHTMLBureau(username, entry, ip): | ||
|
||
header=""" | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<style> | ||
body{ | ||
font-family: Helvetica, sans-serif; | ||
font-size: 14px; | ||
font-color:black; | ||
} | ||
</style>""" | ||
msg = f""" | ||
<body> | ||
🚨 Une personne souhaite ajouter une nouvelle entrée DNS sur hosting : {username} qui veut mettre en ligne {entry} pour l'IP {ip}.<br> | ||
Un admin Hosting doit la valider sur <a href="https://hosting.minet.net">hosting.minet.net</a> | ||
</body></html> | ||
""" | ||
return header+msg | ||
|
||
def mailHTMLAdherent(username: str, entry: str, ip: str, accepted:str): | ||
|
||
header=""" | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<style> | ||
body{ | ||
font-family: Helvetica, sans-serif; | ||
font-size: 14px; | ||
font-color:black; | ||
} | ||
</style>""".replace('\n', ' ').replace('\r', ' ') | ||
msg = f""" | ||
<body> | ||
Bonjour {username}, <br> | ||
Ton entrée DNS <strong>{entry}</strong> pour ta machine d'IP <strong>{ip}</strong> a été {accepted} par un admin sur <a href="https://hosting.minet.net">hosting</a>.<br> | ||
Cordialement,<br> | ||
<table style="font-size: medium; font-family: Arial; background:white; width:vw;" class="sc-gPEVay eQYmiW" cellspacing="0" cellpadding="0"><tbody><tr><td><table style="font-size: medium; font-family: Arial;" class="sc-gPEVay eQYmiW" cellspacing="0" cellpadding="0"><tbody><tr><td style="vertical-align: middle;" width="150"><span style="margin-right: 20px; display: block;" class="sc-kgAjT cuzzPp"><img src="https://www.minet.net/res/img/minet.png" role="presentation" style="max-width: 130px;" class="sc-cHGsZl bHiaRe" width="130"></span></td><td style="vertical-align: middle;"><font color="#000000" size="4"><span style="caret-color: rgb(0, 0, 0);"><b>L'équipe MINET</b></span></font><p color="#000000" font-size="medium" style="margin: 0px; color: rgb(0, 0, 0); font-size: 14px; line-height: 22px;" class="sc-fMiknA bxZCMx"><span></span></p><p color="#000000" font-size="medium" style="margin: 0px; font-weight: 500; color: rgb(0, 0, 0); font-size: 14px; line-height: 22px;" class="sc-dVhcbM fghLuF"><span></span></p></td><td width="30"><div style="width: 30px;"></div></td><td color="#6fa3e8" direction="vertical" style="width: 1px; border-bottom: medium none; border-left: 1px solid rgb(111, 163, 232);" class="sc-jhAzac hmXDXQ" width="1"></td><td width="30"><div style="width: 30px;"></div></td><td style="vertical-align: middle;"><table style="font-size: medium; font-family: Arial;" class="sc-gPEVay eQYmiW" cellspacing="0" cellpadding="0"><tbody><tr><td style="padding: 0px;"><a href="https://tickets.minet.net" color="#000000" style="text-decoration: none; color: rgb(0, 0, 0); font-size: 12px;" class="sc-gipzik iyhjGb"><span style="margin-left:1px; font-family: Arial;">🛟 tickets.minet.net</span></a></td></tr><tr><td style="padding: 0px;"><a href="//www.minet.net" color="#000000" style="text-decoration: none; color: rgb(0, 0, 0); font-size: 12px;" class="sc-gipzik iyhjGb"><span style="margin-left:1px; font-family: Arial;">🌐 www.minet.net</span></a></td></tr><tr style="vertical-align: middle;" height="25"><td style="padding: 0px;"><span color="#000000" style="font-size: 12px; color: rgb(0, 0, 0);" class="sc-csuQGl CQhxV"><span style="margin-left:1px; font-family: Arial;"> 📫 9 rue Charles Fourier, 91000, Evry</span></span></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td></td></tr><tr><td></td></tr></tbody></table> | ||
</body></html> | ||
""".replace('\n', ' ').replace('\r', ' ') | ||
return header+msg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.