You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ra...@apache.org on 2018/09/21 22:42:54 UTC
[trafficcontrol] 01/03: Add sub to validate user input when running
postinstall script changes default cdn name to not include an underscore.
This is an automated email from the ASF dual-hosted git repository.
rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit e50eeb2c7f46828cbe1d461288f2d98ccdd4ebaa
Author: Dylan Souza <dy...@comcast.com>
AuthorDate: Tue Sep 11 13:01:07 2018 -0600
Add sub to validate user input when running postinstall script changes default cdn name to not include an underscore.
Resolves: #2747
---
traffic_ops/install/bin/_postinstall | 2 +-
traffic_ops/install/bin/input.json | 2 +-
traffic_ops/install/lib/InstallUtils.pm | 40 +++++++++++++++++++++++----------
3 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/traffic_ops/install/bin/_postinstall b/traffic_ops/install/bin/_postinstall
index 586855d..a0f4edd 100755
--- a/traffic_ops/install/bin/_postinstall
+++ b/traffic_ops/install/bin/_postinstall
@@ -569,7 +569,7 @@ sub getDefaults {
"config_var" => "tm.url"
},
{
- "Human-readable CDN Name. (No whitespace, please)" => "kabletown_cdn",
+ "Human-readable CDN Name. (No whitespace, please)" => "kabletownCdn",
"config_var" => "cdn_name"
},
{
diff --git a/traffic_ops/install/bin/input.json b/traffic_ops/install/bin/input.json
index 871b139..9ff17d2 100644
--- a/traffic_ops/install/bin/input.json
+++ b/traffic_ops/install/bin/input.json
@@ -136,7 +136,7 @@
"config_var":"tm.url"
},
{
- "Human-readable CDN Name. (No whitespace, please)":"kabletown_cdn",
+ "Human-readable CDN Name. (No whitespace, please)":"kabletownCdn",
"config_var":"cdn_name"
},
{
diff --git a/traffic_ops/install/lib/InstallUtils.pm b/traffic_ops/install/lib/InstallUtils.pm
index a7df222..738c270 100644
--- a/traffic_ops/install/lib/InstallUtils.pm
+++ b/traffic_ops/install/lib/InstallUtils.pm
@@ -23,9 +23,9 @@ package InstallUtils;
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -127,24 +127,40 @@ sub randomWord {
return $secret;
}
+# Any checks to user input configurations can be implemented in this functions.
+sub sanitize{
+ my ($promptString, $userInput) = @_;
+ if (index($promptString, "Human-readable CDN Name") != -1){
+ if ($userInput =~ m/[^-a-zA-Z0-9]/){
+ print "Invalid characters in user input. Try again.\n\n";
+ return false;
+ }
+ }
+ return true;
+}
+
sub promptUser {
my ( $promptString, $defaultValue, $noEcho ) = @_;
- if ($defaultValue) {
- print $promptString, " [", $defaultValue, "]: ";
- }
- else {
- print $promptString, ": ";
- }
-
if ( defined $noEcho && $noEcho ) {
# Set echo mode to off via ReadMode 2
ReadMode 2;
}
- $| = 1;
- $_ = <STDIN>;
- chomp;
+ # Check user input for invalid characters
+ my $sanitized = false;
+ while ($sanitized eq false){
+ if ($defaultValue) {
+ print $promptString, " [", $defaultValue, "]: ";
+ }
+ else {
+ print $promptString, ": ";
+ }
+ $| = 1;
+ $_ = <STDIN>;
+ chomp;
+ $sanitized = sanitize($promptString, $_)
+ }
if ( defined $noEcho && $noEcho ) {
# Set echo mode to on via ReadMode 1