diff --git a/.gitignore b/.gitignore index c4ce7c3ec23318cf3f7ac331d1482417ae0d81f5..c656ce7151bae18b5ef1b7c6ff16bb1271fb4898 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .sass-cache dist node_modules -src/conf/config.ini +src/conf/config.ini* +!src/conf/config.ini.orig src/conf/httpd.conf src/lib/ProductClient.jar diff --git a/src/conf/config.ini.orig b/src/conf/config.ini.orig index 140bfb0ac3a3505f998d98265e8bd939ba70fa15..5c01f97132bd33e351fb3ebaa9a245fcf38fbb49 100644 --- a/src/conf/config.ini.orig +++ b/src/conf/config.ini.orig @@ -1,2 +1,20 @@ -MOUNT_PATH='/absolute/url/path'; -MOUNT_DIR='/absolute/file_system/path'; +MOUNT_PATH = "/mountpath" +SEARCH_STUB = "/query?format=geojson" +OFFSITE_HOST = "hostname.tld" +PDL_JAR_FILE = "/some/path/ProductClient.jar" +PDL_SERVERS = "hostname.tld:port" +PDL_PRIVATE_KEY = "/some/path/id_rsa" +SQUID_SERVERS = "server1,server2" +SQUID_HOSTNAMES = "cname1,cname2" +SESSION_DB_DRIVER = "mysql" +SESSION_DB_HOST = "hostname.tld" +SESSION_DB_PORT = "port" +SESSION_DB_NAME = "dbname" +SESSION_DB_TABLE = "tablename" +SESSION_DB_USER = "adminuser" +SESSION_DB_PASS = "adminpassword" +AD_HOST = "host.tld" +AD_USER = "username" +AD_PASS = "password" +AD_BASE_DN = "DC=dom,DC=tld" +AD_GROUP = "groupname" diff --git a/src/lib/configure.inc.php b/src/lib/configure.inc.php index 04d68c6928fc7accaf1c2a71bcc8929cb487c3d6..ff71a14a5fea5eba54d40e23f3c0427cb146a23c 100644 --- a/src/lib/configure.inc.php +++ b/src/lib/configure.inc.php @@ -1,38 +1,6 @@ <?php -if (!function_exists('configure')) { - function configure ($prompt, $default = null, $secure = false) { - - echo $prompt; - if ($default != null) { - echo ' [' . $default . ']'; - } - echo ': '; - - if (NON_INTERACTIVE) { - // non-interactive - echo '(Non-interactive, using default)' . PHP_EOL; - return $default; - } - - if ($secure) { - system('stty -echo'); - } - - $answer = trim(fgets(STDIN)); - - if ($answer == '') { - $answer = $default; - } - - if ($secure) { - system('stty echo'); - echo "\n"; - } - - return $answer; - } -} +include_once './functions.inc.php'; // This script should only be included by the pre-install.php script. The // calling script is responsible for defining the $CONFIG_FILE_INI and calling @@ -40,18 +8,14 @@ if (!function_exists('configure')) { $CONFIG = array(); if (file_exists($CONFIG_FILE_INI)) { - $answer = configure('A previous configuration exists. ' . - 'Would you like to use it as defaults?', 'Y|n', false); - - if (strtoupper(substr($answer, 0, 1)) == 'Y') { + if (promptYesNo('A previous configuration exists. ' . + 'Would you like to use it as defaults?', true)) { $CONFIG = parse_ini_file($CONFIG_FILE_INI); print_r($CONFIG); } - $answer = configure('Would you like to save the old configuration file?', - 'Y|n', false); - - if (strtoupper(substr($answer, 0, 1)) == 'Y') { + if (promptYesNo('Would you like to save the old configuration file?', + false)) { $BAK_CONFIG_FILE = $CONFIG_FILE_INI . '.' . date('YmdHis'); rename($CONFIG_FILE_INI, $BAK_CONFIG_FILE); echo 'Old configuration saved to file: ' . basename($BAK_CONFIG_FILE) . @@ -159,7 +123,7 @@ $prompts = array( 'SESSION_DB_PASS' => array( 'prompt' => 'Session database user password', 'default' => '', - 'secure' => false + 'secure' => true ), @@ -178,7 +142,7 @@ $prompts = array( 'AD_PASS' => array( 'prompt' => 'Active directory user password', 'default' => '', - 'secure' => false + 'secure' => true ), 'AD_BASE_DN' => array( diff --git a/src/lib/functions.inc.php b/src/lib/functions.inc.php index ec9236086ca92ae9e985a8718f143d262f25316a..4e8f26e3c857d84a7793b730f60bd1dfe47eb735 100644 --- a/src/lib/functions.inc.php +++ b/src/lib/functions.inc.php @@ -1,5 +1,35 @@ <?php +function configure ($prompt, $default = null, $secure = false) { + echo $prompt; + if ($default != null) { + echo ' [' . $default . ']'; + } + echo ': '; + + if (NON_INTERACTIVE) { + // non-interactive + echo '(Non-interactive, using default)' . PHP_EOL; + return $default; + } + + if ($secure) { + system('stty -echo'); + } + + $answer = trim(fgets(STDIN)); + + if ($answer == '') { + $answer = $default; + } + + if ($secure) { + system('stty echo'); + echo "\n"; + } + + return $answer; +} /** * Prompt user with a yes or no question. @@ -12,14 +42,23 @@ * default answer is used when user presses enter with no other input. * @return {Boolean} true if user entered yes, false if user entered no. */ -function promptYesNo ($prompt='Yes or no?', $default=null) { +function promptYesNo ($prompt='Yes or no?', $default=false) { $question = $prompt . ' [' . - ($default === true ? 'Y' : 'y') . '/' . - ($default === false ? 'N' : 'n') . ']: '; + ($default == true ? 'Y' : 'y') . '|' . + ($default == false ? 'N' : 'n') . ']: '; + $answer = null; + while ($answer === null) { echo $question; - $answer = strtoupper(trim(fgets(STDIN))); + + if (NON_INTERACTIVE) { + echo '(Non-interactive, using default)' . PHP_EOL; + $answer = ($default) ? 'Y' : 'N'; + } else { + $answer = strtoupper(trim(fgets(STDIN))); + } + if ($answer === '') { if ($default === true) { $answer = 'Y'; @@ -27,6 +66,7 @@ function promptYesNo ($prompt='Yes or no?', $default=null) { $answer = 'N'; } } + if ($answer !== 'Y' && $answer !== 'N') { $answer = null; echo PHP_EOL; diff --git a/src/lib/pre-install.php b/src/lib/pre-install.php index fb7996721896b73b4a449a76a4ba8821b7140f1e..715771fb0094d063f8cae532fd780926db7faa06 100644 --- a/src/lib/pre-install.php +++ b/src/lib/pre-install.php @@ -69,13 +69,13 @@ file_put_contents($HTTPD_CONF, ' include_once './functions.inc.php'; if (!file_exists($CONFIG['PDL_JAR_FILE'])) { - if (NON_INTERACTIVE || promptYesNo('Download PDL Jar File?')) { + if (promptYesNo('Download PDL Jar File?')) { downloadURL( - 'http://ehppdl1.cr.usgs.gov/ProductClient/ProductClient.jar', + 'https://ehppdl1.cr.usgs.gov/ProductClient/ProductClient.jar', $CONFIG['PDL_JAR_FILE']); } } -if (promptYesNo('Would you like to setup the database or load data', true)) { - include_once 'setup_database.php'; +if (promptYesNo('Would you like to setup the database or load data')) { + include_once './setup_database.php'; }