Page MenuHomePhorge

D2722.1775230663.diff
No OneTemporary

Authored By
Unknown
Size
29 KB
Referenced Files
None
Subscribers
None

D2722.1775230663.diff

diff --git a/bin/quickstart.sh b/bin/quickstart.sh
--- a/bin/quickstart.sh
+++ b/bin/quickstart.sh
@@ -57,7 +57,7 @@
bin/regen-certs
-docker-compose up -d coturn kolab mariadb openvidu kurento-media-server proxy redis
+docker-compose up -d coturn kolab mariadb openvidu kurento-media-server pdns-sql proxy redis
pushd ${base_dir}/src/
diff --git a/docker-compose.yml b/docker-compose.yml
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -100,6 +100,23 @@
tty: true
volumes:
- /etc/letsencrypt/:/etc/letsencrypt/:ro
+ pdns-sql:
+ build:
+ context: ./docker/pdns-sql/
+ container_name: kolab-pdns-sql
+ depends_on:
+ - mariadb
+ hostname: pdns-sql
+ image: apheleia/kolab-pdns-sql
+ network_mode: host
+ tmpfs:
+ - /run
+ - /tmp
+ - /var/run
+ - /var/tmp
+ tty: true
+ volumes:
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
proxy:
build:
context: ./docker/proxy/
diff --git a/docker/pdns-sql/.gitignore b/docker/pdns-sql/.gitignore
new file mode 100644
--- /dev/null
+++ b/docker/pdns-sql/.gitignore
@@ -0,0 +1,2 @@
+*.controlsocket
+*.pid
diff --git a/docker/pdns-sql/Dockerfile b/docker/pdns-sql/Dockerfile
new file mode 100644
--- /dev/null
+++ b/docker/pdns-sql/Dockerfile
@@ -0,0 +1,28 @@
+FROM fedora:33
+
+ENV container docker
+ENV SYSTEMD_PAGER=''
+
+RUN dnf -y install \
+ --setopt 'tsflags=nodocs' \
+ bind-utils \
+ cronie \
+ iproute \
+ iptables \
+ net-tools \
+ pdns \
+ pdns-backend-mysql \
+ pdns-tools \
+ procps-ng \
+ vim-enhanced \
+ wget \
+ which && \
+ dnf clean all
+
+COPY pdns.conf /etc/pdns/pdns.conf
+
+RUN systemctl enable pdns
+
+WORKDIR /root/
+
+CMD ["/lib/systemd/systemd", "--system"]
diff --git a/docker/pdns-sql/pdns.conf b/docker/pdns-sql/pdns.conf
new file mode 100644
--- /dev/null
+++ b/docker/pdns-sql/pdns.conf
@@ -0,0 +1,70 @@
+launch=gmysql
+log-dns-details
+query-logging=yes
+
+local-address=127.0.0.1:9953
+local-ipv6=[::1]:9953
+
+edns-subnet-processing
+
+gmysql-host=127.0.0.1
+gmysql-dbname=kolabdev
+gmysql-password=kolab
+gmysql-user=kolabdev
+
+gmysql-activate-domain-key-query=UPDATE powerdns_cryptokeys SET active=1 WHERE domain_id=(SELECT id FROM domains WHERE name=?) AND powerdns_cryptokeys.id=?
+gmysql-add-domain-key-query=INSERT INTO powerdns_cryptokeys (domain_id, flags, active, content) SELECT id, ?, ?, ? FROM powerdns_domains WHERE name=?
+gmysql-any-id-query=SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM powerdns_records WHERE disabled=0 AND name=? AND domain_id=?
+gmysql-any-query=SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM powerdns_records WHERE disabled=0 AND name=?
+gmysql-basic-query=SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM powerdns_records WHERE disabled=0 AND type=? AND name=?
+gmysql-clear-domain-all-keys-query=delete FROM powerdns_cryptokeys WHERE domain_id=(SELECT id FROM powerdns_domains WHERE name=?)
+gmysql-clear-domain-all-metadata-query=delete FROM powerdns_domain_settings WHERE domain_id=(SELECT id FROM powerdns_domains WHERE name=?)
+gmysql-clear-domain-metadata-query=delete FROM powerdns_domain_settings WHERE domain_id=(SELECT id FROM powerdns_domains WHERE name=?) AND powerdns_domain_settings.kind=?
+gmysql-deactivate-domain-key-query=UPDATE powerdns_cryptokeys SET active=0 WHERE domain_id=(SELECT id FROM powerdns_domains WHERE name=?) AND powerdns_cryptokeys.id=?
+gmysql-delete-comment-rrset-query=DELETE FROM powerdns_comments WHERE domain_id=? AND name=? AND type=?
+gmysql-delete-comments-query=DELETE FROM powerdns_comments WHERE domain_id=?
+gmysql-delete-domain-query=delete FROM powerdns_domains WHERE name=?
+gmysql-delete-empty-non-terminal-query=delete FROM powerdns_records WHERE domain_id=? AND name=? AND type is null
+gmysql-delete-names-query=delete FROM powerdns_records WHERE domain_id=? AND name=?
+gmysql-delete-rrset-query=delete FROM powerdns_records WHERE domain_id=? AND name=? AND type=?
+gmysql-delete-tsig-key-query=delete FROM powerdns_tsigkeys WHERE name=?
+gmysql-delete-zone-query=delete FROM powerdns_records WHERE domain_id=?
+gmysql-get-all-domain-metadata-query=SELECT kind,content FROM powerdns_domains, powerdns_domain_settings WHERE powerdns_domain_settings.domain_id=powerdns_domains.id AND name=?
+gmysql-get-all-domains-query=SELECT powerdns_domains.id, powerdns_domains.name, powerdns_records.content, powerdns_domains.type, powerdns_domains.master, powerdns_domains.notified_serial, powerdns_domains.last_check, powerdns_domains.account FROM powerdns_domains LEFT JOIN powerdns_records ON powerdns_records.domain_id=powerdns_domains.id AND powerdns_records.type='SOA' AND powerdns_records.name=domains.name WHERE powerdns_records.disabled=0 OR ?
+gmysql-get-domain-metadata-query=SELECT content FROM powerdns_domains, powerdns_domain_settings WHERE powerdns_domain_settings.domain_id=powerdns_domains.id AND name=? AND powerdns_domain_settings.kind=?
+gmysql-get-last-inserted-key-id-query=SELECT LAST_INSERT_ID()
+gmysql-get-order-after-query=SELECT ordername FROM powerdns_records WHERE ordername > ? AND domain_id=? AND disabled=0 AND ordername IS NOT NULL ORDER BY 1 ASC LIMIT 1
+gmysql-get-order-before-query=SELECT ordername, name FROM powerdns_records WHERE ordername <= ? AND domain_id=? AND disabled=0 AND ordername IS NOT NULL ORDER BY 1 desc LIMIT 1
+gmysql-get-order-first-query=SELECT ordername FROM powerdns_records WHERE domain_id=? AND disabled=0 AND ordername IS NOT NULL ORDER BY 1 ASC LIMIT 1
+gmysql-get-order-last-query=SELECT ordername, name FROM powerdns_records WHERE ordername != '' AND domain_id=? AND disabled=0 AND ordername IS NOT NULL ORDER BY 1 desc LIMIT 1
+gmysql-get-tsig-key-query=SELECT algorithm, secret FROM powerdns_tsigkeys WHERE name=?
+gmysql-get-tsig-keys-query=SELECT name,algorithm, secret FROM powerdns_tsigkeys
+gmysql-id-query=SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM powerdns_records WHERE disabled=0 AND type=? AND name=? AND domain_id=?
+gmysql-info-all-master-query=SELECT d.id, d.name, d.notified_serial, r.content FROM powerdns_records r join powerdns_domains d on r.name=d.name WHERE r.type='SOA' AND r.disabled=0 AND d.type='MASTER'
+gmysql-info-all-slaves-query=SELECT id,name,master,last_check FROM powerdns_domains WHERE type='SLAVE'
+gmysql-info-zone-query=SELECT id,name,master,last_check,notified_serial,type,account FROM powerdns_domains WHERE name=?
+gmysql-insert-comment-query=INSERT INTO powerdns_comments (domain_id, name, type, modified_at, account, comment) VALUES (?, ?, ?, ?, ?, ?)
+gmysql-insert-empty-non-terminal-order-query=INSERT INTO powerdns_records (type,domain_id,disabled,name,ordername,auth,content,ttl,prio) values (null,?,0,?,?,?,NULL,NULL,NULL)
+gmysql-insert-record-query=INSERT INTO powerdns_records (content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values (?,?,?,?,?,?,?,?,?)
+gmysql-insert-zone-query=INSERT INTO powerdns_domains (type,name,master,account,last_check,notified_serial) values(?,?,?,?,NULL,NULL)
+gmysql-list-comments-query=SELECT domain_id,name,type,modified_at,account,comment FROM powerdns_comments WHERE domain_id=?
+gmysql-list-domain-keys-query=SELECT powerdns_cryptokeys.id, flags, active, content FROM powerdns_domains, powerdns_cryptokeys WHERE powerdns_cryptokeys.domain_id=powerdns_domains.id AND name=?
+gmysql-list-query=SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM powerdns_records WHERE (disabled=0 OR ?) AND domain_id=? ORDER BY name, type
+gmysql-list-subzone-query=SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM powerdns_records WHERE disabled=0 AND (name=? OR name like ?) AND domain_id=?
+gmysql-nullify-ordername-and-update-auth-query=UPDATE powerdns_records SET ordername=NULL,auth=? WHERE domain_id=? AND name=? AND disabled=0
+gmysql-nullify-ordername-and-update-auth-type-query=UPDATE powerdns_records SET ordername=NULL,auth=? WHERE domain_id=? AND name=? AND type=? AND disabled=0
+gmysql-remove-domain-key-query=delete FROM powerdns_cryptokeys WHERE domain_id=(SELECT id FROM powerdns_domains WHERE name=?) AND powerdns_cryptokeys.id=?
+gmysql-remove-empty-non-terminals-from-zone-query=delete FROM powerdns_records WHERE domain_id=? AND type is null
+gmysql-search-comments-query=SELECT domain_id,name,type,modified_at,account,comment FROM powerdns_comments WHERE name LIKE ? OR comment LIKE ? LIMIT ?
+gmysql-search-records-query=SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM powerdns_records WHERE name LIKE ? OR content LIKE ? LIMIT ?
+gmysql-set-domain-metadata-query=INSERT INTO powerdns_domain_settings (domain_id, kind, content) SELECT id, ?, ? FROM powerdns_domains WHERE name=?
+gmysql-set-tsig-key-query=REPLACE INTO powerdns_tsigkeys (name,algorithm,secret) values(?,?,?)
+gmysql-supermaster-query=SELECT account FROM powerdns_masters WHERE ip=? AND nameserver=?
+gmysql-update-account-query=UPDATE powerdns_domains SET account=? WHERE name=?
+gmysql-update-kind-query=UPDATE powerdns_domains SET type=? WHERE name=?
+gmysql-update-lastcheck-query=UPDATE powerdns_domains SET last_check=? WHERE id=?
+gmysql-update-master-query=UPDATE powerdns_domains SET master=? WHERE name=?
+gmysql-update-ordername-and-auth-query=UPDATE powerdns_records SET ordername=?,auth=? WHERE domain_id=? AND name=? AND disabled=0
+gmysql-update-ordername-and-auth-type-query=UPDATE powerdns_records SET ordername=?,auth=? WHERE domain_id=? AND name=? AND type=? AND disabled=0
+gmysql-update-serial-query=UPDATE powerdns_domains SET notified_serial=? WHERE id=?
+
diff --git a/src/app/Console/Commands/PowerDNS/Domain/CreateCommand.php b/src/app/Console/Commands/PowerDNS/Domain/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/PowerDNS/Domain/CreateCommand.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace App\Console\Commands\PowerDNS\Domain;
+
+use Illuminate\Console\Command;
+
+class CreateCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'powerdns:domain:create {domain}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Create a domain in PowerDNS';
+
+ /**
+ * Create a new command instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $name = $this->argument('domain');
+
+ if (substr($name, -1) == '.') {
+ \Log::error("Domain can not end in '.'");
+ return 1;
+ }
+
+ if (substr_count($name, '.') < 1) {
+ \Log::error("Invalid syntax for a domain.");
+ return 1;
+ }
+
+ $domain = \App\PowerDNS\Domain::where('name', $name)->first();
+
+ if ($domain) {
+ \Log::error("Domain already exists");
+ return 1;
+ }
+
+ \App\PowerDNS\Domain::create(['name' => $name]);
+ }
+}
diff --git a/src/app/Console/Commands/PowerDNS/Domain/DeleteCommand.php b/src/app/Console/Commands/PowerDNS/Domain/DeleteCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/PowerDNS/Domain/DeleteCommand.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Console\Commands\PowerDNS\Domain;
+
+use Illuminate\Console\Command;
+
+class DeleteCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'powerdns:domain:delete {domain}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Delete a PowerDNS domain';
+
+ /**
+ * Create a new command instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $name = $this->argument('domain');
+
+ $domain = \App\PowerDNS\Domain::where('name', $name)->first();
+
+ if (!$domain) {
+ return 1;
+ }
+
+ $domain->delete();
+ }
+}
diff --git a/src/app/Console/Commands/PowerDNS/Domain/ReadCommand.php b/src/app/Console/Commands/PowerDNS/Domain/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/PowerDNS/Domain/ReadCommand.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Console\Commands\PowerDNS\Domain;
+
+use Illuminate\Console\Command;
+
+class ReadCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'powerdns:domain:read {domain}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Read a PowerDNS domain';
+
+ /**
+ * Create a new command instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $name = $this->argument('domain');
+
+ $domain = \App\PowerDNS\Domain::where('name', $name)->first();
+
+ if (!$domain) {
+ return 1;
+ }
+
+ foreach ($domain->records as $record) {
+ $this->info($record->toString());
+ }
+ }
+}
diff --git a/src/app/Observers/PowerDNS/DomainObserver.php b/src/app/Observers/PowerDNS/DomainObserver.php
new file mode 100644
--- /dev/null
+++ b/src/app/Observers/PowerDNS/DomainObserver.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Observers\PowerDNS;
+
+use App\PowerDNS\Domain;
+
+class DomainObserver
+{
+ public function created(Domain $domain)
+ {
+ \App\PowerDNS\Record::create(
+ [
+ 'domain_id' => $domain->id,
+ 'name' => $domain->name,
+ 'type' => "SOA",
+ 'content' => sprintf(
+ "ns.%s. hostmaster.%s. %s 1200 600 1814400 60",
+ $domain->name,
+ $domain->name,
+ \Carbon\Carbon::now()->format('Ymd') . '01'
+ )
+ ]
+ );
+
+ \App\PowerDNS\Record::withoutEvents(
+ function () use ($domain) {
+ \App\PowerDNS\Record::create(
+ [
+ 'domain_id' => $domain->id,
+ 'name' => $domain->name,
+ 'type' => "NS",
+ 'content' => "ns1." . $domain->name . "."
+ ]
+ );
+ }
+ );
+
+ \App\PowerDNS\Record::withoutEvents(
+ function () use ($domain) {
+ \App\PowerDNS\Record::create(
+ [
+ 'domain_id' => $domain->id,
+ 'name' => "ns1." . $domain->name,
+ 'type' => "A",
+ 'content' => "127.0.0.1"
+ ]
+ );
+ }
+ );
+
+ \App\PowerDNS\Record::withoutEvents(
+ function () use ($domain) {
+ \App\PowerDNS\Record::create(
+ [
+ 'domain_id' => $domain->id,
+ 'name' => $domain->name,
+ 'type' => "NS",
+ 'content' => "ns2." . $domain->name . "."
+ ]
+ );
+ }
+ );
+
+ \App\PowerDNS\Record::withoutEvents(
+ function () use ($domain) {
+ \App\PowerDNS\Record::create(
+ [
+ 'domain_id' => $domain->id,
+ 'name' => "ns2." . $domain->name,
+ 'type' => "A",
+ 'content' => "127.0.0.1"
+ ]
+ );
+ }
+ );
+
+ \App\PowerDNS\DomainSetting::create(
+ [
+ 'domain_id' => $domain->id,
+ 'kind' => 'ENABLE-LUA-RECORDS',
+ 'content' => "0"
+ ]
+ );
+ }
+}
diff --git a/src/app/Observers/PowerDNS/RecordObserver.php b/src/app/Observers/PowerDNS/RecordObserver.php
new file mode 100644
--- /dev/null
+++ b/src/app/Observers/PowerDNS/RecordObserver.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Observers\PowerDNS;
+
+use App\PowerDNS\Record;
+
+class RecordObserver
+{
+ public function created($record)
+ {
+ if ($record->{'type'} == "SOA") {
+ return;
+ }
+
+ $record->domain->bumpSerial();
+ }
+
+ public function deleted($record)
+ {
+ if ($record->{'type'} == "SOA") {
+ return;
+ }
+
+ $record->domain->bumpSerial();
+ }
+
+ public function updated($record)
+ {
+ if ($record->{'type'} == "SOA") {
+ return;
+ }
+
+ $record->domain->bumpSerial();
+ }
+}
diff --git a/src/app/PowerDNS/Comment.php b/src/app/PowerDNS/Comment.php
new file mode 100644
--- /dev/null
+++ b/src/app/PowerDNS/Comment.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace App\PowerDNS;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Comment extends Model
+{
+ protected $table = 'powerdns_comments';
+}
diff --git a/src/app/PowerDNS/CryptoKey.php b/src/app/PowerDNS/CryptoKey.php
new file mode 100644
--- /dev/null
+++ b/src/app/PowerDNS/CryptoKey.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace App\PowerDNS;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CryptoKey extends Model
+{
+ protected $table = 'powerdns_cryptokeys';
+}
diff --git a/src/app/PowerDNS/Domain.php b/src/app/PowerDNS/Domain.php
new file mode 100644
--- /dev/null
+++ b/src/app/PowerDNS/Domain.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace App\PowerDNS;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Domain extends Model
+{
+ protected $fillable = [
+ 'name'
+ ];
+
+ protected $table = 'powerdns_domains';
+
+ public function bumpSerial()
+ {
+ $soa = $this->records()->where('type', 'SOA')->first();
+
+ list($ns, $hm, $serial, $a, $b, $c, $d) = explode(" ", $soa->content);
+
+ $today = \Carbon\Carbon::now()->format('Ymd');
+ $date = substr($serial, 0, 8);
+
+ if ($date != $today) {
+ $serial = $today . '01';
+ } else {
+ $change = (int)(substr($serial, 8, 2));
+
+ $serial = sprintf("%s%02s", $date, ($change + 1));
+ }
+
+ $soa->content = "{$ns} {$hm} {$serial} {$a} {$b} {$c} {$d}";
+ $soa->save();
+ }
+
+ public function getSerial()
+ {
+ $soa = $this->records()->where('type', 'SOA')->first();
+
+ list($ns, $hm, $serial, $a, $b, $c, $d) = explode(" ", $soa->content);
+
+ return $serial;
+ }
+
+ public function records()
+ {
+ return $this->hasMany('App\PowerDNS\Record', 'domain_id');
+ }
+
+ //public function setSerial() { }
+}
diff --git a/src/app/PowerDNS/DomainSetting.php b/src/app/PowerDNS/DomainSetting.php
new file mode 100644
--- /dev/null
+++ b/src/app/PowerDNS/DomainSetting.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\PowerDNS;
+
+use Illuminate\Database\Eloquent\Model;
+
+class DomainSetting extends Model
+{
+ protected $fillable = [
+ 'domain_id',
+ 'kind',
+ 'content',
+ ];
+
+ protected $table = 'powerdns_domain_settings';
+}
diff --git a/src/app/PowerDNS/Record.php b/src/app/PowerDNS/Record.php
new file mode 100644
--- /dev/null
+++ b/src/app/PowerDNS/Record.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\PowerDNS;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Record extends Model
+{
+ protected $fillable = [
+ 'domain_id',
+ 'name',
+ 'type',
+ 'content'
+ ];
+
+ protected $table = 'powerdns_records';
+
+ public function domain()
+ {
+ return $this->belongsTo('App\PowerDNS\Domain', 'domain_id', 'id');
+ }
+
+ public function toString()
+ {
+ return "{$this->name}. {$this->type} {$this->content}";
+ }
+}
diff --git a/src/app/PowerDNS/SuperMaster.php b/src/app/PowerDNS/SuperMaster.php
new file mode 100644
--- /dev/null
+++ b/src/app/PowerDNS/SuperMaster.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace App\PowerDNS;
+
+use Illuminate\Database\Eloquent\Model;
+
+class SuperMaster extends Model
+{
+ protected $table = 'powerdns_masters';
+}
diff --git a/src/app/PowerDNS/TSIGKey.php b/src/app/PowerDNS/TSIGKey.php
new file mode 100644
--- /dev/null
+++ b/src/app/PowerDNS/TSIGKey.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace App\PowerDNS;
+
+use Illuminate\Database\Eloquent\Model;
+
+class TSIGKey extends Model
+{
+ protected $table = 'powerdns_tsigkeys';
+}
diff --git a/src/app/Providers/AppServiceProvider.php b/src/app/Providers/AppServiceProvider.php
--- a/src/app/Providers/AppServiceProvider.php
+++ b/src/app/Providers/AppServiceProvider.php
@@ -46,6 +46,9 @@
\App\VerificationCode::observe(\App\Observers\VerificationCodeObserver::class);
\App\Wallet::observe(\App\Observers\WalletObserver::class);
+ \App\PowerDNS\Domain::observe(\App\Observers\PowerDNS\DomainObserver::class);
+ \App\PowerDNS\Record::observe(\App\Observers\PowerDNS\RecordObserver::class);
+
Schema::defaultStringLength(191);
// Log SQL queries in debug mode
diff --git a/src/database/migrations/2020_06_04_115409_create_powerdns_tables.php b/src/database/migrations/2020_06_04_115409_create_powerdns_tables.php
new file mode 100644
--- /dev/null
+++ b/src/database/migrations/2020_06_04_115409_create_powerdns_tables.php
@@ -0,0 +1,147 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+// phpcs:ignore
+class CreatePowerDNSTables extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create(
+ 'powerdns_domains',
+ function (Blueprint $table) {
+ $table->bigIncrements('id');
+ $table->string('name', 255)->unique()->index();
+ $table->string('master', 128)->nullable();
+ $table->datetime('last_check')->nullable();
+ $table->string('type', 6)->default('NATIVE');
+ $table->integer('notified_serial')->unsigned()->nullable();
+ $table->string('account', 40)->nullable();
+ $table->timestamps();
+ }
+ );
+
+ Schema::create(
+ 'powerdns_records',
+ function (Blueprint $table) {
+ $table->bigIncrements('id');
+ $table->bigInteger('domain_id')->unsigned();
+ $table->string('name', 255)->nullable();
+ $table->string('type', 10)->nullable();
+ $table->longtext('content')->nullable();
+ $table->integer('ttl')->unsigned()->nullable();
+ $table->integer('prio')->unsigned()->nullable();
+ $table->boolean('disabled')->default(false);
+ $table->binary('ordername', 255)->nullable();
+ $table->boolean('auth')->default(true);
+ $table->timestamps();
+
+ $table->foreign('domain_id')->references('id')->on('powerdns_domains')
+ ->onDelete('cascade');
+
+ $table->index('domain_id');
+ $table->index(['name', 'type']);
+ $table->index('ordername');
+ }
+ );
+
+ Schema::create(
+ 'powerdns_masters',
+ function (Blueprint $table) {
+ $table->string('ip', 64);
+ $table->string('nameserver', 255);
+ $table->string('account', 40);
+
+ $table->primary(['ip', 'nameserver']);
+
+ $table->timestamps();
+ }
+ );
+
+ Schema::create(
+ 'powerdns_comments',
+ function (Blueprint $table) {
+ $table->bigIncrements('id');
+ $table->bigInteger('domain_id')->unsigned();
+ $table->string('name', 255);
+ $table->string('type', 10);
+ $table->string('account', 40)->nullable();
+ $table->text('comment');
+ $table->timestamps();
+
+ $table->index(['name', 'type']);
+ $table->index(['domain_id', 'updated_at']);
+
+ $table->foreign('domain_id')->references('id')->on('powerdns_domains')
+ ->onDelete('cascade');
+ }
+ );
+
+ Schema::create(
+ 'powerdns_domain_settings',
+ function (Blueprint $table) {
+ $table->bigIncrements('id');
+ $table->bigInteger('domain_id')->unsigned();
+ $table->string('kind', 32);
+ $table->text('content');
+ $table->timestamps();
+
+ $table->foreign('domain_id')->references('id')->on('powerdns_domains')
+ ->onDelete('cascade');
+ }
+ );
+
+ Schema::create(
+ 'powerdns_cryptokeys',
+ function (Blueprint $table) {
+ $table->bigIncrements('id');
+ $table->bigInteger('domain_id')->unsigned();
+ $table->integer('flags');
+ $table->boolean('active');
+ $table->text('content');
+ $table->timestamps();
+
+ $table->index('domain_id');
+
+ $table->foreign('domain_id')->references('id')->on('powerdns_domains')
+ ->onDelete('cascade');
+ }
+ );
+
+ Schema::create(
+ 'powerdns_tsigkeys',
+ function (Blueprint $table) {
+ $table->bigIncrements('id');
+ $table->string('name', 255);
+ $table->string('algorithm', 50);
+ $table->string('secret', 255);
+ $table->timestamps();
+
+ $table->index(['name', 'algorithm']);
+ }
+ );
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('powerdns_tsigkeys');
+ Schema::dropIfExists('powerdns_cryptokeys');
+ Schema::dropIfExists('powerdns_domain_settings');
+ Schema::dropIfExists('powerdns_comments');
+ Schema::dropIfExists('powerdns_masters');
+ Schema::dropIfExists('powerdns_records');
+ Schema::dropIfExists('powerdns_domains');
+ }
+}
diff --git a/src/database/seeds/DatabaseSeeder.php b/src/database/seeds/DatabaseSeeder.php
--- a/src/database/seeds/DatabaseSeeder.php
+++ b/src/database/seeds/DatabaseSeeder.php
@@ -21,6 +21,7 @@
'SkuSeeder',
'PackageSeeder',
'PlanSeeder',
+ 'PowerDNSSeeder',
'UserSeeder',
'OpenViduRoomSeeder',
];
diff --git a/src/database/seeds/local/PowerDNSSeeder.php b/src/database/seeds/local/PowerDNSSeeder.php
new file mode 100644
--- /dev/null
+++ b/src/database/seeds/local/PowerDNSSeeder.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Database\Seeds\Local;
+
+use App\Domain;
+use Illuminate\Database\Seeder;
+
+class PowerDNSSeeder extends Seeder
+{
+ /**
+ * Run the database seeds.
+ *
+ * @return void
+ */
+ public function run()
+ {
+ $domain = \App\PowerDNS\Domain::create(
+ [
+ 'name' => '_woat.' . \config('app.domain')
+ ]
+ );
+
+ /*
+ $domainLuaSetting = \App\PowerDNS\DomainSetting::where(
+ ['domain_id' => $domain->id, 'kind' => 'ENABLE-LUA-RECORDS']
+ )->first();
+
+ $domainLuaSetting->{'content'} = "1";
+ $domainLuaSetting->save();
+ */
+
+ /*
+ \App\PowerDNS\Record::create(
+ [
+ 'domain_id' => $domain->id,
+ 'name' => $domain->{'name'},
+ 'type' => 'A',
+ 'content' => '10.4.2.23'
+ ]
+ );
+ */
+ }
+}
diff --git a/src/tests/Feature/PowerDNS/DomainTest.php b/src/tests/Feature/PowerDNS/DomainTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/PowerDNS/DomainTest.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Tests\Feature\PowerDNS;
+
+use App\PowerDNS\Domain;
+use App\PowerDNS\Record;
+use Tests\TestCase;
+
+class DomainTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->domain = Domain::firstOrCreate(
+ [
+ 'name' => 'test-domain.com'
+ ]
+ );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function tearDown(): void
+ {
+ $this->domain->delete();
+
+ parent::tearDown();
+ }
+
+ public function testDomainCreate(): void
+ {
+ $this->assertCount(1, $this->domain->records()->where('type', 'SOA')->get());
+ $this->assertCount(2, $this->domain->records()->where('type', 'NS')->get());
+ }
+
+ public function testCreateRecord(): void
+ {
+ $before = $this->domain->getSerial();
+
+ Record::create(
+ [
+ 'domain_id' => $this->domain->id,
+ 'name' => $this->domain->{'name'},
+ 'type' => "MX",
+ 'content' => '10 mx01.' . $this->domain->{'name'} . '.'
+ ]
+ );
+
+ Record::create(
+ [
+ 'domain_id' => $this->domain->id,
+ 'name' => 'mx01.' . $this->domain->{'name'},
+ 'type' => "A",
+ 'content' => '127.0.0.1'
+ ]
+ );
+
+ $after = $this->domain->getSerial();
+
+ $this->assertTrue($before < $after);
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 3:37 PM (7 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18824526
Default Alt Text
D2722.1775230663.diff (29 KB)

Event Timeline