Project

General

Profile

« Previous | Next » 

Revision 1423

Added by DarkViper almost 14 years ago

add FINGERPRINT_WITH_IP_OCTETS to table settings

View differences:

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

  
13 13
------------------------------------- 2.8.2 -------------------------------------
14
30 Jan-2011 Build 1423 Werner v.d.Decken(DarkViper)
15
! add FINGERPRINT_WITH_IP_OCTETS to table settings
14 16
30 Jan-2011 Build 1422 Dietmar Woellbrink (Luisehahne)
15 17
! update SecureForm.php to work behind Proxies
16 18
27 Jan-2011 Build 1421 Dietmar Woellbrink (Luisehahne)
branches/2.8.x/wb/upgrade-script.php
1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         installation
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
@require_once('config.php');
20

  
21
// this function checks the basic configurations of an existing WB intallation
22
function status_msg($message, $class='check', $element='span') {
23
	// returns a status message
24
	echo '<'.$element .' class="' .$class .'">' .$message .'</' .$element.'>';
25
}
26

  
27
$version = '2.8.2';
28
// database tables including in WB package
29
$table_list = array (
30
    'settings','groups','addons','pages','sections','search','users',
31
    'mod_captcha_control','mod_code','mod_droplets','mod_form_fields',
32
    'mod_form_settings','mod_form_submissions','mod_jsadmin','mod_menu_link',
33
    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
34
    'mod_output_filter','mod_wrapper','mod_wysiwyg'
35
);
36

  
37
// analyze/check database tables
38
function mysqlCheckTables( $dbName )
39
{
40
    global $table_list;
41
    $table_prefix = TABLE_PREFIX;
42
    $sql = "SHOW TABLES FROM " . $dbName;
43
    $result = @mysql_query( $sql );
44
    $data = array();
45
    $x = 0;
46

  
47
    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
48
    {
49
        $tmp = str_replace($table_prefix, '', $row[0]);
50

  
51
        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$table_list) )
52
        {
53
            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
54
            $analyze = @mysql_query( $sql );
55
            $rowFetch = @mysql_fetch_array( $analyze, MYSQL_ASSOC );
56
            $data[$x]['Op'] = $rowFetch["Op"];
57
            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
58
            $msgColor = '<span class="error">';
59
            $data[$x]['Table'] = $row[0];
60
           // print  " ";
61
            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
62
            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
63
           // print  "<br />";
64
            $x++;
65
        }
66
    }
67

  
68

  
69

  
70

  
71
    return $data;
72
}
73

  
74

  
75
// check existings tables for upgrade or install
76
function check_wb_tables()
77
{
78
    global $database,$table_list;
79

  
80
 // if prefix inludes '_' or '%'
81
 $search_for = addcslashes ( TABLE_PREFIX, '%_' );
82
 $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
83

  
84
        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
85
        $all_tables = array();
86
        if($get_result->numRows() > 0)
87
        {
88
            while ($data = $get_result->fetchRow())
89
            {
90
                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
91
                if(in_array($tmp,$table_list))
92
                {
93
                    $all_tables[] = $tmp;
94
                }
95
            }
96
        }
97
     return $all_tables;
98
}
99

  
100
// check existing tables
101
$all_tables = check_wb_tables();
102

  
103
// only for array tests
104
function show_array($array=array())
105
{
106
    print '<pre>';
107
    print_r ($array);
108
    print '</pre>';
109
}
110

  
111
?>
112
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
113
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
114
<head>
115
<title>Upgrade script</title>
116
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
117
<style type="text/css">
118
html { overflow: -moz-scrollbars-vertical; /* Force firefox to always show room for a vertical scrollbar */ }
119

  
120
body {
121
	margin:0;
122
	padding:0;
123
	border:0;
124
	background: #EBF7FC;
125
	color:#000;
126
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
127
	font-size: small;
128
	height:101%;
129
}
130

  
131
#container {
132
	width:85%;
133
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
134
	border:1px solid #000;
135
	color:#000;
136
	margin:2em auto;
137
	padding:0 15px;
138
	min-height: 500px;
139
	text-align:left;
