Location: PHPKode > projects > Network Managment / Inventory System > clearsite/upgrade.php
<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2007-2008 Xinn.org                                        |
 |                                                                         |
 | This program is free software; you can redistribute it and/or           |
 | modify it under the terms of the GNU General Public License             |
 | as published by the Free Software Foundation; either version 2          |
 | of the License, or (at your option) any later version.                  |
 |                                                                         |
 | This program is distributed in the hope that it will be useful,         |
 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
 | GNU General Public License for more details.                            |
 +-------------------------------------------------------------------------+
 | ClearSite/ALOE, A Long Overdue Enterprise network managment solution!   |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Xinn.org. See     |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://aloeusers.net                                                    |
 | http://clearsite.sourceforge.net                                        |
 | http://aloenms.net                                                      |
 | http://clear-site.net                                                   |
 | http://clear-site.info                                                  |
 | http://xinn.org/ClearSite.html                                          |
 +-------------------------------------------------------------------------+
*/

$cs_base_path = substr(__FILE__, 0, -12);
$form_data = $_POST;
$new_clearsite_ver = "4.25b";

print "
     <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
     <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\">
     <head>
      <meta http-equiv=\"Pragma\" content=\"no-cache\" />
      <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />
      <meta http-equiv=\"cache-control\" content=\"no-cache\" />
      <meta http-equiv=\"expires\" content=\"0\" />
      <meta name=\"robots\" content=\"index,follow\" />
      <meta name=\"publisher\" content=\"&lt;Company_Name&gt;\" />
      <meta name=\"copyright\" content=\"&lt;Company_Name&gt; 2008\" />
      <meta name=\"author\" content=\"Designed by AZE\" />
      <meta name=\"distribution\" content=\"global\" />
      <meta name=\"description\" content=\"&lt;Company_Name&gt; security, voice and data management\" />
      <meta name=\"keywords\" content=\"voip, security, network management, graphing, clearsite\" />
      <link rel=\"icon\" type=\"image/x-icon\" href=\"./images/favicon.ico\" />
      <title>Clearsite Installation</title>
      <link href=\"./css/install.css\" type=\"text/css\" rel=\"stylesheet\" />
    </head>
    <!-- Global IE fix to avoid layout crash when single word size wider than column width -->
    <!-- Following line MUST remain as a comment to have the proper effect -->
    <!--[if IE]><style type=\"text/css\"> body {word-wrap: break-word;}</style><![endif]-->
    <body>
    <div class=\"container\">
      <div class=\"rnd-header\">
       <b class=\"rhtop\">
        <b class=\"rh1\"></b>
        <b class=\"rh2\"></b>
        <b class=\"rh3\"></b>
        <b class=\"rh4\"></b>
       </b>
      </div>
      <div class=\"header\">
       <div class=\"header-top\">
        <img alt=\"\" src=\"images/clearsite86.png\" />
      </div>
      </div>
      <div class=\"rnd-header\">
       <b class=\"rhbottom\">
        <b class=\"rh4\"></b>
        <b class=\"rh3\"></b>
        <b class=\"rh2\"></b>
        <b class=\"rh1\"></b>
       </b>
      </div>
      <br />
      <div class=\"tabs\">
       <div class=\"navbar\">
        <ul>
         <li>
          <div class=\"rnd-tab\">
           <b class=\"rhtab\">
            <b class=\"rt1\"></b>
            <b class=\"rt2\"></b>
            <b class=\"rt3\"></b>
            <b class=\"rt4\"></b>
           </b>
           <h3>
            <a href=\"install.php\">Installation</a>
           </h3>
          </div>
         </li>
         <li>
          <div class=\"rnd-tab\">
           <b class=\"rhtab\">
            <b class=\"rt1\"></b>
            <b class=\"rt2\"></b>
            <b class=\"rt3\"></b>
            <b class=\"rt4\"></b>
           </b>
           <h3>
            <a href=\"upgrade.php\">Upgrade</a>
           </h3>
          </div>
         </li>
        </ul>
       </div>
      </div>
      <div id=\"clear\"></div>
      <div class=\"rnd-header\">
       <b class=\"rhtop\">
        <b class=\"rh1\"></b>
        <b class=\"rh2\"></b>
        <b class=\"rh3\"></b>
        <b class=\"rh4\"></b>
       </b>
      </div>
      <div class=\"main\">
       <div id=\"targetArea\">
       <div class=\"install\">";

