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:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
10 Mar-2013 Build 1884 Dietmar Woellbrink (Luisehahne)
15
! from security reasons the new installation has changed 
16
  from the old config.php into new setup.ini.php without 
17
  using global constants for critical values like username & password and so on.
14 18
07 Mar-2013 Build 1883 Dietmar Woellbrink (Luisehahne)
15 19
! groups change languages class to translate class
16 20
! prepare upgrade-script for WB Version 2.8.4 (versioncompare)
branches/2.8.x/wb/config.php.new
1
<?php
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.3');
54
if(!defined('REVISION')) define('REVISION', '1883');
54
if(!defined('REVISION')) define('REVISION', '1884');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/initialize.php
98 98
		if(sizeof($x) != 0) {
99 99
			foreach($x as $aStep) {
100 100
				// define the scripts which can read the configuration
101
				if(preg_match('/(index.php|config.php|upgrade-script.php)$/si', $aStep['file'])) {
101
				if(preg_match('/(save.php|index.php|config.php|upgrade-script.php)$/si', $aStep['file'])) {
102 102
					$bValidRequest = true;
103 103
					break;
104 104
				}
105 105
			}
106
		}else {
106
		} else {
107 107
			$bValidRequest = true;
108 108
		}
109 109
		if(!$bValidRequest) {
branches/2.8.x/wb/install/stylesheet.css
1
@charset "UTF-8";
1
@charset "utf-8";
2 2
/* <![CDATA[ */
3 3
/*
4 4
*/
5 5
* { margin :0px auto; padding :0px; }
6 6
* html body * { overflow :visible; }
7

  
8
html {
9
	padding:0; 	margin:0; border:0;
10
	font-size:85%; font-family: Arial, Verdana, Helvetica, sans-serif;
11
	color: #202020;
12
   overflow :-moz-scrollbars-vertical; overflow-x :auto;
13
}
14
table {font-size: 1em;}
15
body {
16
	padding: 0; border:0; margin: 0;
17
	background: url('background.png') repeat-x 0px 0px;
18
	background-color: #a8bccb;
19
	height: 101%;
20
}
21

  
22
div.body {
23
	width: 790px;
24
	margin: 1em auto;
25
	padding: 20px 20px 5px 20px;
26
	background-color: #ffffff;
27
	border: solid 1px #305c8d
28
}
29
div.content {
30
	margin-top:20px;
31
}
32

  
7
html { padding :0; margin :0; border :0; font-size :85%; font-family :Arial, Verdana, Helvetica, sans-serif; color :#202020; overflow :-moz-scrollbars-vertical; overflow-x :auto; }
8
table { font-size :1em; }
9
body { padding :0; border :0; margin :0; background :url('background.png') repeat-x 0px 0px; height :101%; background :#A8BCCB; }
10
div.body { width :790px; margin :1em auto; padding :20px 20px 5px 20px; border :solid 1px #305C8D; background :#FFFFFF; }
11
div.content { margin-top :20px; }
33 12
/*
34 13
	TABLE Elements
35 14
*/
36
table {
37
	background-color: #f8f8ff;
38
	margin-top: 15px;
39
	margin-bottom: 5px;
40
	width: 100%;
41
	border-style: solid;
42
	border-width: 1px 2px 2px 1px;
43
	border-color: #a3baca;
44
}
45
	table > thead {
46
		background-color: #f2f1ff;
47
	}
48
		table > thead > tr {
49
		}
50
			table > thead > tr > th {
51
				color: #555758;
52
				font-size: 1.15em;
53
				padding: 1.2em 1em;
54
			}
55
			table > thead > tr > td {
56
				color: #555758;
57
				font-size: 1.08em;
58
				padding: 1.2em 1em;
59
			}
60
	table > tbody {
61
		display: block;
62
	}
63
		table > tbody > tr {
64
   border-bottom :1px solid #222222; /* #d2d1cc; */
65
   padding :0.8em 0 0.2em 0;
66
   width :100%;
67
}
68
			table > tbody > tr > th {
69
				font-size: 1em;
70
				width: 1%;
71
				padding-left: 0.8em; padding-right: 0.8em;
72
				vertical-align: top;
73
				text-align: right;
74
				white-space: nowrap;
75
			}
76
			table > tbody > tr > td {
77
				font-size: 1em;
78
				width: 19%;
79
				padding-left: 0.8em; padding-right: 0.8em;
80
				vertical-align: top;
81
				text-align: left;
82
            line-height :2em;
83
			}
84

  
85
td.step-row {
86
   line-height : 3em;
87
   color : #666666;
88
   font-weight : bold;
89
   font-size : 100%;
90
}
91
td.name { 
92
   width : 180px;
93
   color: #666666;
94
   vertical-align :middle;
95
   font-weight : bold;
96
   font-size : 90%;
97
   float :left;
98
 }
99
td.value { 
100
   width : 100%;
101
   vertical-align :middle;
102
 }
103
td.value input { 
104
   width : 100%;
105
   vertical-align :middle;
106
 }
107
 
108
 
109
h1.step-row {
110
   margin : 0;
111
   display :inline;
112
   color : #6699ff;
113
}
15
table { margin-top :15px; margin-bottom :5px; width :100%; border-style :solid; border-width :1px 2px 2px 1px; border-color :#A3BACA; background :#F8F8FF; }
16
	table > thead { background :#F2F1FF; }
17
		table > thead > tr { }
18
			table > thead > tr > th { color :#555758; font-size :1.15em; padding :1.2em 1em; }
19
			table > thead > tr > td { color :#555758; font-size :1.08em; padding :1.2em 1em; }
20
	table > tbody { display :block; }
21
		table > tbody > tr { border-bottom :1px solid #222222; /* #d2d1cc; */ padding :0.8em 0 0.2em 0; width :100%; }
22
			table > tbody > tr > th { font-size :1em; width :1%; padding-left :0.8em; padding-right :0.8em; vertical-align :top; text-align :right; white-space :nowrap; }
23
			table > tbody > tr > td { font-size :1em; width :19%; padding-left :0.8em; padding-right :0.8em; vertical-align :top; text-align :left; line-height :2em; }
24
td.step-row { line-height :3em; color :#666666; font-weight :bold; font-size :100%; }
25
td.name { width :180px; color :#666666; vertical-align :middle; font-weight :bold; font-size :90%; float :left; }
26
td.value { width :100%; vertical-align :middle; }
27
td.value input { width :100%; vertical-align :middle; }
28
h1.step-row { margin :0; display :inline; color :#6699FF; }
114 29
/*
115 30
	FORM Elements
116 31
*/
117
form { margin: 0; }
118
input, select { padding: 2px; border: solid 1px #a3baca; }
119
input:focus, select:focus { background: #fdf8e8; }
120
input.submit    {
121
	color: #305c8d;
122
	font-size: 12px;
123
	font-weight: bold;
124
	text-transform: uppercase;
125
	letter-spacing: 1px;
126
	padding: 6px;
127
	margin: 1em 0;
128
	cursor: pointer;
129
	border: outset 2px green;
130
}
131
input.submit:hover  {
132
	border-style: inset;
133
}
134
input.submit.bad {
135
	background-color: #fde8e8;
136
	border-color: red;
137
}
138
input.submit.good {
139
	background-color: #deffde;
140
	border-color: green;
141
}
32
form { margin :0; }
33
input, select { padding :2px; border :solid 1px #A3BACA; }
34
input:focus, select:focus { background :#FDF8E8; }
35
input.submit { color :#305C8D; font-size :12px; font-weight :bold; text-transform :uppercase; letter-spacing :1px; padding :6px; margin :1em 0; cursor :pointer; border :outset 2px #008000; }
36
input.submit:hover { border-style :inset; }
37
input.submit.bad { border-color :#FF0000; background :#FDE8E8; }
38
input.submit.good { border-color :#008000; background :#DEFFDE; }
142 39
/*
143 40
	COMMON Elements
144 41
*/
145
img {border: none; }
146
p  { margin: 11px 0 4px 0 }
147
h1 { color: #3a628f; font-size: 1.3em; margin: 10px 0 5px; border-top: medium none }
148
a, a:link, a:visited, a:active  { color: #003366; text-decoration: underline }
149
a:focus {outline: none; }
150
a:hover  { color: #336699 }
42
img { border :none; }
43
p { margin :11px 0 4px 0; }
44
h1 { color :#3A628F; font-size :1.3em; margin :10px 0 5px; border-top :medium none; }
45
a, a:link, a:visited, a:active { color :#003366; text-decoration :underline; }
46
a:focus { outline :none; }
47
a:hover { color :#336699; }
151 48
/*
152 49
	HINTS
153 50
*/
154

  
155
.warning, .error {
156
	color: #b70000;
157
	line-height: 1.2em;
158
	background-color: #fde8e8;
159
	margin-top: 0.5em;
160
	padding: 0.3em 0.5em;
161
	border: solid 1px
162
}
163
.warning {
164
	color: #ca6800;
165
}
166
.bad { color: #b70000; }
167
.good { color: #118301; }
168
.warn { color: #ca6800; }
169
.hint { color: #464646; font-size: 0.85em; }
170
.small { font-size: 0.85em; }
171
.italic { font-style: italic; }
172
.center { text-align: center; }
173
.hide { display: none; }
51
.warning, .error { color :#B70000; line-height :1.2em; margin-top :0.5em; padding :0.3em 0.5em; border :solid 1px; background :#FDE8E8; }
52
.warning { color :#CA6800; }
53
.bad { color :#B70000; }
54
.good { color :#118301; }
55
.warn { color :#CA6800; }
56
.hint { color :#464646; font-size :0.85em; }
57
.small { font-size :0.85em; }
58
.italic { font-style :italic; }
59
.center { text-align :center; }
60
.hide { display :none; }
174 61
/*
175 62
	List Elements
176 63
*/
177
ul  { margin: 0; padding: 2px 0 2px 15px; }
178
li  { list-style-type: square; margin: 0; }
64
ul { margin :0; padding :2px 0 2px 15px; }
65
li { list-style-type :square; margin :0; }
179 66
/* ************************************************************************** */
branches/2.8.x/wb/install/save.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          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$
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
 * save.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
$debug = true;
19 37

  
20 38
include(dirname(dirname(__FILE__)).'/framework/globalExceptionHandler.php'); 
21 39
include(dirname(dirname(__FILE__)).'/framework/WbAutoloader.php');
22 40
WbAutoloader::doRegister(array('admin'=>'a', 'modules'=>'m'));
23 41

  
42
/**
43
 * Set constants for system/install values
44
 * @throws RuntimeException
45
 */
46
	function _SetInstallPathConstants() {
47
		if(!defined('DEBUG')){ define('DEBUG', false); } // normaly set in config file
48
		if(!defined('ADMIN_DIRECTORY')){ define('ADMIN_DIRECTORY', 'admin'); }
49
		if(!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
50
			throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
51
		}
52
		if(!defined('WB_PATH')){ define('WB_PATH', dirname(dirname(__FILE__))); }
53
		if(!defined('ADMIN_URL')){ define('ADMIN_URL', WB_URL.'/'.ADMIN_DIRECTORY); }
54
		if(!defined('ADMIN_PATH')){ define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY); }
55
		if(!defined('WB_REL')){
56
			$x1 = parse_url(WB_URL);
57
			define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
58
		}
59
		define('ADMIN_REL', WB_REL.'/'.ADMIN_DIRECTORY);
60
		if(!defined('DOCUMENT_ROOT')) {
61
			
62
			define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(WB_REL, '/').'$/', '', WB_PATH));
63
		}
64
		define('TMP_PATH', WB_PATH.'/temp');
65
	}
66

  
67
/**
68
 * Read DB settings from configuration file
69
 * @return string
70
 * @throws RuntimeException
71
 * 
72
 */
73
	function _readConfiguration($sRetvalType = 'url') {
74
		// check for valid file request. Becomes more stronger in next version
75
		$x = debug_backtrace();
76
		$bValidRequest = false;
77
		if(sizeof($x) != 0) {
78
			foreach($x as $aStep) {
79
				// define the scripts which can read the configuration
80
				if(preg_match('/(save.php|index.php|config.php|upgrade-script.php)$/si', $aStep['file'])) {
81
					$bValidRequest = true;
82
					break;
83
				}
84
			}
85
		}else {
86
			$bValidRequest = true;
87
		}
88
		if(!$bValidRequest) {
89
			throw new RuntimeException('illegal function request!'); 
90
		}
91
		$aRetval = array();
92
		$sSetupFile = dirname(dirname(__FILE__)).'/setup.ini.php';
93
		if(is_readable($sSetupFile)) {
94
			$aCfg = parse_ini_file($sSetupFile, true);
95
			foreach($aCfg['Constants'] as $key=>$value) {
96
				if($key == 'debug') { $value = filter_var($value, FILTER_VALIDATE_BOOLEAN); }
97
				if(!defined(strtoupper($key))) { define(strtoupper($key), $value); }
98
			}
99
			$db = $aCfg['DataBase'];
100
			$db['type'] = isset($db['type']) ? $db['type'] : 'mysql';
101
			$db['user'] = isset($db['user']) ? $db['user'] : 'foo';
102
			$db['pass'] = isset($db['pass']) ? $db['pass'] : 'bar';
103
			$db['host'] = isset($db['host']) ? $db['host'] : 'localhost';
104
			$db['port'] = isset($db['port']) ? $db['port'] : '3306';
105
			$db['port'] = ($db['port'] != '3306') ? $db['port'] : '';
106
			$db['name'] = isset($db['name']) ? $db['name'] : 'dummy';
107
			$db['charset'] = isset($db['charset']) ? $db['charset'] : 'utf8';
108
			$db['table_prefix'] = (isset($db['table_prefix']) ? $db['table_prefix'] : '');
109
			define('TABLE_PREFIX', $db['table_prefix']);
110
			if($sRetvalType == 'dsn') {
111
				$aRetval[0] = $db['type'].':dbname='.$db['name'].';host='.$db['host'].';'
112
				            . ($db['port'] != '' ? 'port='.(int)$db['port'].';' : '');
113
				$aRetval[1] = array('CHARSET' => $db['charset'], 'TABLE_PREFIX' => $db['table_prefix']);
114
				$aRetval[2] = array( 'user' => $db['user'], 'pass' => $db['pass']);
115
			}else { // $sRetvalType == 'url'
116
				$aRetval[0] = $db['type'].'://'.$db['user'].':'.$db['pass'].'@'
117
				            . $db['host'].($db['port'] != '' ? ':'.$db['port'] : '').'/'.$db['name'];
118
			}
119
			unset($db, $aCfg);
120
			return $aRetval;
121
		}
122
		throw new RuntimeException('unable to read setup.ini.php');
123
	}
124

  
24 125
if (true === $debug) {
25 126
	ini_set('display_errors', 1);
26 127
	error_reporting(E_ALL);
......
142 243
	$wb_url = $_POST['wb_url'];
143 244
}
144 245
// Remove any slashes at the end of the URL
145
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
146
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
147
}
148
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
149
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
150
}
151
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
152
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
153
}
154
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
155
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
156
}
246
$wb_url = rtrim($wb_url,'/\\');
157 247
// Get the default time zone
158 248
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
159 249
	set_error('Please select a valid default timezone', 'default_timezone');
......
228 318
	$database_username = $_POST['database_username'];
229 319
}
230 320
// Check if user has entered a database password
231
if(!isset($_POST['database_password'])) {
321
if(!isset($_POST['database_password'])&& ($_POST['database_password']==='') ) {
232 322
	set_error('Please enter a database password', 'database_password');
233 323
} else {
234 324
	$database_password = $_POST['database_password'];
......
281 371
// End admin user details code
282 372

  
283 373
// Try and write settings to config file
284
$config_content = "" .
285
"<?php\n".
286
"\n".
287
"define('DEBUG', false);\n".
288
"define('DB_TYPE', 'mysql');\n".
289
"define('DB_HOST', '$database_host');\n".
290
"define('DB_NAME', '$database_name');\n".
291
"define('DB_USERNAME', '$database_username');\n".
292
"define('DB_PASSWORD', '$database_password');\n".
293
"define('TABLE_PREFIX', '$table_prefix');\n".
294
"\n".
295
"define('WB_URL', '$wb_url');\n".
296
"define('ADMIN_DIRECTORY', 'admin'); // no leading/trailing slash or backslash!! A simple directory only!!\n".
297
"\n".
298
"require_once(dirname(__FILE__).'/framework/initialize.php');\n";
299

  
300
$config_filename = '../config.php';
374
$sConfigContent = 
375
 ";<?php die('sorry, illegal file access'); ?>#####\n"
376
.";################################################\n"
377
."; WebsiteBaker configuration file\n"
378
."; auto generated ".date('Y-m-d h:i:s A e ')."\n"
379
.";################################################\n"
380
."[Constants]\n"
381
."debug     = false\n"
382
."wb_url    = ".$wb_url."\n"
383
."admin_directory = admin\n"
384
.";##########\n"
385
."[DataBase]\n"
386
."type    = \"mysql\"\n"
387
."user    = \"".$database_username."\"\n"
388
."pass    = \"".$database_password."\"\n"
389
."host    = \"".$database_host."\"\n"
390
."port    = \"3306\"\n"
391
."name    = \"".$database_name."\"\n"
392
."charset = \"utf8\"\n"
393
."table_prefix = \"".$table_prefix."\"\n"
394
.";\n"
395
.";################################################\n";
396
$sConfigFile = realpath('../setup.ini.php');
397
$sConfigName = basename($sConfigFile);
301 398
// Check if the file exists and is writable first.
302
if(file_exists($config_filename) AND is_writable($config_filename)) {
303
	if(!$handle = fopen($config_filename, 'w')) {
304
		set_error("Cannot open the configuration file ($config_filename)");
399
if(file_exists($sConfigFile) && is_writable($sConfigFile)) {
400
	if(!$handle = fopen($sConfigFile, 'w')) {
401
		set_error("Cannot open the configuration file ($sConfigName)");
305 402
	} else {
306
		if (fwrite($handle, $config_content) === FALSE) {
307
			set_error("Cannot write to the configuration file ($config_filename)");
403
		if (fwrite($handle, $sConfigContent) === FALSE) {
404
			set_error("Cannot write to the configuration file ($sConfigName)");
308 405
		}
309 406
		// Close file
310 407
		fclose($handle);
311 408
	}
312 409
} else {
313
	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
410
	set_error("The configuration file $sConfigName is not writable. Change its permissions so it is, then re-run step 4.");
314 411
}
315 412

  
316
// Define configuration vars
317
define('DEBUG', false);
318
define('DB_TYPE', 'mysql');
319
define('DB_HOST', $database_host);
320
define('DB_NAME', $database_name);
321
define('DB_USERNAME', $database_username);
322
define('DB_PASSWORD', $database_password);
323
define('TABLE_PREFIX', $table_prefix);
324
define('WB_PATH', dirname(dirname(__FILE__)));
325
define('WB_URL', $wb_url);
326
define('ADMIN_DIRECTORY', 'admin');
327
define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY);
328
define('ADMIN_URL', $wb_url.'/'.ADMIN_DIRECTORY);
413
// load db configuration ---
414
$sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn'
415
$aSqlData = _readConfiguration($sDbConnectType);
329 416

  
330
// Check if the user has entered a correct path
331
	if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
332
		set_error('It appears the Absolute path that you entered is incorrect');
417
_SetInstallPathConstants();
418

  
419
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
420
	set_error('It appears the Absolute path that you entered is incorrect');
421
}
422

  
423
$database = WbDatabase::getInstance();
424
try{
425
	if($sDbConnectType == 'dsn') {
426
		$bTmp = @$database->doConnect($aSqlData[0], $aSqlData[1]['user'], $aSqlData[1]['pass'], $aSqlData[2]);
427
	}else {
428
		$bTmp = @$database->doConnect($aSqlData[0], TABLE_PREFIX);
333 429
	}
334
	$sSqlUrl = DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME;
335
	$database = WbDatabase::getInstance();
336
	$database->doConnect($sSqlUrl);
430
} catch (RuntimeException $e) {
431
	if(!file_put_contents($sConfigFile,"<?php\n")) {
432
		set_error("Cannot write to the configuration file ($sSetupFile)");
433
	}
434
	set_error($e->getMessage()); 
435
}
337 436

  
338
	$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
339
	$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
340
	require_once($sSecMod);
341
	require_once(WB_PATH.'/framework/class.admin.php');
437
unset($aSqlData);
438
// write the config.php
439
$sConfigContent = "<?php\n"
440
    ."/* this file is for backward compatibility only */\n"
441
    ."include_once(dirname(__FILE__).'/framework/initialize.php');\n";
442
$sSetupFile = WB_PATH.'/config.php';
443
if(!file_put_contents($sSetupFile,$sConfigContent)) {
444
	set_error("Cannot write to the configuration file ($sSetupFile)");
445
}
446
$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
447
$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
448
require_once($sSecMod);
449
require_once(WB_PATH.'/framework/class.admin.php');
342 450

  
343 451
// Dummy class to allow modules' install scripts to call $admin->print_error
344 452
	class admin_dummy extends admin
345 453

  
branches/2.8.x/wb/install/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