140
}
141

  
142
p { line-height:1.5em; }
143

  
144
h1,h2,h3,h4,h5,h6 {
145
	font-family: Verdana, Arial, Helvetica, sans-serif;
146
	color: #369;
147
	margin-top: 1.0em;
148
	margin-bottom: 0.1em;
149
}
150

  
151
h1 { font-size:150%; }
152
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
153
h3 { font-size: 120%; }
154

  
155
.ok, .error { font-weight:bold; }
156
.ok { color:green; }
157
.error { color:red; }
158
.check { color:#555; }
159

  
160
.warning {
161
	width: 98%;
162
	background:#FFDBDB;
163
	padding:0.2em;
164
	margin-top:0.5em;
165
	border: 1px solid black;
166
}
167
.info {
168
	width: 98%;
169
	background:#99CC99;
170
	padding:0.2em;
171
	margin-top:0.5em;
172
	border: 1px solid black;
173
}
174

  
175
</style>
176
</head>
177
<body>
178
<div id="container">
179
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
180

  
181
<h1>WebsiteBaker Upgrade</h1>
182
<p>This script upgrades an existing WebsiteBaker <strong>Version 2.7 and higher</strong> installation to the <strong>Version <?php echo $version ?></strong>. The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
183

  
184
<?php
185
/**
186
 * Check if disclaimer was accepted
187
 */
188
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
189
<h2>Step 1: Backup your files</h2>
190
<p>It is highly recommended to <strong>create a manual backup</strong> of the entire <strong>/pages folder</strong> and the <strong>MySQL database</strong> before proceeding.<br /><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
191

  
192
<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
193
<textarea cols="80" rows="5">DISCLAIMER: The WebsiteBaker upgrade script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. One needs to confirm that a manual backup of the /pages folder (including all files and subfolders contained in it) and backup of the entire WebsiteBaker MySQL database was created before you can proceed.</textarea>
194
<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;I confirm that a manual backup of the /pages folder and the MySQL database was created.
195
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
196
</form>
197
<br />
198

  
199
<?php
200
	status_msg('<strong>Notice:</strong><br />You need to confirm that you have created a manual backup of the /pages directory and the MySQL database before you can proceed.', 'warning', 'div');
201
	echo '<br /><br />';
202
    echo "</div>
203
    </body>
204
    </html>
205
    ";
206
	exit();
207
}
208

  
209
echo '<h2>Step 2: Updating database entries</h2>';
210

  
211
require_once(WB_PATH.'/framework/functions.php');
212
require_once(WB_PATH.'/framework/class.admin.php');
213
$admin = new admin('Addons', 'modules', false, false);
214

  
215
$OK   = '<span class="ok">OK</span>';
216
$FAIL = '<span class="error">FAILED</span>';
217

  
218
// function to add a var/value-pair into settings-table
219
function db_add_key_value($key, $value) {
220
	global $database; global $OK; global $FAIL;
221
	$table = TABLE_PREFIX.'settings';
222
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
223
	if($query->numRows() > 0) {
224
		echo "$key: already exists. $OK.<br />";
225
		return true;
226
	} else {
227
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
228
		echo (mysql_error()?mysql_error().'<br />':'');
229
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
230
		if($query->numRows() > 0) {
231
			echo "$key: $OK.<br />";
232
			return true;
233
		} else {
234
			echo "$key: $FAIL!<br />";
235
			return false;
236
		}
237
	}
238
}
239

  
240
// function to add a new field into a table
241
function db_add_field($field, $table, $desc) {
242
	global $database; global $OK; global $FAIL;
243
	$table = TABLE_PREFIX.$table;
244
	$query = $database->query("DESCRIBE $table '$field'");
245
	if($query->numRows() == 0) { // add field
246
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
247
		echo (mysql_error()?mysql_error().'<br />':'');
248
		$query = $database->query("DESCRIBE $table '$field'");
249
		echo (mysql_error()?mysql_error().'<br />':'');
250
		if($query->numRows() > 0) {
251
			echo "'$field' added. $OK.<br />";
252
		} else {
253
			echo "adding '$field' $FAIL!<br />";
254
		}
255
	} else {
256
		echo "'$field' already exists. $OK.<br />";
257
	}
258
}
259

  
260
/**********************************************************
261
 *  - Adding field default_theme to settings table
262
 */
263
echo "<br />Adding default_theme to settings table<br />";
264
$cfg = array(
265
	'default_theme' => 'wb_theme'
266
);
267

  
268
foreach($cfg as $key=>$value) {
269
	db_add_key_value($key, $value);
270
}
271

  
272
/**********************************************************
273
 *  - install droplets
274
 */
275
    $drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
276
    echo $drops;
277

  
278
     $file_name = (!in_array ( "mod_droplets", $all_tables)) ? "install.php" : "upgrade.php";
279
     require_once (WB_PATH."/modules/droplets/".$file_name);
280

  
281
// check again all tables, to get a new array
282
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
283
/**********************************************************
284
 *  - check tables comin with WebsiteBaker
285
 */
286
    $check_text = 'total ';
287
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
288

  
289
    if(sizeof($all_tables) == 22)
290
    {
291
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
292
    }
293
    else
294
    {
295
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
296
    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
297
        $result = array_diff ( $table_list, $all_tables );
298
        echo '<h4 class="warning"><br />';
299
        while ( list ( $key, $val ) = each ( $result ) )
300
        {
301
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
302
        }
303
        echo '<br /></h4>';
304
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
305
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
306
    	echo '</form>';
307
        if(defined('ADMIN_URL'))
308
        {
309
        	echo '<form action="'.ADMIN_URL.'" target="_self">';
310
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
311
        	echo '</form>';
312
        }
313
        echo "<br /><br /></div>
314
        </body>
315
        </html>
316
        ";
317
        exit();
318
    }
319

  
320
/**********************************************************
321
 *  - Adding field sec_anchor to settings table
322
 */
323

  
324
echo "<br />Adding sec_anchor to settings table<br />";
325
$cfg = array(
326
	'sec_anchor' => 'wb_'
327
);
328
foreach($cfg as $key=>$value) {
329
	db_add_key_value($key, $value);
330
}
331

  
332
/**********************************************************
333
 *  - Adding redirect timer to settings table
334
 */
335
echo "<br />Adding redirect timer to settings table<br />";
336
$cfg = array(
337
	'redirect_timer' => '1500'
338
);
339
foreach($cfg as $key=>$value) {
340
	db_add_key_value($key, $value);
341
}
342

  
343
/**********************************************************
344
 *  - Adding mediasettings to settings table
345
 */
346
echo "<br />Adding mediasettings to settings table<br />";
347
$cfg = array(
348
	'mediasettings' => ''
349
);
350
foreach($cfg as $key=>$value) {
351
	db_add_key_value($key, $value);
352
}
353

  
354
/**********************************************************
355
 *  - Add field "redirect_type" to table "mod_menu_link"
356
 */
