From 228d07c602091d117b71e34cedbc629c4b489751 Mon Sep 17 00:00:00 2001 From: Frank Fegert Date: Sun, 10 May 2009 21:04:57 +0000 Subject: [PATCH] - added checks for PHP extension modules. - added checks for external binaries (dsmadmc, php) and logfile. --- includes/functions.php | 42 +++- includes/global.php | 11 + install.php | 219 ++++++++++++++---- .../{0_1_to_0_1_1.php => 0_1_0_to_0_1_1.php} | 0 4 files changed, 220 insertions(+), 52 deletions(-) rename install/{0_1_to_0_1_1.php => 0_1_0_to_0_1_1.php} (100%) diff --git a/includes/functions.php b/includes/functions.php index e04d36c..ab90286 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -85,8 +85,8 @@ function initialize() { $configarray = $_SESSION['configarray']; // timeout - if( !ini_get('safe_mode') && ini_get('max_execution_time') != $configarray["timeout"]) { - ini_set('max_execution_time', $configarray["timeout"]); + if( !ini_get('safe_mode') && ini_get('max_execution_time') != $configarray["settings"]["timeout"]) { + ini_set('max_execution_time', $configarray["settings"]["timeout"]); } // set defaults if vars are empty @@ -1318,7 +1318,7 @@ function getConfigArray() { global $conn; $retArray = array(); - //Navigation + // Navigation $query = "SELECT * from cfg_mainmenu"; $mainmenutablerows = fetchArrayDB($query, $conn); @@ -1387,7 +1387,7 @@ function getConfigArray() { $adminmenuarray["q=logout"] = "Logout"; $retArray["adminmenuarray"] = $adminmenuarray; - //Overview Boxes + // Overview Boxes $ret = array(); $query = "SELECT * from cfg_overviewboxes order by sortorder asc"; @@ -1405,7 +1405,7 @@ function getConfigArray() { } $retArray["infoboxarray"] = $ret; - //Queries + // Queries $dbret = array(); $query = "SELECT * from cfg_queries"; $querytablerows = fetchArrayDB($query, $conn); @@ -1414,17 +1414,21 @@ function getConfigArray() { } $retArray["queryarray"] = $dbret; - // Set Timeout - $query = "SELECT * from cfg_config where confkey='timeout'"; - $row = fetchArrayDB($query, $conn); - $retArray["timeout"] = $row[0]['confval']; + // General settings + $query = "SELECT * from cfg_config"; + $rows = fetchArrayDB($query, $conn); + $ret = array(); + foreach ($rows as $key => $val) { + $ret[$val['confkey']] = $val['confval']; + } + $retArray["settings"] = $ret; // Set Stylesheet $query = "SELECT stylesheet from cfg_users where username='".$_SESSION["logindata"]["user"]."'"; $row = fetchArrayDB($query, $conn); $retArray["stylesheet"] = $row[0]['stylesheet']; - //Colors + // Colors $query = "SELECT * from cfg_colors"; $rows = fetchArrayDB($query, $conn); @@ -1451,6 +1455,22 @@ function getConfigArray() { } +/** + * findPath - find a external program in the search path + * + * @param string $binary the external program to search for + * @param string $search_path the search path in which to look for the external program + * @return string the full path to the external program or empty string if not found + */ +function findPath($binary, $search_path) { + foreach ($search_path as $path) { + if ((file_exists($path . "/" . $binary)) && (is_readable($path . "/" . $binary))) { + return($path . "/" . $binary); + } + } +} + + /** * connectDB - establish a DB connection via ADODB * @@ -1670,7 +1690,7 @@ function fetchSplitArrayDB($sql, $DBconn = FALSE, $rows_per_page = '20') { * @return string Auto-increment ID if insert was performed */ function updateDB($table, $cells, $keys, $DBconn = FALSE, $autoquote = TRUE) { -// $DBconn->debug = true; + //$DBconn->debug = true; $DBconn->Replace($table, $cells, $keys, $autoquote); return $DBconn->Insert_ID(); diff --git a/includes/global.php b/includes/global.php index 30d6dd4..f0aeca2 100644 --- a/includes/global.php +++ b/includes/global.php @@ -57,7 +57,18 @@ $config = array(); // ** Current TSM Monitor version ** // $config["tsm_monitor_version"] = '0.1.0'; +// ** Set TSM Monitor server OS to a general value (only 'unix' or 'win32') ** // +$config["server_os"] = (strstr(PHP_OS, "WIN")) ? "win32" : "unix"; + +// ** Search paths for external programs (dsmadmc, php, ...) ** // +if ($config["server_os"] == "win32") { + $config["search_path"] = array('c:/php', 'c:/progra~1/php', 'd:/php', 'd:/progra~1/php', 'c:/progra~1/tivoli/tsm/baclient', 'd:/progra~1/tivoli/tsm/baclient'); +} elseif ($config["server_os"] == "unix") { + $config["search_path"] = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin', '/usr/tivoli/tsm/client/admin/bin', '/opt/tivoli/tsm/client/ba/bin'); +} + // ** Paths (libraries, includes, ...) ** // +$config["base_path"] = ereg_replace("(.*[\\\/])includes", "\\1", dirname(__FILE__)); $config["library_path"] = ereg_replace("(.*[\\\/])includes", "\\1extlib", dirname(__FILE__)); $config["include_path"] = dirname(__FILE__); diff --git a/install.php b/install.php index 6464353..11a9adb 100644 --- a/install.php +++ b/install.php @@ -29,13 +29,37 @@ */ include_once "includes/global.php"; -if ($_REQUEST["step"] != "30" && $_REQUEST["step"] != "40") { +if ($_REQUEST["step"] != "50" || $_REQUEST["refresh"] != "") { include_once "includes/page_head.php"; } // 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 +$exts = array("session", "sockets"); +$ext_load = true; +foreach ($exts as $ext) { + if (!extension_loaded($ext)){ + $ext_load = false; + $ext_miss .= "
  • $ext
  • \n"; + } +} +if (!$ext_load) { + echo " +

    Error

    +

    The following PHP extensions are missing:

    + +

    Please install those PHP extensions and retry the installation process.

    + + + +"; + exit; +} + $tsm_monitor_versions = array("0.1.0", "0.1.1"); $old_tsm_monitor_version = fetchCellDB("select confval from cfg_config where confkey='version'", '', $conn); @@ -43,30 +67,69 @@ $old_tsm_monitor_version = fetchCellDB("select confval from cfg_config where con // try to find current (old) version in the array $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

    \n -

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

    \n - \n - \n -\n -\n"; +

    Error

    +

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

    + + + +"; exit; } elseif (empty($old_tsm_monitor_version)) { echo " -

    Error

    \n -

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

    \n -

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

    \n -

    This error may also be generated if the TSM Monitor database user does not have correct permissions on the TSM Monitor database.
    \n - 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.

    \n - \n - \n - \n -\n"; +

    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.

    + + + +"; exit; } +// dsmadmc binary path +$input["path_dsmadmc"] = $configarray["settings"]["path_dsmadmc"]; +$input["path_dsmadmc"]["name"] = "dsmadmc Binary Path"; +$input["path_dsmadmc"]["desc"] = "The path to the TSM admin client binary."; +$which_dsmadmc = findPath("dsmadmc", $config["search_path"]); +if (isset($configarray["settings"]["path_dsmadmc"])) { + $input["path_dsmadmc"]["default"] = $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"] = $configarray["settings"]["path_php"]; +$input["path_php"]["name"] = "PHP Binary Path"; +$input["path_php"]["desc"] = "The path to the PHP binary."; +$which_php = findPath("php", $config["search_path"]); +if(!isset($which_php)) { + $which_php = findPath("php5", $config["search_path"]); +} +if (isset($configarray["settings"]["path_php"])) { + $input["path_php"]["default"] = $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"] = $configarray["settings"]["path_tmlog"]; +$input["path_tmlog"]["name"] = "TSM Monitor Logfile Path"; +$input["path_tmlog"]["desc"] = "The path to the TSM Monitor log file."; +if (isset($configarray["settings"]["path_tmlog"])) { + $input["path_tmlog"]["default"] = $configarray["settings"]["path_tmlog"]; +} else { + $input["path_tmlog"]["default"] = $config["base_path"] . "tsmmonitor.log"; +} + // default for the install type if (!isset($_REQUEST["install_type"])) { $_REQUEST["install_type"] = 0; @@ -79,27 +142,43 @@ if ($old_tsm_monitor_version == "new_install") { } // pre-processing that needs to be done for each step +// Intro and license page if (empty($_REQUEST["step"])) { $_REQUEST["step"] = 10; } else { + // Install or update chooser 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"] = "90"; + $_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]; + } + } + } elseif ($_REQUEST["step"] == "50") { $_REQUEST["step"] = "90"; } } if ($_REQUEST["step"] == "90") { // Flush updated data to DB - // ... - // ... - // ... + foreach ($input as $name => $array) { + if (isset($_POST[$name])) { + updateDB('cfg_config', array(confkey => "$name", confval => $_POST[$name], description => $array['name']), 'confkey', $conn); + } + } updateDB('cfg_config', array(confkey => 'version', confval => $config['tsm_monitor_version']), 'confkey', $conn); closeDB($conn); header("Location: index.php"); @@ -108,21 +187,21 @@ if ($_REQUEST["step"] == "90") { // if the version is not found, die if (!is_int($old_version_index)) { echo " -

    Error

    \n -

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

    Error

    +

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

    - \n - \n -\n -\n"; + + + +"; exit; } // 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") { - include "install/0_1_to_0_1_1.php"; + if ($tsm_monitor_versions[$i] == "0.1.0") { + include "install/0_1_0_to_0_1_1.php"; upgrade_to_0_1_1(); } /* elseif ($tsm_monitor_versions[$i] == "0.1.1") { include "install/0_1_1_to_0_1_2.php"; @@ -153,9 +232,9 @@ if ($_REQUEST["step"] == "90") { - - + - + diff --git a/install/0_1_to_0_1_1.php b/install/0_1_0_to_0_1_1.php similarity index 100% rename from install/0_1_to_0_1_1.php rename to install/0_1_0_to_0_1_1.php
    +

    @@ -195,7 +274,7 @@ if ($_REQUEST["step"] == "90") { http://www.gnu.org/licenses/.

    @@ -208,7 +287,7 @@ if ($_REQUEST["step"] == "90") {

    @@ -216,29 +295,86 @@ if ($_REQUEST["step"] == "90") {

    Upgrade stuff could be done here ...

    - + + + +

    + Please check if the following values have been correctly determined for your + system and correct if necessary. +

    + $array) { + if (isset($input[$name])) { + $file = $array["default"]; + $resStr = ""; + $capStr = ""; + + if (file_exists($file)) { + $resStr = "[FOUND] "; + $capStr = "
    [OK: FILE FOUND]
    "; + } else { + $resStr = "[NOT FOUND] "; + $capStr = "
    [ERROR: FILE NOT FOUND]
    "; + } + echo " +

    + " . $resStr . $array["name"]; + if (!empty($array["name"])) { + echo ": " . $array["desc"]; + } else { + echo $array["desc"] . ""; + } + echo " +
    + " . $capStr . " +
    +

    "; + } + } + ?> + +

    + 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". +

    +
      
    +

    - + - + +

    +
    +

    + - +

    @@ -252,6 +388,7 @@ if ($_REQUEST["step"] == "90") { +