GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( af7d4e...39a71a )
by gyeong-won
09:41
created

installController::_makeDbInfoByInstallConfig()   D

Complexity

Conditions 9
Paths 64

Size

Total Lines 34
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 25
nc 64
nop 0
dl 0
loc 34
rs 4.909
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  installController
5
 * @author NAVER ([email protected])
6
 * @brief install module of the Controller class
7
 */
8
class installController extends install
9
{
10
	var $db_tmp_config_file = '';
11
	var $etc_tmp_config_file = '';
12
	var $flagLicenseAgreement = './files/env/license_agreement';
13
14
	/**
15
	 * @brief Initialization
16
	 */
17
	function init()
18
	{
19
		// Error occurs if already installed
20
		if($this->act !== 'procInstallLicenseAggrement' && Context::isInstalled())
21
		{
22
			$this->stop('msg_already_installed');
23
		}
24
25
		$this->db_tmp_config_file = _XE_PATH_.'files/config/tmpDB.config.php';
26
		$this->etc_tmp_config_file = _XE_PATH_.'files/config/tmpEtc.config.php';
27
	}
28
29
	/**
30
	 * @brief cubrid db setting wrapper, becase Server Side Validator...
31
	 * Server Side Validatro can use only one proc, one ruleset
32
	 */
33
	function procCubridDBSetting()
34
	{
35
		return $this->_procDBSetting();
36
	}
37
38
	/**
39
	 * @brief firebird db setting wrapper, becase Server Side Validator...
40
	 * Server Side Validatro can use only one proc, one ruleset
41
	 */
42
	function procFirebirdDBSetting()
43
	{
44
		return $this->_procDBSetting();
45
	}
46
47
	/**
48
	 * @brief mssql db setting wrapper, becase Server Side Validator...
49
	 * Server Side Validatro can use only one proc, one ruleset
50
	 */
51
	function procMssqlDBSetting()
52
	{
53
		return $this->_procDBSetting();
54
	}
55
56
	/**
57
	 * @brief mysql db setting wrapper, becase Server Side Validator...
58
	 * Server Side Validatro can use only one proc, one ruleset
59
	 */
60
	function procMysqlDBSetting()
61
	{
62
		return $this->_procDBSetting();
63
	}
64
65
	/**
66
	 * @brief postgresql db setting wrapper, becase Server Side Validator...
67
	 * Server Side Validatro can use only one proc, one ruleset
68
	 */
69
	function procPostgresqlDBSetting()
70
	{
71
		return $this->_procDBSetting();
72
	}
73
74
	/**
75
	 * @brief sqlite db setting wrapper, becase Server Side Validator...
76
	 * Server Side Validatro can use only one proc, one ruleset
77
	 */
78
	function procSqliteDBSetting()
79
	{
80
		return $this->_procDBSetting();
81
	}
82
83
	/**
84
	 * @brief division install step... DB Config temp file create
85
	 */
86
	function _procDBSetting()
87
	{
88
		// Get DB-related variables
89
		$con_string = Context::gets('db_type','db_port','db_hostname','db_userid','db_password','db_database','db_table_prefix');
90
91
		$db_info = new stdClass();
92
		$db_info->master_db = get_object_vars($con_string);
93
		$db_info->slave_db = array($db_info->master_db);
94
		$db_info->default_url = Context::getRequestUri();
95
		$db_info->lang_type = Context::getLangType();
96
		$db_info->use_mobile_view = 'Y';
97
98
		// Set DB type and information
99
		Context::setDBInfo($db_info);
100
101
		// Check if available to connect to the DB
102
		$oDB = &DB::getInstance();
103
		$output = $oDB->getError();
104
		if(!$output->toBool()) return $output;
105
		if(!$oDB->isConnected()) return $oDB->getError();
106
107
		// Create a db temp config file
108
		if(!$this->makeDBConfigFile()) return new Object(-1, 'msg_install_failed');
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->makeDBConfigFile() of type null|boolean is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
109
110 View Code Duplication
		if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON')))
111
		{
112
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'act', 'dispInstallConfigForm');
113
			header('location:'.$returnUrl);
114
			return;
115
		}
116
	}