357
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
358
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
359

  
360

  
361

  
362
if (version_compare(WB_VERSION, '2.8.0') < 0)
363
{
364
    /**********************************************************
365
     *  - Update search no results database filed to create
366
     *  valid XHTML if search is empty
367
     */
368
    echo "<br />Updating database field `no_results` of search table: ";
369
    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
370
    $sql = "UPDATE `" . TABLE_PREFIX . "search` SET `value` = '$search_no_results' WHERE `name`= 'no_results'";
371
    $database->query($sql);
372
    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL<br />";
373
    /**********************************************************
374
     *  - Update settings of News Modul
375
     */
376

  
377
    // These are the default setting
378
    $header = '<table cellpadding=\"0\" cellspacing=\"0\" class=\"loop-header\">'."\n";
379
    $post_loop = '<tr class=\"post_top\">
380
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
381
<td class=\"post_date\">[PUBLISHED_TIME], [PUBLISHED_DATE]</td>
382
</tr>
383
<tr>
384
<td class=\"post_short\" colspan=\"2\">
385
[SHORT]
386
<span style=\"visibility:[SHOW_READ_MORE];\"><a href=\"[LINK]\">[TEXT_READ_MORE]</a></span>
387
</td>
388
</tr>';
389
    $footer = '</table>
390
<table cellpadding="0" cellspacing="0" class="page-header" style="display: [DISPLAY_PREVIOUS_NEXT_LINKS]">
391
<tr>
392
<td class="page-left">[PREVIOUS_PAGE_LINK]</td>
393
<td class="page-center">[OF]</td>
394
<td class="page-right">[NEXT_PAGE_LINK]</td>
395
</tr>
396
</table>';
397
    $post_header = addslashes('<table cellpadding="0" cellspacing="0" class="post-header">
398
<tr>
399
<td><h1>[TITLE]</h1></td>
400
<td rowspan="3" style="display: [DISPLAY_IMAGE]">[GROUP_IMAGE]</td>
401
</tr>
402
<tr>
403
<td class="public-info"><b>[TEXT_POSTED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [PUBLISHED_DATE]</b></td>
404
</tr>
405
<tr style="display: [DISPLAY_GROUP]">
406
<td class="group-page"><a href="[BACK]">[PAGE_TITLE]</a> &gt;&gt; <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
407
</tr>
408
</table>');
409
    $post_footer = '<p>[TEXT_LAST_CHANGED]: [MODI_DATE] [TEXT_AT] [MODI_TIME]</p>
410
<a href=\"[BACK]\">[TEXT_BACK]</a>';
411
    $comments_header = addslashes('<br /><br />
412
<h2>[TEXT_COMMENTS]</h2>
413
<table cellpadding="2" cellspacing="0" class="comment-header">');
414
    $comments_loop = addslashes('<tr>
415
<td class="comment_title">[TITLE]</td>
416
<td class="comment_info">[TEXT_BY] [DISPLAY_NAME] [TEXT_ON] [DATE] [TEXT_AT] [TIME]</td>
417
</tr>
418
<tr>
419
<td colspan="2" class="comment_text">[COMMENT]</td>
420
</tr>');
421
    $comments_footer = '</table>
422
<br /><a href=\"[ADD_COMMENT_URL]\">[TEXT_ADD_COMMENT]</a>';
423
    $comments_page = '<h1>[TEXT_COMMENT]</h1>
424
<h2>[POST_TITLE]</h2>
425
<br />';
426

  
427
if(in_array('mod_news_settings', $all_tables))
428
{
429
   // Insert default settings into database
430
   $query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
431
   if($query_dates->numRows() > 1)
432
   {
433
        while($result = $query_dates->fetchRow())
434
        {
435

  
436
        	echo "<br /><u>Add default settings to database for news section_id= ".$result['section_id']."</u><br />";
437
        	$section_id = $result['section_id'];
438

  
439
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
440
        		echo 'Database data header added successfully';
441
        	}
442
        	echo mysql_error().'<br />';
443

  
444
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
445
        		echo 'Database data post_loop added successfully';
446
        	}
447
        	echo mysql_error().'<br />';
448

  
449
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `footer` = '$footer' WHERE `section_id` = $section_id")) {
450
        		echo 'Database data footer added successfully';
451
        	}
452
        	echo mysql_error().'<br />';
453

  
454
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
455
        		echo 'Database data post_header added successfully';
456
        	}
457
        	echo mysql_error().'<br />';
458

  
459
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
460
        		echo 'Database data post_footer added successfully';
461
        	}
462
        	echo mysql_error().'<br />';
463

  
464
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
465
        		echo 'Database data comments_header added successfully';
466
        	}
467
        	echo mysql_error().'<br />';
468

  
469
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_loop` = '$comments_loop' WHERE `section_id` = $section_id")) {
470
        		echo 'Database data comments_loop added successfully';
471
        	}
472
        	echo mysql_error().'<br />';
473

  
474
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_footer` = '$comments_footer' WHERE `section_id` = $section_id")) {
475
        		echo 'Database data comments_footer added successfully';
476
        	}
477
        	echo mysql_error().'<br />';
478

  
479
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_page` = '$comments_page' WHERE `section_id` = $section_id")) {
480
        		echo 'Database data comments_page added successfully';
481
        	}
482
        	echo mysql_error().'<br />';
483

  
484
        }
485

  
486

  
487
      if ((version_compare(WB_VERSION, '2.8.1') <= 0) && file_exists(WB_PATH."/modules/news/upgrade.php"))
488
      {
489
              echo '<h4>Upgrade existings postfiles to new format</h4><br />';
490
              // change old postfiles to new postfiles
491
              require_once(WB_PATH."/modules/news/upgrade.php");
492
      }
493
    }
494

  
495
   }
496

  
497
}
498

  
499
/**********************************************************
500
 *  - Set Version to WB 2.8.2
501
 */
502
echo "<br />Update database version number to 2.8.2 : ";
503
echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
504

  
505
/**********************************************************
506
 *  - Reload all addons
507
 */
508

  
509
//delete modules
510
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
511
// Load all modules
512
if($handle = opendir(WB_PATH.'/modules/')) {
513
	while(false !== ($file = readdir($handle))) {
514
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
515
			load_module(WB_PATH.'/modules/'.$file);
516
		}
517
	}
518
	closedir($handle);
519
}
520
echo '<br />Modules reloaded<br />';
521

  
522
//delete templates		
523
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
524
// Load all templates
525
if($handle = opendir(WB_PATH.'/templates/')) {
526
	while(false !== ($file = readdir($handle))) {
527
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
528
			load_template(WB_PATH.'/templates/'.$file);
529
		}
530
	}
531
	closedir($handle);
532
}
533
echo '<br />Templates reloaded<br />';
534

  
535
//delete languages
536
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
537
// Load all languages
538
if($handle = opendir(WB_PATH.'/languages/')) {
539
	while(false !== ($file = readdir($handle))) {
540
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
541
			load_language(WB_PATH.'/languages/'.$file);
542
		}
543
	}
544
	closedir($handle);
545
}
546
echo '<br />Languages reloaded<br />';
547

  
548

  
549
/**********************************************************
550
 *  - End of upgrade script
551
 */
552

  
553
// require(WB_PATH.'/framework/initialize.php');
554

  
555
if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', 'wb_theme'); }
556
if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
557

  
558
echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
559
status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
560
// show buttons to go to the backend or frontend
561
echo '<br />';
562
if(defined('WB_URL')) {
563
	echo '<form action="'.WB_URL.'">';
564
	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
565
	echo '</form>';
566
}
567
if(defined('ADMIN_URL')) {
568
	echo '<form action="'.ADMIN_URL.'">';
569
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
570
	echo '</form>';
571
}
572
echo '<p>&nbsp;</p>';
573

  
574
?>
575
</div>
576
</body>
1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         installation
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
@require_once('config.php');
20

  
21
// this function checks the basic configurations of an existing WB intallation
22
function status_msg($message, $class='check', $element='span') {
23
	// returns a status message
24
	echo '<'.$element .' class="' .$class .'">' .$message .'</' .$element.'>';
25
}
26

  
27
$version = '2.8.2';
28
// database tables including in WB package
29
$table_list = array (
30
    'settings','groups','addons','pages','sections','search','users',
31
    'mod_captcha_control','mod_code','mod_droplets','mod_form_fields',
32
    'mod_form_settings','mod_form_submissions','mod_jsadmin','mod_menu_link',
33
    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
34
    'mod_output_filter','mod_wrapper','mod_wysiwyg'
35
);
36

  
37
// analyze/check database tables
38
function mysqlCheckTables( $dbName )
39
{
40
    global $table_list;
41
    $table_prefix = TABLE_PREFIX;
42
    $sql = "SHOW TABLES FROM " . $dbName;
43
    $result = @mysql_query( $sql );
44
    $data = array();
45
    $x = 0;
46

  
47
    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
48
    {
49
        $tmp = str_replace($table_prefix, '', $row[0]);
50

  
51
        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$table_list) )
52
        {
53
            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
54
            $analyze = @mysql_query( $sql );
55
            $rowFetch = @mysql_fetch_array( $analyze, MYSQL_ASSOC );
56
            $data[$x]['Op'] = $rowFetch["Op"];
57
            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
58
            $msgColor = '<span class="error">';
59
            $data[$x]['Table'] = $row[0];
60
           // print  " ";
61
            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
62
            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
63
           // print  "<br />";
64
            $x++;
65
        }
66
    }
67

  
68

  
69

  
70

  
71
    return $data;
72
}
73

  
74

  
75
// check existings tables for upgrade or install
76
function check_wb_tables()
77
{
78
    global $database,$table_list;
79

  
80
 // if prefix inludes '_' or '%'
81
 $search_for = addcslashes ( TABLE_PREFIX, '%_' );
82
 $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
83

  
84
        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
85
        $all_tables = array();
86
        if($get_result->numRows() > 0)
87
        {
88
            while ($data = $get_result->fetchRow())
89
            {
90
                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
91
                if(in_array($tmp,$table_list))
92
                {
93
                    $all_tables[] = $tmp;
94
                }
95
            }
96
        }
97
     return $all_tables;
98
}
99

  
100
// check existing tables
101
$all_tables = check_wb_tables();
102

  
103
// only for array tests
104
function show_array($array=array())
105
{
106
    print '<pre>';
107
    print_r ($array);
108
    print '</pre>';
109
}
110

  
111
?>
112
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
113
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
114
<head>
115
<title>Upgrade script</title>
116
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
117
<style type="text/css">
118
html { overflow: -moz-scrollbars-vertical; /* Force firefox to always show room for a vertical scrollbar */ }
119

  
120
body {
121
	margin:0;
122
	padding:0;
123
	border:0;
124
	background: #EBF7FC;
125
	color:#000;
126
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
127
	font-size: small;
128
	height:101%;
129
}
130

  
131
#container {
132
	width:85%;
133
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
134
	border:1px solid #000;
135
	color:#000;
136
	margin:2em auto;
137
	padding:0 15px;
138
	min-height: 500px;
139
	text-align:left;
140
}
141

  
142
p { line-height:1.5em; }
143

  
144
h1,h2,h3,h4,h5,h6 {
145
	font-family: Verdana, Arial, Helvetica, sans-serif;
146
	color: #369;
147
	margin-top: 1.0em;
148
	margin-bottom: 0.1em;
149
}
150

  
151
h1 { font-size:150%; }
152
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
153
h3 { font-size: 120%; }
154

  
155
.ok, .error { font-weight:bold; }
156
.ok { color:green; }
157
.error { color:red; }
158
.check { color:#555; }
159

  
160
.warning {
161
	width: 98%;
162
	background:#FFDBDB;
163
	padding:0.2em;
164
	margin-top:0.5em;
165
	border: 1px solid black;
166
}
167
.info {
168
	width: 98%;
169
	background:#99CC99;
170
	padding:0.2em;
171
	margin-top:0.5em;
172
	border: 1px solid black;
173
}
174

  
175
</style>
176
</head>
177
<body>
178
<div id="container">
179
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
180

  
181
<h1>WebsiteBaker Upgrade</h1>
182
<p>This script upgrades an existing WebsiteBaker <strong>Version 2.7 and higher</strong> installation to the <strong>Version <?php echo $version ?></strong>. The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
183

  
184
<?php
185
/**
186
 * Check if disclaimer was accepted
187
 */
188
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
189
<h2>Step 1: Backup your files</h2>
190
<p>It is highly recommended to <strong>create a manual backup</strong> of the entire <strong>/pages folder</strong> and the <strong>MySQL database</strong> before proceeding.<br /><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
191

  
192
<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
193
<textarea cols="80" rows="5">DISCLAIMER: The WebsiteBaker upgrade script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. One needs to confirm that a manual backup of the /pages folder (including all files and subfolders contained in it) and backup of the entire WebsiteBaker MySQL database was created before you can proceed.</textarea>
194
<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;I confirm that a manual backup of the /pages folder and the MySQL database was created.
195
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
196
</form>
197
<br />
198

  
199
<?php
200
	status_msg('<strong>Notice:</strong><br />You need to confirm that you have created a manual backup of the /pages directory and the MySQL database before you can proceed.', 'warning', 'div');
201
	echo '<br /><br />';
202
    echo "</div>
203
    </body>
204
    </html>
205
    ";
206
	exit();
207
}
208

  
209
echo '<h2>Step 2: Updating database entries</h2>';
210

  
211
require_once(WB_PATH.'/framework/functions.php');
212
require_once(WB_PATH.'/framework/class.admin.php');
213
$admin = new admin('Addons', 'modules', false, false);
214

  
215
$OK   = '<span class="ok">OK</span>';
216
$FAIL = '<span class="error">FAILED</span>';
217

  
218
// function to add a var/value-pair into settings-table
219
function db_add_key_value($key, $value) {
220
	global $database; global $OK; global $FAIL;
221
	$table = TABLE_PREFIX.'settings';
222
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
223
	if($query->numRows() > 0) {
224
		echo "$key: already exists. $OK.<br />";
225
		return true;
226
	} else {
227
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
228
		echo (mysql_error()?mysql_error().'<br />':'');
229
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
230
		if($query->numRows() > 0) {
231
			echo "$key: $OK.<br />";
232
			return true;
233
		} else {
234
			echo "$key: $FAIL!<br />";
235
			return false;
236
		}
237
	}
238
}
239

  
240
// function to add a new field into a table
241
function db_add_field($field, $table, $desc) {
242
	global $database; global $OK; global $FAIL;
243
	$table = TABLE_PREFIX.$table;
244
	$query = $database->query("DESCRIBE $table '$field'");
245
	if($query->numRows() == 0) { // add field
246
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
247
		echo (mysql_error()?mysql_error().'<br />':'');
248
		$query = $database->query("DESCRIBE $table '$field'");
249
		echo (mysql_error()?mysql_error().'<br />':'');
250
		if($query->numRows() > 0) {
251
			echo "'$field' added. $OK.<br />";
252
		} else {
253
			echo "adding '$field' $FAIL!<br />";
254
		}
255
	} else {
256
		echo "'$field' already exists. $OK.<br />";
257
	}
258
}
259

  
260
/**********************************************************
261
 *  - Adding field default_theme to settings table
262
 */
263
echo "<br />Adding default_theme to settings table<br />";
264
$cfg = array(
265
	'default_theme' => 'wb_theme'
266
);
267

  
268
foreach($cfg as $key=>$value) {
269
	db_add_key_value($key, $value);
270
}
271

  
272
/**********************************************************
273
 *  - install droplets
274
 */
275
    $drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
276
    echo $drops;
277

  
278
     $file_name = (!in_array ( "mod_droplets", $all_tables)) ? "install.php" : "upgrade.php";
279
     require_once (WB_PATH."/modules/droplets/".$file_name);
280

  
281
// check again all tables, to get a new array
282
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
283
/**********************************************************
284
 *  - check tables comin with WebsiteBaker
285
 */
286
    $check_text = 'total ';
287
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
288

  
289
    if(sizeof($all_tables) == 22)
290
    {
291
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
292
    }
293
    else
294
    {
295
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
296
    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
297
        $result = array_diff ( $table_list, $all_tables );
298
        echo '<h4 class="warning"><br />';
299
        while ( list ( $key, $val ) = each ( $result ) )
300
        {
301
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
302
        }
303
        echo '<br /></h4>';
304
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
305
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
306
    	echo '</form>';
307
        if(defined('ADMIN_URL'))
308
        {
309
        	echo '<form action="'.ADMIN_URL.'" target="_self">';
310
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
311
        	echo '</form>';
312
        }
313
        echo "<br /><br /></div>
314
        </body>
315
        </html>
316
        ";
317
        exit();
318
    }
319

  
320
/**********************************************************
321
 *  - Adding field sec_anchor to settings table
322
 */
323

  
324
echo "<br />Adding sec_anchor to settings table<br />";
325
$cfg = array(
326
	'sec_anchor' => 'wb_'
327
);
328
foreach($cfg as $key=>$value) {
329
	db_add_key_value($key, $value);
330
}
331

  
332
/**********************************************************
333
 *  - Adding redirect timer to settings table
334
 */
335
echo "<br />Adding redirect timer to settings table<br />";
336
$cfg = array(
337
	'redirect_timer' => '1500'
338
);
339
foreach($cfg as $key=>$value) {
340
	db_add_key_value($key, $value);
341
}
342

  
343
/**********************************************************
344
 *  - Adding mediasettings to settings table
345
 */
346
echo "<br />Adding mediasettings to settings table<br />";
347
$cfg = array(
348
	'mediasettings' => ''
349
);
350
foreach($cfg as $key=>$value) {
351
	db_add_key_value($key, $value);
352
}
353

  
354
/**********************************************************
355
 *  - Adding fingerprint_with_ip_octets to settings table
356
 */
357
echo "<br />Adding fingerprint_with_ip_octets to settings table<br />";
358
$cfg = array(
359
	'fingerprint_with_ip_octets' => '3'
360
);
361
foreach($cfg as $key=>$value) {
362
	db_add_key_value($key, $value);
363
}
364

  
365
/**********************************************************
366
 *  - Add field "redirect_type" to table "mod_menu_link"
367
 */
368
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
369
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
370

  
371

  
372

  
373
if (version_compare(WB_VERSION, '2.8.0') < 0)
374
{
375
    /**********************************************************
376
     *  - Update search no results database filed to create
377
     *  valid XHTML if search is empty
378
     */
379
    echo "<br />Updating database field `no_results` of search table: ";
380
    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
381
    $sql = "UPDATE `" . TABLE_PREFIX . "search` SET `value` = '$search_no_results' WHERE `name`= 'no_results'";
382
    $database->query($sql);
383
    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL<br />";
384
    /**********************************************************
385
     *  - Update settings of News Modul
386
     */
387

  
388
    // These are the default setting
389
    $header = '<table cellpadding=\"0\" cellspacing=\"0\" class=\"loop-header\">'."\n";
390
    $post_loop = '<tr class=\"post_top\">
391
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
392
<td class=\"post_date\">[PUBLISHED_TIME], [PUBLISHED_DATE]</td>
393
</tr>
394
<tr>
395
<td class=\"post_short\" colspan=\"2\">
396
[SHORT]
397
<span style=\"visibility:[SHOW_READ_MORE];\"><a href=\"[LINK]\">[TEXT_READ_MORE]</a></span>
398
</td>
399
</tr>';
400
    $footer = '</table>
401
<table cellpadding="0" cellspacing="0" class="page-header" style="display: [DISPLAY_PREVIOUS_NEXT_LINKS]">
402
<tr>
403
<td class="page-left">[PREVIOUS_PAGE_LINK]</td>
404
<td class="page-center">[OF]</td>
405
<td class="page-right">[NEXT_PAGE_LINK]</td>
406
</tr>
407
</table>';
408
    $post_header = addslashes('<table cellpadding="0" cellspacing="0" class="post-header">
409
<tr>
410
<td><h1>[TITLE]</h1></td>
411
<td rowspan="3" style="display: [DISPLAY_IMAGE]">[GROUP_IMAGE]</td>
412
</tr>
413
<tr>
414
<td class="public-info"><b>[TEXT_POSTED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [PUBLISHED_DATE]</b></td>
415
</tr>
416
<tr style="display: [DISPLAY_GROUP]">
417
<td class="group-page"><a href="[BACK]">[PAGE_TITLE]</a> &gt;&gt; <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
418
</tr>
419
</table>');
420
    $post_footer = '<p>[TEXT_LAST_CHANGED]: [MODI_DATE] [TEXT_AT] [MODI_TIME]</p>
421
<a href=\"[BACK]\">[TEXT_BACK]</a>';
422
    $comments_header = addslashes('<br /><br />
423
<h2>[TEXT_COMMENTS]</h2>
424
<table cellpadding="2" cellspacing="0" class="comment-header">');
425
    $comments_loop = addslashes('<tr>
426
<td class="comment_title">[TITLE]</td>
427
<td class="comment_info">[TEXT_BY] [DISPLAY_NAME] [TEXT_ON] [DATE] [TEXT_AT] [TIME]</td>
428
</tr>
429
<tr>
430
<td colspan="2" class="comment_text">[COMMENT]</td>
431
</tr>');
432
    $comments_footer = '</table>
433
<br /><a href=\"[ADD_COMMENT_URL]\">[TEXT_ADD_COMMENT]</a>';
434
    $comments_page = '<h1>[TEXT_COMMENT]</h1>
435
<h2>[POST_TITLE]</h2>
436
<br />';
437

  
438
if(in_array('mod_news_settings', $all_tables))
439
{
440
   // Insert default settings into database
441
   $query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
442
   if($query_dates->numRows() > 1)
443
   {
444
        while($result = $query_dates->fetchRow())
445
        {
446

  
447
        	echo "<br /><u>Add default settings to database for news section_id= ".$result['section_id']."</u><br />";
448
        	$section_id = $result['section_id'];
449

  
450
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
451
        		echo 'Database data header added successfully';
452
        	}
453
        	echo mysql_error().'<br />';
454

  
455
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
456
        		echo 'Database data post_loop added successfully';
457
        	}
458
        	echo mysql_error().'<br />';
459

  
460
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `footer` = '$footer' WHERE `section_id` = $section_id")) {
461
        		echo 'Database data footer added successfully';
462
        	}
463
        	echo mysql_error().'<br />';
464

  
465
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
466
        		echo 'Database data post_header added successfully';
467
        	}
468
        	echo mysql_error().'<br />';
469

  
470
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
471
        		echo 'Database data post_footer added successfully';
472
        	}
473
        	echo mysql_error().'<br />';
474

  
475
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
476
        		echo 'Database data comments_header added successfully';
477
        	}
478
        	echo mysql_error().'<br />';
479

  
480
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_loop` = '$comments_loop' WHERE `section_id` = $section_id")) {
481
        		echo 'Database data comments_loop added successfully';
482
        	}
