summaryrefslogtreecommitdiff
path: root/includes/create_config_inc.php
blob: 82a537d86ed25d07df63beee4ee1bb55ff4f631f (plain)
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
<?php
/**
 * @version $Header$
 * @package install
 * @subpackage functions
 */

/**
 * create_config
 */

/**
 * create configuration file
 *
 * 
 * @param array $pParamHash
 * @var string  $pParamHash['gBitDbHost']
 * @var string  $pParamHash['gBitDbUser']
 * @var string  $pParamHash['gBitDbPassword']
 * @var string  $pParamHash['gBitDbName']
 * @var numeric $pParamHash['gBitDbCaseSensitivity']
 * @var string  $pParamHash['bit_db_prefix']
 * @var string  $pParamHash['bit_root_url']
 * @var boolean $pParamHash['auto_bug_submit']
 * @var boolean $pParamHash['is_live']
 * @return void
 */
function create_config( $pParamHash ) {
	// assign values to their keys
	extract( $pParamHash );

	$bit_db_prefix  = empty( $bit_db_prefix ) ? "" : $bit_db_prefix;

	$gBitDbType     = addslashes( $gBitDbType );
	$gBitDbHost     = addslashes( $gBitDbHost );
	$gBitDbUser     = addslashes( $gBitDbUser );
	$gBitDbPassword = addslashes( $gBitDbPassword );
	$gBitDbName     = addslashes( $gBitDbName );
	$bit_db_prefix  = addslashes( $bit_db_prefix );

	if( preg_match( '/\./', $bit_db_prefix ) ) {
		if( $gBitDbType == 'mysql' ) {
			$bit_db_prefix = preg_replace( '/[`.]/', '', $bit_db_prefix );
		} elseif( !preg_match( '/`\.`/', $bit_db_prefix ) ) {
			$bit_db_prefix = preg_replace( '/\./', '`.`', $bit_db_prefix );
		}
	}

	$config_file = empty( $_SERVER['CONFIG_INC'] ) ? '../config/kernel/config_inc.php' : $_SERVER['CONFIG_INC'];
	if( !file_exists( dirname( dirname( $config_file ) ) ) ) {
		mkdir( dirname( dirname( $config_file ) ) );
	}
	if( !file_exists( dirname( $config_file ) ) ) {
		mkdir( dirname( $config_file ) );
	}

	// We can't call clean_file_path here even though we would like to.
	$config_file = ( strpos( $_SERVER["SERVER_SOFTWARE"],"IIS" ) ? str_replace( "/", "\\", $config_file ) : $config_file );

	$fw = fopen( $config_file, 'w' );
	if( isset( $fw )) {
		$filetowrite = "<?php
// Copyright (c) 2006, bitweaver.org
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE.

// The following line is required and should not be altered
global \$gBitDbType, \$gBitDbHost, \$gBitDbUser, \$gBitDbPassword, \$gBitDbName, \$gBitDbCaseSensitivity, \$smarty_force_compile, \$gDebug, \$gPreScan;


             /******************************************************\
              ***************   Database settings   **************** 
             \******************************************************/

// You can choose between different Database abstraction layers. Currently we support:
//    adodb          ADODB
//                   this is the default setting and is bundled with bitweaver
//    pear           PEAR::DB
//                   when using this, you can even remove the util/adodb directory
\$gBitDbSystem = \"adodb\";


// bitweaver can store its data in multiple different back-ends. Currently we
// support MySQL, MSSQL, Firebird, Sybase, PostgreSQL and Oracle.  Enter the
// hostname where your database lives, and the username and password you use to
// connect to it.
//
// You must specify the name of a database that already exists. bitweaver will not
// create the database for you, because it's very difficult to do that in a
// reliable, database-neutral fashion. The user that you use should have the
// following permissions:
//
//    SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP
//
// The possible database types that we support are:
//    mysql          Standard MySQL
//    mysqli         New MySQL driver
//    sqlite         SQLLite
//    mssql          MS-SQL (experimental)
//    postgres       PostgreSQL 7.x
//    oci8po         Oracle (9i and newer)
//    firebird       FireBird
//    sybase         Sybase
\$gBitDbType=\"$gBitDbType\";

// Hostname or IP for your database.
// Some examples:
//    'localhost' if you are running the database on the same machine as bitweaver
//    If you use Oracle, insert your TNS Name here
//    If you use SQLite, insert the path and filename to your database file
\$gBitDbHost=\"$gBitDbHost\";

// Database username
\$gBitDbUser=\"$gBitDbUser\";

// Database password
\$gBitDbPassword=\"$gBitDbPassword\";

// Database name
\$gBitDbName=\"$gBitDbName\";

// Database field case default
\$gBitDbCaseSensitivity=\"$gBitDbCaseSensitivity\";

// This prefix will be prepended to the begining of every table name to allow
// multiple independent installs to share a single database. By ending the prefix
// with a '.' (period) you can use a schema in systems that support it. Backticks
// '`' around the '.' are required if present. A schema example is: 'bit`.`'
define( 'BIT_DB_PREFIX', '$bit_db_prefix' );


             /******************************************************\
              *************** Environment Settings  **************** 
             \******************************************************/

// Setting IS_LIVE to TRUE will let the application know that this site is a live
// production site and is not used for testing purposes.  This will prevent any
// nasty error pages from appearing and will redirect the user to a 'nicer' error
// page. Errors should still show up in your error logs. Please use these when
// submitting bugs to http://sourceforge.net/tracker/?group_id=141358&atid=749176
define( 'IS_LIVE', $is_live );


// if you set AUTO_BUG_SUBMIT to TRUE bitweaver will automatically email the team
// with details regarding the error.  Alternatively you can submit bugs to
// http://sourceforge.net/tracker/?group_id=141358&atid=749176 which will probably
// get processed faster since more people have access to these.
define( 'AUTO_BUG_SUBMIT', $auto_bug_submit );


// This is the path from the server root to your bitweaver location.  i.e. if you
// access bitweaver as 'http://MyServer.com/applications/new/wiki/index.php' you
// should enter '/applications/new/'
define( 'BIT_ROOT_URL', '$bit_root_url' );


// Here you can set the valid base URI for your site. If you do not set this, we
// will automatically determine a working value. You can force the use of a 
// specific URI here by putting something like: 'http://myfiles.example.com'
//define( 'BIT_ROOT_URI', 'http://myfiles.example.com' );


// Add default STORAGE_HOST_URI for optionally splitting off storage files to 
// separate host. This will allow you to serve thumbnails and other files from 
// a different server to your web server. If this is not set, we will use 
// BIT_ROOT_URI instead. Put something like: 'http://myfiles.example.com'
//define( 'STORAGE_HOST_URI', 'http://myfiles.example.com' );


// This allows you to set a custom path to your PHP tmp directory - used for ADODB
// caching if active, and other stuff This is usually only needed in very
// restrictive hosting environments.
//\$gTempDir = '/path/to/private/directory';


// \$gPreScan can be used to specify the order in which packages are scanned by
// the kernel.  In the example provided below, the kernel package is processed
// first, followed by the users and liberty packages.  Any packages not specified
// in \$gPreScan are processed in the traditional order
//\$gPreScan = [ 'kernel', 'storage', 'liberty', 'themes', 'users' ];

// \$gThumbSizes defines the image thumbnail sizes that will be autogenerated when
// images are uploaded and processed. The example provided shows the default sizes
// that are used. You can add as many sizes as you want if you override the default. 
/*
\$gThumbSizes = [
		'extra-large'  => [ 'width' => 1024, 'height' => 1024 ],
		'large'  => [ 'width' => 800, 'height' => 800 ],
		'medium' => [ 'width' => 400, 'height' => 400 ],
		'small'  => [ 'width' => 160, 'height' => 160 ],
		'avatar' => [ 'width' => 100, 'height' => 100 ],
		'icon'   => [ 'width' => 48,  'height' => 48 ],
];
*/";

		if( substr( PHP_OS, 0, 3 ) == 'WIN' ) {
			$filetowrite .= "


// Insert the absolute path to your php magic database. This is required for 
// us to check and verify the mime type of uploaded files. This setting is only 
// required on windows machines.
//define( 'PHP_MAGIC_PATH', 'C:\\Program Files\\PHP\\extras\\magic.mime' );";
		}

		if( defined( 'ROLE_MODEL' )) {
			$filetowrite .= "

define( 'LIBERTY_DEFAULT_MIME_HANDLER', 'mimeflatdefault' );";
		}

		$filetowrite .= "


             /******************************************************\
              ***************   Debugging Options   **************** 
             \******************************************************/

// If you wish to force compiling of every page, you can set the next setting to
// TRUE. this will, however, severly impact performance since every page that is
// generated is generated afresh and the cache is recreated every time.
\$smarty_force_compile = FALSE;


// Setting TEMPLATE_DEBUG = TRUE will output <!-- <called templates> --> in your
// templates, which will allow you to track all used templates in the HTML source
// of the page. This will also disable stripping of whitespace making it easier to
// read the templates. You will only see the effect of the strip changes by
// clearing out your cache or setting \$smarty_force_compile = TRUE;
// Note: be sure to set this to FALSE and clear out the cache once done since it
//       will increase the page size by at least 10%.
//define( 'TEMPLATE_DEBUG', TRUE );

// If you want to go a step further with template debugging then this enables
// smarty's debugging console.  A popup with a dump of all of the vars the
// template(s) have been passed.
\$smarty_debugging = FALSE;


// This statement will enable you to view all database queries made
//\$gDebug = TRUE;


// This will turn on ADODB performance monitoring and log all queries. This should
// not be enabled except when doing query analysis due to an overall performance
// drop.  see kernel/admin/db_performance.php for statistics
//define( 'DB_PERFORMANCE_STATS', TRUE );
";
		fwrite( $fw, $filetowrite );
		fclose( $fw );
	} else {
		print "UNABLE TO WRITE TO ".realpath( $config_file );
	}
}