2017-08-05 22:20:07 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-08-05 22:20:07 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-08-05 22:20:07 +00:00
|
|
|
*/
|
|
|
|
|
2017-08-06 02:10:32 +00:00
|
|
|
namespace Pterodactyl\Http\Requests\Admin\Node;
|
2017-08-05 22:20:07 +00:00
|
|
|
|
|
|
|
use Pterodactyl\Models\Node;
|
2017-08-06 02:10:32 +00:00
|
|
|
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
|
2017-08-05 22:20:07 +00:00
|
|
|
|
|
|
|
class NodeFormRequest extends AdminFormRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get rules to apply to data in this request.
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
if ($this->method() === 'PATCH') {
|
2019-09-05 05:26:28 +00:00
|
|
|
return Node::getRulesForUpdate($this->route()->parameter('node'));
|
2017-08-05 22:20:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 05:26:28 +00:00
|
|
|
return Node::getRules();
|
2017-08-05 22:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run validation after the rules above have been applied.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Validation\Validator $validator
|
|
|
|
*/
|
|
|
|
public function withValidator($validator)
|
|
|
|
{
|
|
|
|
$validator->after(function ($validator) {
|
2022-10-05 02:03:52 +00:00
|
|
|
// 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)) {
|
2017-08-05 22:20:07 +00:00
|
|
|
$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'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|