32 lines
883 B
TypeScript
32 lines
883 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { exec } from 'child_process';
|
|
|
|
@Injectable()
|
|
export class RNDCService {
|
|
private host = this.config.get<string>('rndc.host');
|
|
private port = this.config.get<number>('rndc.port');
|
|
private keyFile = this.config.get<string>('rndc.keyFile');
|
|
|
|
constructor(private config: ConfigService) {}
|
|
|
|
private async rndc(command: string, data: string): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
exec(
|
|
`rndc -k ${this.keyFile} -s ${this.host} -p ${this.port} ${command} ${data}`,
|
|
(error, stdout) => {
|
|
if (error) {
|
|
reject(error);
|
|
return;
|
|
}
|
|
resolve(stdout);
|
|
},
|
|
);
|
|
});
|
|
}
|
|
|
|
public async reload(domain: string): Promise<string> {
|
|
return this.rndc('reload', domain);
|
|
}
|
|
}
|