@@ -24,6 +24,7 @@ class Subdomain extends Model implements HasLabel
2424 protected $ fillable = [
2525 'name ' ,
2626 'record_type ' ,
27+ 'cloudflare_id ' ,
2728 'domain_id ' ,
2829 'server_id ' ,
2930 ];
@@ -47,12 +48,12 @@ protected static function boot(): void
4748
4849 public function domain (): BelongsTo
4950 {
50- return $ this ->BelongsTo (CloudflareDomain::class, 'domain_id ' );
51+ return $ this ->belongsTo (CloudflareDomain::class, 'domain_id ' );
5152 }
5253
5354 public function server (): BelongsTo
5455 {
55- return $ this ->BelongsTo (Server::class);
56+ return $ this ->belongsTo (Server::class);
5657 }
5758
5859 public function getLabel (): string |Htmlable |null
@@ -62,42 +63,46 @@ public function getLabel(): string|Htmlable|null
6263
6364 protected function createOnCloudflare (): void
6465 {
65- if (!$ this ->server ->allocation || $ this ->cloudflare_id ) {
66+ if (!$ this ->server ->allocation || $ this ->server -> allocation -> ip === ' 0.0.0.0 ' || $ this -> server -> allocation -> ip === ' :: ' ) {
6667 return ;
6768 }
6869
69- $ response = Http::cloudflare ()->post ("zones/ {$ this ->domain ->cloudflare_id }/dns_records " , [
70- 'name ' => $ this ->name ,
71- 'ttl ' => 120 ,
72- 'type ' => $ this ->record_type ,
73- 'comment ' => 'Created by Pelican Subdomains plugin ' ,
74- 'content ' => $ this ->server ->allocation ->ip ,
75- 'proxied ' => false ,
76- ])->json ();
77-
78- if ($ response ['success ' ]) {
79- $ dnsRecord = $ response ['result ' ];
80-
81- $ this ->updateQuietly ([
82- 'cloudflare_id ' => $ dnsRecord ->id ,
83- ]);
70+ if (!$ this ->cloudflare_id ) {
71+ $ response = Http::cloudflare ()->post ("zones/ {$ this ->domain ->cloudflare_id }/dns_records " , [
72+ 'name ' => $ this ->name ,
73+ 'ttl ' => 120 ,
74+ 'type ' => $ this ->record_type ,
75+ 'comment ' => 'Created by Pelican Subdomains plugin ' ,
76+ 'content ' => $ this ->server ->allocation ->ip ,
77+ 'proxied ' => false ,
78+ ])->json ();
79+
80+ if ($ response ['success ' ]) {
81+ $ dnsRecord = $ response ['result ' ];
82+
83+ $ this ->updateQuietly ([
84+ 'cloudflare_id ' => $ dnsRecord ['id ' ],
85+ ]);
86+ }
8487 }
8588 }
8689
8790 protected function updateOnCloudflare (): void
8891 {
89- if (!$ this ->server ->allocation || ! $ this ->cloudflare_id ) {
92+ if (!$ this ->server ->allocation || $ this ->server -> allocation -> ip === ' 0.0.0.0 ' || $ this -> server -> allocation -> ip === ' :: ' ) {
9093 return ;
9194 }
9295
93- Http::cloudflare ()->patch ("zones/ {$ this ->domain ->cloudflare_id }/dns_records/ {$ this ->cloudflare_id }" , [
94- 'name ' => $ this ->name ,
95- 'ttl ' => 120 ,
96- 'type ' => $ this ->record_type ,
97- 'comment ' => 'Created by Pelican Subdomains plugin ' ,
98- 'content ' => $ this ->server ->allocation ->ip ,
99- 'proxied ' => false ,
100- ]);
96+ if ($ this ->cloudflare_id ) {
97+ Http::cloudflare ()->patch ("zones/ {$ this ->domain ->cloudflare_id }/dns_records/ {$ this ->cloudflare_id }" , [
98+ 'name ' => $ this ->name ,
99+ 'ttl ' => 120 ,
100+ 'type ' => $ this ->record_type ,
101+ 'comment ' => 'Created by Pelican Subdomains plugin ' ,
102+ 'content ' => $ this ->server ->allocation ->ip ,
103+ 'proxied ' => false ,
104+ ]);
105+ }
101106 }
102107
103108 protected function deleteOnCloudflare (): void
0 commit comments