483
        	echo mysql_error().'<br />';
484

  
485
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_footer` = '$comments_footer' WHERE `section_id` = $section_id")) {
486
        		echo 'Database data comments_footer added successfully';
487
        	}
488
        	echo mysql_error().'<br />';
489

  
490
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_page` = '$comments_page' WHERE `section_id` = $section_id")) {
491
        		echo 'Database data comments_page added successfully';
492
        	}
493
        	echo mysql_error().'<br />';
494

  
495
        }
496

  
497

  
498
      if ((version_compare(WB_VERSION, '2.8.1') <= 0) && file_exists(WB_PATH."/modules/news/upgrade.php"))
499
      {
500
              echo '<h4>Upgrade existings postfiles to new format</h4><br />';
501
              // change old postfiles to new postfiles
502
              require_once(WB_PATH."/modules/news/upgrade.php");
503
      }
504
    }
505

  
506
   }
507

  
508
}
509

  
510
/**********************************************************
511
 *  - Set Version to WB 2.8.2
512
 */
513
echo "<br />Update database version number to 2.8.2 : ";
514
echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
515

  
516
/**********************************************************
517
 *  - Reload all addons
518
 */
519

  
520
//delete modules
521
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
522
// Load all modules
523
if($handle = opendir(WB_PATH.'/modules/')) {
524
	while(false !== ($file = readdir($handle))) {
525
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
526
			load_module(WB_PATH.'/modules/'.$file);
527
		}
528
	}