117
118
	/**
119
	 * @brief division install step... rewrite, time_zone Config temp file create
120
	 */
121
	function procConfigSetting()
122
	{
123
		// Get variables
124
		$config_info = Context::gets('use_rewrite','time_zone');
125
		if($config_info->use_rewrite!='Y') $config_info->use_rewrite = 'N';
126
127
		// Create a db temp config file
128
		if(!$this->makeEtcConfigFile($config_info)) return new Object(-1, 'msg_install_failed');
129
130 View Code Duplication
		if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON')))
131
		{
132
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'act', 'dispInstallManagerForm');
133
			header('location:'.$returnUrl);
134
			return;
135
		}
136
	}
137
138
	/**
139
	 * @brief Install with received information
140
	 */
141
	function procInstall()
142
	{
143
		// Check if it is already installed
144
		if(Context::isInstalled()) return new Object(-1, 'msg_already_installed');
145
146
		// Assign a temporary administrator when installing
147
		$logged_info = new stdClass();
148
		$logged_info->is_admin = 'Y';
149
		Context::set('logged_info', $logged_info);
0 ignored issues
show
Documentation introduced by
$logged_info is of type object<stdClass>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
150
151
		// check install config
152
		if(Context::get('install_config'))
153
		{
154
			$db_info = $this->_makeDbInfoByInstallConfig();
155
		}
156
		// install by default XE UI
157
		else
158
		{
159
			if(FileHandler::exists($this->db_tmp_config_file)) include $this->db_tmp_config_file;
0 ignored issues
show
Bug Best Practice introduced by
The expression \FileHandler::exists($this->db_tmp_config_file) of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
160
			if(FileHandler::exists($this->etc_tmp_config_file)) include $this->etc_tmp_config_file;
0 ignored issues
show
Bug Best Practice introduced by
The expression \FileHandler::exists($this->etc_tmp_config_file) of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
161
		}
162
163
		// Set DB type and information
164
		Context::setDBInfo($db_info);
0 ignored issues
show
Bug introduced by
The variable $db_info does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
165
		// Create DB Instance
166
		$oDB = &DB::getInstance();
167
		// Check if available to connect to the DB
168
		if(!$oDB->isConnected()) return $oDB->getError();
169
170
		// Install all the modules
171
		try {
172
			$oDB->begin();
173
			$this->installDownloadedModule();
174
			$oDB->commit();
175
		} catch(Exception $e) {
176
			$oDB->rollback();
177
			return new Object(-1, $e->getMessage());
178
		}
179
180
		// Create a config file
181
		if(!$this->makeConfigFile()) return new Object(-1, 'msg_install_failed');
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->makeConfigFile() of type null|boolean is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
182
183
		// load script
184
		$scripts = FileHandler::readDir(_XE_PATH_ . 'modules/install/script', '/(\.php)$/');
185
		if(count($scripts)>0)
186
		{
187
			sort($scripts);
188
			foreach($scripts as $script)
189
			{
190
				$script_path = FileHandler::getRealPath('./modules/install/script/');
191
				$output = include($script_path . $script);
192
			}
193
		}
194
195
		// save selected lang info
196
		$oInstallAdminController = getAdminController('install');
197
		$oInstallAdminController->saveLangSelected(array(Context::getLangType()));
198
199
		// Display a message that installation is completed
200
		$this->setMessage('msg_install_completed');
201
202
		unset($_SESSION['use_rewrite']);
203
204 View Code Duplication
		if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON')))
205
		{
206
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('');
207
			header('location:'.$returnUrl);
208
			return new Object();
209
		}
210
	}
211
212
	/**
213
	 * @brief Make DB Information by Install Config
214
	 */
215
	function _makeDbInfoByInstallConfig()
