Allow IP if not using SSL

This commit is contained in:
Dane Everitt 2016-08-16 18:45:22 -04:00
parent 81da5766f9
commit 7c80588fd3
3 changed files with 20 additions and 10 deletions

View File

@ -64,12 +64,14 @@ class NodeRepository {
throw new DisplayValidationException($validator->errors());
}
// Verify the FQDN
if (filter_var($data['fqdn'], FILTER_VALIDATE_IP)) {
throw new DisplayException('The FQDN provided was an IP address. You must use a FQDN.');
// Verify the FQDN if using SSL
if (filter_var($data['fqdn'], FILTER_VALIDATE_IP) && $data['scheme'] === 'https') {
throw new DisplayException('A fully qualified domain name is required to use secure comunication on this node.');
}
// Verify FQDN is resolvable, or if not using SSL that the IP is valid.
if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
throw new DisplayException('The FQDN provided does not resolve to a valid IP address.');
throw new DisplayException('The FQDN (or IP Address) provided does not resolve to a valid IP address.');
}
// Should we be nulling the overallocations?
@ -91,6 +93,8 @@ class NodeRepository {
public function update($id, array $data)
{
$node = Models\Node::findOrFail($id);
// Validate Fields
$validator = $validator = Validator::make($data, [
'name' => 'regex:/^([\w .-]{1,100})$/',
@ -116,12 +120,19 @@ class NodeRepository {
// Verify the FQDN
if (isset($data['fqdn'])) {
if (filter_var($data['fqdn'], FILTER_VALIDATE_IP)) {
throw new DisplayException('The FQDN provided was an IP address. You must use a FQDN.');
// Verify the FQDN if using SSL
if ((isset($data['scheme']) && $data['scheme'] === 'https') || (!isset($data['scheme']) && $node->scheme === 'https')) {
if (filter_var($data['fqdn'], FILTER_VALIDATE_IP)) {
throw new DisplayException('A fully qualified domain name is required to use secure comunication on this node.');
}
}
// Verify FQDN is resolvable, or if not using SSL that the IP is valid.
if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
throw new DisplayException('The FQDN provided does not resolve to a valid IP address.');
throw new DisplayException('The FQDN (or IP Address) provided does not resolve to a valid IP address.');
}
}
// Should we be nulling the overallocations?
@ -141,7 +152,6 @@ class NodeRepository {
}
// Store the Data
$node = Models\Node::findOrFail($id);
return $node->update($data);
}

View File

@ -67,7 +67,7 @@
<div>
<input type="text" autocomplete="off" name="fqdn" class="form-control" value="{{ old('fqdn') }}" />
</div>
<p class="text-muted"><small>This <strong>must</strong> be a fully qualified domain name, you may not enter an IP address or a domain that does not exist.
<p class="text-muted"><small>Please enter domain name (e.g <code>node.example.com</code>) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node.
<a tabindex="0" data-toggle="popover" data-trigger="focus" title="Why do I need a FQDN?" data-content="In order to secure communications between your server and this node we use SSL. We cannot generate a SSL certificate for IP Addresses, and as such you will need to provide a FQDN.">Why?</a>
</small></p>
</div>

View File

@ -149,7 +149,7 @@
<div>
<input type="text" autocomplete="off" name="fqdn" class="form-control" value="{{ old('fqdn', $node->fqdn) }}" />
</div>
<p class="text-muted"><small>This <strong>must</strong> be a fully qualified domain name, you may not enter an IP address or a domain that does not exist.
<p class="text-muted"><small>Please enter domain name (e.g <code>node.example.com</code>) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node.
<a tabindex="0" data-toggle="popover" data-trigger="focus" title="Why do I need a FQDN?" data-content="In order to secure communications between your server and this node we use SSL. We cannot generate a SSL certificate for IP Addresses, and as such you will need to provide a FQDN.">Why?</a>
</small></p>
</div>