529
	closedir($handle);
530
}
531
echo '<br />Modules reloaded<br />';
532

  
533
//delete templates		
534
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
535
// Load all templates
536
if($handle = opendir(WB_PATH.'/templates/')) {
537
	while(false !== ($file = readdir($handle))) {
538
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
539
			load_template(WB_PATH.'/templates/'.$file);
540
		}
541
	}
542
	closedir($handle);
543
}
544
echo '<br />Templates reloaded<br />';
545

  
546
//delete languages
547
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
548
// Load all languages
549
if($handle = opendir(WB_PATH.'/languages/')) {
550
	while(false !== ($file = readdir($handle))) {
551
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
552
			load_language(WB_PATH.'/languages/'.$file);
553
		}
554
	}
555
	closedir($handle);
556
}
557
echo '<br />Languages reloaded<br />';
558

  
559

  
560
/**********************************************************
561
 *  - End of upgrade script
562
 */
563

  
564
// require(WB_PATH.'/framework/initialize.php');
565

  
566
if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', 'wb_theme'); }
567
if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
568

  
569
echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
570
status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
571
// show buttons to go to the backend or frontend
572
echo '<br />';
573
if(defined('WB_URL')) {
574
	echo '<form action="'.WB_URL.'">';
575
	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
576
	echo '</form>';
577
}
578
if(defined('ADMIN_URL')) {
579
	echo '<form action="'.ADMIN_URL.'">';
580
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
581
	echo '</form>';
582
}
583
echo '<p>&nbsp;</p>';
584

  
585
?>
586
</div>
587
</body>
577 588
</html>
branches/2.8.x/wb/admin/interface/version.php
52 52

  
53 53
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
54 54
if(!defined('VERSION')) define('VERSION', '2.8.2.RC5');
55
if(!defined('REVISION')) define('REVISION', '1422');
55
if(!defined('REVISION')) define('REVISION', '1423');
56 56

  
57 57
?>
branches/2.8.x/wb/install/save.php
1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         install
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version      	$Id$
14
 * @filesource		$HeadURL:  $
