Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,31 @@
<label>{{ 'add-zone-dialog.header' | transloco }}</label>
</div>
<div class="flex gap-x-1 justify-between">
<md-textbox
[(ngModel)]="dnsZone.zone_name"
[placeholder]="t('add-zone-dialog.domain-input')"
class="grow"
appRequired
/>
<md-textbox [(ngModel)]="dnsZone.zone_name" [placeholder]="t('add-zone-dialog.zone_name')" class="grow" appRequired />
</div>
<!-- <div class="flex gap-x-1 justify-between">-->
<!-- <md-textbox-->
<!-- [(ngModel)]="dnsZone.ttl"-->
<!-- type="number"-->
<!-- [placeholder]="t('add-zone-dialog.ttl-input')"-->
<!-- class="grow"-->
<!-- appRequired-->
<!-- />-->
<!-- </div>-->
<div class="flex gap-x-1 justify-between">
<md-textbox
[(ngModel)]="dnsZone.ttl"
type="number"
[placeholder]="t('add-zone-dialog.ttl-input')"
class="grow"
appRequired
/>
</div>
<div class="flex gap-x-1 justify-between">
<md-textbox
[(ngModel)]="ipString"
[placeholder]="t('add-zone-dialog.allowed-ip-input')"
class="grow"
/>
<md-button (click)="openIpAddressDialog()">{{
'add-zone-dialog.add' | transloco
}}</md-button>
<md-textbox [(ngModel)]="ipString" [placeholder]="t('add-zone-dialog.allowed-ip-input')" class="grow" />
<!-- <md-button (click)="openIpAddressDialog()">{{-->
<!-- 'add-zone-dialog.add' | transloco-->
<!-- }}</md-button>-->
</div>
</div>
<div class="flex gap-x-1 justify-between">
<md-checkbox [(ngModel)]="dnsZone.dnssec" class="grow">
{{ 'entity-attributes.with-values-only' | transloco }}
</md-checkbox>
</div>
<div class="flex justify-end pt-4">
<md-button [primary]="true" [disabled]="!form.valid" [submit]="true">{{
'add-zone-dialog.apply' | transloco
}}</md-button>
<md-button [primary]="true" [disabled]="!form.valid" [submit]="true">{{ 'add-zone-dialog.apply' | transloco }}</md-button>
</div>
</md-form>
</app-dialog>
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,15 @@ 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);
private dialogService: DialogService = inject(DialogService);
private dialogRef: DialogRef = inject(DialogRef);

dnsZone = new DnsAddZoneRequest({
zone_type: 'master',
dnssec: false,
});

onSumbit(event: SubmitEvent) {
Expand All @@ -44,71 +37,72 @@ 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<IplistDialogData, IplistDialogData, IpListDialogComponent>({
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<IplistDialogData, IplistDialogData, IpListDialogComponent>({
// 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() {
return this._ipString;
}
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(', ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
<div class="app-modal-header">{{ 'add-forward-zone-dialog.modal-header' | transloco }}</div>
<div class="flex flex-row gap-2 py-2">
<label>{{ 'add-forward-zone-dialog.zone-name' | transloco }}</label>
<md-textbox [(ngModel)]="zone.name" name="zoneName" required></md-textbox>
<md-textbox [(ngModel)]="zone.zone_name" name="zoneName" required></md-textbox>
</div>

<div class="grid grid-cols-2 grid-rows-4 h-full w-full">
<div
class="col-1 row-1 col-span-3 row-span-3 flex flex-col gap-2 overflow-y-auto max-h-64 px-2"
>
@for (forwarder of zone.forwarders; track $index) {
<div class="col-1 row-1 col-span-3 row-span-3 flex flex-col gap-2 overflow-y-auto max-h-64 px-2">
@for (forwarder of zone.servers; track $index) {
<form (submit)="submitForwarder(form, $index)" #form="ngForm">
<div
[ngClass]="{
Expand All @@ -20,16 +18,9 @@
(click)="selectedForwaderIndex = $index"
>
<div class="flex flex-row w-full gap-2 px-2" (click)="submitForwarder(form, $index)">
<md-textbox [(ngModel)]="zone.forwarders[$index]" name="ip"></md-textbox>
<div
class="decoration-dotted underline cursor-pointer"
[attr.data-tooltip]="tooltip"
>
{{
forwarderResponse.has($index)
? (forwarderResponse.get($index)?.FQDN ?? 'FQDN')
: 'FQDN'
}}
<md-textbox [(ngModel)]="zone.servers[$index]" name="ip"></md-textbox>
<div class="decoration-dotted underline cursor-pointer" [attr.data-tooltip]="tooltip">
{{ forwarderResponse.has($index) ? (forwarderResponse.get($index)?.FQDN ?? 'FQDN') : 'FQDN' }}
</div>
</div>
<div class="px-2">
Expand All @@ -43,10 +34,7 @@
}
</div>
<div>
<md-plane-button
class="control-button max-h-4"
(click)="onDeleteForwarderClick(forwarder)"
>
<md-plane-button class="control-button max-h-4" (click)="onDeleteForwarderClick(forwarder)">
<img class="control-button-logo" [src]="'assets/trash.svg'" />
</md-plane-button>
</div>
Expand All @@ -56,18 +44,14 @@
</div>

<div class="row-4 col-1 col-span-4 whitespace-nowrap flex flex-row gap-2 py-2">
<md-button (click)="addForwarder()">{{
'add-forward-zone-dialog.add' | transloco
}}</md-button>
<md-button (click)="addForwarder()">{{ 'add-forward-zone-dialog.add' | transloco }}</md-button>
</div>
</div>

<div class="app-modal-footer">
<div class="w-full flex justify-end gap-2 px-2">
<md-button (click)="cancel()">{{ 'add-forward-zone-dialog.cancel' | transloco }}</md-button>
<md-button [disabled]="!zoneForm.valid" (click)="apply()">{{
'add-forward-zone-dialog.apply' | transloco
}}</md-button>
<md-button [disabled]="!zoneForm.valid" (click)="apply()">{{ 'add-forward-zone-dialog.apply' | transloco }}</md-button>
</div>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
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';
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',
})
Expand All @@ -40,42 +30,38 @@ 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;
}

moveDown() {
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() {
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--;
}

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() {
Expand Down
Loading