216
	{
217
		$db_info = new stdClass();
218
		$db_info->master_db = array(
219
			'db_type' => Context::get('db_type'),
220
			'db_port' => Context::get('db_port'),
221
			'db_hostname' => Context::get('db_hostname'),
222
			'db_userid' => Context::get('db_userid'),
223
			'db_password' => Context::get('db_password'),
224
			'db_database' => Context::get('db_database'),
225
			'db_table_prefix' => Context::get('db_table_prefix')
226
		);
227
		$db_info->slave_db = array($db_info->master_db);
228
		$db_info->default_url = Context::getRequestUri();
229
		$db_info->lang_type = Context::get('lang_type') ? Context::get('lang_type') : Context::getLangType();
230
		Context::setLangType($db_info->lang_type);
231
		$db_info->use_rewrite = Context::get('use_rewrite');
232
		$db_info->time_zone = Context::get('time_zone');
233
234
		if($_SERVER['HTTPS'] == 'on')
235
		{
236
			$https_port = (Context::get('https_port')) ? Context::get('https_port') : $_SERVER['SERVER_PORT'];
237
			$https_port = (!$https_port != 443) ? $https_port : null;
238
		}
239
		else
240
		{
241
			$http_port = (Context::get('http_port')) ? Context::get('http_port') : $_SERVER['SERVER_PORT'];
242
			$http_port = (!$http_port != 80) ? $http_port : null;
243
		}
244
		if($http_port) $db_info->http_port = $http_port;
0 ignored issues
show
Bug introduced by
The variable $http_port does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
245
		if($https_port) $db_info->https_port = $https_port;
0 ignored issues
show
Bug introduced by
The variable $https_port does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
246
247
		return $db_info;
248
	}
249
250
	/**
251
	 * @brief Set FTP Information
252
	 */
253
	function procInstallFTP()
254
	{
255
		if(Context::isInstalled()) return new Object(-1, 'msg_already_installed');
256
		$ftp_info = Context::gets('ftp_host', 'ftp_user','ftp_password','ftp_port','ftp_root_path');
257
		$ftp_info->ftp_port = (int)$ftp_info->ftp_port;
258
		if(!$ftp_info->ftp_port) $ftp_info->ftp_port = 21;
259
		if(!$ftp_info->ftp_host) $ftp_info->ftp_host = '127.0.0.1';
260
		if(!$ftp_info->ftp_root_path) $ftp_info->ftp_root_path = '/';
261
262
		$buff = array('<?php if(!defined("__XE__")) exit();');
263
		$buff[] = "\$ftp_info = new stdClass();";
264
		foreach($ftp_info as $key => $val)
0 ignored issues
show
Bug introduced by
The expression $ftp_info of type object<stdClass> is not traversable.
Loading history...
265
		{
266
			$buff[] = sprintf("\$ftp_info->%s='%s';", $key, str_replace("'","\\'",$val));
267
		}
268
269
		// If safe_mode
270
		if(ini_get('safe_mode'))
271
		{
272
			if(!$ftp_info->ftp_user || !$ftp_info->ftp_password) return new Object(-1,'msg_safe_mode_ftp_needed');
273
274
			require_once(_XE_PATH_.'libs/ftp.class.php');
275
			$oFtp = new ftp();
276 View Code Duplication
			if(!$oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port)) return new Object(-1, sprintf(Context::getLang('msg_ftp_not_connected'), 'host'));
277
278 View Code Duplication
			if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password))
279
			{
280
				$oFtp->ftp_quit();
281
				return new Object(-1,'msg_ftp_invalid_auth_info');
282
			}
283
284 View Code Duplication
			if(!is_dir(_XE_PATH_.'files') && !$oFtp->ftp_mkdir($ftp_info->ftp_root_path.'files'))
285
			{
286
				$oFtp->ftp_quit();
287
				return new Object(-1,'msg_ftp_mkdir_fail');
288
			}
289
290 View Code Duplication
			if(!$oFtp->ftp_site("CHMOD 777 ".$ftp_info->ftp_root_path.'files'))
291
			{
292
				$oFtp->ftp_quit();
293
				return new Object(-1,'msg_ftp_chmod_fail');
294
			}
295
296 View Code Duplication
			if(!is_dir(_XE_PATH_.'files/config') && !$oFtp->ftp_mkdir($ftp_info->ftp_root_path.'files/config'))