15
 * @lastmodified    $Date: $
16
 *
17
 */
18

  
19
$debug = true;
20

  
21
if (true === $debug) {
22
	ini_set('display_errors', 1);
23
	error_reporting(E_ALL);
24
}
25
// Start a session
26
if(!defined('SESSION_STARTED')) {
27
	session_name('wb_session_id');
28
	session_start();
29
	define('SESSION_STARTED', true);
30
}
31
// get random-part for session_name()
32
list($usec,$sec) = explode(' ',microtime());
33
srand((float)$sec+((float)$usec*100000));
34
$session_rand = rand(1000,9999);
35

  
36
// Function to set error
37
function set_error($message, $field_name = '') {
38
	global $_POST;
39
	if(isset($message) AND $message != '') {
40
		// Copy values entered into session so user doesn't have to re-enter everything
41
		if(isset($_POST['website_title'])) {
42
			$_SESSION['wb_url'] = $_POST['wb_url'];
43
			$_SESSION['default_timezone'] = $_POST['default_timezone'];
44
			$_SESSION['default_language'] = $_POST['default_language'];
45
			if(!isset($_POST['operating_system'])) {
46
				$_SESSION['operating_system'] = 'linux';
47
			} else {
48
				$_SESSION['operating_system'] = $_POST['operating_system'];
49
			}
50
			if(!isset($_POST['world_writeable'])) {
51
				$_SESSION['world_writeable'] = false;
52
			} else {
53
				$_SESSION['world_writeable'] = true;
54
			}
55
			$_SESSION['database_host'] = $_POST['database_host'];
56
			$_SESSION['database_username'] = $_POST['database_username'];
57
			$_SESSION['database_password'] = $_POST['database_password'];
58
			$_SESSION['database_name'] = $_POST['database_name'];
59
			$_SESSION['table_prefix'] = $_POST['table_prefix'];
60
			if(!isset($_POST['install_tables'])) {
61
				$_SESSION['install_tables'] = false;
62
			} else {
63
				$_SESSION['install_tables'] = true;
64
			}
65
			$_SESSION['website_title'] = $_POST['website_title'];
66
			$_SESSION['admin_username'] = $_POST['admin_username'];
67
			$_SESSION['admin_email'] = $_POST['admin_email'];
68
			$_SESSION['admin_password'] = $_POST['admin_password'];
69
			$_SESSION['admin_repassword'] = $_POST['admin_repassword'];
70
		}
71
		// Set the message
72
		$_SESSION['message'] = $message;
73
		// Set the element(s) to highlight
74
		if($field_name != '') {
75
			$_SESSION['ERROR_FIELD'] = $field_name;
76
		}
77
		// Specify that session support is enabled
78
		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
79
		// Redirect to first page again and exit
80
		header('Location: index.php?sessions_checked=true');
81
		exit();
82
	}
83
}
84

  
85
// Dummy class to allow modules' install scripts to call $admin->print_error
86
class admin_dummy
87
{
88
	var $error='';
89
	function print_error($message)
90
	{
91
		$this->error=$message;
92
	}
93
}
94

  
95
// Function to workout what the default permissions are for files created by the webserver
96
function default_file_mode($temp_dir) {
97
	$v = explode(".",PHP_VERSION);
98
	$v = $v[0].$v[1];
99
	if($v > 41 AND is_writable($temp_dir)) {
100
		$filename = $temp_dir.'/test_permissions.txt';
101
		$handle = fopen($filename, 'w');
102
		fwrite($handle, 'This file is to get the default file permissions');
103
		fclose($handle);
104
		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
105
		unlink($filename);
106
	} else {
107
		$default_file_mode = '0777';
108
	}
109
	return $default_file_mode;
110
}
111

  
112
// Function to workout what the default permissions are for directories created by the webserver
113
function default_dir_mode($temp_dir) {
114
	$v = explode(".",PHP_VERSION);
115
	$v = $v[0].$v[1];
116
	if($v > 41 AND is_writable($temp_dir)) {
117
		$dirname = $temp_dir.'/test_permissions/';
118
		mkdir($dirname);
119
		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
120
		rmdir($dirname);
121
	} else {
122
		$default_dir_mode = '0777';
123
	}
124
	return $default_dir_mode;
125
}
126

  
127
function add_slashes($input) {
128
	if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
129
		return $input;
130
	}
