1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
<?php
/**
* @version $Header: /cvsroot/bitweaver/_bit_install/install_packages.php,v 1.24 2006/02/03 10:41:53 lsces Exp $
* @package install
* @subpackage functions
*/
// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// we set this variable since || admin >> kernel >> packages || uses this file as well
if( !isset( $step ) ) {
$step = NULL;
}
// set the maximum execution time to very high
ini_set( "max_execution_time", "86400" );
// assign next step in installation process
$gBitSmarty->assign( 'next_step', $step );
// pass all package data to template
$schema = $gBitInstaller->mPackages;
ksort( $schema );
$gBitSmarty->assign_by_ref( 'schema', $schema );
// confirm that we have all the admin data in the session before proceeding
if( !empty( $_REQUEST['packages'] ) && in_array( 'users', $_REQUEST['packages'] ) && ( empty( $_SESSION['login'] ) || empty( $_SESSION['password'] ) || empty( $_SESSION['email'] ) ) ) {
// we have lost our session password and we are not installed
header( 'Location: install.php?step=1' );
die;
}
if( !empty( $_REQUEST['cancel'] ) ) {
header( 'Location: install.php?step='.( $step + 1 ) );
} elseif( !empty( $_REQUEST['packages'] ) && is_array( $_REQUEST['packages'] ) && !empty( $_REQUEST['method'] ) && !empty( $_REQUEST['submit_packages'] ) ) {
// make sure that required pkgs are only present when we are installing
if( ( $method = ( $_REQUEST['method'] ) ) == 'install' && !$_SESSION['first_install'] ) {
foreach( array_keys( $gBitInstaller->mPackages ) as $package ) {
if( in_array( $package, $_REQUEST['packages'] ) && !empty( $gBitInstaller->mPackages[$package]['required'] ) ) {
$gBitSmarty->assign( 'warning', "There was a problem with the package selection. we just caught it in time before your system got destroyed." );
$method = FALSE;
}
}
}
if( $gBitDbType == 'sybase' ) {
// avoid database change messages
ini_set('sybct.min_server_severity', '11');
}
$gBitInstallDb = &ADONewConnection( $gBitDbType );
if( !empty( $gDebug ) || !empty( $_REQUEST['debug'] ) ) {
$gBitInstaller->debug();
$gBitInstallDb->debug = 99;
}
// by now $method should be populated with something
if( $gBitInstallDb->Connect( $gBitDbHost, $gBitDbUser, $gBitDbPassword, $gBitDbName ) && !empty( $method ) ) {
if ( $_SESSION['first_install'] && $gBitDbType == 'firebird' ) {
$result = $gBitInstallDb->Execute( "DECLARE EXTERNAL FUNCTION LOWER CSTRING(80) RETURNS CSTRING(80) FREE_IT ENTRY_POINT 'IB_UDF_lower' MODULE_NAME 'ib_udf'" );
}
$tablePrefix = $gBitInstaller->getTablePrefix();
$dict = NewDataDictionary( $gBitInstallDb, $gBitDbType );
// SHOULD HANDLE INNODB so foreign keys are cool - XOXO spiderr
// $tableOptions = array('mysql' => 'TYPE=INNODB', 'REPLACE');
$sqlArray = array();
//error_reporting( E_ALL );
// packages are sorted alphabetically. but we really need a /etc/rc.d/rc.3 style loading precidence!
// We perform several loops through mPackages due to foreign keys, and some packages may insert
// value into other packages tables - typically users_permissions, bit_preferences, etc...
sort( $_REQUEST['packages'] );
// 1. let's generate all the tables's
foreach( array_keys( $gBitInstaller->mPackages ) as $package ) {
if( in_array( $package, $_REQUEST['packages'] ) ) {
// work out what we're going to do with this package
if ( $method == 'install' && $_SESSION['first_install'] ) {
$build = array( 'NEW' );
} elseif( $method == "install" && empty( $gBitInstaller->mPackages[$package]['installed'] ) ) {
$build = array( 'NEW' );
} elseif( $method == "reinstall" && !empty( $gBitInstaller->mPackages[$package]['installed'] ) ) {
$build = array( 'REPLACE' );
} elseif( $method == "uninstall" && $gBitInstaller->mPackages[$package]['installed'] == 1 ) {
$build = array( 'DROP' );
}
// Install tables
if( !empty( $gBitInstaller->mPackages[$package]['tables'] ) && is_array( $gBitInstaller->mPackages[$package]['tables'] ) ) {
foreach( array_keys( $gBitInstaller->mPackages[$package]['tables'] ) as $tableName ) {
$completeTableName = $tablePrefix.$tableName;
$sql = $dict->CreateTableSQL( $completeTableName, $gBitInstaller->mPackages[$package]['tables'][$tableName], $build );
// Uncomment this line to see the create sql
//vd( $sql );
if( $sql && ( $dict->ExecuteSQLArray( $sql ) > 0 ) ) {
} else {
print '<span class="error">Failed to create '.$completeTableName.'</span>';
array_push( $failedcommands, $sql );
}
}
}
}
}
// 2. let's generate all the indexes, and sequences
foreach( array_keys( $gBitInstaller->mPackages ) as $package ) {
if( in_array( $package, $_REQUEST['packages'] ) ) {
if( $method == 'install' || $method == 'reinstall' ) {
$schemaQuote = strrpos( BIT_DB_PREFIX, '`' );
$sequencePrefix = ( $schemaQuote ? substr( BIT_DB_PREFIX, $schemaQuote + 1 ) : BIT_DB_PREFIX );
// Install Indexes
if( isset( $gBitInstaller->mPackages[$package]['indexes'] ) && is_array( $gBitInstaller->mPackages[$package]['indexes'] ) ) {
foreach( array_keys( $gBitInstaller->mPackages[$package]['indexes'] ) as $tableIdx ) {
$completeTableName = $sequencePrefix.$gBitInstaller->mPackages[$package]['indexes'][$tableIdx]['table'];
$sql = $dict->CreateIndexSQL( $tableIdx, $completeTableName, $gBitInstaller->mPackages[$package]['indexes'][$tableIdx]['cols'], $gBitInstaller->mPackages[$package]['indexes'][$tableIdx]['opts'] );
if( $sql && ($dict->ExecuteSQLArray( $sql ) > 0 ) ) {
} else {
print '<span class="error">Failed to create '.$completeTableName.'</span>';
array_push( $failedcommands, $sql );
}
}
}
if( isset( $gBitInstaller->mPackages[$package]['sequences'] ) && is_array( $gBitInstaller->mPackages[$package]['sequences'] ) ) {
foreach( array_keys( $gBitInstaller->mPackages[$package]['sequences'] ) as $sequenceIdx ) {
$sql = $gBitInstallDb->CreateSequence( $sequencePrefix.$sequenceIdx, $gBitInstaller->mPackages[$package]['sequences'][$sequenceIdx]['start'] );
}
}
} elseif( $method == 'uninstall' ) {
if( isset( $gBitInstaller->mPackages[$package]['sequences'] ) && is_array( $gBitInstaller->mPackages[$package]['sequences'] ) ) {
foreach( array_keys( $gBitInstaller->mPackages[$package]['sequences'] ) as $sequenceIdx ) {
$sql = $gBitInstallDb->DropSequence( $sequencePrefix.$sequenceIdx );
}
}
}
}
}
// Force a reload of all our preferences
$gBitInstaller->mPrefs = '';
$gBitInstaller->loadPreferences();
// 3. activate all selected & required packages
foreach( array_keys( $gBitInstaller->mPackages ) as $package ) {
if( in_array( $package, $_REQUEST['packages'] ) ) {
if( $method == 'install' || $method == 'reinstall' ) {
$gBitInstaller->storePreference( 'package_'.strtolower( $package ), 'y', $package );
// we'll default wiki to the home page
if( defined( 'WIKI_PKG_NAME' ) && $package == WIKI_PKG_NAME ) {
$gBitSystem->storePreference( "bitIndex", WIKI_PKG_NAME );
}
} elseif( $method == 'uninstall' ) {
// TODO: allow option to remove related content from liberty_content and liberty_structures
// should be possible using $gLibertySystem->mContentTypes and the appropriate GUIDs
// Cascade user_preferences if necessary
// this has to be done using the individual content_ids from liberty_content
// $delete = "DELETE FROM `".$tablePrefix."liberty_content_prefs` " .
// "WHERE `pref_name` IN ( SELECT `name` FROM `kernel_prefs` WHERE `package` = '".$package."')";
// $gBitInstaller->mDb->query( $delete );
// Delete user_permissions ( need to ensure package is set in table )
$delete = "DELETE FROM `".$tablePrefix."users_permissions`
WHERE `package` = '".$package."'";
$gBitInstaller->mDb->query( $delete );
// Delete preferences ( need to ensure package is set in table )
$delete = "DELETE FROM `".$tablePrefix."kernel_prefs`
WHERE `package` = '".$package."'";
$gBitInstaller->mDb->query( $delete );
}
}
}
// and let's turn on phpBB so people can find it easily.
if( defined( 'PHPBB_PKG_NAME' ) ) {
$gBitInstaller->storePreference( 'package_phpbb', 'y' );
}
// 4. run the defaults through afterwards so we can be sure all tables needed have been created
foreach( array_keys( $gBitInstaller->mPackages ) as $package ) {
if( in_array( $package, $_REQUEST['packages'] ) || ( empty( $gBitInstaller->mPackages[$package]['installed'] ) && !empty( $gBitInstaller->mPackages[$package]['required'] ) ) ) {
if( $method == 'install' || $method == 'reinstall' ) {
// this list of installed packages is used to show newly installed packages
if( !empty( $gBitInstaller->mPackages[$package]['defaults'] ) ) {
foreach( $gBitInstaller->mPackages[$package]['defaults'] as $def ) {
if ($gBitInstaller->mDb->mType == 'firebird' ) $def = preg_replace("/\\\'/","''", $def );
$gBitInstaller->mDb->query( $def );
}
}
} else {
// This is where any links to clear data not in the current package will be processed
}
// this is to list any processed packages
$packageList[$method][] = $package;
}
}
// only install modules during the first install
if( isset( $_SESSION['first_install'] ) && $_SESSION['first_install'] == TRUE ) {
/**
* Some packages have some special things to take care of here.
*/
require_once( KERNEL_PKG_PATH.'mod_lib.php' );
foreach( $gBitInstaller->mInstallModules as $mod ) {
$mod['user_id'] = ROOT_USER_ID;
if( !isset( $mod['layout'] ) ) {
$mod['layout'] = DEFAULT_PACKAGE;
}
$modlib->storeModule( $mod );
$modlib->storeLayout( $mod );
}
}
// Installing users has some special things to take care of here and needs a separate check.
if( in_array( 'users', $_REQUEST['packages'] ) && empty( $gBitInstaller->mPackages['users']['installed'] ) ) {
// now let's set up some default data. Group_id's are hardcoded in users/schema_inc defaults
$gBitUser->assign_level_permissions( ANONYMOUS_GROUP_ID, 'basic' );
$gBitUser->assign_level_permissions( 3, 'registered' );
$gBitUser->assign_level_permissions( 2, 'editors' );
$gBitUser->assign_level_permissions( 1, 'admin' );
// Create 'Anonymous' user has id= -1 just like phpBB
$anonUser = new BitPermUser();
$storeHash = array( 'real_name' => 'Guest', 'login' => 'guest', 'password' => $_SESSION['password'], 'email' =>'guest@localhost', 'pass_due' => FALSE, 'user_id' => ANONYMOUS_USER_ID, 'default_group_id' => ANONYMOUS_USER_ID );
if( $anonUser->store( $storeHash ) ) {
// Remove anonymous from registered group
$regGroupId = $anonUser->groupExists( 'Registered', ROOT_USER_ID );
$anonUser->removeUserFromGroup( ANONYMOUS_USER_ID, $regGroupId );
$anonUser->addUserToGroup( ANONYMOUS_USER_ID, ANONYMOUS_GROUP_ID);
}
// Creating 'root' user has id=1. phpBB starts with user_id=2, so this is a hack to keep things in sync
$rootUser = new BitPermUser();
$storeHash = array( 'real_name' => 'root', 'login' => 'root', 'password' => $_SESSION['password'], 'email' => 'root@localhost', 'pass_due' => FALSE, 'user_id' => ROOT_USER_ID );
if( $rootUser->store( $storeHash ) ) {
$rootUser->addUserToGroup( ROOT_USER_ID, 1 );
}
$adminUser = new BitPermUser();
$storeHash = array( 'real_name' => $_SESSION['real_name'], 'login' => $_SESSION['login'], 'password' => $_SESSION['password'], 'email' =>$_SESSION['email'], 'pass_due' => FALSE );
if( $adminUser->store( $storeHash ) ) {
$adminUser->addUserToGroup($adminUser->mUserId, 1 );
}
// kill admin info in $_SESSION
unset( $_SESSION['real_name'] );
unset( $_SESSION['login'] );
unset( $_SESSION['password'] );
unset( $_SESSION['email'] );
}
$gBitSmarty->assign( 'next_step', $step + 1 );
asort( $packageList );
$gBitSmarty->assign( 'packageList', $packageList );
$gBitSmarty->assign( 'failedcommands', !empty( $failedcommands ) ? $failedcommands : NULL );
// display the confirmation page
$app = '_done';
} else {
// if we can't connect to the db, move back 2 steps
header( "Location: ".$_SERVER['PHP_SELF']."?step=".$step - 2 );
}
} elseif( !empty( $_REQUEST['submit_packages'] ) ) {
$gBitSmarty->assign( 'warning', "No package was selected to install or uninstall" );
}
?>
|