Pull ip addresses into selector
This commit is contained in:
		
							parent
							
								
									89b6f70cde
								
							
						
					
					
						commit
						2812129d00
					
				| @ -171,23 +171,11 @@ class ServerResource extends Resource | |||||||
|                             ->whereNull('server_id'), |                             ->whereNull('server_id'), | ||||||
|                     ) |                     ) | ||||||
|                     ->createOptionForm(fn (Forms\Get $get) => [ |                     ->createOptionForm(fn (Forms\Get $get) => [ | ||||||
|                         Forms\Components\TextInput::make('allocation_ip') |                         Forms\Components\Select::make('allocation_ip') | ||||||
|                             ->ipv4() |                             ->options(Node::find($get('node_id'))?->ipAddresses() ?? []) | ||||||
|                             ->datalist(function () use ($get) { |  | ||||||
|                                 $node = Node::find($get('node_id')); |  | ||||||
|                                 if (is_ip($node->fqdn)) { |  | ||||||
|                                     return [$node->fqdn]; |  | ||||||
|                                 } |  | ||||||
| 
 |  | ||||||
|                                 $validRecords = gethostbynamel($node->fqdn); |  | ||||||
|                                 if (!$validRecords) { |  | ||||||
|                                     return []; |  | ||||||
|                                 } |  | ||||||
| 
 |  | ||||||
|                                 return $validRecords ?: []; |  | ||||||
|                             }) |  | ||||||
|                             ->label('IP Address') |                             ->label('IP Address') | ||||||
|                             ->helperText("Usually your machine's public IP unless you are port forwarding.") |                             ->helperText("Usually your machine's public IP unless you are port forwarding.") | ||||||
|  |                             ->selectablePlaceholder(false) | ||||||
|                             ->required(), |                             ->required(), | ||||||
|                         Forms\Components\TextInput::make('allocation_alias') |                         Forms\Components\TextInput::make('allocation_alias') | ||||||
|                             ->label('Alias') |                             ->label('Alias') | ||||||
|  | |||||||
| @ -300,4 +300,25 @@ class Node extends Model | |||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     public function ipAddresses(): array | ||||||
|  |     { | ||||||
|  |         return cache()->remember("nodes.$this->id.servers", now()->addHour(), function () { | ||||||
|  |             $ips = collect(); | ||||||
|  |             if (is_ip($this->fqdn)) { | ||||||
|  |                 $ips = $ips->add($this->fqdn); | ||||||
|  |             } else if ($dnsRecords = gethostbynamel($this->fqdn)) { | ||||||
|  |                 $ips = $ips->merge($dnsRecords); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             try { | ||||||
|  |                 $addresses = Http::daemon($this)->connectTimeout(1)->timeout(1)->get('/api/system/ips')->json(); | ||||||
|  |                 $ips = $ips->merge(fluent($addresses)->get('ip_addresses')); | ||||||
|  |             } catch (Exception) { | ||||||
|  |                 // pass
 | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             return $ips->all(); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Lance Pioch
						Lance Pioch