131
	$output = addslashes($input);
132
	return $output;
133
}
134

  
135
// Begin check to see if form was even submitted
136
// Set error if no post vars found
137
if(!isset($_POST['website_title'])) {
138
	set_error('Please fill-in the form below');
139
}
140
// End check to see if form was even submitted
141

  
142
// Begin path and timezone details code
143

  
144
// Check if user has entered the installation url
145
if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
146
	set_error('Please enter an absolute URL', 'wb_url');
147
} else {
148
	$wb_url = $_POST['wb_url'];
149
}
150
// Remove any slashes at the end of the URL
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
}
157
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
158
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
159
}
160
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
161
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
162
}
163
// Get the default time zone
164
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
165
	set_error('Please select a valid default timezone', 'default_timezone');
166
} else {
167
	$default_timezone = $_POST['default_timezone']*60*60;
168
}
169
// End path and timezone details code
170

  
171
// Get the default language
172
$allowed_languages = array('BG','CA', 'CS', 'DA', 'DE', 'EN', 'ES', 'ET', 'FI', 'FR', 'HR', 'HU', 'IT', 'LV', 'NL', 'NO', 'PL', 'PT', 'RU','SE','SK','TR');
173
if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
174
	set_error('Please select a valid default backend language','default_language');
175
} else {
176
	$default_language = $_POST['default_language'];
177
	// make sure the selected language file exists in the language folder
178
	if(!file_exists('../languages/' .$default_language .'.php')) {
179
		set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language','default_language');
180
	}
181
}
182
// End default language details code
183

  
184
// Begin operating system specific code
185
// Get operating system
186
if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
187
	set_error('Please select a valid operating system');
