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