phpBMS

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/install/update_include.php

    r285 r485  
    11<?php 
    22 
    3          
     3define("APP_DEBUG",false); 
     4define("noStartup",true); 
     5 
     6require("../include/session.php"); 
     7 
     8        class updater{ 
     9 
     10                // database object 
     11                var $db; 
     12 
     13                // module list 
     14                var $list; 
     15 
     16                var $phpbmsSession; 
    417 
    518 
    6 //======================================================================================= 
    7 //======================================================================================= 
    8         function loadSettings() {        
    9                 $settingsfile =  fopen("../settings.php","r"); 
    10                 if($settingsfile){ 
    11                         //loop through the settings file and load variables into the session  
    12                         while( !feof($settingsfile)) { 
    13                                 $line=NULL; 
    14                                 $key=NULL; 
    15                                 $value=NULL; 
    16                                 $line=fscanf($settingsfile,"%[^=]=%[^[]]",$key,$value); 
    17                                 if ($line){ 
    18                                         $key=trim($key); 
    19                                         $value=trim($value); 
    20                                         if($key!="" and !strpos($key,"]")){      
    21                                                 $startpos=strpos($value,"\""); 
    22                                                 $endpos=strrpos($value,"\""); 
    23                                                 if($endpos!=false) 
    24                                                         $value=substr($value,$startpos+1,$endpos-$startpos-1); 
    25                                                 $variables[$key]=$value; 
    26                                         } 
    27                                 } 
    28                         } 
    29                         if(!isset($variables["mysql_pconnect"])) 
    30                         $variables["mysql_pconnect"]="true"; 
    31                         fclose($settingsfile); 
    32                         return $variables; 
    33                 } else return "Cannot open setting.php file"; 
    34         } 
     19                function updater(){ 
    3520 
    36          
    37         function getNewVersion($dir="."){ 
    38                 $file =  @ fopen($dir."/version.txt","r"); 
    39                 $version=fgets($file,1024); 
    40                 @ fclose($file); 
    41                 return $version; 
    42         } 
    43          
    44         function showModules(){ 
    45                 $vars=loadSettings(); 
    46                 if(!is_array($vars)) { 
    47                         echo "<option>Could Not Open Settings File</option>"; 
    48                         return false; 
    49                 } 
    50                 if($vars["mysql_pconnect"]=="true") 
    51                         $dblink = @  mysql_pconnect($vars["mysql_server"],$vars["mysql_user"],$vars["mysql_userpass"]); 
    52                 else 
    53                         $dblink = @  mysql_connect($vars["mysql_server"],$vars["mysql_user"],$vars["mysql_userpass"]); 
    54                 @ mysql_select_db($vars["mysql_database"],$dblink); 
    55                  
    56                 $querystatement="SELECT name,version FROM modules WHERE name!=\"base\" "; 
    57                 $queryresult=$db->query($querystatement); 
    58                  
    59                 while($modulerecord=$db->fetchArray($queryresult)){ 
    60                         $newVersion=getNewVersion("../modules/".$modulerecord["name"]."/install"); 
    61                         if($newVersion!=$modulerecord["version"]) 
    62                                 echo "<OPTION value=\"".$modulerecord["name"]."\">".$modulerecord["name"]." (".$modulerecord["version"]." -&gt; ".$newVersion.")</OPTION>\n"; 
    63                 } 
    64                  
    65         } 
     21                        $this->phpbmsSession = new phpbmsSession; 
    6622 
    67         $version=getNewVersion(); 
     23                        if($this->phpbmsSession->loadDBSettings(false)){ 
    6824 
     25                                @ include_once("include/db.php"); 
     26 
     27                                $this->db = new db(false); 
     28                                $this->db->stopOnError = false; 
     29                                $this->db->showError = false; 
     30                                $this->db->logError = false; 
     31 
     32                        } else 
     33                                $error = new appError(-300,"","",true,true,false); 
     34 
     35                        if(!$this->db->connect()) 
     36                                $error = new appError(-400,"Could not connect to database server.\n\n".$this->db->getError(),"Database Error",true,true,false); 
     37 
     38                        if(!$this->db->selectSchema()) 
     39                                $error = new appError(-410,"Could not open schema ".$this->db->schema,"Database Error", true, true, false); 
     40 
     41                }//end function init 
     42 
     43 
     44                function buildList(){ 
     45 
     46                        $thedir = @ opendir("../modules/"); 
     47 
     48                        $modules = array(); 
     49 
     50                        //this helps build the modules array 
     51                        // each included modules version.php should add to the 
     52                        // array 
     53                        while($entry = readdir($thedir)){ 
     54 
     55                                if($entry != "." && $entry != ".." && $entry != "base" && $entry != "sample" && is_dir("../modules/".$entry)){ 
     56 
     57                                        if(file_exists("../modules/".$entry."/install/update.php") && file_exists("../modules/".$entry."/version.php")){ 
     58 
     59                                                include("../modules/".$entry."/version.php"); 
     60 
     61                                        }//endif 
     62 
     63                                }//endif 
     64 
     65                        }//end if 
     66 
     67                        //Next we add the base version in 
     68                        include("../phpbmsversion.php"); 
     69 
     70                        //go retrieve current versions 
     71                        foreach($modules as $key=>$value) 
     72                                $modules[$key]["currentversion"] = $this->getCurrentVersion($key); 
     73 
     74                        $this->list = $modules; 
     75 
     76                }//end function buildList 
     77 
     78 
     79                function getMySQLVersion(){ 
     80 
     81                        $querystatement = "SELECT VERSION() AS ver"; 
     82                        $queryresult = $this->db->query($querystatement); 
     83                        if($this->db->error) 
     84                                $error = new appError(-425,"Could not retrieve mysql verson. ","Database Error", true, true, false); 
     85 
     86                        $therecord = $this->db->fetchArray($queryresult); 
     87 
     88                        return $therecord["ver"]; 
     89 
     90                }//endif 
     91 
     92 
     93                function getCurrentVersion($module){ 
     94 
     95                        $querystatement = " 
     96                                SELECT 
     97                                        version 
     98                                FROM 
     99                                        modules 
     100                                WHERE 
     101                                        name = '".$module."'"; 
     102 
     103                        $queryresult = $this->db->query($querystatement); 
     104                        if($this->db->error) 
     105                                $error = new appError(-600,"Could not retrieve current version information for ".$module.": ".$this->db->error,"Cannot load module information",true,true,false); 
     106 
     107                        if($this->db->numRows($queryresult)){ 
     108 
     109                                $therecord = $this->db->fetchArray($queryresult); 
     110 
     111                                return floatval($therecord["version"]); 
     112 
     113                        } else 
     114                                return 0; 
     115 
     116                }//end function getCurrentVersion 
     117 
     118 
     119                function checkBaseUpdate(){ 
     120 
     121                        return ($this->list["base"]["version"] == $this->list["base"]["currentversion"]); 
     122 
     123                }//end function showBaseUpdate 
     124 
     125 
     126                function showModulesUpdate(){ 
     127 
     128                        ?> 
     129                        <table id="moduleTable" cellpadding="0" cellspacing="0" border="0"> 
     130                                <thead> 
     131                                        <tr> 
     132                                                <th>module</th> 
     133                                                <th>database version</th> 
     134                                                <th>file version</th> 
     135                                                <th>&nbsp;</th> 
     136                                        </tr> 
     137                                </thead> 
     138                                <tbody> 
     139                        <?php 
     140 
     141                        ksort($this->list); 
     142 
     143                        foreach($this->list as $key=>$module){ 
     144 
     145                                if($key != "base"){ 
     146 
     147                                        ?> 
     148                                        <tr> 
     149                                                <td> 
     150                                                        <h3><strong><?php echo $module["name"]?></strong></h3> 
     151                                                        <p><?php echo $module["description"]?></p> 
     152                                                        <p class="notes"><strong>Requirements:</strong> <?php echo $module["requirements"]?> 
     153                                                </td> 
     154                                                <td><?php echo $module["version"] ?></td> 
     155                                                <td><?php echo $module["currentversion"] ?></td> 
     156 
     157                                                <td class="moduleInstall"> 
     158                                                        <?php 
     159                                                                if($module["version"] != $module["currentversion"]){ 
     160                                                                        if($module["currentversion"] == 0) { 
     161                                                        ?> 
     162                                                                Not Installed> 
     163                                                        <?php 
     164                                                                        } else {} 
     165                                                        ?> 
     166 
     167                                                                <button class="Buttons moduleButtons" id="moduleButton<?php echo $key ?>">Update Module</button> 
     168                                                                <p><span class="" id="Results<?php echo $key?>"></span></p> 
     169 
     170                                                        <?php } else {?> 
     171                                                                Versions Match<br /> 
     172                                                                Update Unnecessary 
     173                                                        <?php }//endif version!=currentversion ?> 
     174                                                </td> 
     175                                        </tr> 
     176                                        <?php 
     177 
     178                                }//end if 
     179 
     180                        }//end foreach 
     181 
     182                        ?></tbody></table><?php 
     183 
     184                }//end function showModuleUpdate 
     185 
     186        }//end class 
    69187?> 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.