From 19ab40d585478d269a5673e6c0d3bcda58afcae3 Mon Sep 17 00:00:00 2001 From: Valt7 Date: Sun, 21 Apr 2024 12:49:12 +0200 Subject: [PATCH 1/3] wrong display of ressources after creating or deleting VM --- frontend/src/app/cancel-update.guard.ts | 1 - .../src/app/common/services/vms.service.ts | 27 ++++++++++++++++--- frontend/src/app/home/home.component.ts | 5 ++++ frontend/src/app/vms/vms.component.html | 4 +-- frontend/src/app/vms/vms.component.ts | 3 +-- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/cancel-update.guard.ts b/frontend/src/app/cancel-update.guard.ts index 9a31937..177213a 100644 --- a/frontend/src/app/cancel-update.guard.ts +++ b/frontend/src/app/cancel-update.guard.ts @@ -13,7 +13,6 @@ export class CancelUpdateGuard implements CanActivate { const url = route.url.join('/'); if (url === 'dns' || url.startsWith('vms/') || url === 'history') { this.vmsService.cancelUpdateVms(); - console.log(route.url); } return true; } diff --git a/frontend/src/app/common/services/vms.service.ts b/frontend/src/app/common/services/vms.service.ts index 9f2b109..2e9fa41 100644 --- a/frontend/src/app/common/services/vms.service.ts +++ b/frontend/src/app/common/services/vms.service.ts @@ -228,11 +228,20 @@ export class VmsService { ).subscribe(rep => { const vmstate = rep.body['status']; if (vmstate == "deleted") { - this.vmIds$.pipe( - map(vmIds => vmIds.filter(id => id !== vmid)) - ) + //wipe out les vms pour recalculer les ressources + this.vmIds$ = new Observable(); + this.vmsSubject = new BehaviorSubject>(new Map()); + this.VMCount = 0; + this.CPUCount = 0; + this.RAMCount = 0; + this.DISKCount = 0; + this.ActiveVMCount = 0; + this.vmToRestoreCounter = 0; + this.updateVmIds(); this.updateVms(0); + + unsubscribeTimer.next(); observer.next({ deletionStatus: "deleted", errorcode: null, errorDescription: null }); observer.complete(); @@ -240,8 +249,20 @@ export class VmsService { }, error => { if (error.status == 403 || error.status == 404) { // the vm is deleted + //wipe out les vms pour recalculer les ressources + this.vmIds$ = new Observable(); + this.vmsSubject = new BehaviorSubject>(new Map()); + this.VMCount = 0; + this.CPUCount = 0; + this.RAMCount = 0; + this.DISKCount = 0; + this.ActiveVMCount = 0; + this.vmToRestoreCounter = 0; + this.updateVmIds(); this.updateVms(0); + + unsubscribeTimer.next(); observer.next({ deletionStatus: "deleted", errorcode: null, errorDescription: null }); observer.complete(); diff --git a/frontend/src/app/home/home.component.ts b/frontend/src/app/home/home.component.ts index 5c0a3c7..b03d241 100644 --- a/frontend/src/app/home/home.component.ts +++ b/frontend/src/app/home/home.component.ts @@ -286,6 +286,11 @@ export class HomeComponent implements OnInit { await delay(2000); } if (isStarted){ // There were no errors, we show the vm + + this.vmsService.CPUCount += this.nb_cpu_selected; + this.vmsService.RAMCount += this.nb_ram_selected; + this.vmsService.DISKCount += this.nb_storage_selected; + this.loading = false; this.progress = 100; this.router.navigate(['/vms/' + id]); } else { // There was an error, we show the form for a new submit diff --git a/frontend/src/app/vms/vms.component.html b/frontend/src/app/vms/vms.component.html index a45f820..824b122 100644 --- a/frontend/src/app/vms/vms.component.html +++ b/frontend/src/app/vms/vms.component.html @@ -1,5 +1,5 @@ -
+
{{ "vms.loading" | translate}} @@ -100,7 +100,7 @@

{{ "vms.noVmsAdmin" | translate}}

-
+
{{ "vms.loading" | translate}} diff --git a/frontend/src/app/vms/vms.component.ts b/frontend/src/app/vms/vms.component.ts index 38c681a..e0ac92c 100644 --- a/frontend/src/app/vms/vms.component.ts +++ b/frontend/src/app/vms/vms.component.ts @@ -17,7 +17,7 @@ import { debounceTime, map, tap } from 'rxjs/operators'; export class VmsComponent implements OnInit, OnDestroy { showSsh = false; errorcode = 201; - searchFilter = ""; + searchFilter = ''; searchTextChanged = new BehaviorSubject(''); vmToRestoreCounter = 0; // Number VMs that need to be restored @@ -58,7 +58,6 @@ export class VmsComponent implements OnInit, OnDestroy { this.searchTextChanged.pipe(debounceTime(200)) // attendre 200ms après chaque changement de valeur ]).pipe( map(([vms, searchFilter]) => { - console.log(searchFilter); // Display the searchFilter in the console return vms.filter(vm => searchFilter == "" || (vm.name && vm.name.includes(searchFilter)) || From 1c9c0bf53d82c702c10bc29820d37eed01767d46 Mon Sep 17 00:00:00 2001 From: Valt7 Date: Tue, 23 Apr 2024 17:57:37 +0200 Subject: [PATCH 2/3] final faster frontend --- frontend/src/app/vms/vms.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/vms/vms.component.html b/frontend/src/app/vms/vms.component.html index 824b122..142507f 100644 --- a/frontend/src/app/vms/vms.component.html +++ b/frontend/src/app/vms/vms.component.html @@ -100,7 +100,7 @@

{{ "vms.noVmsAdmin" | translate}}

-
+
{{ "vms.loading" | translate}} From 0a1c4e0c785bc256b9c1aa37a0bca9ec359808b1 Mon Sep 17 00:00:00 2001 From: Valt7 Date: Mon, 6 May 2024 12:41:00 +0200 Subject: [PATCH 3/3] send mail to adherent when validate dns entry --- backend/proxmox_api/__main__.py | 2 +- .../controllers/default_controller.py | 28 +- backend/proxmox_api/db/db_functions.py | 2 +- backend/proxmox_api/ddns.py | 6 +- backend/proxmox_api/proxmox.py | 29 +- backend/proxmox_api/swagger/swagger.yaml | 7 + backend/proxmox_api/util.py | 90 ++- backend/swagger_client/api/default_api.py | 17 +- .../src/app/common/services/dns.service.ts | 2 +- .../src/app/common/services/vms.service.ts | 8 +- .../src/app/deletevm/deletevm.component.html | 4 +- frontend/src/app/dns/dns.component.html | 38 +- frontend/src/app/dns/dns.component.ts | 36 +- frontend/src/app/models/dns.ts | 4 +- frontend/src/app/vm/vm.component.html | 546 +++++++++--------- frontend/src/app/vm/vm.component.ts | 1 + 16 files changed, 492 insertions(+), 328 deletions(-) diff --git a/backend/proxmox_api/__main__.py b/backend/proxmox_api/__main__.py index 5e55838..6959838 100644 --- a/backend/proxmox_api/__main__.py +++ b/backend/proxmox_api/__main__.py @@ -24,9 +24,9 @@ def create_app(): app = connexion.App(__name__, specification_dir='./swagger/') app.app.json_encoder = encoder.JSONEncoder app.app.config['SQLALCHEMY_DATABASE_URI'] = config.DATABASE_URI - CORS(app.app) scheduler = APScheduler() app.add_api('swagger.yaml', arguments={'title': 'Proxmox'}, pythonic_params=True) + CORS(app.app) return app, scheduler diff --git a/backend/proxmox_api/controllers/default_controller.py b/backend/proxmox_api/controllers/default_controller.py index 0bf8c69..be32d38 100644 --- a/backend/proxmox_api/controllers/default_controller.py +++ b/backend/proxmox_api/controllers/default_controller.py @@ -1,18 +1,11 @@ -from logging import error from proxmox_api import proxmox + import connexion -import requests -import json from threading import Thread -from requests.api import head -from slugify import slugify -from proxmox_api.models.dns_entry_item import DnsEntryItem # noqa: E501 from proxmox_api.models.dns_item import DnsItem # noqa: E501 -from proxmox_api.models.vm_id_item import VmIdItem # noqa: E501 from proxmox_api.models.vm_item import VmItem # noqa: E501 from proxmox_api import util from proxmox_api.db.db_functions import * -from datetime import datetime import proxmox_api.db.db_functions as dbfct from proxmox_api.proxmox import is_admin from proxmox_api.db import db_models @@ -57,11 +50,10 @@ def validate_dns(): # noqa: E501 try: userid = update_body['userid'] - except: + except KeyError: return {"error": "Bad userid"}, 400 - - return proxmox.accept_user_dns(update_body['userid'], update_body['dnsentry'], update_body['dnsip']) + return proxmox.accept_user_dns(userid, update_body['dnsentry'], update_body['dnsip']) def create_dns(body=None): # noqa: E501 """create dns entry @@ -652,7 +644,6 @@ def renew_ip(): def delete_dns_id(dnsid): # noqa: E501 - print("delete dns entry") """delete dns entry by id # noqa: E501 @@ -666,6 +657,9 @@ def delete_dns_id(dnsid): # noqa: E501 dnsid = int(dnsid) except: return {"status": "error not an integer"}, 500 + + # Get the sendMail parameter from the request + sendMail = connexion.request.args.get('sendMail', default=False, type=bool) headers = {"Authorization": connexion.request.headers["Authorization"]} status_code, cas = util.check_cas_token(headers) @@ -697,14 +691,20 @@ def delete_dns_id(dnsid): # noqa: E501 return {"status": "cotisation expired"}, 403 user_id = cas['sub'] + + # print(update_body) + # try: + # sendMail = bool(update_body['sendMail']) + # except KeyError: + # return {"error": "Not a boolean"}, 400 if "attributes" in cas: if "memberOf" in cas["attributes"]: if is_admin(cas["attributes"]["memberOf"]): - return proxmox.del_user_dns(dnsid) + return proxmox.del_user_dns(dnsid, sendMail) if dnsid in map(int, proxmox.get_user_dns(user_id)[0]): - return proxmox.del_user_dns(dnsid) + return proxmox.del_user_dns(dnsid, sendMail) else: return {"status": "error"}, 500 diff --git a/backend/proxmox_api/db/db_functions.py b/backend/proxmox_api/db/db_functions.py index 1898eb1..7303ea0 100644 --- a/backend/proxmox_api/db/db_functions.py +++ b/backend/proxmox_api/db/db_functions.py @@ -270,7 +270,7 @@ def get_entry_host_and_validation(id): if domainName is None: return {"dns": "not found"}, 404 else: - return {"host": domainName.entry, "validated" : domainName.validated}, 201 + return {"host": domainName.entry, "validated" : domainName.validated, "ip" : domainName.ip, "userId" : domainName.userId}, 201 def get_entry_userid(dnsid): diff --git a/backend/proxmox_api/ddns.py b/backend/proxmox_api/ddns.py index cf8a970..870f6d8 100644 --- a/backend/proxmox_api/ddns.py +++ b/backend/proxmox_api/ddns.py @@ -36,13 +36,17 @@ def delete_dns_record(entry): """ Delete a record with ddns protocole in configuration.MAIN_DNS_SERVER_IP DNS server """ print("Deleting entry: " + str(entry)) dns_domain = "%s." % configuration.HOSTING_DOMAIN + print(keyring) + update = dns.update.Update(dns_domain, keyring=keyring) + print(update) update.present(entry) update.delete(entry) response = dns.query.tcp(update, configuration.MAIN_DNS_SERVER_IP, timeout=5) + print(response) if response.rcode() == 0: return {"dns": "entry deleted"}, 201 if response.rcode() == 3: return {"dns": "entry does not exist"}, 201 #C'est très crade, mais c'est dans le cas ou l'entrée n'a pas été validée, mais l'appel à ddns se fais quand même. - logging.error("Problem in get_vm_status(" + str(vmid) + ") when getting VM status: " + str(e)) + logging.error("Problem in delete_dns_id(" + entry + ")") return {"dns": "error occured"}, 500 \ No newline at end of file diff --git a/backend/proxmox_api/proxmox.py b/backend/proxmox_api/proxmox.py index e0898b9..09ca992 100644 --- a/backend/proxmox_api/proxmox.py +++ b/backend/proxmox_api/proxmox.py @@ -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 bureau@listes.minet.net") + 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 diff --git a/backend/proxmox_api/swagger/swagger.yaml b/backend/proxmox_api/swagger/swagger.yaml index 4c4a8a7..7d4ce5a 100644 --- a/backend/proxmox_api/swagger/swagger.yaml +++ b/backend/proxmox_api/swagger/swagger.yaml @@ -652,6 +652,13 @@ paths: schema: type: string example: "3" + - name: sendMail + in: query + description: do we send an email to the user + required: false + schema: + type: string + example: "sendMail: true" responses: "201": description: deleted dns entry by id diff --git a/backend/proxmox_api/util.py b/backend/proxmox_api/util.py index 29ab1e8..d55c0f8 100644 --- a/backend/proxmox_api/util.py +++ b/backend/proxmox_api/util.py @@ -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'] = "hosting-noreply@minet.net" + msg['To'] = "bureau@listes.minet.net" + # msg['Bcc'] = "archive_expired_cotisation_hosting@listes.minet.net" + 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'] = "hosting-noreply@minet.net" + print(usermail) + msg['To'] = usermail + # msg['Bcc'] = "archive_expired_cotisation_hosting@listes.minet.net" + 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=""" + + + + + +""" + msg = f""" + + 🚨 Une personne souhaite ajouter une nouvelle entrée DNS sur hosting : {username} qui veut mettre en ligne {entry} pour l'IP {ip}.
+ Un admin Hosting doit la valider sur hosting.minet.net + + """ + return header+msg + +def mailHTMLAdherent(username: str, entry: str, ip: str, accepted:str): + + header=""" + + + + + +""".replace('\n', ' ').replace('\r', ' ') + msg = f""" + + + Bonjour {username},
+ Ton entrée DNS {entry} pour ta machine d'IP {ip} a été {accepted} par un admin sur hosting.
+ Cordialement,
+
L'équipe MINET

🛟 tickets.minet.net
🌐 www.minet.net
📫 9 rue Charles Fourier, 91000, Evry
+ + """.replace('\n', ' ').replace('\r', ' ') + return header+msg + \ No newline at end of file diff --git a/backend/swagger_client/api/default_api.py b/backend/swagger_client/api/default_api.py index a019978..c5c52c4 100644 --- a/backend/swagger_client/api/default_api.py +++ b/backend/swagger_client/api/default_api.py @@ -211,7 +211,7 @@ def create_vm_with_http_info(self, **kwargs): # noqa: E501 collection_formats=collection_formats) - def delete_dns_id(self, dnsid, **kwargs): # noqa: E501 + def delete_dns_id(self, dnsid, sendMail, **kwargs): # noqa: E501 """delete dns entry by id # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -227,12 +227,12 @@ def delete_dns_id(self, dnsid, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_dns_id_with_http_info(dnsid, **kwargs) # noqa: E501 + return self.delete_dns_id_with_http_info(dnsid, sendMail, **kwargs) # noqa: E501 else: - (data) = self.delete_dns_id_with_http_info(dnsid, **kwargs) # noqa: E501 + (data) = self.delete_dns_id_with_http_info(dnsid, sendMail, **kwargs) # noqa: E501 return data - def delete_dns_id_with_http_info(self, dnsid, **kwargs): # noqa: E501 + def delete_dns_id_with_http_info(self, dnsid, sendMail, **kwargs): # noqa: E501 """delete dns entry by id # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -247,7 +247,7 @@ def delete_dns_id_with_http_info(self, dnsid, **kwargs): # noqa: E501 returns the request thread. """ - all_params = ['dnsid'] # noqa: E501 + all_params = ['dnsid', 'sendMail'] # noqa: E501 all_params.append('async_req') all_params.append('_return_http_data_only') all_params.append('_preload_content') @@ -266,12 +266,19 @@ def delete_dns_id_with_http_info(self, dnsid, **kwargs): # noqa: E501 if ('dnsid' not in params or params['dnsid'] is None): raise ValueError("Missing the required parameter `dnsid` when calling `delete_dns_id`") # noqa: E501 + + if ('sendMail' not in params or + params['sendMail'] is None): + raise ValueError("Missing the required parameter `sendMail` when calling `delete_dns_id`") # noqa: E501 collection_formats = {} path_params = {} if 'dnsid' in params: path_params['dnsid'] = params['dnsid'] # noqa: E501 + + if 'sendMail' in params: + path_params['sendMail'] = params['sendMail'] # noqa: E501 query_params = [] diff --git a/frontend/src/app/common/services/dns.service.ts b/frontend/src/app/common/services/dns.service.ts index dcd53c1..53bf3cb 100644 --- a/frontend/src/app/common/services/dns.service.ts +++ b/frontend/src/app/common/services/dns.service.ts @@ -121,7 +121,7 @@ export class DnsService { dns.ip = response.body['ip']; dns.user = response.body['user']; dns.validated = response.body['validated']; - + dns.status = 'created'; if (dns.validated) { this.ActiveDNSCount++; } diff --git a/frontend/src/app/common/services/vms.service.ts b/frontend/src/app/common/services/vms.service.ts index 2e9fa41..414df7b 100644 --- a/frontend/src/app/common/services/vms.service.ts +++ b/frontend/src/app/common/services/vms.service.ts @@ -229,8 +229,8 @@ export class VmsService { const vmstate = rep.body['status']; if (vmstate == "deleted") { //wipe out les vms pour recalculer les ressources - this.vmIds$ = new Observable(); - this.vmsSubject = new BehaviorSubject>(new Map()); + this.vmIds$ = of([]); + this.vmsSubject.next(new Map()); this.VMCount = 0; this.CPUCount = 0; this.RAMCount = 0; @@ -250,8 +250,8 @@ export class VmsService { error => { if (error.status == 403 || error.status == 404) { // the vm is deleted //wipe out les vms pour recalculer les ressources - this.vmIds$ = new Observable(); - this.vmsSubject = new BehaviorSubject>(new Map()); + this.vmIds$ = of([]); + this.vmsSubject.next(new Map()); this.VMCount = 0; this.CPUCount = 0; this.RAMCount = 0; diff --git a/frontend/src/app/deletevm/deletevm.component.html b/frontend/src/app/deletevm/deletevm.component.html index ddfebcd..4d14cfb 100644 --- a/frontend/src/app/deletevm/deletevm.component.html +++ b/frontend/src/app/deletevm/deletevm.component.html @@ -15,7 +15,7 @@
Owner: {{ vm.user }}

Created: {{ vm.createdOn }}

- +
@@ -30,7 +30,7 @@
Owner: {{ vm.user }}
{{ "deletevm.loading" | translate }}
-

{{ "deletevm.noVms" | translate}}

+

{{ "deletevm.noVms" | translate}}

diff --git a/frontend/src/app/dns/dns.component.html b/frontend/src/app/dns/dns.component.html index 706f4bf..a3e8865 100644 --- a/frontend/src/app/dns/dns.component.html +++ b/frontend/src/app/dns/dns.component.html @@ -26,7 +26,7 @@

{{'dns.title.admin' | translate}
-
+
{{'dns.loading' | translate}} @@ -109,7 +109,7 @@

{{'dns.title.admin' | translate}

-
+

{{'dns.noEntries.user' | translate}}

{{'dns.noEntries.admin' | translate}}

@@ -163,10 +163,31 @@

{{'dns.pendingEntries.admin' | translate}} - - + +
+ +
+
+ +
+ + +
+ +
+
+ +
+              - + +
+ +
+
+ +
+ @@ -220,9 +241,12 @@

{{'dns.validatedEntries.admin' | translate}} {{dns.id}} - - + + +
+ +
diff --git a/frontend/src/app/dns/dns.component.ts b/frontend/src/app/dns/dns.component.ts index 289ba8f..ad5e27e 100644 --- a/frontend/src/app/dns/dns.component.ts +++ b/frontend/src/app/dns/dns.component.ts @@ -151,13 +151,14 @@ export class DnsComponent implements OnInit, OnDestroy { return authorized_ip.test(ip.trim()) } - accept_entry(userid: string, dnsentry: string, dnsip: string): void { + accept_entry(dns: Dns): void { if(this.user.admin) { + dns.status = "accepting" this.http.post(this.authService.SERVER_URL + '/dns/validation', { - userid: userid, - dnsentry: dnsentry, - dnsip: dnsip + userid: dns.user, + dnsentry: dns.entry, + dnsip: dns.ip }, {observe: 'response'} ) @@ -167,26 +168,31 @@ export class DnsComponent implements OnInit, OnDestroy { console.log("ok"); }, error => { - console.log("error"); + console.log(error); this.errorcode = error.status; this.httpErrorMessage = this.utils.getHttpErrorMessage(this.errorcode) + dns.status = "created" } ); } } - delete_entry(id: string): void { + delete_entry(dns: Dns, sendMail: boolean): void { if(this.user.chartevalidated || this.user.admin) { - this.http.delete(this.authService.SERVER_URL + '/dns/' + id, {observe: 'response'}) - .subscribe( - () => { - window.location.reload(); - }, - error => { - this.errorcode = error.status; - this.httpErrorMessage = this.utils.getHttpErrorMessage(this.errorcode) - }); + dns.status = "deleting"; + this.http.delete(`${this.authService.SERVER_URL}/dns/${dns.id}` + , { params: { sendMail: sendMail.toString() } } + ).subscribe( + () => { + window.location.reload(); + }, + error => { + this.errorcode = error.status; + this.httpErrorMessage = this.utils.getHttpErrorMessage(this.errorcode) + console.log(error); + dns.status = "created" + }); } } } diff --git a/frontend/src/app/models/dns.ts b/frontend/src/app/models/dns.ts index 0a91f6f..fc1db10 100644 --- a/frontend/src/app/models/dns.ts +++ b/frontend/src/app/models/dns.ts @@ -4,7 +4,7 @@ export class Dns { public entry?: string, public ip?: string, public user?: string, - public validated?: boolean - + public validated?: boolean, + public status?: string ) { } } diff --git a/frontend/src/app/vm/vm.component.html b/frontend/src/app/vm/vm.component.html index 6dbeb32..c68520b 100644 --- a/frontend/src/app/vm/vm.component.html +++ b/frontend/src/app/vm/vm.component.html @@ -37,304 +37,306 @@

{{'account.expired.title' | translate }}

-
-

VM: {{ (vm$ | async).name }}

-
-
- -
{{'vm.status' | translate}} : {{ deletionStatus != 'None' ? deletionStatus : (vm$ | async).status | translate }}
- -
{{"vm.error" | translate}} {{errorcode}} : {{utils.getHttpErrorMessage(errorcode)}}
-

- -
- -
- - -