Cleanup FQDN validation logic, fallback to old hostname check (#4409)

Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
Matthew Penner 2022-10-09 16:19:16 -06:00 committed by GitHub
parent c748fa9842
commit 95e15d2c8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 49 deletions

View file

@ -1,14 +1,8 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Http\Requests\Admin\Node;
use Pterodactyl\Rules\Fqdn;
use Pterodactyl\Models\Node;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
@ -23,30 +17,9 @@ class NodeFormRequest extends AdminFormRequest
return Node::getRulesForUpdate($this->route()->parameter('node'));
}
return Node::getRules();
}
$data = Node::getRules();
$data['fqdn'][] = Fqdn::make('scheme');
/**
* Run validation after the rules above have been applied.
*
* @param \Illuminate\Validation\Validator $validator
*/
public function withValidator($validator)
{
$validator->after(function ($validator) {
// Note, this function will also resolve CNAMEs for us automatically,
// there is no need to manually resolve them here.
//
// Using @ as workaround to fix https://bugs.php.net/bug.php?id=73149
$records = @dns_get_record($this->input('fqdn'), DNS_A + DNS_AAAA);
if (empty($records)) {
$validator->errors()->add('fqdn', trans('admin/node.validation.fqdn_not_resolvable'));
}
// Check that if using HTTPS the FQDN is not an IP address.
if (filter_var($this->input('fqdn'), FILTER_VALIDATE_IP) && $this->input('scheme') === 'https') {
$validator->errors()->add('fqdn', trans('admin/node.validation.fqdn_required_for_ssl'));
}
});
return $data;
}
}