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
6 changes: 6 additions & 0 deletions subdomains/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ By default every server has a subdomain limit of 0. You can change this limit by

Note: You can't create subdomains for servers with `0.0.0.0` or `::` as allocation!

## Configuring domains

Each domain is composed of a name and an optional prefix. The name must be a valid Cloudflare Zone, while the prefix can be used to specify a subdomain on which the server subdomains will be created.

For example: when creating a subdomain `server1` on a domain with name `example.com` and prefix `abc`, the created record will be `server1.abc.example.com`.

## SRV Records

In order to create SRV records instead of A/AAAA you need to do the following:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('cloudflare_domains', function (Blueprint $table) {
$table->string('prefix')->nullable()->after('name');
});
}

public function down(): void
{
Schema::table('cloudflare_domains', function (Blueprint $table) {
$table->dropColumn('prefix');
});
}
};
1 change: 1 addition & 0 deletions subdomains/lang/de/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'create_subdomain' => 'Subdomain erstellen',

'name' => 'Name',
'prefix' => 'Präfix',
'record_type' => 'Record Typ',
'is_synced' => 'Ist synchronisiert?',
'srv_target' => 'SRV Ziel',
Expand Down
1 change: 1 addition & 0 deletions subdomains/lang/en/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'create_subdomain' => 'Create Subdomain',

'name' => 'Name',
'prefix' => 'Prefix',
'record_type' => 'Record type',
'is_synced' => 'Is Synced?',
'srv_target' => 'SRV target',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public static function table(Table $table): Table
->columns([
TextColumn::make('name')
->label(trans('subdomains::strings.name')),
TextColumn::make('prefix')
->label(trans('subdomains::strings.prefix')),
TextColumn::make('subdomains_count')
->label(trans_choice('subdomains::strings.subdomain', 2))
->counts('subdomains'),
Expand Down Expand Up @@ -116,12 +118,14 @@ public static function table(Table $table): Table
public static function form(Schema $schema): Schema
{
return $schema
->columns(1)
->columns(2)
->components([
TextInput::make('name')
->label(trans('subdomains::strings.name'))
->required()
->unique(),
TextInput::make('prefix')
->label(trans('subdomains::strings.prefix')),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function form(Schema $schema): Schema
->alphaDash()
->rule(new NotOnBlacklist())
->columnSpanFull()
->suffix(fn (Get $get) => '.' . CloudflareDomain::find($get('domain_id'))?->name),
->suffix(fn (Get $get) => '.' . CloudflareDomain::find($get('domain_id'))?->nameWithPrefix()),
Select::make('domain_id')
->label(trans_choice('subdomains::strings.domain', 1))
->disabledOn('edit')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static function form(Schema $schema): Schema
->alphaDash()
->rule(new NotOnBlacklist())
->columnSpanFull()
->suffix(fn (Get $get) => '.' . CloudflareDomain::find($get('domain_id'))?->name),
->suffix(fn (Get $get) => '.' . CloudflareDomain::find($get('domain_id'))?->nameWithPrefix()),
Select::make('domain_id')
->label(trans_choice('subdomains::strings.domain', 1))
->disabledOn('edit')
Expand Down
12 changes: 12 additions & 0 deletions subdomains/src/Models/CloudflareDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
/**
* @property int $id
* @property string $name
* @property ?string $prefix
* @property ?string $cloudflare_id
*/
class CloudflareDomain extends Model
{
protected $fillable = [
'name',
'prefix',
'cloudflare_id',
];

Expand All @@ -33,6 +35,16 @@ public function subdomains(): HasMany
return $this->hasMany(Subdomain::class, 'domain_id');
}

public function nameWithPrefix(): string
{
return is_null($this->prefix) ? $this->name : "$this->prefix.$this->name";
}

public function prependPrefix(string $subdomain): string
{
return is_null($this->prefix) ? $subdomain : "$subdomain.$this->prefix";
}

/** @throws Exception */
public function fetchCloudflareId(): void
{
Expand Down
6 changes: 3 additions & 3 deletions subdomains/src/Models/Subdomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function server(): BelongsTo

public function getLabel(): string|Htmlable|null
{
return $this->name . '.' . $this->domain->name;
return $this->name . '.' . $this->domain->nameWithPrefix();
}

/** @throws Exception */
Expand All @@ -75,7 +75,7 @@ public function upsertOnCloudflare(): void
throw new Exception('Server has no SRV type');
}

$searchName = "$srvServiceType->value.$this->name";
$searchName = $this->domain->prependPrefix("$srvServiceType->value.$this->name");
Comment thread
gavidroselj marked this conversation as resolved.

$payload = [
'name' => $searchName,
Expand All @@ -94,7 +94,7 @@ public function upsertOnCloudflare(): void
throw new Exception('Server has invalid allocation ip (0.0.0.0 or ::)');
}

$searchName = $this->name;
$searchName = $this->domain->prependPrefix($this->name);

$payload = [
'name' => $searchName,
Expand Down