Revision 1352
Added by Luisehahne almost 15 years ago
| install.php | ||
|---|---|---|
| 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$ |
|
| 14 |
* @filesource $HeadURL$ |
|
| 15 |
* @lastmodified $Date$ |
|
| 16 |
* |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
// Check if user uploaded a file |
|
| 20 |
if(!isset($_FILES['userfile'])) {
|
|
| 21 |
header("Location: index.php");
|
|
| 22 |
exit(0); |
|
| 23 |
} |
|
| 24 |
|
|
| 25 |
// do not display notices and warnings during installation |
|
| 26 |
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); |
|
| 27 |
|
|
| 28 |
// Setup admin object |
|
| 29 |
require('../../config.php');
|
|
| 30 |
require_once(WB_PATH.'/framework/class.admin.php'); |
|
| 31 |
$admin = new admin('Addons', 'modules_install');
|
|
| 32 |
|
|
| 33 |
// Include the WB functions file |
|
| 34 |
require_once(WB_PATH.'/framework/functions.php'); |
|
| 35 |
|
|
| 36 |
// Set temp vars |
|
| 37 |
$temp_dir = WB_PATH.'/temp/'; |
|
| 38 |
$temp_file = $temp_dir . $_FILES['userfile']['name']; |
|
| 39 |
$temp_unzip = WB_PATH.'/temp/unzip/'; |
|
| 40 |
|
|
| 41 |
// Try to upload the file to the temp dir |
|
| 42 |
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) |
|
| 43 |
{
|
|
| 44 |
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']); |
|
| 45 |
} |
|
| 46 |
|
|
| 47 |
// Include the PclZip class file (thanks to |
|
| 48 |
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php'); |
|
| 49 |
|
|
| 50 |
// Remove any vars with name "module_directory" |
|
| 51 |
unset($module_directory); |
|
| 52 |
|
|
| 53 |
// Setup the PclZip object |
|
| 54 |
$archive = new PclZip($temp_file); |
|
| 55 |
// Unzip the files to the temp unzip folder |
|
| 56 |
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip); |
|
| 57 |
|
|
| 58 |
// Check if uploaded file is a valid Add-On zip file |
|
| 59 |
if (!($list && file_exists($temp_unzip . 'index.php'))) |
|
| 60 |
{
|
|
| 61 |
$admin->print_error($MESSAGE['GENERIC']['INVALID_ADDON_FILE']); |
|
| 62 |
} |
|
| 63 |
|
|
| 64 |
// Include the modules info file |
|
| 65 |
require($temp_unzip.'info.php'); |
|
| 66 |
|
|
| 67 |
// Perform Add-on requirement checks before proceeding |
|
| 68 |
require(WB_PATH . '/framework/addon.precheck.inc.php'); |
|
| 69 |
preCheckAddon($temp_file); |
|
| 70 |
|
|
| 71 |
// Delete the temp unzip directory |
|
| 72 |
rm_full_dir($temp_unzip); |
|
| 73 |
|
|
| 74 |
// Check if the file is valid |
|
| 75 |
if(!isset($module_directory)) |
|
| 76 |
{
|
|
| 77 |
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
|
| 78 |
$admin->print_error($MESSAGE['GENERIC']['INVALID']); |
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
// Check if this module is already installed |
|
| 82 |
// and compare versions if so |
|
| 83 |
$new_module_version=$module_version; |
|
| 84 |
$action="install"; |
|
| 85 |
if(is_dir(WB_PATH.'/modules/'.$module_directory)) |
|
| 86 |
{
|
|
| 87 |
if(file_exists(WB_PATH.'/modules/'.$module_directory.'/info.php')) |
|
| 88 |
{
|
|
| 89 |
require(WB_PATH.'/modules/'.$module_directory.'/info.php'); |
|
| 90 |
// Version to be installed is older than currently installed version |
|
| 91 |
if (versionCompare($module_version, $new_module_version, '>=')) |
|
| 92 |
{
|
|
| 93 |
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
|
| 94 |
$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']); |
|
| 95 |
} |
|
| 96 |
|
|
| 97 |
$action="upgrade"; |
|
| 98 |
|
|
| 99 |
} |
|
| 100 |
} |
|
| 101 |
|
|
| 102 |
// Check if module dir is writable |
|
| 103 |
if(!is_writable(WB_PATH.'/modules/')) |
|
| 104 |
{
|
|
| 105 |
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
|
| 106 |
$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']); |
|
| 107 |
} |
|
| 108 |
|
|
| 109 |
// Set module directory |
|
| 110 |
$module_dir = WB_PATH.'/modules/'.$module_directory; |
|
| 111 |
|
|
| 112 |
// Make sure the module dir exists, and chmod if needed |
|
| 113 |
make_dir($module_dir); |
|
| 114 |
|
|
| 115 |
// Unzip module to the module dir |
|
| 116 |
$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir); |
|
| 117 |
if(!$list) |
|
| 118 |
{
|
|
| 119 |
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']); |
|
| 120 |
} |
|
| 121 |
|
|
| 122 |
// Delete the temp zip file |
|
| 123 |
if(file_exists($temp_file)) { unlink($temp_file); }
|
|
| 124 |
|
|
| 125 |
// Chmod all the uploaded files |
|
| 126 |
$dir = dir($module_dir); |
|
| 127 |
while (false !== $entry = $dir->read()) |
|
| 128 |
{
|
|
| 129 |
// Skip pointers |
|
| 130 |
if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($module_dir.'/'.$entry)) |
|
| 131 |
{
|
|
| 132 |
// Chmod file |
|
| 133 |
change_mode($module_dir.'/'.$entry, 'file'); |
|
| 134 |
} |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
// Run the modules install // upgrade script if there is one |
|
| 138 |
if(file_exists($module_dir.'/'.$action.'.php')) |
|
| 139 |
{
|
|
| 140 |
require($module_dir.'/'.$action.'.php'); |
|
| 141 |
} |
|
| 142 |
|
|
| 143 |
// Print success message |
|
| 144 |
if ($action=="install") |
|
| 145 |
{
|
|
| 146 |
// Load module info into DB |
|
| 147 |
load_module(WB_PATH.'/modules/'.$module_directory, false); |
|
| 148 |
$admin->print_success($MESSAGE['GENERIC']['INSTALLED']); |
|
| 149 |
} elseif ($action=="upgrade") |
|
| 150 |
{
|
|
| 151 |
upgrade_module($module_directory, false); |
|
| 152 |
$admin->print_success($MESSAGE['GENERIC']['UPGRADED']); |
|
| 153 |
} |
|
| 154 |
|
|
| 155 |
// Print admin footer |
|
| 156 |
$admin->print_footer(); |
|
| 157 |
|
|
| 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$ |
|
| 14 |
* @filesource $HeadURL$ |
|
| 15 |
* @lastmodified $Date$ |
|
| 16 |
* |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
// Check if user uploaded a file |
|
| 20 |
if(!isset($_FILES['userfile'])) {
|
|
| 21 |
header("Location: index.php");
|
|
| 22 |
exit(0); |
|
| 23 |
} |
|
| 24 |
|
|
| 25 |
// do not display notices and warnings during installation |
|
| 26 |
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); |
|
| 27 |
|
|
| 28 |
// Setup admin object |
|
| 29 |
require('../../config.php');
|
|
| 30 |
require_once(WB_PATH.'/framework/class.admin.php'); |
|
| 31 |
$admin = new admin('Addons', 'modules_install');
|
|
| 32 |
|
|
| 33 |
// Include the WB functions file |
|
| 34 |
require_once(WB_PATH.'/framework/functions.php'); |
|
| 35 |
|
|
| 36 |
// Set temp vars |
|
| 37 |
$temp_dir = WB_PATH.'/temp/'; |
|
| 38 |
$temp_file = $temp_dir . $_FILES['userfile']['name']; |
|
| 39 |
$temp_unzip = WB_PATH.'/temp/unzip/'; |
|
| 40 |
|
|
| 41 |
// Try to upload the file to the temp dir |
|
| 42 |
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file)) |
|
| 43 |
{
|
|
| 44 |
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UPLOAD']); |
|
| 45 |
} |
|
| 46 |
|
|
| 47 |
// Include the PclZip class file (thanks to |
|
| 48 |
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php'); |
|
| 49 |
|
|
| 50 |
// Remove any vars with name "module_directory" |
|
| 51 |
unset($module_directory); |
|
| 52 |
|
|
| 53 |
// Setup the PclZip object |
|
| 54 |
$archive = new PclZip($temp_file); |
|
| 55 |
// Unzip the files to the temp unzip folder |
|
| 56 |
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip); |
|
| 57 |
|
|
| 58 |
// Check if uploaded file is a valid Add-On zip file |
|
| 59 |
if (!($list && file_exists($temp_unzip . 'index.php'))) |
|
| 60 |
{
|
|
| 61 |
$admin->print_error($MESSAGE['GENERIC']['INVALID_ADDON_FILE']); |
|
| 62 |
} |
|
| 63 |
|
|
| 64 |
// Include the modules info file |
|
| 65 |
require($temp_unzip.'info.php'); |
|
| 66 |
|
|
| 67 |
// Perform Add-on requirement checks before proceeding |
|
| 68 |
require(WB_PATH . '/framework/addon.precheck.inc.php'); |
|
| 69 |
preCheckAddon($temp_file); |
|
| 70 |
// Delete the temp unzip directory |
|
| 71 |
rm_full_dir($temp_unzip); |
|
| 72 |
|
|
| 73 |
// Check if the file is valid |
|
| 74 |
if(!isset($module_directory)) |
|
| 75 |
{
|
|
| 76 |
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
|
| 77 |
$admin->print_error($MESSAGE['GENERIC']['INVALID']); |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
// Check if this module is already installed |
|
| 81 |
// and compare versions if so |
|
| 82 |
$new_module_version = $module_version; |
|
| 83 |
$action="install"; |
|
| 84 |
if(is_dir(WB_PATH.'/modules/'.$module_directory)) |
|
| 85 |
{
|
|
| 86 |
if(file_exists(WB_PATH.'/modules/'.$module_directory.'/info.php')) |
|
| 87 |
{
|
|
| 88 |
require(WB_PATH.'/modules/'.$module_directory.'/info.php'); |
|
| 89 |
// Version to be installed is older than currently installed version |
|
| 90 |
if (versionCompare($module_version, $new_module_version, '>=')) |
|
| 91 |
{
|
|
| 92 |
|
|
| 93 |
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
|
| 94 |
$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']); |
|
| 95 |
} |
|
| 96 |
|
|
| 97 |
$action="upgrade"; |
|
| 98 |
|
|
| 99 |
} |
|
| 100 |
} |
|
| 101 |
|
|
| 102 |
// Check if module dir is writable |
|
| 103 |
if(!is_writable(WB_PATH.'/modules/')) |
|
| 104 |
{
|
|
| 105 |
if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
|
|
| 106 |
$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']); |
|
| 107 |
} |
|
| 108 |
|
|
| 109 |
// Set module directory |
|
| 110 |
$module_dir = WB_PATH.'/modules/'.$module_directory; |
|
| 111 |
|
|
| 112 |
// Make sure the module dir exists, and chmod if needed |
|
| 113 |
make_dir($module_dir); |
|
| 114 |
|
|
| 115 |
// Unzip module to the module dir |
|
| 116 |
$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir); |
|
| 117 |
|
|
| 118 |
if(!$list) |
|
| 119 |
{
|
|
| 120 |
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']); |
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
// Delete the temp zip file |
|
| 124 |
if(file_exists($temp_file)) { unlink($temp_file); }
|
|
| 125 |
|
|
| 126 |
// Chmod all the uploaded files |
|
| 127 |
$dir = dir($module_dir); |
|
| 128 |
while (false !== $entry = $dir->read()) |
|
| 129 |
{
|
|
| 130 |
// Skip pointers |
|
| 131 |
if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($module_dir.'/'.$entry)) |
|
| 132 |
{
|
|
| 133 |
// Chmod file |
|
| 134 |
change_mode($module_dir.'/'.$entry, 'file'); |
|
| 135 |
} |
|
| 136 |
} |
|
| 137 |
/* |
|
| 138 |
// Run the modules install // upgrade script if there is one |
|
| 139 |
if(file_exists($module_dir.'/'.$action.'.php')) |
|
| 140 |
{
|
|
| 141 |
require($module_dir.'/'.$action.'.php'); |
|
| 142 |
} |
|
| 143 |
*/ |
|
| 144 |
// Print success message |
|
| 145 |
if ($action=="install") |
|
| 146 |
{
|
|
| 147 |
// Load module info into DB |
|
| 148 |
load_module(WB_PATH.'/modules/'.$module_directory, false); |
|
| 149 |
$admin->print_success($MESSAGE['GENERIC']['INSTALLED']); |
|
| 150 |
} elseif ($action=="upgrade") |
|
| 151 |
{
|
|
| 152 |
|
|
| 153 |
upgrade_module($module_directory, true); |
|
| 154 |
$admin->print_success($MESSAGE['GENERIC']['UPGRADED']); |
|
| 155 |
} |
|
| 156 |
|
|
| 157 |
// Print admin footer |
|
| 158 |
$admin->print_footer(); |
|
| 159 |
|
|
| 158 | 160 |
?> |
Also available in: Unified diff
fix if upgrade module can now overwrite existing newer files in modules folder
same fix for upgrade templates