Project

General

Profile

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 1551 2011-12-27 14:40:04Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/modules/install.php $
15
 * @lastmodified    $Date: 2011-12-27 15:40:04 +0100 (Tue, 27 Dec 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_header();
29
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
30
}
31
// After check print the header
32
$admin->print_header();
33

    
34
// Check if user uploaded a file
35
if(!isset($_FILES['userfile'])) {
36
	header("Location: index.php");
37
	exit(0);
38
}
39

    
40
// Include the WB functions file
41
require_once(WB_PATH.'/framework/functions.php');
42

    
43
// Set temp vars
44
$temp_dir = WB_PATH.'/temp/';
45
$temp_file = $temp_dir . $_FILES['userfile']['name'];
46
$temp_unzip = WB_PATH.'/temp/unzip/';
47

    
48
if(!$_FILES['userfile']['error']) {
49
	// Try to upload the file to the temp dir
50
	if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file))
51
	{
52
		$admin->print_error($MESSAGE['GENERIC_BAD_PERMISSIONS']);
53
	}
54
} else {
55
// index for language files
56
	$key = 'UNKNOW_UPLOAD_ERROR';
57
    switch ($error_code) {
58
        case UPLOAD_ERR_INI_SIZE:
59
            $key = 'UPLOAD_ERR_INI_SIZE';
60
        case UPLOAD_ERR_FORM_SIZE:
61
            $key = 'UPLOAD_ERR_FORM_SIZE';
62
        case UPLOAD_ERR_PARTIAL:
63
            $key = 'UPLOAD_ERR_PARTIAL';
64
        case UPLOAD_ERR_NO_FILE:
65
            $key = 'UPLOAD_ERR_NO_FILE';
66
        case UPLOAD_ERR_NO_TMP_DIR:
67
            $key = 'UPLOAD_ERR_NO_TMP_DIR';
68
        case UPLOAD_ERR_CANT_WRITE:
69
            $key = 'UPLOAD_ERR_CANT_WRITE';
70
        case UPLOAD_ERR_EXTENSION:
71
            $key = 'UPLOAD_ERR_EXTENSION';
72
        default:
73
            $key = 'UNKNOW_UPLOAD_ERROR';
74
    }
75
	$admin->print_error($MESSAGE[$key].'<br />'.$MESSAGE['GENERIC_CANNOT_UPLOAD']);
76
}
77

    
78
// Include the PclZip class file (thanks to 
79
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
80

    
81
// Remove any vars with name "module_directory"
82
unset($module_directory);
83

    
84
// Setup the PclZip object
85
$archive = new PclZip($temp_file);
86
// Unzip the files to the temp unzip folder
87
$list = $archive->extract(PCLZIP_OPT_PATH, $temp_unzip);
88

    
89
// Check if uploaded file is a valid Add-On zip file
90
if (!($list && file_exists($temp_unzip . 'index.php')))
91
{
92
  $admin->print_error($MESSAGE['GENERIC_INVALID_ADDON_FILE']);
93
}
94

    
95
// Include the modules info file
96
require($temp_unzip.'info.php');
97

    
98
// Perform Add-on requirement checks before proceeding
99
require(WB_PATH . '/framework/addon.precheck.inc.php');
100
preCheckAddon($temp_file);
101
// Delete the temp unzip directory
102
rm_full_dir($temp_unzip);
103

    
104
// Check if the file is valid
105
if(!isset($module_directory))
106
{
107
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
108
	$admin->print_error($MESSAGE['GENERIC']['INVALID']);
109
}
110

    
111
// Check if this module is already installed
112
// and compare versions if so
113
$new_module_version = $module_version;
114
$action="install";
115
if(is_dir(WB_PATH.'/modules/'.$module_directory))
116
{
117
	if(file_exists(WB_PATH.'/modules/'.$module_directory.'/info.php'))
118
    {
119
		require(WB_PATH.'/modules/'.$module_directory.'/info.php');
120
		// Version to be installed is older than currently installed version
121
		if (versionCompare($module_version, $new_module_version, '>='))
122
        {
123

    
124
			if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
125
			$admin->print_error($MESSAGE['GENERIC']['ALREADY_INSTALLED']);
126
		}
127

    
128
		$action="upgrade";
129

    
130
	}
131
}
132

    
133
// Check if module dir is writable
134
if(!is_writable(WB_PATH.'/modules/'))
135
{
136
	if(file_exists($temp_file)) { unlink($temp_file); } // Remove temp file
137
	$admin->print_error($MESSAGE['GENERIC']['BAD_PERMISSIONS']);
138
}
139

    
140
// Set module directory
141
$module_dir = WB_PATH.'/modules/'.$module_directory;
142

    
143
// Make sure the module dir exists, and chmod if needed
144
make_dir($module_dir);
145

    
146
// Unzip module to the module dir
147
if(isset($_POST['overwrite'])){
148
	$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir, PCLZIP_OPT_REPLACE_NEWER );
149
} else {
150
	$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir );
151
}
152

    
153
if(!$list)
154
{
155
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNZIP']);
156
}
157
/*
158

    
159
if ($list == 0) {
160
  $admin->print_error("ERROR : ".$archive->errorInfo(true));
161
}
162
*/
163
// Delete the temp zip file
164
if(file_exists($temp_file)) { unlink($temp_file); }
165

    
166
// Chmod all the uploaded files
167
$dir = dir($module_dir);
168
while (false !== $entry = $dir->read())
169
{
170
	// Skip pointers
171
	if(substr($entry, 0, 1) != '.' AND $entry != '.svn' AND !is_dir($module_dir.'/'.$entry))
172
    {
173
		// Chmod file
174
		change_mode($module_dir.'/'.$entry, 'file');
175
	}
176
}
177
/* */
178
// Run the modules install // upgrade script if there is one
179
if(file_exists($module_dir.'/'.$action.'.php'))
180
{
181
	require($module_dir.'/'.$action.'.php');
182
}
183

    
184
// Print success message
185
if ($action=="install")
186
{
187
	// Load module info into DB
188
	load_module(WB_PATH.'/modules/'.$module_directory, false);
189
	$admin->print_success($MESSAGE['GENERIC']['INSTALLED']);
190
} elseif ($action=="upgrade")
191
{
192

    
193
	upgrade_module($module_directory, false);
194
	$admin->print_success($MESSAGE['GENERIC']['UPGRADED']);
195
}
196

    
197
// Print admin footer
198
$admin->print_footer();
199

    
200
?>
(3-3/5)