| 1 | <?php
 | 
  
    | 2 | /**
 | 
  
    | 3 |  *
 | 
  
    | 4 |  * @category        admin
 | 
  
    | 5 |  * @package         modules
 | 
  
    | 6 |  * @author          WebsiteBaker Project
 | 
  
    | 7 |  * @copyright       2004-2009, Ryan Djurovich
 | 
  
    | 8 |  * @copyright       2009-2011, Website Baker Org. e.V.
 | 
  
    | 9 |  * @link			http://www.websitebaker2.org/
 | 
  
    | 10 |  * @license         http://www.gnu.org/licenses/gpl.html
 | 
  
    | 11 |  * @platform        WebsiteBaker 2.8.x
 | 
  
    | 12 |  * @requirements    PHP 5.2.2 and higher
 | 
  
    | 13 |  * @version         $Id: install.php 1467 2011-07-02 00:06:53Z Luisehahne $
 | 
  
    | 14 |  * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/modules/install.php $
 | 
  
    | 15 |  * @lastmodified    $Date: 2011-07-02 02:06:53 +0200 (Sat, 02 Jul 2011) $
 | 
  
    | 16 |  *
 | 
  
    | 17 |  */
 | 
  
    | 18 | 
 | 
  
    | 19 | // do not display notices and warnings during installation
 | 
  
    | 20 | error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
 | 
  
    | 21 | 
 | 
  
    | 22 | // Setup admin object
 | 
  
    | 23 | require('../../config.php');
 | 
  
    | 24 | require_once(WB_PATH.'/framework/class.admin.php');
 | 
  
    | 25 | $admin = new admin('Addons', 'modules_install', false);
 | 
  
    | 26 | if( !$admin->checkFTAN() )
 | 
  
    | 27 | {
 | 
  
    | 28 | 	$admin->print_header();
 | 
  
    | 29 | 	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
 | 
  
    | 30 | }
 | 
  
    | 31 | // After check print the header
 | 
  
    | 32 | $admin->print_header();
 | 
  
    | 33 | 
 | 
  
    | 34 | // Check if user uploaded a file
 | 
  
    | 35 | if(!isset($_FILES['userfile'])) {
 | 
  
    | 36 | 	header("Location: index.php");
 | 
  
    | 37 | 	exit(0);
 | 
  
    | 38 | }
 | 
  
    | 39 | 
 | 
  
    | 40 | // Include the WB functions file
 | 
  
    | 41 | require_once(WB_PATH.'/framework/functions.php');
 | 
  
    | 42 | 
 | 
  
    | 43 | // Set temp vars
 | 
  
    | 44 | $temp_dir = WB_PATH.'/temp/';
 | 
  
    | 45 | $temp_file = $temp_dir . $_FILES['userfile']['name'];
 | 
  
    | 46 | $temp_unzip = WB_PATH.'/temp/unzip/';
 | 
  
    | 47 | 
 | 
  
    | 48 | // Try to upload the file to the temp dir
 | 
  
    | 49 | if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file))
 | 
  
    | 50 | {
 | 
  
    | 51 | 	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']);
 | 
  
    | 52 | }
 | 
  
    | 53 | 
 | 
  
    | 54 | // Include the PclZip class file (thanks to 
 | 
  
    | 55 | require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
 | 
  
    | 56 | 
 | 
  
    | 57 | // Remove any vars with name "module_directory"
 | 
  
    | 58 | unset($module_directory);
 | 
  
    | 59 | 
 | 
  
    | 60 | // Setup the PclZip object
 | 
  
    | 61 | $archive = new PclZip($temp_file);
 | 
  
    | 62 | // Unzip the files to the temp unzip folder
 | 
  
    | 63 | $list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
 | 
  
    | 64 | 
 | 
  
    | 65 | // Check if uploaded file is a valid Add-On zip file
 | 
  
    | 66 | if (!($list && file_exists($temp_unzip . 'index.php')))
 | 
  
    | 67 | {
 | 
  
    | 68 |   $admin->print_error($MESSAGE['GENERIC']['INVALID_ADDON_FILE']);
 | 
  
    | 69 | }
 | 
  
    | 70 | 
 | 
  
    | 71 | // Include the modules info file
 | 
  
    | 72 | require($temp_unzip.'info.php');
 | 
  
    | 73 | 
 | 
  
    | 74 | // Perform Add-on requirement checks before proceeding
 | 
  
    | 75 | require(WB_PATH . '/framework/addon.precheck.inc.php');
 | 
  
    | 76 | preCheckAddon($temp_file);
 | 
  
    | 77 | // Delete the temp unzip directory
 | 
  
    | 78 | rm_full_dir($temp_unzip);
 | 
  
    | 79 | 
 | 
  
    | 80 | // Check if the file is valid
 | 
  
    | 81 | if(!isset($module_directory))
 | 
  
    | 82 | {
 | 
  
    | 83 | 	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
 | 
  
    | 84 | 	$admin->print_error($MESSAGE['GENERIC']['INVALID']);
 | 
  
    | 85 | }
 | 
  
    | 86 | 
 | 
  
    | 87 | // Check if this module is already installed
 | 
  
    | 88 | // and compare versions if so
 | 
  
    | 89 | $new_module_version = $module_version;
 | 
  
    | 90 | $action="install";
 | 
  
    | 91 | if(is_dir(WB_PATH.'/modules/'.$module_directory))
 | 
  
    | 92 | {
 | 
  
    | 93 | 	if(file_exists(WB_PATH.'/modules/'.$module_directory.'/info.php'))
 | 
  
    | 94 |     {
 | 
  
    | 95 | 		require(WB_PATH.'/modules/'.$module_directory.'/info.php');
 | 
  
    | 96 | 		// Version to be installed is older than currently installed version
 | 
  
    | 97 | 		if (versionCompare($module_version, $new_module_version, '>='))
 | 
  
    | 98 |         {
 | 
  
    | 99 | 
 | 
  
    | 100 | 			if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
 | 
  
    | 101 | 			$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
 | 
  
    | 102 | 		}
 | 
  
    | 103 | 
 | 
  
    | 104 | 		$action="upgrade";
 | 
  
    | 105 | 
 | 
  
    | 106 | 	}
 | 
  
    | 107 | }
 | 
  
    | 108 | 
 | 
  
    | 109 | // Check if module dir is writable
 | 
  
    | 110 | if(!is_writable(WB_PATH.'/modules/'))
 | 
  
    | 111 | {
 | 
  
    | 112 | 	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
 | 
  
    | 113 | 	$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']);
 | 
  
    | 114 | }
 | 
  
    | 115 | 
 | 
  
    | 116 | // Set module directory
 | 
  
    | 117 | $module_dir = WB_PATH.'/modules/'.$module_directory;
 | 
  
    | 118 | 
 | 
  
    | 119 | // Make sure the module dir exists, and chmod if needed
 | 
  
    | 120 | make_dir($module_dir);
 | 
  
    | 121 | 
 | 
  
    | 122 | // Unzip module to the module dir
 | 
  
    | 123 | if(isset($_POST['overwrite'])){
 | 
  
    | 124 | 	$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir, PCLZIP_OPT_REPLACE_NEWER );
 | 
  
    | 125 | } else {
 | 
  
    | 126 | 	$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir );
 | 
  
    | 127 | }
 | 
  
    | 128 | 
 | 
  
    | 129 | if(!$list)
 | 
  
    | 130 | {
 | 
  
    | 131 | 	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']);
 | 
  
    | 132 | }
 | 
  
    | 133 | /*
 | 
  
    | 134 | 
 | 
  
    | 135 | if ($list == 0) {
 | 
  
    | 136 |   $admin->print_error("ERROR : ".$archive->errorInfo(true));
 | 
  
    | 137 | }
 | 
  
    | 138 | */
 | 
  
    | 139 | // Delete the temp zip file
 | 
  
    | 140 | if(file_exists($temp_file)) { unlink($temp_file); }
 | 
  
    | 141 | 
 | 
  
    | 142 | // Chmod all the uploaded files
 | 
  
    | 143 | $dir = dir($module_dir);
 | 
  
    | 144 | while (false !== $entry = $dir->read())
 | 
  
    | 145 | {
 | 
  
    | 146 | 	// Skip pointers
 | 
  
    | 147 | 	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($module_dir.'/'.$entry))
 | 
  
    | 148 |     {
 | 
  
    | 149 | 		// Chmod file
 | 
  
    | 150 | 		change_mode($module_dir.'/'.$entry, 'file');
 | 
  
    | 151 | 	}
 | 
  
    | 152 | }
 | 
  
    | 153 | /* */
 | 
  
    | 154 | // Run the modules install // upgrade script if there is one
 | 
  
    | 155 | if(file_exists($module_dir.'/'.$action.'.php'))
 | 
  
    | 156 | {
 | 
  
    | 157 | 	require($module_dir.'/'.$action.'.php');
 | 
  
    | 158 | }
 | 
  
    | 159 | 
 | 
  
    | 160 | // Print success message
 | 
  
    | 161 | if ($action=="install")
 | 
  
    | 162 | {
 | 
  
    | 163 | 	// Load module info into DB
 | 
  
    | 164 | 	load_module(WB_PATH.'/modules/'.$module_directory, false);
 | 
  
    | 165 | 	$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
 | 
  
    | 166 | } elseif ($action=="upgrade")
 | 
  
    | 167 | {
 | 
  
    | 168 | 
 | 
  
    | 169 | 	upgrade_module($module_directory, false);
 | 
  
    | 170 | 	$admin->print_success($MESSAGE['GENERIC']['UPGRADED']);
 | 
  
    | 171 | }
 | 
  
    | 172 | 
 | 
  
    | 173 | // Print admin footer
 | 
  
    | 174 | $admin->print_footer();
 | 
  
    | 175 | 
 | 
  
    | 176 | ?>
 |