297
			{
298
				$oFtp->ftp_quit();
299
				return new Object(-1,'msg_ftp_mkdir_fail');
300
			}
301
302 View Code Duplication
			if(!$oFtp->ftp_site("CHMOD 777 ".$ftp_info->ftp_root_path.'files/config'))
303
			{
304
				$oFtp->ftp_quit();
305
				return new Object(-1,'msg_ftp_chmod_fail');
306
			}
307
308
			$oFtp->ftp_quit();
309
		}
310
311
		FileHandler::WriteFile(Context::getFTPConfigFile(), join(PHP_EOL, $buff));
312
	}
313
314
	function procInstallCheckFtp()
315
	{
316
		$ftp_info = Context::gets('ftp_user','ftp_password','ftp_port','sftp');
317
		$ftp_info->ftp_port = (int)$ftp_info->ftp_port;
318
		if(!$ftp_info->ftp_port) $ftp_info->ftp_port = 21;
319
		if(!$ftp_info->sftp) $ftp_info->sftp = 'N';
320
321
		if(!$ftp_info->ftp_user || !$ftp_info->ftp_password) return new Object(-1,'msg_safe_mode_ftp_needed');
322
323
		if($ftp_info->sftp == 'Y')
324
		{
325
			$connection = ssh2_connect('localhost', $ftp_info->ftp_port);
326
			if(!ssh2_auth_password($connection, $ftp_info->ftp_user, $ftp_info->ftp_password))
327
			{
328
				return new Object(-1,'msg_ftp_invalid_auth_info');
329
			}
330
		}
331
		else
332
		{
333
			require_once(_XE_PATH_.'libs/ftp.class.php');
334
			$oFtp = new ftp();
335
			if(!$oFtp->ftp_connect('127.0.0.1', $ftp_info->ftp_port)) return new Object(-1, sprintf(Context::getLang('msg_ftp_not_connected'), 'localhost'));
336
337 View Code Duplication
			if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password))
338
			{
339
				$oFtp->ftp_quit();
340
				return new Object(-1,'msg_ftp_invalid_auth_info');
341
			}
342
			$oFtp->ftp_quit();
343
		}
344
345
		$this->setMessage('msg_ftp_connect_success');
346
	}
347
348
	/**
349
	 * @brief Result returned after checking the installation environment
350
	 */
351
	function checkInstallEnv()
