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