Project

General

Profile

« Previous | Next » 

Revision 1884

Added by Dietmar over 11 years ago

! from security reasons the new installation has changed
from the old config.php into new setup.ini.php without
using global constants for critical values like username & password and so on.

View differences:

index.php
1 1
<?php
2 2
/**
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 4
 *
4
 * @category        backend
5
 * @package         install
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker.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$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
15 9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17
 */
17 18

  
19
/**
20
 * index.php
21
 * 
22
 * @category     Core
23
 * @package      Core_Environment
24
 * @subpackage   Installer
25
 * @author       Dietmar Wöllbrink <dietmar.woellbrink@websitebaker.org>
26
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28
 * @version      0.0.2
29
 * @revision     $Revision$
30
 * @link         $HeadURL$
31
 * @lastmodified $Date$
32
 * @since        File available since 2012-04-01
33
 * @description  xyz
34
 */
35

  
18 36
// Start a session
19 37
if(!defined('SESSION_STARTED')) {
20 38
	session_name('wb_session_id');
......
22 40
	define('SESSION_STARTED', true);
23 41
}
24 42

  
25
$mod_path = dirname(str_replace('\\', '/', __FILE__));
26
$doc_root = rtrim(realpath($_SERVER['DOCUMENT_ROOT']),'/');
27
$mod_name = basename($mod_path);
28
$wb_path = dirname(dirname(realpath( __FILE__)));
29
$wb_root = str_replace(realpath($doc_root),'',$wb_path);
43
$doc_root = str_replace('\\','/',rtrim(realpath($_SERVER['DOCUMENT_ROOT']),'/').'/');
44
$wb_path = str_replace('\\','/',rtrim(dirname(dirname(realpath( __FILE__))),'/')).'/';
45
$wb_root = str_replace(($doc_root),'',$wb_path);
30 46

  
31 47
// Function to highlight input fields which contain wrong/missing data
32 48
function field_error($field_name='') {
......
68 84
	}
69 85
}
70 86

  
71
$sapi_type = php_sapi_name();
72

  
87
//$sapi_type = php_sapi_name();
73 88
if(!isset($_SESSION['operating_system'])) {
74
    $operating_system = ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? 'windows' : 'linux');
89
	$operating_system = ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? 'windows' : 'linux');
75 90
} else {
76
    $operating_system = $_SESSION['operating_system'];
91
	$operating_system = $_SESSION['operating_system'];
77 92
}
93

  
94
function checkConfigFile ($sWbPath,$sType ) {
95
	$config = '';
96
	$sConfigContent	= "<?php\n";
97
	$sConfigFile = $sWbPath.$sType.'.php';
98

  
99
// config.php or config.php.new
100
		if( (file_exists($sConfigFile)==true))
101
		{
102
// next operation only if file is writeable
103
			if(is_writeable($sConfigFile))
104
			{
105
// already installed? it's not empty
106
				if ( filesize($sConfigFile) > 128)
107
				{
108
					$config = '<font class="bad">Already installed? Check!</font>';
109
// try to open and to write
110
				} elseif( !$handle = fopen($sConfigFile, 'w') )
111
				{
112
					$config = '<font class="bad">Not Writeable</font>';
113
				} else {
114
					if (fwrite($handle, $sConfigContent) === FALSE) {
115
						$config = '<font class="bad">Not Writeable</font>';
116
					} else {
117
						$config = '';
118
						$_SESSION[$sType.'_rename'] = true;
119
					}
120
					// Close file
121
					fclose($handle);
122
					}
123
			} else {
124
				$config = '<font class="bad">Not Writeable</font>';
125
			}
126
// it's config.php.new
127
		} elseif((file_exists($sConfigFile.'.new')==true))
128
		{
129
			$config = '<font class="bad">Please rename to '.$sType.'.php</font>';
130
		} else {
131
			$config = '<font class="bad">Missing!!?</font>';
132
		}
133
	return $config;
134
}
135

  
136

  
78 137
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
79 138
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
80 139
<head>
......
152 211
			<td><?php echo $session_support; ?></td>
