Project

General

Profile

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 2098 darkviper
$oTrans = Translate::getInstance();
30
$oTrans->enableAddon('admin\\modules');
31 1457 Luisehahne
$admin = new admin('Addons', 'modules_install', false);
32
if( !$admin->checkFTAN() )
33
{
34 1467 Luisehahne
	$admin->print_header();
35 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS);
36 1457 Luisehahne
}
37
// After check print the header
38
$admin->print_header();
39 1352 Luisehahne
40 1457 Luisehahne
// Check if user uploaded a file
41
if(!isset($_FILES['userfile'])) {
42
	header("Location: index.php");
43
	exit(0);
44
}
45
46 1352 Luisehahne
// Include the WB functions file
47
require_once(WB_PATH.'/framework/functions.php');
48
49
// Set temp vars
50
$temp_dir = WB_PATH.'/temp/';
51
$temp_file = $temp_dir . $_FILES['userfile']['name'];
52
$temp_unzip = WB_PATH.'/temp/unzip/';
53
54 1551 Luisehahne
if(!$_FILES['userfile']['error']) {
55
	// Try to upload the file to the temp dir
56
	if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file))
57
	{
58 2098 darkviper
		$admin->print_error($oTrans->MESSAGE_GENERIC_BAD_PERMISSIONS);
59 1551 Luisehahne
	}
60
} else {
61 2044 Luisehahne
    $iErrorMessage = ( isset($_FILES['userfile']['error']) && ( $_FILES['userfile']['error'] > 0 ) ? $_FILES['userfile']['error'] : UNKNOW_UPLOAD_ERROR );
62 1551 Luisehahne
// index for language files
63
	$key = 'UNKNOW_UPLOAD_ERROR';
64 2044 Luisehahne
    switch ( $iErrorMessage ) {
65 1551 Luisehahne
        case UPLOAD_ERR_INI_SIZE:
66
            $key = 'UPLOAD_ERR_INI_SIZE';
67 2044 Luisehahne
            break;
68 1551 Luisehahne
        case UPLOAD_ERR_FORM_SIZE:
69
            $key = 'UPLOAD_ERR_FORM_SIZE';
70 2044 Luisehahne
            break;
71 1551 Luisehahne
        case UPLOAD_ERR_PARTIAL:
72
            $key = 'UPLOAD_ERR_PARTIAL';
73 2044 Luisehahne
            break;
74 1551 Luisehahne
        case UPLOAD_ERR_NO_FILE:
75
            $key = 'UPLOAD_ERR_NO_FILE';
76 2044 Luisehahne
             break;
77
       case UPLOAD_ERR_NO_TMP_DIR:
78 1551 Luisehahne
            $key = 'UPLOAD_ERR_NO_TMP_DIR';
79 2044 Luisehahne
            break;
80 1551 Luisehahne
        case UPLOAD_ERR_CANT_WRITE:
81
            $key = 'UPLOAD_ERR_CANT_WRITE';
82 2044 Luisehahne
            break;
83 1551 Luisehahne
        case UPLOAD_ERR_EXTENSION:
84
            $key = 'UPLOAD_ERR_EXTENSION';
85 2044 Luisehahne
            break;
86 1551 Luisehahne
        default:
87
            $key = 'UNKNOW_UPLOAD_ERROR';
88
    }
89 2098 darkviper
    $admin->print_error($oTrans->{'MESSAGE_'.$key}.'<br />'.$oTrans->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 2098 darkviper
  $admin->print_error($oTrans->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 2098 darkviper
	$admin->print_error($oTrans->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 2098 darkviper
			$admin->print_error($oTrans->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 2098 darkviper
	$admin->print_error($oTrans->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 2098 darkviper
	$admin->print_error($oTrans->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 2098 darkviper
	$admin->print_success($oTrans->MESSAGE_GENERIC_INSTALLED);
204 1352 Luisehahne
} elseif ($action=="upgrade")
205
{
206 1381 Luisehahne
207 1361 Luisehahne
	upgrade_module($module_directory, false);
208 2098 darkviper
	$admin->print_success($oTrans->MESSAGE_GENERIC_UPGRADED);
209 1361 Luisehahne
}
210 1352 Luisehahne
211
// Print admin footer
212 1712 Luisehahne
$admin->print_footer();