| 1 | 1352 | Luisehahne | <?php
 | 
      
        | 2 |  |  | /**
 | 
      
        | 3 |  |  |  *
 | 
      
        | 4 |  |  |  * @category        admin
 | 
      
        | 5 |  |  |  * @package         modules
 | 
      
        | 6 | 1712 | Luisehahne |  * @author          Ryan Djurovich,WebsiteBaker Project
 | 
      
        | 7 |  |  |  * @copyright       2009-2012, WebsiteBaker Org. e.V.
 | 
      
        | 8 | 1352 | Luisehahne |  * @link			http://www.websitebaker2.org/
 | 
      
        | 9 |  |  |  * @license         http://www.gnu.org/licenses/gpl.html
 | 
      
        | 10 |  |  |  * @platform        WebsiteBaker 2.8.x
 | 
      
        | 11 | 1374 | Luisehahne |  * @requirements    PHP 5.2.2 and higher
 | 
      
        | 12 | 1352 | Luisehahne |  * @version         $Id$
 | 
      
        | 13 |  |  |  * @filesource		$HeadURL$
 | 
      
        | 14 |  |  |  * @lastmodified    $Date$
 | 
      
        | 15 |  |  |  *
 | 
      
        | 16 |  |  |  */
 | 
      
        | 17 |  |  | 
 | 
      
        | 18 |  |  | // do not display notices and warnings during installation
 | 
      
        | 19 |  |  | error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
 | 
      
        | 20 |  |  | 
 | 
      
        | 21 |  |  | // Setup admin object
 | 
      
        | 22 | 2044 | Luisehahne | //require('../../config.php');
 | 
      
        | 23 |  |  | $config_file = realpath('../../config.php');
 | 
      
        | 24 |  |  | if(file_exists($config_file) && !defined('WB_URL'))
 | 
      
        | 25 |  |  | {
 | 
      
        | 26 |  |  | 	require($config_file);
 | 
      
        | 27 |  |  | }
 | 
      
        | 28 |  |  | 
 | 
      
        | 29 |  |  | //require_once(WB_PATH.'/framework/class.admin.php');
 | 
      
        | 30 | 1457 | Luisehahne | $admin = new admin('Addons', 'modules_install', false);
 | 
      
        | 31 |  |  | if( !$admin->checkFTAN() )
 | 
      
        | 32 |  |  | {
 | 
      
        | 33 | 1467 | Luisehahne | 	$admin->print_header();
 | 
      
        | 34 | 1457 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
 | 
      
        | 35 |  |  | }
 | 
      
        | 36 |  |  | // After check print the header
 | 
      
        | 37 |  |  | $admin->print_header();
 | 
      
        | 38 | 1352 | Luisehahne | 
 | 
      
        | 39 | 1457 | Luisehahne | // Check if user uploaded a file
 | 
      
        | 40 |  |  | if(!isset($_FILES['userfile'])) {
 | 
      
        | 41 |  |  | 	header("Location: index.php");
 | 
      
        | 42 |  |  | 	exit(0);
 | 
      
        | 43 |  |  | }
 | 
      
        | 44 |  |  | 
 | 
      
        | 45 | 1352 | Luisehahne | // Include the WB functions file
 | 
      
        | 46 |  |  | require_once(WB_PATH.'/framework/functions.php');
 | 
      
        | 47 |  |  | 
 | 
      
        | 48 |  |  | // Set temp vars
 | 
      
        | 49 |  |  | $temp_dir = WB_PATH.'/temp/';
 | 
      
        | 50 |  |  | $temp_file = $temp_dir . $_FILES['userfile']['name'];
 | 
      
        | 51 |  |  | $temp_unzip = WB_PATH.'/temp/unzip/';
 | 
      
        | 52 |  |  | 
 | 
      
        | 53 | 1551 | Luisehahne | if(!$_FILES['userfile']['error']) {
 | 
      
        | 54 |  |  | 	// Try to upload the file to the temp dir
 | 
      
        | 55 |  |  | 	if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file))
 | 
      
        | 56 |  |  | 	{
 | 
      
        | 57 |  |  | 		$admin->print_error($MESSAGE['GENERIC_BAD_PERMISSIONS']);
 | 
      
        | 58 |  |  | 	}
 | 
      
        | 59 |  |  | } else {
 | 
      
        | 60 | 2044 | Luisehahne |     $iErrorMessage = ( isset($_FILES['userfile']['error']) && ( $_FILES['userfile']['error'] > 0 ) ? $_FILES['userfile']['error'] : UNKNOW_UPLOAD_ERROR );
 | 
      
        | 61 | 1551 | Luisehahne | // index for language files
 | 
      
        | 62 |  |  | 	$key = 'UNKNOW_UPLOAD_ERROR';
 | 
      
        | 63 | 2044 | Luisehahne |     switch ( $iErrorMessage ) {
 | 
      
        | 64 | 1551 | Luisehahne |         case UPLOAD_ERR_INI_SIZE:
 | 
      
        | 65 |  |  |             $key = 'UPLOAD_ERR_INI_SIZE';
 | 
      
        | 66 | 2044 | Luisehahne |             break;
 | 
      
        | 67 | 1551 | Luisehahne |         case UPLOAD_ERR_FORM_SIZE:
 | 
      
        | 68 |  |  |             $key = 'UPLOAD_ERR_FORM_SIZE';
 | 
      
        | 69 | 2044 | Luisehahne |             break;
 | 
      
        | 70 | 1551 | Luisehahne |         case UPLOAD_ERR_PARTIAL:
 | 
      
        | 71 |  |  |             $key = 'UPLOAD_ERR_PARTIAL';
 | 
      
        | 72 | 2044 | Luisehahne |             break;
 | 
      
        | 73 | 1551 | Luisehahne |         case UPLOAD_ERR_NO_FILE:
 | 
      
        | 74 |  |  |             $key = 'UPLOAD_ERR_NO_FILE';
 | 
      
        | 75 | 2044 | Luisehahne |              break;
 | 
      
        | 76 |  |  |        case UPLOAD_ERR_NO_TMP_DIR:
 | 
      
        | 77 | 1551 | Luisehahne |             $key = 'UPLOAD_ERR_NO_TMP_DIR';
 | 
      
        | 78 | 2044 | Luisehahne |             break;
 | 
      
        | 79 | 1551 | Luisehahne |         case UPLOAD_ERR_CANT_WRITE:
 | 
      
        | 80 |  |  |             $key = 'UPLOAD_ERR_CANT_WRITE';
 | 
      
        | 81 | 2044 | Luisehahne |             break;
 | 
      
        | 82 | 1551 | Luisehahne |         case UPLOAD_ERR_EXTENSION:
 | 
      
        | 83 |  |  |             $key = 'UPLOAD_ERR_EXTENSION';
 | 
      
        | 84 | 2044 | Luisehahne |             break;
 | 
      
        | 85 | 1551 | Luisehahne |         default:
 | 
      
        | 86 |  |  |             $key = 'UNKNOW_UPLOAD_ERROR';
 | 
      
        | 87 |  |  |     }
 | 
      
        | 88 | 2044 | Luisehahne | 
 | 
      
        | 89 | 1551 | Luisehahne | 	$admin->print_error($MESSAGE[$key].'<br />'.$MESSAGE['GENERIC_CANNOT_UPLOAD']);
 | 
      
        | 90 | 1352 | Luisehahne | }
 | 
      
        | 91 |  |  | 
 | 
      
        | 92 | 1712 | Luisehahne | // Include the PclZip class file (thanks to
 | 
      
        | 93 | 1352 | Luisehahne | require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
 | 
      
        | 94 |  |  | 
 | 
      
        | 95 |  |  | // Remove any vars with name "module_directory"
 | 
      
        | 96 |  |  | unset($module_directory);
 | 
      
        | 97 |  |  | 
 | 
      
        | 98 |  |  | // Setup the PclZip object
 | 
      
        | 99 |  |  | $archive = new PclZip($temp_file);
 | 
      
        | 100 |  |  | // Unzip the files to the temp unzip folder
 | 
      
        | 101 |  |  | $list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
 | 
      
        | 102 |  |  | 
 | 
      
        | 103 |  |  | // Check if uploaded file is a valid Add-On zip file
 | 
      
        | 104 |  |  | if (!($list && file_exists($temp_unzip . 'index.php')))
 | 
      
        | 105 |  |  | {
 | 
      
        | 106 | 1551 | Luisehahne |   $admin->print_error($MESSAGE['GENERIC_INVALID_ADDON_FILE']);
 | 
      
        | 107 | 1352 | Luisehahne | }
 | 
      
        | 108 |  |  | 
 | 
      
        | 109 |  |  | // Include the modules info file
 | 
      
        | 110 |  |  | require($temp_unzip.'info.php');
 | 
      
        | 111 |  |  | 
 | 
      
        | 112 |  |  | // Perform Add-on requirement checks before proceeding
 | 
      
        | 113 |  |  | require(WB_PATH . '/framework/addon.precheck.inc.php');
 | 
      
        | 114 |  |  | preCheckAddon($temp_file);
 | 
      
        | 115 |  |  | // Delete the temp unzip directory
 | 
      
        | 116 |  |  | rm_full_dir($temp_unzip);
 | 
      
        | 117 |  |  | 
 | 
      
        | 118 |  |  | // Check if the file is valid
 | 
      
        | 119 |  |  | if(!isset($module_directory))
 | 
      
        | 120 |  |  | {
 | 
      
        | 121 |  |  | 	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
 | 
      
        | 122 | 1712 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_INVALID']);
 | 
      
        | 123 | 1352 | Luisehahne | }
 | 
      
        | 124 |  |  | 
 | 
      
        | 125 |  |  | // Check if this module is already installed
 | 
      
        | 126 |  |  | // and compare versions if so
 | 
      
        | 127 |  |  | $new_module_version = $module_version;
 | 
      
        | 128 |  |  | $action="install";
 | 
      
        | 129 |  |  | if(is_dir(WB_PATH.'/modules/'.$module_directory))
 | 
      
        | 130 |  |  | {
 | 
      
        | 131 |  |  | 	if(file_exists(WB_PATH.'/modules/'.$module_directory.'/info.php'))
 | 
      
        | 132 |  |  |     {
 | 
      
        | 133 |  |  | 		require(WB_PATH.'/modules/'.$module_directory.'/info.php');
 | 
      
        | 134 |  |  | 		// Version to be installed is older than currently installed version
 | 
      
        | 135 |  |  | 		if (versionCompare($module_version, $new_module_version, '>='))
 | 
      
        | 136 |  |  |         {
 | 
      
        | 137 |  |  | 
 | 
      
        | 138 |  |  | 			if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
 | 
      
        | 139 | 1712 | Luisehahne | 			$admin->print_error($MESSAGE['GENERIC_ALREADY_INSTALLED']);
 | 
      
        | 140 | 1352 | Luisehahne | 		}
 | 
      
        | 141 |  |  | 
 | 
      
        | 142 |  |  | 		$action="upgrade";
 | 
      
        | 143 |  |  | 
 | 
      
        | 144 |  |  | 	}
 | 
      
        | 145 |  |  | }
 | 
      
        | 146 |  |  | 
 | 
      
        | 147 |  |  | // Check if module dir is writable
 | 
      
        | 148 |  |  | if(!is_writable(WB_PATH.'/modules/'))
 | 
      
        | 149 |  |  | {
 | 
      
        | 150 |  |  | 	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
 | 
      
        | 151 | 1712 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_BAD_PERMISSIONS']);
 | 
      
        | 152 | 1352 | Luisehahne | }
 | 
      
        | 153 |  |  | 
 | 
      
        | 154 |  |  | // Set module directory
 | 
      
        | 155 |  |  | $module_dir = WB_PATH.'/modules/'.$module_directory;
 | 
      
        | 156 |  |  | 
 | 
      
        | 157 |  |  | // Make sure the module dir exists, and chmod if needed
 | 
      
        | 158 |  |  | make_dir($module_dir);
 | 
      
        | 159 |  |  | 
 | 
      
        | 160 |  |  | // Unzip module to the module dir
 | 
      
        | 161 | 1381 | Luisehahne | if(isset($_POST['overwrite'])){
 | 
      
        | 162 | 1361 | Luisehahne | 	$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir, PCLZIP_OPT_REPLACE_NEWER );
 | 
      
        | 163 |  |  | } else {
 | 
      
        | 164 |  |  | 	$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir );
 | 
      
        | 165 |  |  | }
 | 
      
        | 166 | 1352 | Luisehahne | 
 | 
      
        | 167 |  |  | if(!$list)
 | 
      
        | 168 |  |  | {
 | 
      
        | 169 | 1712 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_CANNOT_UNZIP']);
 | 
      
        | 170 | 1352 | Luisehahne | }
 | 
      
        | 171 | 1361 | Luisehahne | /*
 | 
      
        | 172 | 1352 | Luisehahne | 
 | 
      
        | 173 | 1361 | Luisehahne | if ($list == 0) {
 | 
      
        | 174 |  |  |   $admin->print_error("ERROR : ".$archive->errorInfo(true));
 | 
      
        | 175 |  |  | }
 | 
      
        | 176 |  |  | */
 | 
      
        | 177 | 1352 | Luisehahne | // Delete the temp zip file
 | 
      
        | 178 |  |  | if(file_exists($temp_file)) { unlink($temp_file); }
 | 
      
        | 179 |  |  | 
 | 
      
        | 180 |  |  | // Chmod all the uploaded files
 | 
      
        | 181 |  |  | $dir = dir($module_dir);
 | 
      
        | 182 |  |  | while (false !== $entry = $dir->read())
 | 
      
        | 183 |  |  | {
 | 
      
        | 184 |  |  | 	// Skip pointers
 | 
      
        | 185 |  |  | 	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($module_dir.'/'.$entry))
 | 
      
        | 186 |  |  |     {
 | 
      
        | 187 |  |  | 		// Chmod file
 | 
      
        | 188 |  |  | 		change_mode($module_dir.'/'.$entry, 'file');
 | 
      
        | 189 |  |  | 	}
 | 
      
        | 190 |  |  | }
 | 
      
        | 191 | 1361 | Luisehahne | /* */
 | 
      
        | 192 | 1352 | Luisehahne | // Run the modules install // upgrade script if there is one
 | 
      
        | 193 |  |  | if(file_exists($module_dir.'/'.$action.'.php'))
 | 
      
        | 194 |  |  | {
 | 
      
        | 195 |  |  | 	require($module_dir.'/'.$action.'.php');
 | 
      
        | 196 |  |  | }
 | 
      
        | 197 | 1361 | Luisehahne | 
 | 
      
        | 198 | 1352 | Luisehahne | // Print success message
 | 
      
        | 199 |  |  | if ($action=="install")
 | 
      
        | 200 |  |  | {
 | 
      
        | 201 |  |  | 	// Load module info into DB
 | 
      
        | 202 |  |  | 	load_module(WB_PATH.'/modules/'.$module_directory, false);
 | 
      
        | 203 | 1712 | Luisehahne | 	$admin->print_success($MESSAGE['GENERIC_INSTALLED']);
 | 
      
        | 204 | 1352 | Luisehahne | } elseif ($action=="upgrade")
 | 
      
        | 205 |  |  | {
 | 
      
        | 206 | 1381 | Luisehahne | 
 | 
      
        | 207 | 1361 | Luisehahne | 	upgrade_module($module_directory, false);
 | 
      
        | 208 | 1712 | Luisehahne | 	$admin->print_success($MESSAGE['GENERIC_UPGRADED']);
 | 
      
        | 209 | 1361 | Luisehahne | }
 | 
      
        | 210 | 1352 | Luisehahne | 
 | 
      
        | 211 |  |  | // Print admin footer
 | 
      
        | 212 | 1712 | Luisehahne | $admin->print_footer();
 |