diff --git a/projects/multidirectory-app/src/app/core/validators/ip6-address.directive.ts b/projects/multidirectory-app/src/app/core/validators/ip6-address.directive.ts index 577e3f00..1576f136 100644 --- a/projects/multidirectory-app/src/app/core/validators/ip6-address.directive.ts +++ b/projects/multidirectory-app/src/app/core/validators/ip6-address.directive.ts @@ -16,7 +16,6 @@ import { translate } from '@jsverse/transloco'; export class Ip6AddressValidatorDirective implements Validator { readonly errorLabel = input(translate('error-message.ip6-valid')); ipPattern = new RegExp('^([a-f0-9:]+:+)+[a-f0-9]+$'); - validate(control: AbstractControl): ValidationErrors | null { const result = this.ipPattern.test(control.value); if (result) { diff --git a/projects/multidirectory-app/src/app/features/dns/add-zone-dialog/add-zone-dialog.component.html b/projects/multidirectory-app/src/app/features/dns/add-zone-dialog/add-zone-dialog.component.html index 6d4e07b5..1650dd78 100644 --- a/projects/multidirectory-app/src/app/features/dns/add-zone-dialog/add-zone-dialog.component.html +++ b/projects/multidirectory-app/src/app/features/dns/add-zone-dialog/add-zone-dialog.component.html @@ -6,37 +6,31 @@
- +
+ + + + + + + + +
- -
-
- - {{ - 'add-zone-dialog.add' | transloco - }} + + + +
+
+ + {{ 'entity-attributes.with-values-only' | transloco }} + +
- {{ - 'add-zone-dialog.apply' | transloco - }} + {{ 'add-zone-dialog.apply' | transloco }}
diff --git a/projects/multidirectory-app/src/app/features/dns/add-zone-dialog/add-zone-dialog.component.ts b/projects/multidirectory-app/src/app/features/dns/add-zone-dialog/add-zone-dialog.component.ts index a6e49966..5537bb9b 100644 --- a/projects/multidirectory-app/src/app/features/dns/add-zone-dialog/add-zone-dialog.component.ts +++ b/projects/multidirectory-app/src/app/features/dns/add-zone-dialog/add-zone-dialog.component.ts @@ -18,14 +18,7 @@ import { RequiredWithMessageDirective } from '@core/validators/required-with-mes selector: 'app-add-zone-dialog', templateUrl: './add-zone-dialog.component.html', styleUrls: ['./add-zone-dialog.component.scss'], - imports: [ - FormsModule, - DialogComponent, - TranslocoModule, - MultidirectoryUiKitModule, - CommonModule, - RequiredWithMessageDirective, - ], + imports: [FormsModule, DialogComponent, TranslocoModule, MultidirectoryUiKitModule, CommonModule, RequiredWithMessageDirective], }) export class AddZoneDialogComponent { private api = inject(DnsApiService); @@ -33,7 +26,7 @@ export class AddZoneDialogComponent { private dialogRef: DialogRef = inject(DialogRef); dnsZone = new DnsAddZoneRequest({ - zone_type: 'master', + dnssec: false, }); onSumbit(event: SubmitEvent) { @@ -44,41 +37,41 @@ export class AddZoneDialogComponent { }); } - openIpAddressDialog() { - let aclparameters = this.dnsZone.params.find((x) => x.name == 'acl'); - if (!aclparameters) { - aclparameters = new DnsZoneParam({ name: 'acl', value: [] }); - this.dnsZone.params.push(aclparameters); - } - - let address: IpOption[] = []; - if (aclparameters.value instanceof Array) { - address = aclparameters.value.flatMap((x) => this.toIpOption(x)); - } - - this.dialogService - .open({ - component: IpListDialogComponent, - dialogConfig: { - data: { - addresses: address, - }, - }, - }) - .closed.pipe(take(1)) - .subscribe((result) => { - if (!result) { - return; - } - let aclparameters = this.dnsZone.params.find((x) => x.name == 'acl'); - if (!aclparameters) { - aclparameters = new DnsZoneParam({ name: 'acl', value: [] }); - this.dnsZone.params.push(aclparameters); - } - this._ipString = this.fromIpOption(result.addresses); - aclparameters.value = this._ipString.split(',').map((x) => x.trim()); - }); - } + // openIpAddressDialog() { + // let aclparameters = this.dnsZone.params.find((x) => x.name == 'acl'); + // if (!aclparameters) { + // aclparameters = new DnsZoneParam({ name: 'acl', value: [] }); + // this.dnsZone.params.push(aclparameters); + // } + // + // let address: IpOption[] = []; + // if (aclparameters.value instanceof Array) { + // address = aclparameters.value.flatMap((x) => this.toIpOption(x)); + // } + // + // this.dialogService + // .open({ + // component: IpListDialogComponent, + // dialogConfig: { + // data: { + // addresses: address, + // }, + // }, + // }) + // .closed.pipe(take(1)) + // .subscribe((result) => { + // if (!result) { + // return; + // } + // let aclparameters = this.dnsZone.params.find((x) => x.name == 'acl'); + // if (!aclparameters) { + // aclparameters = new DnsZoneParam({ name: 'acl', value: [] }); + // this.dnsZone.params.push(aclparameters); + // } + // this._ipString = this.fromIpOption(result.addresses); + // aclparameters.value = this._ipString.split(',').map((x) => x.trim()); + // }); + // } private _ipString = ''; get ipString() { @@ -86,29 +79,30 @@ export class AddZoneDialogComponent { } set ipString(x: string) { this._ipString = x; - let aclparameters = this.dnsZone.params.find((x) => x.name == 'acl'); - if (!aclparameters) { - aclparameters = new DnsZoneParam({ name: 'acl', value: [] }); - this.dnsZone.params.push(aclparameters); - } - aclparameters.value = this.fromIpOption(this.toIpOption(x)) - .split(',') - .map((x) => x.trim()); + this.dnsZone.nameserver_ip = this._ipString; + // let aclparameters = this.dnsZone.params.find((x) => x.name == 'acl'); + // if (!aclparameters) { + // aclparameters = new DnsZoneParam({ name: 'acl', value: [] }); + // this.dnsZone.params.push(aclparameters); + // } + // aclparameters.value = this.fromIpOption(this.toIpOption(x)) + // .split(',') + // .map((x) => x.trim()); } - toIpOption(ipString: string): IpOption[] { - return ipString.split(',').map((x) => { - x = x.trim(); - if (x.includes('-')) { - const parts = x.split('-').map((x) => x.trim()); - return new IpRange({ - start: parts[0], - end: parts[1], - }); - } - return x.trim(); - }); - } + // toIpOption(ipString: string): IpOption[] { + // return ipString.split(',').map((x) => { + // x = x.trim(); + // if (x.includes('-')) { + // const parts = x.split('-').map((x) => x.trim()); + // return new IpRange({ + // start: parts[0], + // end: parts[1], + // }); + // } + // return x.trim(); + // }); + // } fromIpOption(ips: IpOption[]) { return ips.map((x: any) => (x instanceof Object ? x.start + '-' + x.end : x)).join(', '); diff --git a/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/add-forward-zone-dialog/add-forward-zone-dialog.component.html b/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/add-forward-zone-dialog/add-forward-zone-dialog.component.html index 0fec0246..4252252d 100644 --- a/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/add-forward-zone-dialog/add-forward-zone-dialog.component.html +++ b/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/add-forward-zone-dialog/add-forward-zone-dialog.component.html @@ -3,14 +3,12 @@
{{ 'add-forward-zone-dialog.modal-header' | transloco }}
- +
-
- @for (forwarder of zone.forwarders; track $index) { +
+ @for (forwarder of zone.servers; track $index) {
- -
- {{ - forwarderResponse.has($index) - ? (forwarderResponse.get($index)?.FQDN ?? 'FQDN') - : 'FQDN' - }} + +
+ {{ forwarderResponse.has($index) ? (forwarderResponse.get($index)?.FQDN ?? 'FQDN') : 'FQDN' }}
@@ -43,10 +34,7 @@ }
- +
@@ -56,18 +44,14 @@
- {{ - 'add-forward-zone-dialog.add' | transloco - }} + {{ 'add-forward-zone-dialog.add' | transloco }}
diff --git a/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/add-forward-zone-dialog/add-forward-zone-dialog.component.ts b/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/add-forward-zone-dialog/add-forward-zone-dialog.component.ts index 742b2d0e..c1dbc5c6 100644 --- a/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/add-forward-zone-dialog/add-forward-zone-dialog.component.ts +++ b/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/add-forward-zone-dialog/add-forward-zone-dialog.component.ts @@ -1,5 +1,5 @@ import { Component, inject } from '@angular/core'; -import { DialogComponent } from '../../../../components/modals/components/core/dialog/dialog.component'; +import { DialogComponent } from '@components/modals/components/core/dialog/dialog.component'; import { translate, TranslocoModule } from '@jsverse/transloco'; import { DialogService } from '@components/modals/services/dialog.service'; import { DIALOG_DATA, DialogRef } from '@angular/cdk/dialog'; @@ -7,23 +7,13 @@ import { AddForwardZoneDialogData } from './add-forward-zone-dialog.interface'; import { FormsModule, NgForm } from '@angular/forms'; import { CommonModule } from '@angular/common'; import { DnsApiService } from '@services/dns-api.service'; -import { - DnsCheckForwardZoneRequest, - DnsCheckForwardZoneResponse, -} from '@models/api/dns/dns-check-forward-zone'; +import { DnsCheckForwardZoneRequest, DnsCheckForwardZoneResponse } from '@models/api/dns/dns-check-forward-zone'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; import { faCheck, faClose } from '@fortawesome/free-solid-svg-icons'; import { MultidirectoryUiKitModule } from 'multidirectory-ui-kit'; @Component({ - imports: [ - DialogComponent, - TranslocoModule, - MultidirectoryUiKitModule, - FormsModule, - CommonModule, - FontAwesomeModule, - ], + imports: [DialogComponent, TranslocoModule, MultidirectoryUiKitModule, FormsModule, CommonModule, FontAwesomeModule], templateUrl: './add-forward-zone-dialog.component.html', styleUrl: './add-forward-zone-dialog.component.scss', }) @@ -40,7 +30,7 @@ export class AddForwardZoneDialogComponent { tooltip = translate('add-forward-zone-dialog.tooltip'); onDeleteForwarderClick(toDelete: string) { - this.zone.forwarders = this.zone.forwarders.filter((forwarder) => forwarder !== toDelete); + this.zone.servers = this.zone.servers.filter((forwarder) => forwarder !== toDelete); this.selectedForwaderIndex = undefined; } @@ -48,10 +38,9 @@ export class AddForwardZoneDialogComponent { if (this.selectedForwaderIndex == undefined) { return; } - const temp = this.zone.forwarders?.[this.selectedForwaderIndex + 1]; - this.zone.forwarders[this.selectedForwaderIndex + 1] = - this.zone.forwarders[this.selectedForwaderIndex]; - this.zone.forwarders[this.selectedForwaderIndex] = temp; + const temp = this.zone.servers?.[this.selectedForwaderIndex + 1]; + this.zone.servers[this.selectedForwaderIndex + 1] = this.zone.servers[this.selectedForwaderIndex]; + this.zone.servers[this.selectedForwaderIndex] = temp; this.selectedForwaderIndex++; } moveUp() { @@ -59,23 +48,20 @@ export class AddForwardZoneDialogComponent { return; } - const temp = this.zone.forwarders?.[this.selectedForwaderIndex - 1]; - this.zone.forwarders[this.selectedForwaderIndex - 1] = - this.zone.forwarders[this.selectedForwaderIndex]; - this.zone.forwarders[this.selectedForwaderIndex] = temp; + const temp = this.zone.servers?.[this.selectedForwaderIndex - 1]; + this.zone.servers[this.selectedForwaderIndex - 1] = this.zone.servers[this.selectedForwaderIndex]; + this.zone.servers[this.selectedForwaderIndex] = temp; this.selectedForwaderIndex--; } addForwarder() { - this.zone.forwarders.push(''); + this.zone.servers.push(''); } submitForwarder(form: NgForm, index: number) { - this.dns - .checkForwardZone(new DnsCheckForwardZoneRequest({ dns_server_ips: [form.value.ip] })) - .subscribe((response) => { - this.forwarderResponse?.set(index, response[0]); - }); + this.dns.checkForwardZone(new DnsCheckForwardZoneRequest({ dns_server_ips: [form.value.ip] })).subscribe((response) => { + this.forwarderResponse?.set(index, response[0]); + }); } apply() { diff --git a/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/dns-forward-zones.component.ts b/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/dns-forward-zones.component.ts index 24359b0f..a8040df3 100644 --- a/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/dns-forward-zones.component.ts +++ b/projects/multidirectory-app/src/app/features/dns/dns-forward-zones/dns-forward-zones.component.ts @@ -6,14 +6,11 @@ import { ToastrService } from 'ngx-toastr'; import { DialogService } from '../../../components/modals/services/dialog.service'; import { CommonModule } from '@angular/common'; import { DnsApiService } from '@services/dns-api.service'; -import { DnsForwardZone } from '@models/api/dns/dns-forward-zone'; -import { - AddForwardZoneDialogData, - AddForwardZoneDialogReturnData, -} from './add-forward-zone-dialog/add-forward-zone-dialog.interface'; +import { DnsForwardGetData, DnsForwardZone } from '@models/api/dns/dns-forward-zone'; +import { AddForwardZoneDialogData, AddForwardZoneDialogReturnData } from './add-forward-zone-dialog/add-forward-zone-dialog.interface'; import { AddForwardZoneDialogComponent } from './add-forward-zone-dialog/add-forward-zone-dialog.component'; import { DnsAddZoneRequest } from '@models/dhcp/areas/dhcp-add-areas-response'; -import { EMPTY, switchMap, take } from 'rxjs'; +import { EMPTY, filter, switchMap, take } from 'rxjs'; import { TableColumn } from 'ngx-datatable-gimefork'; @Component({ @@ -43,22 +40,18 @@ export class DnsForwardZonesComponent implements OnInit { } private loadData() { - this.dnsApi.getForwardZones().subscribe((forwardZones) => { + this.dnsApi.getForwardZones().subscribe((forwardZones: DnsForwardZone[]) => { this.selectedRedirectionZones.set([]); this.redirectionZonesRows.set(forwardZones); this.total = forwardZones.length; }); } - selectedRedirectionZones = signal([]); + selectedRedirectionZones = signal([]); onAddRedirectionZone() { this.dialogService - .open< - AddForwardZoneDialogReturnData, - AddForwardZoneDialogData, - AddForwardZoneDialogComponent - >({ + .open({ component: AddForwardZoneDialogComponent, dialogConfig: { minWidth: '620px', @@ -67,11 +60,12 @@ export class DnsForwardZonesComponent implements OnInit { }) .closed.pipe( take(1), - switchMap((result) => { + filter((x) => !!x), + switchMap((result: DnsForwardZone) => { if (!result) { return EMPTY; } - return this.dnsApi.addZone(result.toDnsAddZoneRequest()); + return this.dnsApi.addForwardZone(result); }), ) .subscribe((result) => { @@ -79,26 +73,24 @@ export class DnsForwardZonesComponent implements OnInit { }); } - onEditRedirectionZone($event: InputEvent) { + onEditRedirectionZone($event: any) { + const dialogData = new DnsForwardZone({ servers: ($event.row as DnsForwardGetData).servers, zone_name: ($event as any).row.name }); this.dialogService - .open< - AddForwardZoneDialogReturnData, - AddForwardZoneDialogData, - AddForwardZoneDialogComponent - >({ + .open({ component: AddForwardZoneDialogComponent, dialogConfig: { minWidth: '620px', - data: new DnsForwardZone(($event as any).row as DnsForwardZone), + data: dialogData, }, }) .closed.pipe( take(1), - switchMap((result) => { + filter((x) => !!x), + switchMap((result: DnsForwardZone) => { if (!result) { return EMPTY; } - return this.dnsApi.updateZone(result.toDnsAddZoneRequest()); + return this.dnsApi.changeForwardZones(result); }), ) .subscribe((result) => { @@ -122,13 +114,13 @@ export class DnsForwardZonesComponent implements OnInit { return; } - this.dnsApi.deleteZone(selectedRows.map((x) => x.name)).subscribe((x) => { + this.dnsApi.deleteForwardZones(selectedRows.map((x) => x.id)).subscribe(() => { this.toastr.success(translate('dns-forward-zones.delete-successful')); this.loadData(); }); } - onRedirectionZonesSelectionChanged(rows: DnsForwardZone[]) { + onRedirectionZonesSelectionChanged(rows: DnsForwardGetData[]) { this.selectedRedirectionZones.set(rows); } } diff --git a/projects/multidirectory-app/src/app/features/dns/dns-rule-dialog/dns-rule-dialog.component.html b/projects/multidirectory-app/src/app/features/dns/dns-rule-dialog/dns-rule-dialog.component.html index a2e52a67..12d35860 100644 --- a/projects/multidirectory-app/src/app/features/dns/dns-rule-dialog/dns-rule-dialog.component.html +++ b/projects/multidirectory-app/src/app/features/dns/dns-rule-dialog/dns-rule-dialog.component.html @@ -6,11 +6,7 @@
- +
{{ 'dns-rule-dialog.same-as-zone-name' | transloco }} @@ -19,26 +15,21 @@
@switch (recordDataType) { @case (DnsRuleClass.IP6.valueOf()) { - + } @case (DnsRuleClass.IP4.valueOf()) { - + } @case (DnsRuleClass.SRV.valueOf()) { - + } @default { - + } }
- +
diff --git a/projects/multidirectory-app/src/app/features/dns/dns-rule-dialog/dns-rule-dialog.component.ts b/projects/multidirectory-app/src/app/features/dns/dns-rule-dialog/dns-rule-dialog.component.ts index 2b3947d1..2ec17325 100644 --- a/projects/multidirectory-app/src/app/features/dns/dns-rule-dialog/dns-rule-dialog.component.ts +++ b/projects/multidirectory-app/src/app/features/dns/dns-rule-dialog/dns-rule-dialog.component.ts @@ -1,31 +1,15 @@ -import { - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, - DestroyRef, - inject, - OnInit, - ViewChild, -} from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, inject, OnInit, ViewChild } from '@angular/core'; import { Ip6AddressValidatorDirective } from '@core/validators/ip6-address.directive'; import { IpAddressValidatorDirective } from '@core/validators/ip-address.directive'; import { MdFormComponent, MultidirectoryUiKitModule } from 'multidirectory-ui-kit'; import { RequiredWithMessageDirective } from '@core/validators/required-with-message.directive'; import { TranslocoPipe } from '@jsverse/transloco'; import { FormsModule } from '@angular/forms'; -import { - AvailableDnsRecordTypes, - DnsRuleClass, - DnsRuleType, - DnsTypeToDataType, -} from '@models/api/dns/dns-rule-type'; +import { AvailableDnsRecordTypes, DnsRuleClass, DnsRuleType, DnsTypeToDataType } from '@models/api/dns/dns-rule-type'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { DIALOG_DATA, DialogRef } from '@angular/cdk/dialog'; import { DialogService } from '../../../components/modals/services/dialog.service'; -import { - DnsRuleDialogData, - DnsRuleDialogReturnData, -} from '../../../components/modals/interfaces/dns-rule-dialog.interface'; +import { DnsRuleDialogData, DnsRuleDialogReturnData } from '../../../components/modals/interfaces/dns-rule-dialog.interface'; import { DialogComponent } from '../../../components/modals/components/core/dialog/dialog.component'; import { DnsRule } from '@models/api/dns/dns-rule'; @@ -69,17 +53,17 @@ export class DnsRuleDialogComponent implements OnInit { set sameAsZoneName(val: boolean) { this._sameAsZoneName = val; if (val) { - this.dnsRule.name = '@'; + this.dnsRule.record_name = '@'; } this.cdr.detectChanges(); } get recordType() { - return this.dnsRule.type; + return this.dnsRule.record_type; } set recordType(type: DnsRuleType) { - this.dnsRule.type = type; + this.dnsRule.record_type = type; this.recordDataType = DnsTypeToDataType.get(type)?.valueOf() ?? -1; this.cdr.detectChanges(); } @@ -90,7 +74,7 @@ export class DnsRuleDialogComponent implements OnInit { this.formValid = x; }); this.dnsRule = this.dialogData.rule ?? {}; - this.recordType = this.dnsRule.type; + this.recordType = this.dnsRule.record_type; } onFinish(event: MouseEvent) { diff --git a/projects/multidirectory-app/src/app/features/dns/dns-rule-list-item/dns-rule-list-item.component.html b/projects/multidirectory-app/src/app/features/dns/dns-rule-list-item/dns-rule-list-item.component.html index 5104a074..7113df17 100644 --- a/projects/multidirectory-app/src/app/features/dns/dns-rule-list-item/dns-rule-list-item.component.html +++ b/projects/multidirectory-app/src/app/features/dns/dns-rule-list-item/dns-rule-list-item.component.html @@ -1,9 +1,9 @@ @if (dnsRule) {
{{ index() }}
-
{{ dnsRule.name }}
-
{{ dnsRule.value }}
-
{{ getType(dnsRule.type) }}
+
{{ dnsRule.record_name }}
+
{{ dnsRule.record_value }}
+
{{ getType(dnsRule.record_type) }}
diff --git a/projects/multidirectory-app/src/app/features/dns/dns-settings.component.ts b/projects/multidirectory-app/src/app/features/dns/dns-settings.component.ts index 1527580f..8b0f6200 100644 --- a/projects/multidirectory-app/src/app/features/dns/dns-settings.component.ts +++ b/projects/multidirectory-app/src/app/features/dns/dns-settings.component.ts @@ -10,10 +10,7 @@ import { DnsApiService } from '@services/dns-api.service'; import { ToastrService } from 'ngx-toastr'; import { catchError, EMPTY, switchMap, take } from 'rxjs'; import { ConfirmDialogComponent } from '../../components/modals/components/dialogs/confirm-dialog/confirm-dialog.component'; -import { - ConfirmDialogData, - ConfirmDialogReturnData, -} from '../../components/modals/interfaces/confirm-dialog.interface'; +import { ConfirmDialogData, ConfirmDialogReturnData } from '../../components/modals/interfaces/confirm-dialog.interface'; import { DialogService } from '../../components/modals/services/dialog.service'; import DnsZonesComponent from './dns-zones/dns-zones.component'; import { ConfirmDialogDescriptor } from '@models/api/confirm-dialog/confirm-dialog-descriptor'; @@ -100,36 +97,36 @@ export class DnsSettingsComponent implements OnInit { }); } - onDelete(toDeleteIndex: number) { - const prompt: ConfirmDialogDescriptor = { - promptHeader: translate('remove-confirmation-dialog.prompt-header'), - promptText: translate('remove-confirmation-dialog.prompt-text'), - primaryButtons: [{ id: 'yes', text: translate('remove-confirmation-dialog.yes') }], - secondaryButtons: [{ id: 'cancel', text: translate('remove-confirmation-dialog.cancel') }], - }; - - this.dialogService - .open({ - component: ConfirmDialogComponent, - dialogConfig: { - minHeight: '160px', - data: prompt, - }, - }) - .closed.pipe( - take(1), - switchMap((x) => { - if (x === 'cancel' || !x) { - return EMPTY; - } - const rule = this.enusreHostname(this.rules[toDeleteIndex]); - return this.dns.delete(rule); - }), - ) - .subscribe(() => { - this.rules = this.rules.filter((_, ind) => ind !== toDeleteIndex); - }); - } + // onDelete(toDeleteIndex: number) { + // const prompt: ConfirmDialogDescriptor = { + // promptHeader: translate('remove-confirmation-dialog.prompt-header'), + // promptText: translate('remove-confirmation-dialog.prompt-text'), + // primaryButtons: [{ id: 'yes', text: translate('remove-confirmation-dialog.yes') }], + // secondaryButtons: [{ id: 'cancel', text: translate('remove-confirmation-dialog.cancel') }], + // }; + // + // this.dialogService + // .open({ + // component: ConfirmDialogComponent, + // dialogConfig: { + // minHeight: '160px', + // data: prompt, + // }, + // }) + // .closed.pipe( + // take(1), + // switchMap((x) => { + // if (x === 'cancel' || !x) { + // return EMPTY; + // } + // const rule = this.enusreHostname(this.rules[toDeleteIndex]); + // return this.dns.deleteZoneRule(rule); + // }), + // ) + // .subscribe(() => { + // this.rules = this.rules.filter((_, ind) => ind !== toDeleteIndex); + // }); + // } handleSetupClick() { this.windows @@ -150,7 +147,7 @@ export class DnsSettingsComponent implements OnInit { private enusreHostname(rule: DnsRule): DnsRule { const result = new DnsRule(rule); - result.name = result.name.replace('.' + this.dnsStatus.zone_name, ''); + result.record_name = result.record_name?.replace('.' + this.dnsStatus.zone_name, ''); return result; } } diff --git a/projects/multidirectory-app/src/app/features/dns/dns-zone-details/dns-zone-details.component.html b/projects/multidirectory-app/src/app/features/dns/dns-zone-details/dns-zone-details.component.html index 12bac585..e97f7e4d 100644 --- a/projects/multidirectory-app/src/app/features/dns/dns-zone-details/dns-zone-details.component.html +++ b/projects/multidirectory-app/src/app/features/dns/dns-zone-details/dns-zone-details.component.html @@ -1,25 +1,19 @@ -
- {{ 'dns-zone-details.modal-header' | transloco }} {{ zone().name }} -
+
{{ 'dns-zone-details.modal-header' | transloco }} {{ zone().name }}
- {{ 'dns-zone-details.add' | transloco }} + {{ 'dns-zone-details.add' | transloco }}
- +
- @for (type of zone().records; track $index; let indexA = $index) { + @for (type of zone().rrsets; track $index; let indexA = $index) { @for (record of type.records; track $index; let indexB = $index) { diff --git a/projects/multidirectory-app/src/app/features/dns/dns-zone-details/dns-zone-details.component.ts b/projects/multidirectory-app/src/app/features/dns/dns-zone-details/dns-zone-details.component.ts index 14a907f0..5a3b77cb 100644 --- a/projects/multidirectory-app/src/app/features/dns/dns-zone-details/dns-zone-details.component.ts +++ b/projects/multidirectory-app/src/app/features/dns/dns-zone-details/dns-zone-details.component.ts @@ -1,28 +1,8 @@ -import { - AfterViewInit, - ChangeDetectionStrategy, - Component, - computed, - inject, - OnInit, - output, - signal, -} from '@angular/core'; +import { AfterViewInit, ChangeDetectionStrategy, Component, computed, inject, OnInit, output, signal } from '@angular/core'; import { toObservable, toSignal } from '@angular/core/rxjs-interop'; import { DnsZoneListResponse } from '@models/dns/zones/dns-zone-response'; import { DnsApiService } from '@services/dns-api.service'; -import { - BehaviorSubject, - combineLatest, - EMPTY, - filter, - lastValueFrom, - map, - pipe, - switchMap, - take, - tap, -} from 'rxjs'; +import { BehaviorSubject, combineLatest, EMPTY, filter, lastValueFrom, map, pipe, switchMap, take, tap } from 'rxjs'; import { DnsRuleListItemComponent } from '../dns-rule-list-item/dns-rule-list-item.component'; import { translate, TranslocoModule } from '@jsverse/transloco'; import { ToastrService } from 'ngx-toastr'; @@ -31,10 +11,7 @@ import { DIALOG_DATA } from '@angular/cdk/dialog'; import { DnsZoneDetailsDialogData } from './dns-zone-details-dialog-data'; import { MuiButtonComponent, MuiInputComponent } from '@mflab/mui-kit'; import { DialogService } from '../../../components/modals/services/dialog.service'; -import { - DnsRuleDialogReturnData, - DnsRuleDialogData, -} from '../../../components/modals/interfaces/dns-rule-dialog.interface'; +import { DnsRuleDialogReturnData, DnsRuleDialogData } from '../../../components/modals/interfaces/dns-rule-dialog.interface'; import { DnsRuleDialogComponent } from '../dns-rule-dialog/dns-rule-dialog.component'; import { FormsModule } from '@angular/forms'; import { DnsRule } from '@models/api/dns/dns-rule'; @@ -44,13 +21,7 @@ import { MultidirectoryUiKitModule } from 'multidirectory-ui-kit'; selector: 'app-dns-zone-details', templateUrl: './dns-zone-details.component.html', styleUrls: ['./dns-zone-details.component.scss'], - imports: [ - DnsRuleListItemComponent, - DialogComponent, - MultidirectoryUiKitModule, - FormsModule, - TranslocoModule, - ], + imports: [DnsRuleListItemComponent, DialogComponent, MultidirectoryUiKitModule, FormsModule, TranslocoModule], }) export class DnsZoneDetailsComponent implements AfterViewInit { private readonly dialogData: DnsZoneDetailsDialogData = inject(DIALOG_DATA); @@ -65,17 +36,12 @@ export class DnsZoneDetailsComponent implements AfterViewInit { readonly reloadRx = new BehaviorSubject(false); readonly zone = toSignal( - combineLatest([ - toObservable(this.zoneName), - toObservable(this.search), - this.reloadRx.asObservable(), - ]).pipe( + combineLatest([toObservable(this.zoneName), toObservable(this.search), this.reloadRx.asObservable()]).pipe( switchMap(() => this.dns.zone()), map((zones) => zones.filter((x) => x.name == this.zoneName())?.[0] ?? {}), - tap((zones) => - zones.records.filter((x) => { - x.records = x.records.filter((y) => y?.name?.includes(this.search())); - return x; + tap((zone) => + zone.rrsets.filter((x) => { + return x.name.includes(this.search()); }), ), ), @@ -105,7 +71,7 @@ export class DnsZoneDetailsComponent implements AfterViewInit { }) .closed.pipe( take(1), - switchMap((x) => (x ? this.dns.update(x) : EMPTY)), + switchMap((x) => (x ? this.dns.updateZoneRule(x, this.zone().id) : EMPTY)), ) .subscribe(() => { this.reloadRx.next(true); @@ -113,29 +79,26 @@ export class DnsZoneDetailsComponent implements AfterViewInit { }); } - onDeleteRuleClick(record: DnsRule) { - this.dns.delete(record).subscribe((response) => { + onDeleteRuleClick($event: DnsRule) { + this.dns.deleteZoneRule($event, this.zone().id).subscribe((response) => { this.zoneName.set(this.dialogData.zoneName); + + this.reloadRx.next(true); }); } - onAdd() { + onAddRule() { this.dialog .open({ component: DnsRuleDialogComponent, dialogConfig: { minHeight: '512px', - data: { rule: new DnsRule({ zone_name: this.zoneName() }) }, + data: { rule: new DnsRule({ record_name: this.zoneName() }) }, }, }) .closed.pipe( take(1), - tap((x) => { - if (!!x && !x.name.endsWith(x.zone_name)) { - x.name += '.' + x.zone_name; - } - }), - switchMap((x) => (x ? this.dns.post(x) : EMPTY)), + switchMap((x) => (x ? this.dns.addZoneRule(x, this.zone().id) : EMPTY)), ) .subscribe(() => { this.reloadRx.next(true); diff --git a/projects/multidirectory-app/src/app/features/dns/dns-zones/dns-zones.component.ts b/projects/multidirectory-app/src/app/features/dns/dns-zones/dns-zones.component.ts index daae1eb2..2f9a96d0 100644 --- a/projects/multidirectory-app/src/app/features/dns/dns-zones/dns-zones.component.ts +++ b/projects/multidirectory-app/src/app/features/dns/dns-zones/dns-zones.component.ts @@ -7,24 +7,15 @@ import { translate, TranslocoModule } from '@jsverse/transloco'; import { DialogService } from '../../../components/modals/services/dialog.service'; import { AddZoneDialogComponent } from '../add-zone-dialog/add-zone-dialog.component'; import { DnsRuleDialogComponent } from '../dns-rule-dialog/dns-rule-dialog.component'; -import { - DnsRuleDialogData, - DnsRuleDialogReturnData, -} from '../../../components/modals/interfaces/dns-rule-dialog.interface'; +import { DnsRuleDialogData, DnsRuleDialogReturnData } from '../../../components/modals/interfaces/dns-rule-dialog.interface'; import { EMPTY, switchMap, take } from 'rxjs'; import { ToastrService } from 'ngx-toastr'; import { ConfirmDialogComponent } from '../../../components/modals/components/dialogs/confirm-dialog/confirm-dialog.component'; -import { - ConfirmDialogReturnData, - ConfirmDialogData, -} from '../../../components/modals/interfaces/confirm-dialog.interface'; +import { ConfirmDialogReturnData, ConfirmDialogData } from '../../../components/modals/interfaces/confirm-dialog.interface'; import { ConfirmDialogDescriptor } from '@models/api/confirm-dialog/confirm-dialog-descriptor'; import { DnsRule } from '@models/api/dns/dns-rule'; import { MultidirectoryUiKitModule } from 'multidirectory-ui-kit'; -import { - AddZoneDialogData, - AddZoneDialogReturnData, -} from '../add-zone-dialog/add-zone-dialog.interface'; +import { AddZoneDialogData, AddZoneDialogReturnData } from '../add-zone-dialog/add-zone-dialog.interface'; @Component({ selector: 'app-dns-zones', @@ -62,27 +53,6 @@ export default class DnsZonesComponent implements OnInit { }); } - onEditRuleClick(rule: DnsRule) { - this.dialogService - .open({ - component: DnsRuleDialogComponent, - dialogConfig: { - minHeight: '360px', - data: { rule, isEdit: true }, - }, - }) - .closed.pipe( - take(1), - switchMap((x) => { - if (!x) return EMPTY; - return this.dns.update(rule); - }), - ) - .subscribe(() => { - this.toastr.success(translate('dns-settings.success')); - }); - } - onDeleteZoneClick(zone: DnsZoneListResponse) { const prompt: ConfirmDialogDescriptor = { promptHeader: translate('remove-confirmation-dialog.prompt-header'), @@ -102,7 +72,7 @@ export default class DnsZonesComponent implements OnInit { .closed.pipe(take(1)) .subscribe((result) => { if (result === 'yes') { - this.dns.deleteZone([zone.name]).subscribe((result) => { + this.dns.deleteZone([zone.id]).subscribe((result) => { this.zones = this.zones.filter((x) => x !== zone); }); return; diff --git a/projects/multidirectory-app/src/app/features/forms/dns-setup/dns-setup/dns-setup.component.html b/projects/multidirectory-app/src/app/features/forms/dns-setup/dns-setup/dns-setup.component.html index e9f6fba7..d91d6b74 100644 --- a/projects/multidirectory-app/src/app/features/forms/dns-setup/dns-setup/dns-setup.component.html +++ b/projects/multidirectory-app/src/app/features/forms/dns-setup/dns-setup/dns-setup.component.html @@ -6,11 +6,11 @@
- - + + - - + + {{ 'dns-setup.external_service' | transloco @@ -18,25 +18,13 @@ @if (useExternalService) { - + - + } - +
diff --git a/projects/multidirectory-app/src/app/features/forms/dns-setup/dns-setup/dns-setup.component.ts b/projects/multidirectory-app/src/app/features/forms/dns-setup/dns-setup/dns-setup.component.ts index 9740a49a..9cfd97eb 100644 --- a/projects/multidirectory-app/src/app/features/forms/dns-setup/dns-setup/dns-setup.component.ts +++ b/projects/multidirectory-app/src/app/features/forms/dns-setup/dns-setup/dns-setup.component.ts @@ -1,25 +1,9 @@ -import { - AfterViewInit, - ChangeDetectorRef, - Component, - inject, - Input, - OnDestroy, - output, - viewChild, -} from '@angular/core'; +import { AfterViewInit, ChangeDetectorRef, Component, inject, Input, OnDestroy, output, viewChild } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { RequiredWithMessageDirective } from '@core/validators/required-with-message.directive'; import { TranslocoPipe } from '@jsverse/transloco'; import { DnsSetupRequest } from '@models/api/dns/dns-setup-request'; -import { DnsStatuses } from '@models/api/dns/dns-statuses'; -import { - CheckboxComponent, - MdFormComponent, - NumberComponent, - TextareaComponent, - TextboxComponent, -} from 'multidirectory-ui-kit'; +import { CheckboxComponent, MdFormComponent, NumberComponent, TextareaComponent, TextboxComponent } from 'multidirectory-ui-kit'; import { Subject, takeUntil } from 'rxjs'; @Component({ @@ -54,14 +38,10 @@ export class DnsSetupComponent implements AfterViewInit, OnDestroy { set useExternalService(value: boolean) { this._useExternalService = value; - this.dnsSetupRequest.dns_status = value ? DnsStatuses.HOSTED : DnsStatuses.SELFHOSTED; this.cdr.detectChanges(); } ngAfterViewInit(): void { - this.dnsSetupRequest.dns_status = this._useExternalService - ? DnsStatuses.HOSTED - : DnsStatuses.SELFHOSTED; this.form() .onValidChanges.pipe(takeUntil(this.unsubscribe)) .subscribe((valid) => { diff --git a/projects/multidirectory-app/src/app/features/policies/access-policy/access-policy-view/access-policy-view.component.ts b/projects/multidirectory-app/src/app/features/policies/access-policy/access-policy-view/access-policy-view.component.ts index f61e756d..90570843 100644 --- a/projects/multidirectory-app/src/app/features/policies/access-policy/access-policy-view/access-policy-view.component.ts +++ b/projects/multidirectory-app/src/app/features/policies/access-policy/access-policy-view/access-policy-view.component.ts @@ -7,7 +7,6 @@ import { IpRange } from '@core/access-policy/access-policy-ip-address'; import { MfaAccessEnum } from '@core/access-policy/mfa-access-enum'; import { Constants } from '@core/constants'; import { SearchQueries } from '@core/ldap/search'; -import { IpAddressValidatorDirective } from '@core/validators/ip-address.directive'; import { RequiredWithMessageDirective } from '@core/validators/required-with-message.directive'; import { IpListDialogComponent } from 'projects/multidirectory-app/src/app/components/modals/components/dialogs/access-policy-ip-list/ip-list-dialog.component'; import { translate, TranslocoPipe } from '@jsverse/transloco'; @@ -24,7 +23,7 @@ import { TextboxComponent, } from 'multidirectory-ui-kit'; import { ToastrService } from 'ngx-toastr'; -import { from, map, Observable, of, Subject, switchMap, take, takeUntil } from 'rxjs'; +import { from, map, Observable, of, Subject, switchMap, take } from 'rxjs'; import { DialogService } from '../../../../components/modals/services/dialog.service'; import { IplistDialogData } from '../../../../components/modals/interfaces/ip-list-dialog.interface'; import { MultiselectModel } from 'projects/multidirectory-ui-kit/src/lib/components/multiselect/mutliselect-model'; @@ -47,7 +46,6 @@ import { UniversalIpValidatorDirective } from '@core/validators/ip-universal.dir GroupComponent, ShiftCheckboxComponent, RequiredWithMessageDirective, - IpAddressValidatorDirective, TranslocoPipe, MaxLengthValidatorDirective, UniversalIpValidatorDirective, diff --git a/projects/multidirectory-app/src/app/features/setup/setup/setup.component.ts b/projects/multidirectory-app/src/app/features/setup/setup/setup.component.ts index d2ecdf3a..99116456 100644 --- a/projects/multidirectory-app/src/app/features/setup/setup/setup.component.ts +++ b/projects/multidirectory-app/src/app/features/setup/setup/setup.component.ts @@ -1,12 +1,4 @@ -import { - AfterViewInit, - ChangeDetectorRef, - Component, - inject, - OnDestroy, - OnInit, - viewChild, -} from '@angular/core'; +import { AfterViewInit, ChangeDetectorRef, Component, inject, OnDestroy, OnInit, viewChild } from '@angular/core'; import { Router } from '@angular/router'; import { PasswordGenerator } from '@core/setup/password-generator'; import { AdminSettingsSecondComponent } from '@features/setup/admin-settings-second/admin-settings-second.component'; @@ -74,13 +66,13 @@ export class SetupComponent implements OnInit, AfterViewInit, OnDestroy { ngOnInit(): void { this.setupRequest.domain = window.location.hostname; - this.setupRequest.setupDnsRequest.domain = window.location.hostname; - this.setupRequest.setupDnsRequest.zone_name = window.location.hostname; - this.setupRequestValidatorService.onStepValid - .pipe(takeUntil(this.unsubscribe)) - .subscribe((valid) => { - this.stepValid = valid; - }); + // this.setupRequest.setupDnsRequest = window.location.hostname; + this.setupRequestValidatorService.onStepValid.pipe(takeUntil(this.unsubscribe)).subscribe((valid) => { + this.stepValid = valid; + }); + this.setupRequestValidatorService.onStepValid.pipe(takeUntil(this.unsubscribe)).subscribe((valid) => { + this.stepValid = valid; + }); } ngOnDestroy(): void { @@ -94,10 +86,8 @@ export class SetupComponent implements OnInit, AfterViewInit, OnDestroy { onNext() { if (this.stepper().currentIndex == 1 && this.setupRequest.generateKdcPasswords) { - this.setupRequest.krbadmin_password = this.setupRequest.krbadmin_password_repeat = - PasswordGenerator.generatePassword(); - this.setupRequest.stash_password = this.setupRequest.stash_password_repeat = - PasswordGenerator.generatePassword(); + this.setupRequest.krbadmin_password = this.setupRequest.krbadmin_password_repeat = PasswordGenerator.generatePassword(); + this.setupRequest.stash_password = this.setupRequest.stash_password_repeat = PasswordGenerator.generatePassword(); } this.modal().resizeToContentHeight(); } diff --git a/projects/multidirectory-app/src/app/models/api/dns/dns-forward-zone.ts b/projects/multidirectory-app/src/app/models/api/dns/dns-forward-zone.ts index b7f59731..cc62bde9 100644 --- a/projects/multidirectory-app/src/app/models/api/dns/dns-forward-zone.ts +++ b/projects/multidirectory-app/src/app/models/api/dns/dns-forward-zone.ts @@ -1,22 +1,23 @@ import { DnsAddZoneRequest, DnsZoneParam } from '@models/dhcp/areas/dhcp-add-areas-response'; export class DnsForwardZone { - name: string = ''; - type: string = 'forward'; - forwarders: string[] = ['127.0.0.1', '127.0.0.2']; + zone_name: string = ''; + servers: string[] = ['127.0.0.1', '127.0.0.2']; constructor(obj: Partial) { Object.assign(this, obj); } - toDnsAddZoneRequest(): DnsAddZoneRequest { - return new DnsAddZoneRequest({ - zone_name: this.name, - zone_type: this.type, - params: [ - new DnsZoneParam({ - name: 'forwarders', - value: this.forwarders, - }), - ], - }); +} + +export class DnsForwardGetData { + id: string = ''; + name: string = ''; + rrsets: string[] = []; + type: string = 'zone'; + servers: string[] = []; + recursion_desired: boolean = false; + kind: string = ''; + + constructor(obj: Partial) { + Object.assign(this, obj); } } diff --git a/projects/multidirectory-app/src/app/models/api/dns/dns-rule.ts b/projects/multidirectory-app/src/app/models/api/dns/dns-rule.ts index 1ea632eb..852a9869 100644 --- a/projects/multidirectory-app/src/app/models/api/dns/dns-rule.ts +++ b/projects/multidirectory-app/src/app/models/api/dns/dns-rule.ts @@ -2,21 +2,11 @@ import { Constants } from '@core/constants'; import { DnsRuleType } from './dns-rule-type'; export class DnsRule { - name = ''; - type: DnsRuleType = DnsRuleType.A; - value = ''; - ttl = Constants.DnsTTL; - zone_name = ''; - - static toRequest(obj: DnsRule): any { - return { - record_name: obj.name, - record_type: obj.type, - record_value: obj.value, - zone_name: obj.zone_name, - ttl: obj.ttl, - }; - } + record_name: string = ''; + record_type: DnsRuleType = DnsRuleType['A']; + record_value: string = '0 100 3268 md.localhost.'; + ttl?: number = Constants.DnsTTL; + content?: string = '0 100 3268 md.localhost.'; constructor(obj: Partial) { Object.assign(this, obj); diff --git a/projects/multidirectory-app/src/app/models/api/dns/dns-setup-request.ts b/projects/multidirectory-app/src/app/models/api/dns/dns-setup-request.ts index 82776f60..b03bc8af 100644 --- a/projects/multidirectory-app/src/app/models/api/dns/dns-setup-request.ts +++ b/projects/multidirectory-app/src/app/models/api/dns/dns-setup-request.ts @@ -2,12 +2,9 @@ import { Constants } from '@core/constants'; import { DnsStatuses } from './dns-statuses'; export class DnsSetupRequest { - zone_name = ''; - domain = ''; dns_ip_address?: string = undefined; - default_ttl = Constants.DnsTTL; + default_ttl? = Constants.DnsTTL; tsig_key?: string = undefined; - dns_status: string = DnsStatuses.SELFHOSTED; constructor(obj: Partial) { Object.assign(this, obj); diff --git a/projects/multidirectory-app/src/app/models/dhcp/areas/dhcp-add-areas-response.ts b/projects/multidirectory-app/src/app/models/dhcp/areas/dhcp-add-areas-response.ts index 95eb293e..fcf92d26 100644 --- a/projects/multidirectory-app/src/app/models/dhcp/areas/dhcp-add-areas-response.ts +++ b/projects/multidirectory-app/src/app/models/dhcp/areas/dhcp-add-areas-response.ts @@ -11,9 +11,8 @@ export class DnsZoneParam { export class DnsAddZoneRequest { zone_name: string = ''; - zone_type: string = ''; - ttl = Constants.DnsTTL; - params: DnsZoneParam[] = []; + nameserver_ip: string = ''; + dnssec: boolean = false; constructor(obj: Partial) { Object.assign(this, obj); } diff --git a/projects/multidirectory-app/src/app/models/dns/zones/dns-zone-response.ts b/projects/multidirectory-app/src/app/models/dns/zones/dns-zone-response.ts index 43ff4b53..abbb25ec 100644 --- a/projects/multidirectory-app/src/app/models/dns/zones/dns-zone-response.ts +++ b/projects/multidirectory-app/src/app/models/dns/zones/dns-zone-response.ts @@ -1,8 +1,11 @@ import { DnsRule } from '@models/api/dns/dns-rule'; export class DnsZoneRecordWithType { - type = ''; + name: string = ''; + type: string = ''; records: DnsRule[] = []; + changetype = null; + ttl: number = 3600; constructor(obj: Partial) { Object.assign(this, obj); } @@ -11,7 +14,12 @@ export class DnsZoneRecordWithType { export class DnsZoneListResponse { name = ''; type = ''; - records: DnsZoneRecordWithType[] = []; + zone_name? = ''; + id: string = ''; + rrsets: DnsZoneRecordWithType[] = []; + dnssec: boolean = false; + nameservers: string[] = []; + kind: string = 'Master'; constructor(obj: Partial) { Object.assign(this, obj); diff --git a/projects/multidirectory-app/src/app/services/dns-api.service.ts b/projects/multidirectory-app/src/app/services/dns-api.service.ts index 5be1db8a..805cb77a 100644 --- a/projects/multidirectory-app/src/app/services/dns-api.service.ts +++ b/projects/multidirectory-app/src/app/services/dns-api.service.ts @@ -1,13 +1,8 @@ -import { Injectable, inject } from '@angular/core'; +import { inject, Injectable } from '@angular/core'; import { ApiAdapter } from '@core/api/api-adapter'; import { DnsAdapterSettings } from '@core/api/dns-adapter.settings'; import { MultidirectoryAdapterSettings } from '@core/api/multidirectory-adapter.settings'; -import { DnsForwardZonesComponent } from '@features/dns/dns-forward-zones/dns-forward-zones.component'; -import { - DnsCheckForwardZoneRequest, - DnsCheckForwardZoneResponse, - DnsServerOption, -} from '@models/api/dns/dns-check-forward-zone'; +import { DnsCheckForwardZoneRequest, DnsCheckForwardZoneResponse, DnsServerOption } from '@models/api/dns/dns-check-forward-zone'; import { DnsForwardZone } from '@models/api/dns/dns-forward-zone'; import { DnsRule } from '@models/api/dns/dns-rule'; import { DnsRuleType } from '@models/api/dns/dns-rule-type'; @@ -15,8 +10,8 @@ import { DnsServiceResponse } from '@models/api/dns/dns-service-response'; import { DnsSetupRequest } from '@models/api/dns/dns-setup-request'; import { DnsStatusResponse } from '@models/api/dns/dns-status-response'; import { DnsAddZoneRequest } from '@models/dhcp/areas/dhcp-add-areas-response'; -import { DnsZoneListResponse, DnsZoneRecordWithType } from '@models/dns/zones/dns-zone-response'; -import { map, Observable, of, tap } from 'rxjs'; +import { DnsZoneListResponse } from '@models/dns/zones/dns-zone-response'; +import { BehaviorSubject, concatMap, exhaustMap, map, merge, Observable, switchMap, tap } from 'rxjs'; @Injectable({ providedIn: 'root', @@ -29,33 +24,37 @@ export class DnsApiService { return this.httpClient.get('dns/record').execute(); } - post(rule: DnsRule): Observable { - return this.httpClient - .post('dns/record', DnsRule.toRequest(rule)) - .execute() - .pipe(map(() => rule)); + readonly dnsStatusRx: BehaviorSubject = new BehaviorSubject(false); + get $dnsStatus(): Observable { + return this.dnsStatusRx.asObservable(); } - update(rule: DnsRule): Observable { - return this.httpClient - .patch('dns/record', DnsRule.toRequest(rule)) - .execute() - .pipe(map(() => rule)); - } - - delete(rule: DnsRule): Observable { - return this.httpClient.delete('dns/record', DnsRule.toRequest(rule)).execute(); + set dnsStatus(data: boolean) { + this.dnsStatusRx.next(data); } status(): Observable { - return this.dnsHttpClient.get('dns/status').execute(); + return this.dnsHttpClient + .get('dns/status') + .execute() + .pipe(tap((status: DnsStatusResponse) => (this.dnsStatus = status.dns_status === '1'))); } setup(request: DnsSetupRequest): Observable { + request = !!request.dns_ip_address ? request : {}; + const newState = !!request.dns_ip_address ? '0' : '1'; return this.dnsHttpClient - .post('dns/setup', request) + .post('dns/state', { state: newState }) .execute() - .pipe(map((x) => !!x)); + .pipe( + concatMap((state) => { + if (!!request.dns_ip_address) { + return this.dnsHttpClient.post('dns/setup', request).execute(); + } + return this.dnsHttpClient.post('dns/setup').execute(); + }), + tap(() => this.status()), + ); } zone(): Observable { @@ -65,33 +64,54 @@ export class DnsApiService { .pipe( tap((x) => { for (let zone of x) { - for (let type of zone.records) { - for (let record of type.records) { - record.type = type.type as DnsRuleType; - record.zone_name = zone.name; - } + for (let type of zone.rrsets) { + type.records = type.records.map((record) => ({ + record_type: type.type as DnsRuleType, + record_name: zone.name, + record_value: String(record.content ?? ''), + ttl: type.ttl, + })); } } }), ); } - addZone(request: DnsAddZoneRequest): Observable { return this.dnsHttpClient.post('dns/zone', request).execute(); } updateZone(request: DnsAddZoneRequest): any { return this.dnsHttpClient.patch('dns/zone', request).execute(); } - deleteZone(zoneNames: string[]) { - return this.dnsHttpClient.delete('dns/zone', { zone_names: zoneNames }).execute(); + deleteZone(zone_ids: string[]) { + return this.dnsHttpClient.delete('dns/zone', { zone_ids: zone_ids }).execute(); + } + + getZone(zone_id: string): any { + return this.dnsHttpClient.patch(`dns/record/${zone_id}`).execute(); + } + addZoneRule(request: DnsRule, zone_id: string): Observable { + return this.dnsHttpClient.post(`dns/record/${zone_id}`, request).execute(); + } + updateZoneRule(request: DnsRule, zone_id: string): any { + return this.dnsHttpClient.patch(`dns/record/${zone_id}`, request).execute(); + } + deleteZoneRule(request: DnsRule, zone_id: string) { + return this.dnsHttpClient.delete(`dns/record/${zone_id}`, request).execute(); } getForwardZones(): Observable { return this.dnsHttpClient.get('dns/zone/forward').execute(); } + addForwardZone(request: DnsForwardZone): Observable { + return this.dnsHttpClient.post('dns/zone/forward', request).execute(); + } + changeForwardZones(request: DnsForwardZone): Observable { + return this.dnsHttpClient.patch('dns/zone/forward', request).execute(); + } + deleteForwardZones(zone_ids: string[]): Observable { + return this.dnsHttpClient.delete('dns/zone/forward', { zone_ids: zone_ids }).execute(); + } checkForwardZone(request: DnsCheckForwardZoneRequest): Observable { - return this.dnsHttpClient - .post('dns/forward_check', request) - .execute(); + return this.dnsHttpClient.post('dns/forward_check', request).execute(); } getServerOptions(): Observable { return this.dnsHttpClient.get('dns/server/options').execute(); diff --git a/projects/multidirectory-app/src/assets/i18n/en-US.json b/projects/multidirectory-app/src/assets/i18n/en-US.json index 9314079c..286a3786 100644 --- a/projects/multidirectory-app/src/assets/i18n/en-US.json +++ b/projects/multidirectory-app/src/assets/i18n/en-US.json @@ -281,6 +281,7 @@ "constructed-only": "Constructed", "backlinks-only": "Backlinks", "system-only": "System Only", + "dnssec": "DNSSEC", "filter": "Filter" }, "member-of": { @@ -734,7 +735,8 @@ "modal-header": "Add a new zone", "header": "DNS Zone wizard", "domain-input": "Domain", - "allowed-ip-input": "Allowed IP addresses", + "zone_name": "Zone name", + "allowed-ip-input": "Allowed IP address", "ttl-input": "TTL", "add": "Add", "cancel": "Cancel", diff --git a/projects/multidirectory-app/src/assets/i18n/ru-RU.json b/projects/multidirectory-app/src/assets/i18n/ru-RU.json index b99533d4..6faeb79f 100644 --- a/projects/multidirectory-app/src/assets/i18n/ru-RU.json +++ b/projects/multidirectory-app/src/assets/i18n/ru-RU.json @@ -282,6 +282,7 @@ "constructed-only": "Constructed", "backlinks-only": "Backlinks", "system-only": "Только системные", + "dnssec": "DNSSEC", "filter": "Фильтр" }, "member-of": { @@ -730,7 +731,8 @@ "modal-header": "Добавить новую зону", "header": "Мастер добавления зон DNS", "domain-input": "Домен", - "allowed-ip-input": "Разрешенные IP адреса", + "zone_name": "Название зоны", + "allowed-ip-input": "Разрешенный IP адрес", "ttl-input": "TTL", "add": "Добавить", "apply": "Применить",