188
} else {
189
	$operating_system = $_POST['operating_system'];
190
}
191
// Work-out file permissions
192
if($operating_system == 'windows') {
193
	$file_mode = '0777';
194
	$dir_mode = '0777';
195
} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
196
	$file_mode = '0777';
197
	$dir_mode = '0777';
198
} else {
199
	$file_mode = default_file_mode('../temp');
200
	$dir_mode = default_dir_mode('../temp');
201
}
202
// End operating system specific code
203

  
204
// Begin database details code
205
// Check if user has entered a database host
206
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
207
	set_error('Please enter a database host name', 'database_host');
208
} else {
209
	$database_host = $_POST['database_host'];
210
}
211
// Check if user has entered a database username
212
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
213
	set_error('Please enter a database username','database_username');
214
} else {
215
	$database_username = $_POST['database_username'];
216
}
217
// Check if user has entered a database password
218
if(!isset($_POST['database_password'])) {
219
	set_error('Please enter a database password', 'database_password');
220
} else {
221
	$database_password = $_POST['database_password'];
222
}
223
// Check if user has entered a database name
224
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
225
	set_error('Please enter a database name', 'database_name');
226
} else {
227
	// make sure only allowed characters are specified
228
	if(preg_match('/[^a-z0-9_-]+/i', $_POST['database_name'])) {
229
		// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
230
		set_error('Only characters a-z, A-Z, 0-9, - and _ allowed in database name.', 'database_name');
231
	}
232
	$database_name = $_POST['database_name'];
233
}
234
// Get table prefix
235
if(preg_match('/[^a-z0-9_]+/i', $_POST['table_prefix'])) {
236
	// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
237
	set_error('Only characters a-z, A-Z, 0-9 and _ allowed in table_prefix.', 'table_prefix');
238
} else {
239
	$table_prefix = $_POST['table_prefix'];
240
}
241

  
242
// Find out if the user wants to install tables and data
243
if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
244
	$install_tables = true;
245
} else {
246
	$install_tables = false;
247
}
248
// End database details code
249

  
250
// Begin website title code
251
// Get website title
252
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
253
	set_error('Please enter a website title', 'website_title');
254
} else {
255
	$website_title = add_slashes($_POST['website_title']);
256
}
257
// End website title code
258

  
259
// Begin admin user details code
260
// Get admin username
261
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
262
	set_error('Please enter a username for the Administrator account','admin_username');
263
} else {
264
	$admin_username = $_POST['admin_username'];
265
}
266
// Get admin email and validate it
267
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
268
	set_error('Please enter an email for the Administrator account','admin_email');
269
} else {
270
	if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i', $_POST['admin_email'])) {
271
		$admin_email = $_POST['admin_email'];
272
	} else {
273
		set_error('Please enter a valid email address for the Administrator account','admin_email');
274
	}
275
}
276
// Get the two admin passwords entered, and check that they match
277
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
278
	set_error('Please enter a password for the Administrator account','admin_password');
279
} else {
280
	$admin_password = $_POST['admin_password'];
281
}
282
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
283
	set_error('Please make sure you re-enter the password for the Administrator account','admin_repassword');
284
} else {
285
	$admin_repassword = $_POST['admin_repassword'];
286
}
287
if($admin_password != $admin_repassword) {
288
	set_error('Sorry, the two Administrator account passwords you entered do not match','admin_repassword');
289
}
290
// End admin user details code
291

  
292
// Try and write settings to config file
293
$config_content = "" .
294
"<?php\n".
295
"\n".
296
"define('DB_TYPE', 'mysql');\n".
297
"define('DB_HOST', '$database_host');\n".
298
"define('DB_USERNAME', '$database_username');\n".
299
"define('DB_PASSWORD', '$database_password');\n".
300
"define('DB_NAME', '$database_name');\n".
301
"define('TABLE_PREFIX', '$table_prefix');\n".
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff