From 7c80588fd37f15ac1fc4d6543298b9d7024e15f4 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 16 Aug 2016 18:45:22 -0400 Subject: [PATCH] Allow IP if not using SSL --- app/Repositories/NodeRepository.php | 26 +++++++++++++++------- resources/views/admin/nodes/new.blade.php | 2 +- resources/views/admin/nodes/view.blade.php | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/Repositories/NodeRepository.php b/app/Repositories/NodeRepository.php index 873bf2e90..104ba51f6 100644 --- a/app/Repositories/NodeRepository.php +++ b/app/Repositories/NodeRepository.php @@ -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); } diff --git a/resources/views/admin/nodes/new.blade.php b/resources/views/admin/nodes/new.blade.php index 154fc31f5..0856c7c41 100644 --- a/resources/views/admin/nodes/new.blade.php +++ b/resources/views/admin/nodes/new.blade.php @@ -67,7 +67,7 @@
-

This must be a fully qualified domain name, you may not enter an IP address or a domain that does not exist. +

Please enter domain name (e.g node.example.com) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node. Why?

diff --git a/resources/views/admin/nodes/view.blade.php b/resources/views/admin/nodes/view.blade.php index 191a85aae..2d6c01019 100644 --- a/resources/views/admin/nodes/view.blade.php +++ b/resources/views/admin/nodes/view.blade.php @@ -149,7 +149,7 @@
-

This must be a fully qualified domain name, you may not enter an IP address or a domain that does not exist. +

Please enter domain name (e.g node.example.com) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node. Why?