1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category admin
|
5
|
* @package modules
|
6
|
* @author Ryan Djurovich,WebsiteBaker Project
|
7
|
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: install.php 2044 2013-12-19 03:41:38Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/modules/install.php $
|
14
|
* @lastmodified $Date: 2013-12-19 04:41:38 +0100 (Thu, 19 Dec 2013) $
|
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
|
//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
|
$admin = new admin('Addons', 'modules_install', false);
|
31
|
if( !$admin->checkFTAN() )
|
32
|
{
|
33
|
$admin->print_header();
|
34
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
|
35
|
}
|
36
|
// After check print the header
|
37
|
$admin->print_header();
|
38
|
|
39
|
// Check if user uploaded a file
|
40
|
if(!isset($_FILES['userfile'])) {
|
41
|
header("Location: index.php");
|
42
|
exit(0);
|
43
|
}
|
44
|
|
45
|
// 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
|
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
|
$iErrorMessage = ( isset($_FILES['userfile']['error']) && ( $_FILES['userfile']['error'] > 0 ) ? $_FILES['userfile']['error'] : UNKNOW_UPLOAD_ERROR );
|
61
|
// index for language files
|
62
|
$key = 'UNKNOW_UPLOAD_ERROR';
|
63
|
switch ( $iErrorMessage ) {
|
64
|
case UPLOAD_ERR_INI_SIZE:
|
65
|
$key = 'UPLOAD_ERR_INI_SIZE';
|
66
|
break;
|
67
|
case UPLOAD_ERR_FORM_SIZE:
|
68
|
$key = 'UPLOAD_ERR_FORM_SIZE';
|
69
|
break;
|
70
|
case UPLOAD_ERR_PARTIAL:
|
71
|
$key = 'UPLOAD_ERR_PARTIAL';
|
72
|
break;
|
73
|
case UPLOAD_ERR_NO_FILE:
|
74
|
$key = 'UPLOAD_ERR_NO_FILE';
|
75
|
break;
|
76
|
case UPLOAD_ERR_NO_TMP_DIR:
|
77
|
$key = 'UPLOAD_ERR_NO_TMP_DIR';
|
78
|
break;
|
79
|
case UPLOAD_ERR_CANT_WRITE:
|
80
|
$key = 'UPLOAD_ERR_CANT_WRITE';
|
81
|
break;
|
82
|
case UPLOAD_ERR_EXTENSION:
|
83
|
$key = 'UPLOAD_ERR_EXTENSION';
|
84
|
break;
|
85
|
default:
|
86
|
$key = 'UNKNOW_UPLOAD_ERROR';
|
87
|
}
|
88
|
|
89
|
$admin->print_error($MESSAGE[$key].'<br />'.$MESSAGE['GENERIC_CANNOT_UPLOAD']);
|
90
|
}
|
91
|
|
92
|
// Include the PclZip class file (thanks to
|
93
|
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
|
$admin->print_error($MESSAGE['GENERIC_INVALID_ADDON_FILE']);
|
107
|
}
|
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
|
$admin->print_error($MESSAGE['GENERIC_INVALID']);
|
123
|
}
|
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
|
$admin->print_error($MESSAGE['GENERIC_ALREADY_INSTALLED']);
|
140
|
}
|
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
|
$admin->print_error($MESSAGE['GENERIC_BAD_PERMISSIONS']);
|
152
|
}
|
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
|
if(isset($_POST['overwrite'])){
|
162
|
$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
|
|
167
|
if(!$list)
|
168
|
{
|
169
|
$admin->print_error($MESSAGE['GENERIC_CANNOT_UNZIP']);
|
170
|
}
|
171
|
/*
|
172
|
|
173
|
if ($list == 0) {
|
174
|
$admin->print_error("ERROR : ".$archive->errorInfo(true));
|
175
|
}
|
176
|
*/
|
177
|
// 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
|
/* */
|
192
|
// 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
|
|
198
|
// Print success message
|
199
|
if ($action=="install")
|
200
|
{
|
201
|
// Load module info into DB
|
202
|
load_module(WB_PATH.'/modules/'.$module_directory, false);
|
203
|
$admin->print_success($MESSAGE['GENERIC_INSTALLED']);
|
204
|
} elseif ($action=="upgrade")
|
205
|
{
|
206
|
|
207
|
upgrade_module($module_directory, false);
|
208
|
$admin->print_success($MESSAGE['GENERIC_UPGRADED']);
|
209
|
}
|
210
|
|
211
|
// Print admin footer
|
212
|
$admin->print_footer();
|