153 212
		</tr>
154 213
	<tr>
214
		<td style="color: #666666;">PHP Interface</td>
215
			<td colspan="2">
216
				<?php
217
						?><font class="good">
218
						<?php echo $sapi ?>
219
						</font>
220
			</td>
221
		</tr>
222

  
155 223
		<td style="color: #666666;">Server DefaultCharset</td>
156 224
			<td>
157 225
				<?php
......
192 260
</td>
193 261
</tr>
194 262
<?php } ?>
263
<tr>
264
	<td style="line-height: 0.4em;" colspan="4">&nbsp;</td>
265
</tr>
195 266
</table>
196 267
<table summary="" cellpadding="3" cellspacing="0">
197 268
<tr>
198 269
	<td colspan="6" class="step-row"><h1 class="step-row">Step 2</h1>&nbsp;Please check the following files/folders are writeable before continuing...</td>
199 270
</tr>
200 271
<?php
201
	$config = '<font class="good">Writeable</font>';
202
	$config_content = "<?php\n";
203
	$configFile = '/config.php';
204
	if(!isset($_SESSION['config_rename']) )
205
	{
206
// cnfig.php or config.php.new
207
		if( (file_exists($wb_path.$configFile)==true))
208
		{
209
// next operation only if file is writeable
210
			if(is_writeable($wb_path.$configFile))
211
			{
212
// already installed? it's not empty
213
				if ( filesize($wb_path.$configFile) > 128)
214
				{
215
					$installFlag = false;
216
					$config = '<font class="bad">Already installed? Check!</font>';
217
// try to open and to write
218
				} elseif( !$handle = fopen($wb_path.$configFile, 'w') )
219
				{
220
					$installFlag = false;
221
	                $config = '<font class="bad">Not Writeable</font>';
222
				} else {
223
					if (fwrite($handle, $config_content) === FALSE) {
224
						$installFlag = false;
225
		                $config = '<font class="bad">Not Writeable</font>';
226
					} else {
227
						$config = '<font class="good">Writeable</font>';
228
						$_SESSION['config_rename'] = true;
229
					}
230
					// Close file
231
					fclose($handle);
232
					}
233
			} else {
234
				$installFlag = false;
235
                $config = '<font class="bad">Not Writeable</font>';
236
			}
237
// it's config.php.new
238
		} elseif((file_exists($wb_path.'/config.php.new')==true))
239
		{
240
			$configFile = '/config.php.new';
241
			$installFlag = false;
242
			$config = '<font class="bad">Please rename to config.php</font>';
243
		} else
244
		{
245
			$installFlag = false;
246
			$config = '<font class="bad">Missing!!?</font>';
247
		}
272
	$sTmp = '';
273
	$config = '';
274
	$sConfigFile = 'config.php.new';
275
	if( ($sTmp = checkConfigFile($wb_path,'config')) === '' ) {
276
		$config = '<font class="good">Writeable</font>';
277
	} else {
278
		$config = $sTmp;
248 279
	}
280
	$sConfigFile = preg_match('/(?:rename)/i',$config) ? $sConfigFile : 'setup.ini.php';
281
	$installFlag = $installFlag && ($sTmp == '');
249 282
?>
250 283
		<tr>
251
			<td colspan="2" style="color: #666666;"><?php print $wb_root.$configFile ?></td>
284
			<td colspan="2" style="color: #666666;"><?php print $wb_root.$sConfigFile ?></td>
252 285
			<td colspan="2"><?php echo $config ?></td>
253 286
		</tr>
287
<?php
288
	$sTmp = '';
289
	$config = '';
290
	$sSetupIniFile = 'setup.ini.php.new';
291
	if( ($sTmp = checkConfigFile($wb_path,'setup.ini')) === '' ) {
292
		$config = '<font class="good">Writeable</font>';
293
	} else {
294
		$config = $sTmp;
295
	}
296
	$sSetupIniFile = preg_match('/(?:rename)/i',$config) ? $sSetupIniFile : 'setup.ini.php';
297
	$installFlag = $installFlag && ($sTmp == '');
298
?>
254 299
		<tr>
255
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>/pages/</td>
300
			<td colspan="2" style="color: #666666;"><?php print $wb_root.$sSetupIniFile ?></td>
301
			<td colspan="2"><?php echo $config ?></td>
302
		</tr>
303
		<tr>
304
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>pages/</td>
256 305
			<td><?php if(is_writable('../pages/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists('../pages/')) {$installFlag = false; echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
257
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>/media/</td>
306
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>media/</td>
258 307
			<td><?php if(is_writable('../media/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists('../media/')) {$installFlag = false; echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
259 308
		</tr>
260 309
		<tr>
261
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>/templates/</td>
310
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>templates/</td>
262 311
			<td><?php if(is_writable('../templates/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists('../templates/')) {$installFlag = false; echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
263
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>/modules/</td>
312
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>modules/</td>
264 313
			<td><?php if(is_writable('../modules/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists('../modules/')) {$installFlag = false; echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
265 314
		</tr>
266 315
		<tr>
267
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>/languages/</td>
316
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>languages/</td>
268 317
			<td><?php if(is_writable('../languages/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists('../languages/')) {$installFlag = false; echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
269
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>/temp/</td>
318
			<td colspan="2" style="color: #666666;"><?php print $wb_root ?>temp/</td>
270 319
			<td><?php if(is_writable('../temp/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists('../temp/')) {$installFlag = false; echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
271 320
		</tr>
321
		<tr>
322
			<td style="line-height: 0.4em;" colspan="4">&nbsp;</td>
323
		</tr>
272 324
		</table>
273 325
		<table summary="" cellpadding="3" cellspacing="0" >
274 326
		<tr>
......
364 416
				</select>
365 417
			</td>
366 418
		</tr>
419
		<tr>
420
			<td style="line-height: 0.4em;" colspan="2">&nbsp;</td>
421
		</tr>
367 422
		</table>
368 423
		<table border="0" summary="" cellpadding="0" cellspacing="0">
369 424
		<tr>
......
394 449
				</div>
395 450
			</td>
396 451
		</tr>
452
		<tr>
453
			<td style="line-height: 0.4em;" colspan="2">&nbsp;</td>
454
		</tr>
397 455
		</table>
398 456
		<table summary="" cellpadding="0" cellspacing="0">
399 457
    		<tr>
......
437 495
				<span style="font-size: 1px; color: #666666;">(Please note: May remove existing tables and data)</span>
438 496
			</td>
439 497
		</tr>
498
		<tr>
499
			<td style="line-height: 0.4em;" colspan="2">&nbsp;</td>
500
		</tr>
440 501
		</table>
441 502
		<table summary="" cellpadding="0" cellspacing="0" >
442 503
		<tbody>
......
449 510
				<input <?php echo field_error('website_title');?> type="text" tabindex="13" name="website_title" value="<?php if(isset($_SESSION['website_title'])) { echo $_SESSION['website_title']; } else { echo 'Enter your website title'; } ?>" />
450 511
			</td>
451 512
		</tr>
513
		<tr>
514
			<td style="line-height: 0.4em;" colspan="2">&nbsp;</td>
515
		</tr>
452 516
		</tbody>
453 517
		</table>
454 518
		<table summary="" cellpadding="0" cellspacing="0" border="0">
......
479 543
				<input <?php echo field_error('admin_repassword');?> type="password" tabindex="17" name="admin_repassword" value=""  />
480 544
			</td>
481 545
		</tr>
546
		<tr>
547
			<td style="line-height: 0.4em;" colspan="2">&nbsp;</td>
548
		</tr>
482 549
		</table>
483 550
		<table summary="" cellpadding="0" cellspacing="0">
484 551
				<tr valign="top">
485 552

  

Also available in: Unified diff