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 2098 2014-02-11 01:37:03Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/modules/install.php $
14
 * @lastmodified    $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
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
$oTrans = Translate::getInstance();
30
$oTrans->enableAddon('admin\\modules');
31
$admin = new admin('Addons', 'modules_install', false);
32
if( !$admin->checkFTAN() )
33
{
34
	$admin->print_header();
35
	$admin->print_error($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS);
36
}
37
// After check print the header
38
$admin->print_header();
39

    
40
// Check if user uploaded a file
41
if(!isset($_FILES['userfile'])) {
42
	header("Location: index.php");
43
	exit(0);
44
}
45

    
46
// 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
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
		$admin->print_error($oTrans->MESSAGE_GENERIC_BAD_PERMISSIONS);
59
	}
60
} else {
61
    $iErrorMessage = ( isset($_FILES['userfile']['error']) && ( $_FILES['userfile']['error'] > 0 ) ? $_FILES['userfile']['error'] : UNKNOW_UPLOAD_ERROR );
62
// index for language files
63
	$key = 'UNKNOW_UPLOAD_ERROR';
64
    switch ( $iErrorMessage ) {
65
        case UPLOAD_ERR_INI_SIZE:
66
            $key = 'UPLOAD_ERR_INI_SIZE';
67
            break;
68
        case UPLOAD_ERR_FORM_SIZE:
69
            $key = 'UPLOAD_ERR_FORM_SIZE';
70
            break;
71
        case UPLOAD_ERR_PARTIAL:
72
            $key = 'UPLOAD_ERR_PARTIAL';
73
            break;
74
        case UPLOAD_ERR_NO_FILE:
75
            $key = 'UPLOAD_ERR_NO_FILE';
76
             break;
77
       case UPLOAD_ERR_NO_TMP_DIR:
78
            $key = 'UPLOAD_ERR_NO_TMP_DIR';
79
            break;
80
        case UPLOAD_ERR_CANT_WRITE:
81
            $key = 'UPLOAD_ERR_CANT_WRITE';
82
            break;
83
        case UPLOAD_ERR_EXTENSION:
84
            $key = 'UPLOAD_ERR_EXTENSION';
85
            break;
86
        default:
87
            $key = 'UNKNOW_UPLOAD_ERROR';
88
    }
89
    $admin->print_error($oTrans->{'MESSAGE_'.$key}.'<br />'.$oTrans->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($oTrans->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($oTrans->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($oTrans->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($oTrans->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($oTrans->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($oTrans->MESSAGE_GENERIC_INSTALLED);
204
} elseif ($action=="upgrade")
205
{
206

    
207
	upgrade_module($module_directory, false);
208
	$admin->print_success($oTrans->MESSAGE_GENERIC_UPGRADED);
209
}
210

    
211
// Print admin footer
212
$admin->print_footer();
(3-3/5)