diff --git a/install.php b/install.php index 7cafce3..8edb6fc 100644 --- a/install.php +++ b/install.php @@ -29,14 +29,44 @@ */ include_once "includes/global.php"; -if ($_REQUEST["step"] != "50" || $_REQUEST["refresh"] != "") { +if ($_REQUEST["step"] != "80" || $_REQUEST["refresh"] != "") { include_once "includes/page_head.php"; } -// allow the upgrade script to run for as long as it needs to +// Allow the upgrade script to run for as long as it needs to ini_set("max_execution_time", "0"); -// check if the necessary PHP extensions are loaded +// Some variables and HTML snippets +$input_err = ""; +$page_foot = " + + + +"; +$error_head = "

Error

"; + +// Check if the necessary PHP functions are enabled +$funcs = array("popen"); +$func_ena = true; +foreach ($funcs as $func) { + if (!function_exists($func)){ + $func_ena = false; + $func_miss .= "
  • $func
  • \n"; + } +} +if (!$func_ena) { + echo $error_head; + echo " +

    The following PHP functions are missing:

    + +

    Please enable those PHP functions in your php.ini and retry the installation process.

    "; + echo $page_foot; + exit; +} + +// Check if the necessary PHP extensions are loaded $exts = array("session", "sockets"); $ext_load = true; foreach ($exts as $ext) { @@ -46,156 +76,255 @@ foreach ($exts as $ext) { } } if (!$ext_load) { + echo $error_head; echo " -

    Error

    The following PHP extensions are missing:

    -

    Please install those PHP extensions and retry the installation process.

    - - - -"; +

    Please install those PHP extensions and retry the installation process.

    "; + echo $page_foot; exit; } +// Try to find current (old) version in the array $tsm_monitor_versions = array("0.1.0", "0.1.1"); - -$old_tsm_monitor_version = $adodb->fetchCellDB("select confval from cfg_config where confkey='version'", ''); - -// try to find current (old) version in the array +$old_tsm_monitor_version = $adodb->fetchCellDB("SELECT confval FROM cfg_config WHERE confkey='version'", ''); $old_version_index = array_search($old_tsm_monitor_version, $tsm_monitor_versions); -// do a version check +// Do a version check if ($old_tsm_monitor_version == $config["tsm_monitor_version"]) { + echo $error_head; echo " -

    Error

    -

    This installation is already up-to-date. Click here to use TSM Monitor.

    - - - -"; +

    This installation is already up-to-date. Click here to use TSM Monitor.

    "; + echo $page_foot; exit; -} elseif (empty($old_tsm_monitor_version)) { +} else if (empty($old_tsm_monitor_version)) { + echo $error_head; echo " -

    Error

    You have created a new database, but have not yet imported the 'tsmmonitor.sql' file. At the command line, execute the following to continue:

    mysql -u $db_user -p $db_password < tsmmonitor.sql

    This error may also be generated if the TSM Monitor database user does not have correct permissions on the TSM Monitor database.
    - Please ensure that the TSM Monitor database user has the ability to SELECT, INSERT, DELETE, UPDATE, CREATE, ALTER, DROP, INDEX on the TSM Monitor database.

    - - - -"; + Please ensure that the TSM Monitor database user has the ability to SELECT, INSERT, DELETE, UPDATE, CREATE, ALTER, DROP, INDEX on the TSM Monitor database.

    "; + echo $page_foot; exit; } -// dsmadmc binary path -$input["path_dsmadmc"]["name"] = "dsmadmc Binary Path"; -$input["path_dsmadmc"]["desc"] = "The path to the TSM admin client binary."; -$which_dsmadmc = $tsmmonitor->findPath("dsmadmc", $config["search_path"]); -if (isset($tsmmonitor->configarray["settings"]["path_dsmadmc"])) { - $input["path_dsmadmc"]["default"] = $tsmmonitor->configarray["settings"]["path_dsmadmc"]; -} else if (!empty($which_dsmadmc)) { - $input["path_dsmadmc"]["default"] = $which_dsmadmc; -} else { - $input["path_dsmadmc"]["default"] = "dsmadmc"; -} - -// php/php5 binary path -$input["path_php"]["name"] = "PHP Binary Path"; -$input["path_php"]["desc"] = "The path to the PHP binary."; -$which_php = $tsmmonitor->findPath("php", $config["search_path"]); -if(!isset($which_php)) { - $which_php = $tsmmonitor->findPath("php5", $config["search_path"]); -} -if (isset($tsmmonitor->configarray["settings"]["path_php"])) { - $input["path_php"]["default"] = $tsmmonitor->configarray["settings"]["path_php"]; -} else if (!empty($which_php)) { - $input["path_php"]["default"] = $which_php; -} else { - $input["path_php"]["default"] = "php"; -} - -// logfile path -$input["path_tmlog"]["name"] = "TSM Monitor Logfile Path"; -$input["path_tmlog"]["desc"] = "The path to the TSM Monitor log file."; -if (isset($tsmmonitor->configarray["settings"]["path_tmlog"])) { - $input["path_tmlog"]["default"] = $tsmmonitor->configarray["settings"]["path_tmlog"]; -} else { - $input["path_tmlog"]["default"] = $config["base_path"] . "tsmmonitor.log"; -} - -// default for the install type +// Default for the install type if (!isset($_REQUEST["install_type"])) { $_REQUEST["install_type"] = 0; } -// defaults for the install type dropdown +// Defaults for the install type dropdown if ($old_tsm_monitor_version == "new_install") { $default_install_type = "10"; } else { $default_install_type = "20"; } -// pre-processing that needs to be done for each step +// Pre-processing that needs to be done for each step // Intro and license page if (empty($_REQUEST["step"])) { + // Unset config data remaining from potential previous calls + unset($_SESSION["install"]); $_REQUEST["step"] = 10; } else { - // Install or update chooser + // Install or update chooser page if ($_REQUEST["step"] == "10") { $_REQUEST["step"] = "20"; - } elseif (($_REQUEST["step"] == "20") && ($_REQUEST["install_type"] == "10")) { - $_REQUEST["step"] = "30"; - } elseif (($_REQUEST["step"] == "20") && ($_REQUEST["install_type"] == "20")) { - $_REQUEST["step"] = "40"; - // Install - } elseif ($_REQUEST["step"] == "30") { - $_REQUEST["step"] = "50"; - // Update - } elseif ($_REQUEST["step"] == "40") { - $_REQUEST["step"] = "50"; - } elseif (($_REQUEST["step"] == "50") && ($_POST["refresh"] == "Refresh")) { - $_REQUEST["step"] = "50"; - // get (possibly) updated values from the forms - foreach ($input as $name => $array) { - if (isset($_POST[$name])) { - $input[$name]["default"] = $_POST[$name]; + } + // Initial admin user password page + elseif ($_REQUEST["step"] == "20") { + if ($_REQUEST["install_type"] == "10") { + $_REQUEST["step"] = "30"; + } elseif ($_REQUEST["install_type"] == "20") { + $_REQUEST["step"] = "60"; + } + } + // Binary and logfile path page + elseif ($_REQUEST["step"] == "30") { + // Check if passwords are not empty and match + if ($_POST["adminpw"] == "" || $_POST["adminpwr"] == "") { + $input_err = "Empty passwords are not allowed."; + $_REQUEST["step"] = "30"; + } else if ($_POST["adminpw"] != $_POST["adminpwr"]) { + $input_err = "Passwords do not match."; + $_REQUEST["step"] = "30"; + } else { + $_REQUEST["step"] = "40"; + $_SESSION["install"]["adminpw"] = md5($_POST["adminpw"]); + + // dsmadmc binary path + $_SESSION["install"]["paths"]["path_dsmadmc"]["name"] = "dsmadmc Binary Path"; + $_SESSION["install"]["paths"]["path_dsmadmc"]["desc"] = "The path to the TSM admin client binary."; + $which_dsmadmc = $tsmmonitor->findPath("dsmadmc", $config["search_path"]); + if (isset($tsmmonitor->configarray["settings"]["paths"]["path_dsmadmc"])) { + $_SESSION["install"]["paths"]["path_dsmadmc"]["default"] = $tsmmonitor->configarray["settings"]["path_dsmadmc"]; + } else if (!empty($which_dsmadmc)) { + $_SESSION["install"]["paths"]["path_dsmadmc"]["default"] = $which_dsmadmc; + } else { + $_SESSION["install"]["paths"]["path_dsmadmc"]["default"] = "dsmadmc"; + } + + // php/php5 binary path + $_SESSION["install"]["paths"]["path_php"]["name"] = "PHP Binary Path"; + $_SESSION["install"]["paths"]["path_php"]["desc"] = "The path to the PHP binary."; + $which_php = $tsmmonitor->findPath("php", $config["search_path"]); + if(!isset($which_php)) { + $which_php = $tsmmonitor->findPath("php5", $config["search_path"]); + } + if (isset($tsmmonitor->configarray["settings"]["paths"]["path_php"])) { + $_SESSION["install"]["paths"]["path_php"]["default"] = $tsmmonitor->configarray["settings"]["path_php"]; + } else if (!empty($which_php)) { + $_SESSION["install"]["paths"]["path_php"]["default"] = $which_php; + } else { + $_SESSION["install"]["paths"]["path_php"]["default"] = "php"; + } + + // Logfile path + $_SESSION["install"]["paths"]["path_tmlog"]["name"] = "TSM Monitor Logfile Path"; + $_SESSION["install"]["paths"]["path_tmlog"]["desc"] = "The path to the TSM Monitor log file."; + if (isset($tsmmonitor->configarray["settings"]["paths"]["path_tmlog"])) { + $_SESSION["install"]["paths"]["path_tmlog"]["default"] = $tsmmonitor->configarray["settings"]["path_tmlog"]; + } else { + $_SESSION["install"]["paths"]["path_tmlog"]["default"] = $config["base_path"] . "tsmmonitor.log"; } } - } elseif ($_REQUEST["step"] == "50") { - $_REQUEST["step"] = "90"; + } + // Refresh of binary and logfile path page or server definition page + elseif ($_REQUEST["step"] == "40") { + if ($_POST["refresh"] == "Refresh") { + $_REQUEST["step"] = "40"; + } else { + // Get server entries already in db + $sql = "SELECT * FROM cfg_servers"; + $srvres = $adodb->fetchArrayDB($sql); + $_REQUEST["step"] = "50"; + } + foreach ($_SESSION["install"]["paths"] as $name => $array) { + if (isset($_POST[$name])) { + $_SESSION["install"]["paths"][$name]["default"] = $_POST[$name]; + } + } + } + // Refresh/add on server definition page or finish page + elseif ($_REQUEST["step"] == "50") { + // Get server entries already in db + $sql = "SELECT * FROM cfg_servers"; + $srvres = $adodb->fetchArrayDB($sql); + + if ($_POST["addsrv"] == "Add") { + $_REQUEST["step"] = "50"; + // Get (possibly) updated values from the forms + if (isset($_POST)) { + $tmp_err = ""; + foreach ($_POST as $key => $val) { + if (ereg("^srv_.*", $key)) { + if (($key == "srv_description") || ($val != "")) { + if ($key == "srv_servername") { + $server[$key] = strtoupper($val); + } else { + $server[$key] = $val; + } + } else { + $tmp_key = ereg_replace("^srv_(.*)", "\\1", $key); + $tmp_err .= " ".(($tmp_key == "ip" ) ? strtoupper($tmp_key) : ucfirst($tmp_key)); + } + } + } + if ($tmp_err != "") { + $input_err = "Missing parameter: ".$tmp_err; + } + } + + $sql = "SELECT * FROM cfg_servers WHERE servername='".$server['srv_servername']."'"; + $srvadd = $adodb->fetchArrayDB($sql); + if (isset($srvadd[0])) { + $input_err = "Server already configured in database."; + } + + if ($input_err == "") { + $dsmadmc = $_SESSION["install"]["paths"]["path_dsmadmc"]["default"]; + if (file_exists($dsmadmc) && is_executable($dsmadmc)) { + $oh = popen($dsmadmc." -se=".$server['srv_servername']." -id=".$server['srv_username']." -password=".$server['srv_password']." -TCPServeraddress=".$server['srv_ip']." -COMMMethod=TCPIP -TCPPort=".$server['srv_port']." -dataonly=yes -TAB \"SELECT SERVER_HLA,SERVER_LLA FROM status\" ", 'r'); + if ($oh != 0) { + while (!feof($oh)) { + $read = fgets($oh, 4096); + if (ereg("^ANS.*", $read)) { + $input_err .= "$read "; + } + } + } else { + $input_err = "Cannot open connection to the TSM server. Check the servername,
    username, password and the server entries in dsm.sys or dsm.opt."; + } + pclose($oh); + } else { + $input_err = "$dsmadmc not found or not executeable."; + } + + if ($input_err == "") { + $_SESSION["install"]["servers"][$server['srv_servername']] = $server; + } + } + } elseif (!isset($_SESSION['install']['servers']) && !isset($srvres[0])) { + $_REQUEST["step"] = "50"; + } else { + $_REQUEST["step"] = "80"; + } + } + // Update page + elseif ($_REQUEST["step"] == "60") { + $_REQUEST["step"] = "80"; + } + // Refresh on php limits page or finish and flush data to db + elseif ($_REQUEST["step"] == "80") { + if ($_POST["refresh"] == "Refresh") { + $_REQUEST["step"] = "80"; + } else { + $_REQUEST["step"] = "90"; + } } } if ($_REQUEST["step"] == "90") { // Flush updated data to DB - foreach ($input as $name => $array) { - if (isset($_POST[$name])) { - $adodb->updateDB('cfg_config', array(confkey => "$name", confval => $_POST[$name], description => $array['name']), 'confkey'); + foreach ($_SESSION["install"]["paths"] as $name => $array) { + $adodb->updateDB('cfg_config', array(confkey => "$name", confval => $array["default"], description => $array["name"]), 'confkey'); + } + if (isset($_SESSION["install"]["servers"])) { + foreach ($_SESSION["install"]["servers"] as $name => $array) { + $sqlcols = array(); + $sqlvals = array(); + foreach ($array as $col => $val) { + $tmp_col = ereg_replace("^srv_(.*)", "\\1", $col); + $tmp_col = "`".$tmp_col."`"; + $tmp_val = "'".$val."'"; + array_push($sqlcols, $tmp_col); + array_push($sqlvals, $tmp_val); + } + $sql = "INSERT INTO cfg_servers (".(implode(",", $sqlcols)).") VALUES (".(implode(",", $sqlvals)).")"; + $adodb->execDB($sql); } } + $adodb->updateDB('cfg_users', array(username => 'admin', password => $_SESSION["install"]["adminpw"]), 'username'); + + // set new version, disable installer and redirect to login page $adodb->updateDB('cfg_config', array(confkey => 'version', confval => $config['tsm_monitor_version']), 'confkey'); $adodb->closeDB(); header("Location: index.php"); exit; -} elseif (($_REQUEST["step"] == "40") && ($_REQUEST["install_type"] == "20")) { - // if the version is not found, die +} elseif (($_REQUEST["step"] == "60") && ($_REQUEST["install_type"] == "20")) { + // If the version is not found, die if (!is_int($old_version_index)) { + echo $error_head; echo " -

    Error

    Invalid TSM Monitor version $old_tsm_monitor_version, cannot upgrade to ".$config["tsm_monitor_version"]." -

    - - - -"; +

    "; + echo $page_foot; exit; } - // loop over all versions up to the current and perform incremental updates + // Loop over all versions up to the current and perform incremental updates for ($i = ($old_version_index+1); $i < count($tsm_monitor_versions); $i++) { if ($tsm_monitor_versions[$i] == "0.1.0") { include "install/0_1_0_to_0_1_1.php"; @@ -230,7 +359,7 @@ if ($_REQUEST["step"] == "90") {
    - @@ -270,7 +399,7 @@ if ($_REQUEST["step"] == "90") { along with TSM Monitor. If not, see http://www.gnu.org/licenses/.

    - @@ -283,24 +412,37 @@ if ($_REQUEST["step"] == "90") {

    -

    - Installation stuff could be done here ... -

    - - admin' needs a initial password. + Please choose a password according to your password policies and enter it below. + The default 'admin' user has full rights to the TSM Monitor application, which + is why we recommend using a non-trivial and secure password. Additional users + with less privileges can be created from within TSM Monitor after this install + process is finished. +

    +

    + ERROR: $input_err"; + } ?> - -

    - Upgrade stuff could be done here ... -

    - - + + + + + + + + + +
    Password
    Password (repeat)
    +

    @@ -308,8 +450,8 @@ if ($_REQUEST["step"] == "90") { system and correct if necessary.

    $array) { - if (isset($input[$name])) { + foreach ($_SESSION["install"]["paths"] as $name => $array) { + if (isset($_SESSION["install"]["paths"][$name])) { $file = $array["default"]; $resStr = ""; $capStr = ""; @@ -338,19 +480,153 @@ if ($_REQUEST["step"] == "90") { } ?> -

    - NOTE: Once you click "Finish", the above settings will be - saved "as-is" to the TSM Monitor database. No further validation will be - performed, so please make sure the above settings are correct! Any of the - above settings can later on be changed with the TSM Monitor admin web - interface. -
    - If you did choose to upgrade from a previous version of TSM Monitor, the - database will also be upgraded by clicking "Finish". -

    +

    - PHP memory_limit settings: Default or configured PHP limits + Defined TSM servers in database: +

    + + + fetchArrayDB($sql); + + $th = ""; + foreach ($srvresth as $col) { + if ($col['Field'] != "id") { + if ($col['Field'] == "ip") { + if ((isset($srvres)) && (count($srvres) != 0)) + $th .= ""; + } else { + if ((isset($srvres)) && (count($srvres) != 0)) + $th .= ""; + } + $fields[$col['Field']]['type'] = ereg_replace("([a-z]+)\(.*", "\\1", $col['Type']); + $fields[$col['Field']]['len'] = ereg_replace("[a-z]+\(([0-9]+)\)", "\\1", $col['Type']); + } + } + $th .= ""; + echo "$th"; + + if ((isset($srvres)) && (count($srvres) != 0)) { + foreach ($srvres as $row) { + echo ""; + foreach ($row as $key => $val) { + if ($key != "id") { + if (($key == "libraryclient") || ($key == "default")) { + if ($val == 0 ) { + echo ""; + } else { + echo ""; + } + } else { + echo ""; + } + } + } + echo ""; + } + } else { + echo ""; + } + ?> + +
    ".strtoupper($col['Field'])."".ucfirst($col['Field'])."
    NoYes".$val."
    No TSM server configured in database.
    +

    + Defined TSM servers in the installer session cache: +

    + + "; + foreach ($row as $key => $val) { + if ($key != "id") { + if (($key == "srv_libraryclient") || ($key == "srv_default")) { + if ($val == 0 ) { + echo ""; + } else { + echo ""; + } + } else { + echo ""; + } + } + } + echo ""; + } + } else { + echo ""; + } + ?> + +
    NoYes".$val."
    No TSM server configured in session cache.
    +

    +
    Please define at least one TSM server to be monitored: +

    +

    + ERROR: $input_err"; + } + ?> +

    + + "; + if ($col['Field'] == "ip") { + echo ""; + } else { + echo ""; + } + + if ($input_err != "") { + $value = $_POST["srv_".$col['Field']]; + } + if ($col['Field'] == "password") { + echo ""; + } elseif (($col['Field'] == "libraryclient") || ($col['Field'] == "default")) { + echo ""; + } else { + echo ""; + } + echo ""; + } + } + ?> +
    ".strtoupper($col['Field'])."".ucfirst($col['Field'])."
    + + + +

    + Sorry, this is the initial TSM Monitor version, there are currently no + updates from previous versions available. Please choose "New install" + on the previous page. +

    + + +

    + Default or configured PHP limits +

    +

    + PHP memory_limit settings: - + +

    + NOTE: Once you click "Finish", the previous settings will + be saved "as-is" to the TSM Monitor database. No further validation will + be performed, so please make sure the above settings are correct! Any of + the above settings can later on be changed with the TSM Monitor admin web + interface. +
    + If you did choose to upgrade from a previous version of TSM Monitor, the + database will also be upgraded by clicking "Finish". +

    + @@ -437,16 +720,23 @@ if ($_REQUEST["step"] == "90") { - + -
     
    +

    - - + + + + + +

    + + @@ -468,8 +758,4 @@ if ($_REQUEST["step"] == "90") {

    - - - - +