352
	{
353
		// Check each item
354
		$checklist = array();
355
		// 0. check your version of php (5.2.4 or higher)
356
		$checklist['php_version'] = true;
357
		if(version_compare(PHP_VERSION, __XE_MIN_PHP_VERSION__, '<'))
358
		{
359
			$checklist['php_version'] = false;
360
		}
361
362
		if(version_compare(PHP_VERSION, __XE_RECOMMEND_PHP_VERSION__, '<'))
363
		{
364
			Context::set('phpversion_warning', true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
365
		}
366
367
		// 1. Check permission
368
		if(is_writable('./')||is_writable('./files')) $checklist['permission'] = true;
369
		else $checklist['permission'] = false;
370
		// 2. Check if xml_parser_create exists
371
		if(function_exists('xml_parser_create')) $checklist['xml'] = true;
372
		else $checklist['xml'] = false;
373
		// 3. Check if ini_get (session.auto_start) == 1
374
		if(ini_get('session.auto_start')!=1) $checklist['session'] = true;
375
		else $checklist['session'] = false;
376
		// 4. Check if iconv exists
377
		if(function_exists('iconv')) $checklist['iconv'] = true;
378
		else $checklist['iconv'] = false;
379
		// 5. Check gd(imagecreatefromgif function)
380
		if(function_exists('imagecreatefromgif')) $checklist['gd'] = true;
381
		else $checklist['gd'] = false;
382
		// 6. Check DB
383
		if(DB::getEnableList()) $checklist['db'] = true;
384
		else $checklist['db'] = false;
385
386
		if(!$checklist['php_version'] || !$checklist['permission'] || !$checklist['xml'] || !$checklist['session'] || !$checklist['db']) $install_enable = false;
387
		else $install_enable = true;
388
389
		// Save the checked result to the Context
390
		Context::set('checklist', $checklist);
0 ignored issues
show
Documentation introduced by
$checklist is of type array<string,boolean,{"db":"boolean"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
391
		Context::set('install_enable', $install_enable);
0 ignored issues
show
Documentation introduced by
$install_enable is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
392
		Context::set('phpversion', PHP_VERSION);
393
394
		return $install_enable;
395
	}
396
397
	/**
398
	 * @brief License agreement
399
	 */
400
	function procInstallLicenseAggrement()
401
	{
402
		$vars = Context::getRequestVars();
403
404
		$license_agreement = ($vars->license_agreement == 'Y') ? true : false;
405
406
		if($license_agreement)
407
		{
408
			$currentTime = $_SERVER['REQUEST_TIME'];
409
			FileHandler::writeFile($this->flagLicenseAgreement, $currentTime);
410
		}
411
		else
412
		{
413
			FileHandler::removeFile($this->flagLicenseAgreement);
414
			return new Object(-1, 'msg_must_accept_license_agreement');
415
		}
416
417
		if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON')))
418
		{
419
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'act', 'dispInstallCheckEnv');
420
			$this->setRedirectUrl($returnUrl);
421
		}
422
	}
423
424
	/**
425
	 * check this server can use rewrite module
426
	 * make a file to files/config and check url approach by ".htaccess" rules
427
	 *
428
	 * @return bool
429
	*/
430
	function checkRewriteUsable() {
431
		$checkString = "isApproached";
432
		$checkFilePath = 'files/config/tmpRewriteCheck.txt';
433
434
		FileHandler::writeFile(_XE_PATH_.$checkFilePath, trim($checkString));
435
436
		$scheme = ($_SERVER['HTTPS'] === 'on') ? 'https' : 'http';
437
		$hostname = $_SERVER['SERVER_NAME'];
438
		$port = $_SERVER['SERVER_PORT'];
439
		$str_port = '';
440
		if($port)
441
		{
442
			$str_port = ':' . $port;
443
		}
444
445
		$tmpPath = $_SERVER['DOCUMENT_ROOT'];
446
447
		//if DIRECTORY_SEPARATOR is not /(IIS)
448
		if(DIRECTORY_SEPARATOR !== '/')
449
		{
450
			//change to slash for compare
451
			$tmpPath = str_replace(DIRECTORY_SEPARATOR, '/', $_SERVER['DOCUMENT_ROOT']);
452
		}
453
454
		$query = "/JUST/CHECK/REWRITE/" . $checkFilePath;
455
		$currentPath = str_replace($tmpPath, "", _XE_PATH_);
456
		if($currentPath != "")
457
		{
458
			$query = $currentPath . $query;
459
		}
460
		$requestUrl = sprintf('%s://%s%s%s', $scheme, $hostname, $str_port, $query);
461
		$requestConfig = array();
462
		$requestConfig['ssl_verify_peer'] = false;
463
		$buff = FileHandler::getRemoteResource($requestUrl, null, 3, 'GET', null, array(), array(), array(), $requestConfig);
464
465
		FileHandler::removeFile(_XE_PATH_.$checkFilePath);
466
467
		return (trim($buff) == $checkString);
468
	}
469
470
	/**
471
	 * @brief Create files and subdirectories
472
	 * Local evironment setting before installation by using DB information
473
	 */
474
	function makeDefaultDirectory()
475
	{
476
		$directory_list = array(
477
			'./files/config',
478
			'./files/cache/queries',
479
			'./files/cache/js_filter_compiled',
480
			'./files/cache/template_compiled',
481
		);
482
483
		foreach($directory_list as $dir)
484
		{
485
			FileHandler::makeDir($dir);
486
		}
487
	}
488
489
	/**
490
	 * @brief Install all the modules
491
	 *
492
	 * Create a table by using schema xml file in the shcema directory of each module
493
	 */
494
	function installDownloadedModule()
495
	{
496
		$oModuleModel = getModel('module');
497
		// Create a table ny finding schemas/*.xml file in each module
498
		$module_list = FileHandler::readDir('./modules/', NULL, false, true);
499
		foreach($module_list as $module_path)
500
		{
501
			// Get module name
502
			$tmp_arr = explode('/',$module_path);
503
			$module = $tmp_arr[count($tmp_arr)-1];
504
505
			$xml_info = $oModuleModel->getModuleInfoXml($module);
506
			if(!$xml_info) continue;
507
			$modules[$xml_info->category][] = $module;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$modules was never initialized. Although not strictly required by PHP, it is generally a good practice to add $modules = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
508
		}
509
		// Install "module" module in advance
510
		$this->installModule('module','./modules/module');
511
		$oModule = getClass('module');
512
		if($oModule->checkUpdate()) $oModule->moduleUpdate();
513
		// Determine the order of module installation depending on category
514
		$install_step = array('system','content','member');
515
		// Install all the remaining modules
516
		foreach($install_step as $category)
517
		{
518
			if(count($modules[$category]))
519
			{
520 View Code Duplication
				foreach($modules[$category] as $module)
0 ignored issues
show
Bug introduced by
The variable $modules does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
521
				{
522
					if($module == 'module') continue;
523
					$this->installModule($module, sprintf('./modules/%s', $module));
524
525
					$oModule = getClass($module);
526
					if(is_object($oModule) && method_exists($oModule, 'checkUpdate'))
527
					{
528
						if($oModule->checkUpdate()) $oModule->moduleUpdate();
529
					}
530
				}
531
				unset($modules[$category]);
532
			}
533
		}
534
		// Install all the remaining modules
535
		if(count($modules))
536
		{
537
			foreach($modules as $category => $module_list)
538
			{
539
				if(count($module_list))
540
				{
541 View Code Duplication
					foreach($module_list as $module)
542
					{
543
						if($module == 'module') continue;
544
						$this->installModule($module, sprintf('./modules/%s', $module));
545
546
						$oModule = getClass($module);
547
						if($oModule && method_exists($oModule, 'checkUpdate') && method_exists($oModule, 'moduleUpdate'))
548
						{
549
							if($oModule->checkUpdate()) $oModule->moduleUpdate();
550
						}
551
					}
552
				}
553
			}
554
		}
555
556
		return new Object();
557
	}
558
559
	/**
560
	 * @brief Install an each module
561
	 */
562
	function installModule($module, $module_path)
563
	{
564
		// create db instance
565
		$oDB = &DB::getInstance();
566
		// Create a table if the schema xml exists in the "schemas" directory of the module
567
		$schema_dir = sprintf('%s/schemas/', $module_path);
568
		$schema_files = FileHandler::readDir($schema_dir, NULL, false, true);
569
570
		$file_cnt = count($schema_files);
571
		for($i=0;$i<$file_cnt;$i++)
572
		{
573
			$file = trim($schema_files[$i]);
574
			if(!$file || substr($file,-4)!='.xml') continue;
575
			$output = $oDB->createTableByXmlFile($file);
0 ignored issues
show
Bug introduced by
The method createTableByXmlFile() does not exist on DB. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
576
			if($output === false)
577
				throw new Exception('msg_create_table_failed');
578
		}
579
		// Create a table and module instance and then execute install() method
580
		unset($oModule);
581
		$oModule = getClass($module);
582
		if(method_exists($oModule, 'moduleInstall')) $oModule->moduleInstall();
583
		return new Object();
584
	}
585
586
	function _getDBConfigFileContents($db_info)
587
	{
588
		if(substr($db_info->master_db['db_table_prefix'], -1) != '_')
589
		{
590
			$db_info->master_db['db_table_prefix'] .= '_';
591
		}
592
593
		foreach($db_info->slave_db as &$slave)
594
		{
595
			if(substr($slave['db_table_prefix'], -1) != '_')
596
			{
597
				$slave['db_table_prefix'] .= '_';
598
			}
599
		}
600
601
		$buff = array();
602
		$buff[] = '<?php if(!defined("__XE__")) exit();';
603
		$buff[] = '$db_info = (object)' . var_export(get_object_vars($db_info), TRUE) . ';';
604
605
		return implode(PHP_EOL, $buff);
606
	}
607
608
	/**
609
	 * @brief Create DB temp config file
610
	 * Create the config file when all settings are completed
611
	 */
612
	function makeDBConfigFile()
613
	{
614
		$db_tmp_config_file = $this->db_tmp_config_file;
615
616
		$db_info = Context::getDBInfo();
617
		if(!$db_info) return;
618
619
		$buff = $this->_getDBConfigFileContents($db_info);
620
621
		FileHandler::writeFile($db_tmp_config_file, $buff);
622
623
		if(@file_exists($db_tmp_config_file)) return true;
624
		return false;
625
	}
626
627
	/**
628
	 * @brief Create etc config file
629
	 * Create the config file when all settings are completed
630
	 */
631
	function makeEtcConfigFile($config_info)
632
	{
633
		$etc_tmp_config_file = $this->etc_tmp_config_file;
634
635
		$buff = '<?php if(!defined("__XE__")) exit();'."\n";
636
		foreach($config_info as $key => $val)
637
		{
638
			$buff .= sprintf("\$db_info->%s = '%s';\n", $key, str_replace("'","\\'",$val));
639
		}
640
641
		FileHandler::writeFile($etc_tmp_config_file, $buff);
642
643
		if(@file_exists($etc_tmp_config_file)) return true;
644
		return false;
645
	}
646
647
	/**
648
	 * @brief Create config file
649
	 * Create the config file when all settings are completed
650
	 */
651
	function makeConfigFile()
652
	{
653
		try {
654
			$config_file = Context::getConfigFile();
655
			//if(file_exists($config_file)) return;
656
657
			$db_info = Context::getDBInfo();
658
			if(!$db_info) return;
659
660
			$buff = $this->_getDBConfigFileContents($db_info);
661
662
			FileHandler::writeFile($config_file, $buff);
663
664
			if(@file_exists($config_file))
665
			{
666
				FileHandler::removeFile($this->db_tmp_config_file);
667
				FileHandler::removeFile($this->etc_tmp_config_file);
668
				return true;
669
			}
670
			return false;
671
		} catch (Exception $e) {
672
			return false;
673
		}
674
	}
675
676
	function installByConfig($install_config_file)
677
	{
678
		include $install_config_file;
679
		if(!is_array($auto_config)) return false;
0 ignored issues
show
Bug introduced by
The variable $auto_config seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
680
681
		$auto_config['module'] = 'install';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$auto_config was never initialized. Although not strictly required by PHP, it is generally a good practice to add $auto_config = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
682
		$auto_config['act'] = 'procInstall';
683
684
		$fstr = "<%s><![CDATA[%s]]></%s>\r\n";
685
		$fheader = "POST %s HTTP/1.1\r\nHost: %s\r\nContent-Type: application/xml\r\nContent-Length: %s\r\n\r\n%s\r\n";
686
		$body = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<methodCall>\r\n<params>\r\n";
687
		foreach($auto_config as $k => $v)
688
		{
689
			if(!in_array($k,array('host','port','path'))) $body .= sprintf($fstr,$k,$v,$k);
690
		}
691
		$body .= "</params>\r\n</methodCall>";
692
693
		$header = sprintf($fheader,$auto_config['path'],$auto_config['host'],strlen($body),$body);
694
		$fp = @fsockopen($auto_config['host'], $auto_config['port'], $errno, $errstr, 5);
695
696
		if($fp)
697
		{
698
			fputs($fp, $header);
699
			while(!feof($fp))
700
			{
701
				$line = trim(fgets($fp, 4096));
702
				if(strncmp('<error>', $line, 7) === 0)
703
				{
704
					fclose($fp);
705
					return false;
706
				}
707
			}
708
			fclose($fp);
709
		}
710
		return true;
711
712
	}
713
}
714
/* End of file install.controller.php */
715
/* Location: ./modules/install/install.controller.php */
716