if (empty($form_data['action'])) {
  if (is_file($cs_base_path . "/include/db_config.php")) {
    include_once($cs_base_path . "/include/db_config.php");
    print "
            <p>
             Welcome to the ClearSite upgrade page! As with all upgrades, please back up the DataBase before continuing.
            </p>
            <p>
             You will need to grant ALTER, CREATE and DROP priviledges to the " . $DBuser . " sql user on the " . $DBName . " database before continuing.
            </p>
            <p>
             fping is now an option for clearsite.  Please provide the path to fping below.
            </p>
            <p>
             Clicking the button below will modify the DB.  Please overwrite the old clearsite files with the ones contained in this package.
            </p>
            <br />
            <p>
             <fieldset class=\"install\">
              <form action=\"upgrade.php\" method=\"post\">
               <input type=\"hidden\" name=\"action\" value=\"upgrade\" />
               <label for=\"use_fping\">Would you like to use fping rather than ping? (Required for windows)</label><input type=\"checkbox\" name=\"use_fping\" value=\"yes\" checked /><br />
               <label for=\"fping_path\">Path to fping</label><input id=\"fping_path\" name=\"fping_path\" value=\""; if (isset($form_data['fping_path'])) { print $form_data['fping_path']; } else { print "/usr/sbin/fping"; }; print "\" type=\"text\" />"; if (isset($form_data['fping_path']) and ($form_data['fping_path'] != "/usr/sbin/fping")) { print " Default: /usr/sbin/fping"; }; print "<br />
               <input type=\"image\" name=\"Continue\" value=\"Continue\" src=\"images/continue.png\" />
              </form>
             </fieldset>
            </p>
    ";
  } else {
    print "
           <p>
            You do not seem to have clearsite installed on your system at this time.  Please use the <a href=\"install.php\">install</a> section.
           </p>
    ";
  };
} else if ($form_data['action'] == "upgrade") {
  include_once($cs_base_path . "/include/config.php");
  mysql_connect($DBhost . ":" . $DBport, $DBuser, $DBpass) or die("Unable to connect to database");
  @mysql_select_db($DBName) or die("Unable to select database " . $DBName);
  $version_query = "SELECT value FROM config WHERE name=\"clearsite_ver\"";
  $version_result = mysql_query($version_query);
  $version_row = mysql_fetch_assoc($version_result);
  $cur_clearsite_ver = $version_row['value'];
  $table_upgrade = array();
  $table_insert  = array();
  if (empty($cur_clearsite_ver)) {
    $form_data['fping_path'] = addslashes($form_data['fping_path']);
    $table_upgrade[]      = "ALTER TABLE interfaces CHANGE iflastchange iflastchange VARCHAR(128) DEFAULT NULL";
    if (!empty($form_data['use_fping'])) { $use_fping = "yes"; } else { $use_fping = "no"; };
    $table_insert[]       = "INSERT INTO config (name, value) VALUES (\"fping_path\", \"" . $form_data['fping_path'] . "\"), (\"use_fping\", \"" . $use_fping . "\"), (\"clearsite_server_os\", \"" . php_uname("s") . "\")";
  };
  if ($cur_clearsite_ver == "4.20b" or empty($cur_clearsite_ver)) {
    $table_upgrade[]      = "CREATE TABLE snmp_template_hp_switch (mib varchar(64) NOT NULL, oid varchar(64) NOT NULL, anchor varchar(64) NOT NULL, vlan varchar(3) NOT NULL, walk_type varchar(4) NOT NULL, method varchar(4) NOT NULL default \"walk\", PRIMARY KEY  (mib), KEY oid (oid), KEY walk_type (walk_type)) ENGINE=InnoDB DEFAULT CHARSET=latin1";
    $table_insert[]       = "INSERT INTO snmp_template_hp_switch (mib, oid, anchor, vlan, walk_type, method) VALUES ('cpu5min', '1.3.6.1.4.1.11.2.14.11.5.1.9.6.1.0', 'anchor', 'no', 'both', 'get'), (\"ifadminstatus\", \".1.3.6.1.2.1.2.2.1.7\", \"ifname\", \"no\", \"db\", \"walk\"), (\"ifdescr\", \".1.3.6.1.2.1.2.2.1.2\", \"ifname\", \"no\", \"db\", \"walk\"), (\"ifhcinoctets\", \".1.3.6.1.2.1.31.1.1.1.6\", \"ifname\", \"no\", \"rrd\", \"walk\"), (\"ifhcoutoctets\", \".1.3.6.1.2.1.31.1.1.1.10\", \"ifname\", \"no\", \"rrd\", \"walk\"), (\"ifindex\", \".1.3.6.1.2.1.2.2.1.1\", \"ifname\", \"no\", \"both\", \"walk\"), (\"ifindiscards\", \".1.3.6.1.2.1.2.2.1.13\", \"ifname\", \"no\", \"none\", \"walk\"), (\"ifinerrors\", \".1.3.6.1.2.1.2.2.1.14\", \"ifname\", \"no\", \"none\", \"walk\"), (\"ifinoctets\", \".1.3.6.1.2.1.2.2.1.10\", \"ifname\", \"no\", \"rrd\", \"walk\"), (\"ifinunknownprotos\", \".1.3.6.1.2.1.2.2.1.15\", \"ifname\", \"no\", \"none\", \"walk\"), (\"iflastchange\", \".1.3.6.1.2.1.2.2.1.9\", \"ifname\", \"no\", \"db\", \"walk\"), (\"ifname\", \".1.3.6.1.2.1.31.1.1.1.1\", \"anchor\", \"no\", \"both\", \"walk\"), (\"ifoperstatus\", \".1.3.6.1.2.1.2.2.1.8\", \"ifname\", \"no\", \"both\", \"walk\"), (\"ifoutdiscards\", \".1.3.6.1.2.1.2.2.1.19\", \"ifname\", \"no\", \"none\", \"walk\"), (\"ifouterrors\", \".1.3.6.1.2.1.2.2.1.20\", \"ifname\", \"no\", \"none\", \"walk\"), (\"ifoutoctets\", \".1.3.6.1.2.1.2.2.1.16\", \"ifname\", \"no\", \"rrd\", \"walk\"), (\"ifphysaddress\", \".1.3.6.1.2.1.2.2.1.6\", \"ifname\", \"no\", \"db\", \"walk\"), (\"ifspeed\", \".1.3.6.1.2.1.2.2.1.5\", \"ifname\", \"no\", \"db\", \"walk\"), (\"iftype\", \".1.3.6.1.2.1.2.2.1.3\", \"ifname\", \"no\", \"db\", \"walk\"), (\"mactable\", \".1.3.6.1.2.1.17.4.3.1.1\", \"mactoifname\", \"no\", \"db\", \"walk\"), (\"mactoifname\", \".1.3.6.1.2.1.17.4.3.1.2\", \"anchor\", \"no\", \"db\", \"walk\"), (\"portduplex\", \".1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.5\", \"portifindex\", \"no\", \"db\", \"walk\"), (\"portifindex\", \".1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.1\", \"anchor\", \"no\", \"db\", \"walk\"), (\"portname\", \".1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.3\", \"portifindex\", \"no\", \"db\", \"walk\"), (\"porttype\", \".1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.2\", \"portifindex\", \"no\", \"db\", \"walk\"), (\"vlanids\", \".1.3.6.1.2.1.17.7.1.4.3.1.1\", \"anchor\", \"no\", \"both\", \"walk\")";
    $table_insert[]       = "INSERT INTO device_type (device_type_ID, device_type_name, device_model_oid, device_os_oid, device_serial_oid, arp_table_oid, snmpver) VALUES (9, \"hp_procurve_switch\", \"none\", \".1.3.6.1.2.1.1.1.0\", \".1.3.6.1.2.1.47.1.1.1.1.11.1\", \"none\", \"2\")";
    $table_insert[]       = "INSERT INTO snmp_template_list (template_ID, device_type_ID, template_name, template_table) VALUES (11, 9, \"hp_procurve_switch\", \"snmp_template_hp_switch\")";
  };
  if ($cur_clearsite_ver == "4.25b" or $cur_clearsite_ver == "4.20b" or empty($cur_clearsite_ver)) {
  };
  $merror = array();
  foreach ($table_upgrade as $query) {
    $result = mysql_query($query);
    if (mysql_error()) {
      $merror[] = mysql_error();
    };
  };
  foreach ($table_insert as $query) {
    $result = mysql_query($query);
    if (mysql_error()) {
      $merror[] = mysql_error();
    };
  };
  if (empty($cur_clearsite_ver)) {
    mysql_query("INSERT INTO config SET name=\"clearsite_ver\", value=\"" . $new_clearsite_ver . "\"");
  } else {
    mysql_query("UPDATE config SET value=\"" . $new_clearsite_ver . "\" WHERE name=\"clearsite_ver\"");
  };
  mysql_close();
  foreach ($merror as $mer) {
    print $mer . "<br />";
  };
  print "
         <p>
          The DB has been updated.  Enjoy the new version of Clearsite.
         </p>
  ";
};

print "
       </div>
       </div>";

include_once($cs_base_path . "/include/footer.php");

?>
Return current item: Network Managment / Inventory System