Project

General

Profile

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 1712 2012-08-29 11:59:57Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/modules/install.php $
14
 * @lastmodified    $Date: 2012-08-29 13:59:57 +0200 (Wed, 29 Aug 2012) $
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
require_once(WB_PATH.'/framework/class.admin.php');
24
$admin = new admin('Addons', 'modules_install', false);
25
if( !$admin->checkFTAN() )
26
{
27
	$admin->print_header();
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
if(!$_FILES['userfile']['error']) {
48
	// Try to upload the file to the temp dir
49
	if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $temp_file))
50
	{
51
		$admin->print_error($MESSAGE['GENERIC_BAD_PERMISSIONS']);
52
	}
53
} else {
54
// index for language files
55
	$key = 'UNKNOW_UPLOAD_ERROR';
56
    switch ($error_code) {
57
        case UPLOAD_ERR_INI_SIZE:
58
            $key = 'UPLOAD_ERR_INI_SIZE';
59
        case UPLOAD_ERR_FORM_SIZE:
60
            $key = 'UPLOAD_ERR_FORM_SIZE';
61
        case UPLOAD_ERR_PARTIAL:
62
            $key = 'UPLOAD_ERR_PARTIAL';
63
        case UPLOAD_ERR_NO_FILE:
64
            $key = 'UPLOAD_ERR_NO_FILE';
65
        case UPLOAD_ERR_NO_TMP_DIR:
66
            $key = 'UPLOAD_ERR_NO_TMP_DIR';
67
        case UPLOAD_ERR_CANT_WRITE:
68
            $key = 'UPLOAD_ERR_CANT_WRITE';
69
        case UPLOAD_ERR_EXTENSION:
70
            $key = 'UPLOAD_ERR_EXTENSION';
71
        default:
72
            $key = 'UNKNOW_UPLOAD_ERROR';
73
    }
74
	$admin->print_error($MESSAGE[$key].'<br />'.$MESSAGE['GENERIC_CANNOT_UPLOAD']);
75
}
76

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

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

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

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

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

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

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

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

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

    
127
		$action="upgrade";
128

    
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 = $archive->extract(PCLZIP_OPT_PATH, $module_dir, PCLZIP_OPT_REPLACE_NEWER );
148
} else {
149
	$list = $archive->extract(PCLZIP_OPT_PATH, $module_dir );
150
}
151

    
152
if(!$list)
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();
(3-3/5)