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/install_include.php

    r448 r485  
    11<?php 
    2 function processSQLfile($db,$filename){ 
    3         global $dblink; 
    4  
    5         $thefile = @ fopen($filename,"r"); 
    6         if(!$thefile) 
    7                 return "Could not open the file ".$filename.".\n"; 
    8  
    9         $thereturn="Processing SQL from file '".$filename."'\n"; 
    10                 while(!feof($thefile)) { 
    11                         $sqlstatement=trim(fgets($thefile,2048)); 
    12                         if(strrpos($sqlstatement,";")==strlen($sqlstatement)-1){ 
    13                                 $theresult=$db->query($sqlstatement); 
    14                                 if($db->error) 
    15                                         $thereturn = "Error processing SQL file  ".$filename.": ".$db->error."\n".$sqlstatement; 
    16                                 $sqlstatement=""; 
    17                         }//end if; 
    18                 }//end while 
    19  
    20         $thereturn.="Done processing SQL from file '".$filename."'. \n\n"; 
    21         return $thereturn; 
    22 }//end function 
    23  
    24  
    25 function verifyAdminLogin($db,$user,$pass){ 
    26  
    27         if((real) getCurrentVersion($db,"base")>=.7) 
    28                 $querystatement="SELECT id FROM users WHERE login=\"".mysql_real_escape_string($user)."\" AND password=encode(\"".mysql_real_escape_string($pass)."\",\"".ENCRYPTION_SEED."\") AND admin=1"; 
    29         else 
    30                 $querystatement="SELECT id FROM users WHERE login=\"".mysql_real_escape_string($user)."\" AND password=encode(\"".mysql_real_escape_string($pass)."\",\"".ENCRYPTION_SEED."\") AND accesslevel>=90"; 
    31  
    32         $queryresult=$db->query($querystatement); 
    33  
    34         if(!$queryresult) 
    35                 return false; 
    36         return ($db->numRows($queryresult)>0); 
    37 } 
    38  
    39  
    40 function getCurrentVersion($db,$module){ 
    41  
    42         $querystatement="SELECT version FROM modules WHERE name=\"".mysql_real_escape_string($module)."\";"; 
    43         $queryresult=$db->query($querystatement); 
    44  
    45         $ver=$db->fetchArray($queryresult); 
    46         return $ver["version"]; 
    47 } 
    48  
    49  
    50 function loadModules($type){ 
    51         $currdirectory = @getcwd(); 
    52  
    53         $thedir= @ opendir("../modules/"); 
    54  
    55         echo 'modules = Array();'."\n"; 
    56  
    57         $modules = array(); 
    58         while($entry=readdir($thedir)){ 
    59                 if($entry != "." && $entry != ".." && $entry != "base" && $entry != "sample" && is_dir("../modules/".$entry)){ 
    60                         if(file_exists("../modules/".$entry."/install/".$type.".php") && file_exists("../modules/".$entry."/install/version.php")){ 
    61                                 include("../modules/".$entry."/install/version.php"); 
    62                         } 
    63                 } 
    64         } 
    65  
    66         foreach($modules as $name=>$module) 
    67                 if(is_array($module)){ 
    68                         echo 'modules["'.$name.'"] = Array()'."\n"; 
    69                         foreach($module as $key=>$value) 
    70                                 echo 'modules["'.$name.'"]["'.$key.'"] = "'.$value.'";'."\n"; 
    71                 } 
    72  
    73         @ chdir ($currdirectory); 
    74  
    75         return $modules; 
    76 }//end function 
    77  
    78  
    79 function showModules($modules){ 
    80         if(is_array($modules)){ 
    81                 foreach($modules as $name => $module) 
    82                         if($name != "base") 
    83                                 if(is_array($module)){ 
    84                                         ?><option value="<?php echo $name ?>"><?php echo $module["name"]?></option><?php 
    85                                 } 
    86         } 
    87 } 
    88  
    89  
    90 function createTables($db,$sqlfile){ 
    91  
    92         $sqlstatement=""; 
    93         $thereturn = ""; 
    94  
    95         $createfile = @ fopen("createtables.sql","r"); 
    96         if(!$createfile) 
    97                 return "Could not open SQL file: ".$sqlfile; 
    98         else{ 
    99                 while(!feof($createfile)) { 
    100                         $sqlstatement.= @ fgets($createfile,1024); 
    101                         if(strpos($sqlstatement,";")){ 
    102  
    103                                 $theresult = $db->query(trim($sqlstatement)); 
    104  
    105                                 if($db->error){ 
    106                                         return "Error creating tables: ".$db->error."\n\n".trim($sqlstatement); 
    107                                 } 
    108                                 $sqlstatement=""; 
    109                         }//end if; 
    110                 }//end while 
    111  
    112         }//end if 
    113  
    114         return true; 
    115 } 
    116  
    117  
    118 function importData($db,$tablename){ 
    119  
    120         $tablefile = @ fopen($tablename.".sql","rb"); 
    121         if(!$tablefile) 
    122                 return "Could not open the file ".$tablename.".sql\n"; 
    123  
    124         $thereturn=""; 
    125         $counter=0; 
    126         $failure = false; 
    127  
    128         while(!feof($tablefile)) { 
    129                 $sqlstatement=trim(fgets($tablefile,8184)); 
    130                 if(strrpos($sqlstatement,";")==strlen($sqlstatement)-1){ 
    131  
    132                         $theresult=$db->query($sqlstatement); 
    133  
    134                         if($db->error){ 
    135                                 $failure = true; 
    136                                 $thereturn .= "Error importing record into ".$tablename.": ".$db->error."\n"; 
    137                         } 
     2        class installer{ 
     3 
     4                var $db; 
     5 
     6                function installer($db){ 
     7 
     8                        $this->db = $db; 
     9 
     10                }//end function init 
     11 
     12 
     13                function createTables($sqlfile){ 
     14 
     15                        $sqlstatement=""; 
     16                        $thereturn = ""; 
     17                        $line = 1; 
     18 
     19                        $filePointer = @ fopen($sqlfile,"r"); 
     20 
     21                        if(!$filePointer) 
     22                                return "Could not open SQL file: ".$sqlfile; 
     23 
     24                        while(!feof($filePointer)) { 
     25 
     26                                $createstatement .= @ fgets($filePointer,1024); 
     27 
     28                                if(strpos($createstatement,";")){ 
     29 
     30                                        $this->db->query(trim($createstatement)); 
     31 
     32                                        if($this->db->error) 
     33                                                return "Error creating tables on line ".$line.": ".$this->db->error." SQL Statement: ".trim($createstatement); 
     34 
     35                                        $createstatement = ""; 
     36 
     37                                }//end if; 
     38 
     39                                $line++; 
     40 
     41                        }//end while 
     42 
     43                        return true; 
     44 
     45                }//end function createTables 
     46 
     47 
     48                function processSQLfile($filename){ 
     49 
     50                        $thefile = @ fopen($filename,"r"); 
     51                        $line = 1; 
     52                        $thereturn = ""; 
     53 
     54                        if(!$thefile) 
     55                                return "Could not open the SQL file ".$filename; 
     56 
     57                        while(!feof($thefile)) { 
     58 
     59                                $sqlstatement .= @ trim(fgets($thefile)); 
     60 
     61                                // we look for the ; at the end of the line 
     62                                // If it is not there, we keep adding to the sql statement 
     63                                if(strrpos($sqlstatement,";") == strlen($sqlstatement)-1){ 
     64 
     65                                        $this->db->query(trim($sqlstatement)); 
     66                                        if($this->db->error) 
     67                                                $thereturn .= "Error processing SQL file '".$filename."' on line ".$line.": ".$this->db->error." - SQL Statement: ".$sqlstatement."\n"; 
     68 
     69                                        $sqlstatement = ""; 
     70 
     71                                }//end if; 
     72 
     73                                $line++; 
     74 
     75                        }//end while 
     76 
     77                        if($thereturn) 
     78                                return $thereturn; 
    13879                        else 
    139                                 $counter++; 
    140  
    141                         $sqlstatement=""; 
    142                 }//end if; 
    143         }//end while 
    144  
    145         if($failure) 
    146                 $threturn = "Importing of some records in ".$tablename." occured.\n\n"; 
    147         else 
    148                 $thereturn.="Import of ".$counter." record(s) for '".$tablename."' complete.\n"; 
    149  
    150         return $thereturn; 
    151 }//end function 
     80                                return true; 
     81 
     82                }//end function 
     83 
     84        }//end class 
     85 
     86 
     87 
     88        class modules{ 
     89 
     90                var $list = array(); 
     91 
     92                // this loads the modules in to an array 
     93                // type looks for either update, to make sure the 
     94                // module folder has an install folder, and inside the install 
     95                // folder is an install.php or update .php (depending on type) 
     96                // and that it has a version.php file; 
     97                function modules($type = "install"){ 
     98 
     99                        $currdirectory = @getcwd(); 
     100 
     101                        $thedir= @ opendir("../modules/"); 
     102 
     103                        $modules = array(); 
     104 
     105                        //this helps build the modules array 
     106                        // each included modules version.php should add to the 
     107                        // array 
     108                        while($entry = readdir($thedir)){ 
     109 
     110                                if($entry != "." && $entry != ".." && $entry != "base" && $entry != "sample" && is_dir("../modules/".$entry)){ 
     111 
     112                                        if(file_exists("../modules/".$entry."/install/".$type.".php") && file_exists("../modules/".$entry."/version.php")){ 
     113 
     114                                                include("../modules/".$entry."/version.php"); 
     115 
     116                                        }//endif 
     117 
     118                                }//endif 
     119 
     120                        }//end if 
     121 
     122                        @ chdir ($currdirectory); 
     123 
     124                        $this->list = $modules; 
     125 
     126                }//end function init 
     127 
     128 
     129                function displpayJS(){ 
     130 
     131                        echo 'modules = Array();'."\n"; 
     132 
     133                        foreach($this->list as $name=>$module) 
     134                                if(is_array($module) && $name != "base"){ 
     135 
     136                                        echo 'modules["'.$name.'"] = Array()'."\n"; 
     137                                        foreach($module as $key=>$value) 
     138                                                echo 'modules["'.$name.'"]["'.$key.'"] = "'.$value.'";'."\n"; 
     139                                }//endif 
     140 
     141 
     142                }//end function displayJS 
     143 
     144 
     145                function displayInstallTable(){ 
     146 
     147                        ?> 
     148                        <table id="moduleTable" cellpadding="0" cellspacing="0" border="0"> 
     149                                <thead> 
     150                                        <tr> 
     151                                                <th>module</th> 
     152                                                <th>version</th> 
     153                                                <th>&nbsp;</th> 
     154                                        </tr> 
     155                                </thead> 
     156                                <tbody> 
     157                        <?php 
     158 
     159                        ksort($this->list); 
     160 
     161                        foreach($this->list as $key=>$module){ 
     162 
     163                                if($key != "base"){ 
     164 
     165                                        ?> 
     166                                        <tr> 
     167                                                <td> 
     168                                                        <h3><strong><?php echo $module["name"]?></strong></h3> 
     169                                                        <p><?php echo $module["description"]?></p> 
     170                                                        <p class="notes"><strong>Requirements:</strong> <?php echo $module["requirements"]?></p> 
     171                                                </td> 
     172                                                <td><?php echo $module["version"] ?></td> 
     173                                                <td class="moduleInstall"> 
     174                                                        <button class="Buttons moduleButtons" id="moduleButton<?php echo $key ?>">Install Module</button> 
     175                                                        <p><span class="" id="Results<?php echo $key?>"></span></p> 
     176                                                </td> 
     177                                        </tr> 
     178                                        <?php 
     179 
     180                                }//end if 
     181 
     182                        }//end foreach 
     183 
     184                        ?></tbody></table><?php 
     185 
     186                }//end function displayInstallTable 
     187 
     188        }//end class 
     189 
     190 
     191 
     192        class installUpdateBase{ 
     193 
     194                var $db; 
     195                var $phpbmsSession; 
     196 
     197                function returnJSON($success, $details, $extras = null){ 
     198 
     199                        $thereturn["success"] = $success; 
     200                        $thereturn["details"] = $details; 
     201 
     202                        if($extras) 
     203                                $thereturn["extras"] = $extras; 
     204 
     205                        return json_encode($thereturn); 
     206 
     207                }//endfunction returnJSON 
     208 
     209        }//end class installUpdateBase 
     210 
    152211 
    153212?> 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.