Changeset View
Changeset View
Standalone View
Standalone View
src/app/PowerDNS/Domain.php
<?php | <?php | ||||
namespace App\PowerDNS; | namespace App\PowerDNS; | ||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
class Domain extends Model | class Domain extends Model | ||||
{ | { | ||||
protected $fillable = [ | protected $fillable = [ | ||||
'name' | 'name' | ||||
]; | ]; | ||||
protected $table = 'powerdns_domains'; | protected $table = 'powerdns_domains'; | ||||
public function bumpSerial() | /** | ||||
* Bump the SOA record serial | |||||
*/ | |||||
public function bumpSerial(): void | |||||
{ | { | ||||
$soa = $this->records()->where('type', 'SOA')->first(); | $soa = $this->records()->where('type', 'SOA')->first(); | ||||
list($ns, $hm, $serial, $a, $b, $c, $d) = explode(" ", $soa->content); | list($ns, $hm, $serial, $a, $b, $c, $d) = explode(" ", $soa->content); | ||||
$today = \Carbon\Carbon::now()->format('Ymd'); | $today = \Carbon\Carbon::now()->format('Ymd'); | ||||
$date = substr($serial, 0, 8); | $date = substr($serial, 0, 8); | ||||
if ($date != $today) { | if ($date != $today) { | ||||
$serial = $today . '01'; | $serial = $today . '01'; | ||||
} else { | } else { | ||||
$change = (int)(substr($serial, 8, 2)); | $change = (int)(substr($serial, 8, 2)); | ||||
$serial = sprintf("%s%02s", $date, ($change + 1)); | $serial = sprintf("%s%02s", $date, ($change + 1)); | ||||
} | } | ||||
$soa->content = "{$ns} {$hm} {$serial} {$a} {$b} {$c} {$d}"; | $soa->content = "{$ns} {$hm} {$serial} {$a} {$b} {$c} {$d}"; | ||||
$soa->save(); | $soa->save(); | ||||
} | } | ||||
public function getSerial() | /** | ||||
* Returns the SOA record serial | |||||
* | |||||
* @return string | |||||
*/ | |||||
public function getSerial(): string | |||||
{ | { | ||||
$soa = $this->records()->where('type', 'SOA')->first(); | $soa = $this->records()->where('type', 'SOA')->first(); | ||||
list($ns, $hm, $serial, $a, $b, $c, $d) = explode(" ", $soa->content); | list($ns, $hm, $serial, $a, $b, $c, $d) = explode(" ", $soa->content); | ||||
return $serial; | return $serial; | ||||
} | } | ||||
/** | |||||
* Any DNS records assigned to this domain. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | |||||
*/ | |||||
public function records() | public function records() | ||||
{ | { | ||||
return $this->hasMany('App\PowerDNS\Record', 'domain_id'); | return $this->hasMany(Record::class, 'domain_id'); | ||||
} | } | ||||
//public function setSerial() { } | /** | ||||
* Any (additional) properties of this domain. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | |||||
*/ | |||||
public function settings() | |||||
{ | |||||
return $this->hasMany(DomainSetting::class, 'domain_id'); | |||||
} | |||||
} | } |