Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
/*************************
3
  Coppermine Photo Gallery
4
  ************************
5
  Copyright (c) 2003-2005 Coppermine Dev Team
6
  v1.1 originaly written by Gregory DEMAR
7
 
8
  This program is free software; you can redistribute it and/or modify
9
  it under the terms of the GNU General Public License as published by
10
  the Free Software Foundation; either version 2 of the License, or
11
  (at your option) any later version.
12
  ********************************************
13
  Coppermine version: 1.3.3
14
  $Source: /cvsroot/coppermine/stable/install.php,v $
15
  $Revision: 1.14 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:11 $
18
**********************************************/
19
 
20
// Check if standalone is installed in a portal like phpNuke (added by DJMaze)
21
$DIR=preg_split("/[\/\\\]/",dirname($_SERVER['PATH_TRANSLATED']));
22
if ($DIR[count($DIR)-2] == "modules") {
23
    echo "<html><body><h1>ERROR</h1>You installed the standalone Coppermine into your Nuke portal.<br>".
24
         "Please download and install a CPG Port: <a href=\"http://sourceforge.net/project/showfiles.php?group_id=89658\">CPG for PostNuke OR CPG for PHPnuke</a></body></html>";
25
    die();
26
} // end check
27
 
28
error_reporting (E_ALL ^ E_NOTICE);
29
 
30
require('include/sql_parse.php');
31
// ---------------------------- TEST PREREQUIRED --------------------------- //
32
function test_fs()
33
{
34
    global $errors, $DFLT;
35
    // include must be writable to create config file
36
    if (! is_dir($DFLT['cfg_d'])) {
37
        $errors .= "<hr /><br />A subdirectory called '{$DFLT['cfg_d']}' should normally exist in the directory where you uploaded Coppermine. The installer can't find this directory. Check that you have uploaded all Coppermine files to your server.<br /><br />";
38
    } elseif (! is_writable($DFLT['cfg_d'])) {
39
        $errors .= "<hr /><br />The '{$DFLT['cfg_d']}' directory (located in the directory where you uploaded Coppermine) should be writable in order to save your configuration. Use your FTP program to change its mode to 777.<br /><br />";
40
    }
41
    // albums must be writable to upload pictures
42
    if (! is_dir($DFLT['alb_d'])) {
43
        $errors .= "<hr /><br />A subdirectory called '{$DFLT['alb_d']}' should normally exist in the directory where you uploaded Coppermine. The installer can't find this directory. Check that you have uploaded all Coppermine files to your server.<br /><br />";
44
    } elseif (! is_writable($DFLT['alb_d'])) {
45
        $errors .= "<hr /><br />The '{$DFLT['alb_d']}' directory (located in the directory where you uploaded Coppermine) should be writable in order to allow pictures upload. Use your FTP program to change its mode to 777.<br /><br />";
46
    }
47
    // userpics must be writable to upload pictures
48
    if (! is_dir("{$DFLT['alb_d']}/{$DFLT['upl_d']}")) {
49
        $errors .= "<hr /><br />A subdirectory called '{$DFLT['upl_d']}' should normally exist in the 'albums' directory. The installer can't find this directory. Check that you have uploaded all Coppermine files to your server.<br /><br />";
50
    } elseif (! is_writable("{$DFLT['alb_d']}/{$DFLT['upl_d']}")) {
51
        $errors .= "<hr /><br />The '{$DFLT['upl_d']}' directory (located in the 'albums' directory on your server) should be writable in order to allow pictures upload. Use your FTP program to change its mode to 777.<br /><br />";
52
    }
53
    // edit must be writable to edit pictures
54
    if (! is_dir("{$DFLT['alb_d']}/{$DFLT['edit_d']}")) {
55
        $errors .= "<hr /><br />A subdirectory called '{$DFLT['edit_d']}' should normally exist in the 'albums' directory. The installer can't find this directory. Check that you have uploaded all Coppermine files to your server.<br /><br />";
56
    } elseif (! is_writable("{$DFLT['alb_d']}/{$DFLT['edit_d']}")) {
57
        $errors .= "<hr /><br />The '{$DFLT['edit_d']}' directory (located in the 'albums' directory on your server) should be writable in order to allow pictures upload. Use your FTP program to change its mode to 777.<br /><br />";
58
    }
59
    // sql directory must exist
60
    if (! is_dir("{$DFLT['sql_d']}")) {
61
        $errors .= "<hr /><br />A subdirectory called '{$DFLT['sql_d']}' should normally exist in the directory where you uploaded Coppermine. The installer can't find this directory. Check that you have uploaded all Coppermine files to your server.<br /><br />";
62
    }
63
}
64
// ----------------------------- TEST FUNCTIONS ---------------------------- //
65
function test_sql_connection()
66
{
67
    global $errors, $HTTP_POST_VARS;
68
 
69
    if (! $connect_id = @mysql_connect($HTTP_POST_VARS['dbserver'], $HTTP_POST_VARS['dbuser'], $HTTP_POST_VARS['dbpass'])) {
70
        $errors .= "<hr /><br />Could not create a mySQL connection, please check the SQL values entered<br /><br />MySQL error was : " . mysql_error() . "<br /><br />";
71
    } elseif (! mysql_select_db($HTTP_POST_VARS['dbname'], $connect_id)) {
72
        $errors .= "<hr /><br />mySQL could not locate a database called '{$HTTP_POST_VARS['dbname']}' please check the value entered for this<br /><br />";
73
    }
74
}
75
 
76
function test_admin_login()
77
{
78
    global $errors, $HTTP_POST_VARS;
79
 
80
    if ($HTTP_POST_VARS['admin_username'] == '' || $HTTP_POST_VARS['admin_password'] == '')
81
        $errors .= "<hr /><br />It is much better for you to provide a 'username' and a 'password' for the admin.<br /><br />";
82
    if (!preg_match('/\A\w*\Z/', $HTTP_POST_VARS['admin_username']) || !preg_match('/\A\w*\Z/', $HTTP_POST_VARS['admin_password']))
83
        $errors .= "<hr /><br />Admin username and password must only contain alphanumeric characters.<br /><br />";
84
}
85
 
86
function test_im()
87
{
88
    global $errors, $HTTP_POST_VARS, $DFLT, $im_installed;
89
 
90
    $im_installed = false;
91
 
92
    if ($HTTP_POST_VARS['impath'] != '') {
93
        if (!preg_match('|/\Z|', $HTTP_POST_VARS['impath']))
94
            $HTTP_POST_VARS['impath'] .= '/';
95
        if (!is_dir($HTTP_POST_VARS['impath'])) {
96
            $errors .= "<hr /><br />The installer can not find the '{$HTTP_POST_VARS['impath']}' directory you have specified for ImageMagick or it does not have permission to access it. Check that your typing is correct and that you have access to the specified directory.<br /><br />";
97
        } elseif (preg_match('/ /', $HTTP_POST_VARS['impath'])) {
98
            $errors .= "<hr /><br />The path you have entered for ImageMagick ('{$HTTP_POST_VARS['impath']}') contains at least one space. This will cause problems in the script.<br /><br />
99
                        You must move ImageMagick to another directory.<br /><br />";
100
        } elseif (!file_exists($HTTP_POST_VARS['impath'] . 'convert') && !file_exists($HTTP_POST_VARS['impath'] . 'convert.exe')) {
101
            $errors .= "<hr /><br />The installer can not find the 'convert' or 'convert.exe' ImageMagick program in directory '{$HTTP_POST_VARS['impath']}'. Check that you have entered the correct directory name.<br /><br />";
102
        } else {
103
            $output = array();
104
            $tst_image = "{$DFLT['alb_d']}/{$DFLT['upl_d']}/im.gif";
105
            exec ("{$HTTP_POST_VARS['impath']}convert images/nopic.jpg $tst_image", $output, $result);
106
            $size = getimagesize($tst_image);
107
            unlink($tst_image);
108
            $im_installed = ($size[2] == 1);
109
 
110
            if (!$im_installed)
111
                $errors .= "<hr /><br />The installer found the ImageMagick 'convert' program in '{$HTTP_POST_VARS['impath']}', however it can't be executed by the script.<br /><br />
112
                                        You may consider using GD instead of ImageMagick.<br /><br />";
113
 
114
            if ($result && count($output)) {
115
                $errors .= "The convert program said:<br /><pre>";
116
                foreach($output as $line) $errors .= htmlspecialchars($line);
117
                $errors .= "</pre><br /><br />";
118
            }
119
        }
120
    }
121
 
122
    return $im_installed;
123
}
124
// Test is safe_mode is misconfigured
125
function test_silly_safe_mode()
126
{
127
    global $DFLT;
128
 
129
    $test_file = "{$DFLT['alb_d']}/{$DFLT['upl_d']}/dummy/dummy.txt";
130
    @mkdir(dirname($test_file), 0755);
131
    $fd = @fopen($test_file, 'w');
132
    if (!$fd) {
133
        @rmdir(dirname($test_file));
134
        return true;
135
    }
136
    fclose($fd);
137
    @unlink($test_file);
138
    @rmdir(dirname($test_file));
139
}
140
// -------------------------- DETECTION FUNCTIONS -------------------------- //
141
// What package is available for image manipulations
142
function detect_img_package()
143
{
144
    global $errors, $notes, $HTTP_POST_VARS, $DFLT, $im_installed;
145
 
146
    $no_img_package_detected = false;
147
    $tst_image = "{$DFLT['alb_d']}/{$DFLT['upl_d']}/gd1.jpg";
148
    $size = @getimagesize($tst_image);
149
    @unlink($tst_image);
150
    $gd1_installed = ($size[2] == 2);
151
 
152
    $tst_image = "{$DFLT['alb_d']}/{$DFLT['upl_d']}/gd2.jpg";
153
    $size = @getimagesize($tst_image);
154
    @unlink($tst_image);
155
    $gd2_installed = ($size[2] == 2);
156
 
157
    if ($im_installed) {
158
        $HTTP_POST_VARS['thumb_method'] = 'im';
159
    } elseif ($gd2_installed) {
160
        $HTTP_POST_VARS['thumb_method'] = 'gd2';
161
    } elseif ($gd1_installed) {
162
        $HTTP_POST_VARS['thumb_method'] = 'gd1';
163
    } else {
164
        $HTTP_POST_VARS['thumb_method'] = 'gd2';
165
        $no_img_package_detected = true;
166
        $notes .= "<hr /><br />Your installation of PHP does not seem to include the 'GD' graphic library extension and you have not indicated that you want to use ImageMagick. Coppermine has been configured to use GD2 because the automatic GD detection sometimes fail. If GD is installed on your system, the script should work else you will need to install ImageMagick.<br /><br />";
167
    }
168
 
169
    if (!$no_img_package_detected) $notes .= "<br /><br />Your server supports the following image package(s): " . ($im_installed ? ' ImageMagick (im),':'') . ($gd1_installed ? ' GD Library version 1.x (gd1),':'') . ($gd2_installed ? ' GD Library version 2.x (gd2),':'') . " the installer selected '" . $HTTP_POST_VARS['thumb_method'] . "'.";
170
    if ($HTTP_POST_VARS['thumb_method'] == 'gd1' || $HTTP_POST_VARS['thumb_method'] == 'gd2')
171
        $notes .= "<br /><br /><b>Important :</b> the GD graphic library supports only JPEG and PNG images. The script will not be able to create thumbnails for GIF images. If you want the script to create thumbnails for GIF images, you need to use ImageMagick.";
172
}
173
// ------------------------- HTML OUTPUT FUNCTIONS ------------------------- //
174
function html_header()
175
{
176
 
177
    ?>
178
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
179
<html>
180
<head>
181
<title>Coppermine - Installation</title><link type="text/css" rel="stylesheet" href="installer.css">
182
</head>
183
<body>
184
 <div align="center">
185
  <div style="width:600px;">
186
<?php
187
}
188
 
189
function html_logo()
190
{
191
 
192
    ?>
193
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
194
       <tr>
195
        <td valign="top" bgcolor="#EFEFEF"><img src="images/logo.gif"><br />
196
        </td>
197
       </tr>
198
      </table>
199
<?php
200
}
201
 
202
function html_installer_locked()
203
{
204
    global $DFLT;
205
 
206
    ?>
207
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
208
       <tr>
209
            <form action="index.php">
210
        <td class="tableh1" colspan="2"><h2>The installer is locked</h2>
211
        </td>
212
       </tr>
213
       <tr>
214
        <td class="tableh2" colspan="2" align="center"><span class="error">&#149;&nbsp;&#149;&nbsp;&#149;&nbsp;ERROR&nbsp;&#149;&nbsp;&#149;&nbsp;&#149;</span>
215
        </td>
216
       </tr>
217
       <tr>
218
        <td class="tableb" colspan="2">The installer has already been run successfuly once and is now locked.<br /><br />If you want to run the installer again, you first need to delete the '<?php echo $DFLT['lck_f'] ?>' file that was created in the directory where you put Coppermine. You can do this with any FTP program.
219
        </td>
220
       </tr>
221
       <tr>
222
        <td colspan="2" align="center"><br />
223
                <input type="submit" value="Go to the main page"><br /><br />
224
        </td>
225
           </form>
226
       </tr>
227
      </table>
228
<?php
229
}
230
 
231
function html_prereq_errors($error_msg)
232
{
233
 
234
    ?>
235
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
236
       <tr>
237
            <form action="install.php">
238
        <td class="tableh1" colspan="2"><h2>Welcome to Coppermine installation</h2>
239
        </td>
240
       </tr>
241
       <tr>
242
        <td class="tableh2" colspan="2" align="center"><span class="error">&#149;&nbsp;&#149;&nbsp;&#149;&nbsp;ERROR&nbsp;&#149;&nbsp;&#149;&nbsp;&#149;</span>
243
        </td>
244
       </tr>
245
       <tr>
246
        <td class="tableb" colspan="2"> Before you continue with Coppermine installation, there are some problems that need to be fixed.<br /><br /><b><?php echo $error_msg ?></b>Once you are done, hit the "Try again" button.<br />
247
        </td>
248
       </tr>
249
       <tr>
250
        <td colspan="2" align="center"><br />
251
                <input type="submit" value="Try again !"><br /><br />
252
        </td>
253
                </form>
254
       </tr>
255
      </table>
256
<?php
257
}
258
 
259
function html_input_config($error_msg = '')
260
{
261
    global $HTTP_POST_VARS, $im_installed;
262
 
263
    ?>
264
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
265
       <tr>
266
            <form action="install.php" method="post">
267
        <td class="tableh1" colspan="2"><h2>Welcome to Coppermine installation</h2>
268
        </td>
269
       </tr>
270
<?php
271
    if ($error_msg) {
272
 
273
        ?>
274
       <tr>
275
        <td class="tableh2" colspan="2" align="center"><span class="error">&#149;&nbsp;&#149;&nbsp;&#149;&nbsp;ERROR&nbsp;&#149;&nbsp;&#149;&nbsp;&#149;</span>
276
        </td>
277
       </tr>
278
       <tr>
279
        <td class="tableb" colspan="2"> The following errors were encountered and need to be corrected first:<br /><br /><b><?php echo $error_msg ?></b>
280
        </td>
281
       </tr>
282
<?php
283
    }
284
 
285
    ?>
286
       <tr>
287
        <td class="tableh2" colspan="2"><b>Your admin account</b>
288
        </td>
289
       </tr>
290
       <tr>
291
        <td class="tableb" colspan="2"> This section requires information to create your administration account. Use only alphanumeric characters. Enter the data carefully !
292
        </td>
293
       </tr>
294
       <tr>
295
        <td width="40%" class="tableb"><b>Username</b>
296
        </td>
297
        <td width="60%" class="tableb">
298
                <input type='text' class='textinput' name='admin_username' value='<?php echo $HTTP_POST_VARS['admin_username'] ?>'>
299
        </td>
300
       </tr>
301
       <tr>
302
        <td width="40%" class="tableb"><b>Password</b>
303
        </td>
304
        <td width="60%" class="tableb">
305
                <input type='text' class='textinput' name='admin_password' value='<?php echo $HTTP_POST_VARS['admin_password'] ?>'>
306
        </td>
307
       </tr>
308
       <tr>
309
        <td class="tableh2" colspan="2"><b>Your MySQL configuration</b>
310
        </td>
311
       </tr>
312
       <tr>
313
        <td class="tableb" colspan="2"> This section requires information on how to access your MySQL database. If you don't know how to fill them, check with your webhost support.
314
        </td>
315
       </tr>
316
       <tr>
317
        <td width="40%" class="tableb"><b>MySQL Host</b><br />(localhost is usually OK)
318
        </td>
319
        <td width="60%" class="tableb" valign="top">
320
                <input type='text' class='textinput' name='dbserver' value='<?php echo ($HTTP_POST_VARS['dbserver'] ? $HTTP_POST_VARS['dbserver'] : 'localhost') ?>'>
321
        </td>
322
       </tr>
323
       <tr>
324
        <td width="40%" class="tableb"><b>MySQL Database Name</b>
325
        </td>
326
        <td width="60%" class="tableb">
327
                <input type='text' class='textinput' name='dbname' value='<?php echo $HTTP_POST_VARS['dbname'] ?>'>
328
        </td>
329
       </tr>
330
       <tr>
331
        <td width="40%" class="tableb"><b>MySQL Username</b>
332
        </td>
333
        <td width="60%" class="tableb">
334
                <input type='text' class='textinput' name='dbuser' value='<?php echo $HTTP_POST_VARS['dbuser'] ?>'>
335
        </td>
336
       </tr>
337
       <tr>
338
        <td width="40%" class="tableb"><b>MySQL Password</b>
339
        </td>
340
        <td width="60%" class="tableb">
341
                <input type='text' class='textinput' name='dbpass' value='<?php echo $HTTP_POST_VARS['dbpass'] ?>'>
342
        </td>
343
       </tr>
344
       <tr>
345
        <td width="40%" class="tableb"><b>MySQL table prefix</b><br />(default value is OK; do not use dots!)
346
        </td>
347
        <td width="60%" class="tableb" valign="top">
348
                <input type='text' class='textinput' name='table_prefix' value='<?php echo ($HTTP_POST_VARS['table_prefix'] ? $HTTP_POST_VARS['table_prefix'] : 'cpg133_') ?>'>
349
        </td>
350
       </tr>
351
       <tr>
352
        <td class="tableh2" colspan="2"><b>ImageMagick</b>
353
        </td>
354
       </tr>
355
       <tr>
356
        <td class="tableb" colspan="2">Coppermine can use the <a href="http://www.imagemagick.org/" target="_blank">ImageMagick</a> 'convert' program to create thumbnails. Quality of images produced by ImageMagick is superior to GD1 but equivalent to GD2.<br /><br />
357
        If ImageMagick is installed on your system and you want to use it, you need to input the full path to the 'convert' program below. On Windows the path should look like 'c:/ImageMagick/' (use / not \ in the path) and should not contain any space, on Unix is it something like '/usr/bin/X11/'.
358
        </td>
359
       </tr>
360
       <tr>
361
        <td width="40%" class="tableb"><b>ImageMagick path</b>
362
        </td>
363
        <td width="60%" class="tableb" valign="top">
364
                <input type='text' class='textinput' name='impath' value='<?php echo $HTTP_POST_VARS['impath'] ?>'>
365
        </td>
366
       </tr>
367
       <tr>
368
        <td colspan="2" align="center" class="tableh2"><br />
369
         <input type="submit" value="Let's Go !"><br /><br />
370
        </td>
371
                </form>
372
       </tr>
373
      </table>
374
   <img src="install.php?test_gd1=1&reload=<?php echo uniqid('') ?>" alt="" width="1" height="1" border="0">
375
   <img src="install.php?test_gd2=1&reload=<?php echo uniqid('') ?>" alt="" width="1" height="1" border="0">
376
<?php
377
}
378
 
379
function html_install_success($notes)
380
{
381
    global $DFLT, $HTTP_POST_VARS;
382
 
383
    ?>
384
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="maintable">
385
       <tr>
386
            <form action="login.php" method="post">
387
        <td class="tableh1" colspan="2"><h2>Installation completed</h2>
388
        </td>
389
       </tr>
390
       <tr>
391
        <td class="tableb" colspan="2"> <a href="index.php">Coppermine</a> is now properly configured and ready to roll.<br /><br /><a href="login.php?">Login</a> using the information you provided for your admin account. Do <b>not</b> hit back, do <b>not</b> re-submit the installer form!<?php echo $notes ?>
392
        </td>
393
       </tr>
394
       <tr>
395
        <td colspan="2" align="center" class="tableh2"><br />
396
                 <input type="hidden" name="username" value="<?php echo $HTTP_POST_VARS['admin_username'] ?>"
397
                 <input type="hidden" name="password" value="<?php echo $HTTP_POST_VARS['admin_password'] ?>"
398
                <input type="submit" name="submitted" value="Let's continue !"><br /><br />
399
        </td>
400
                </form>
401
       </tr>
402
      </table>
403
<?php
404
}
405
 
406
function html_footer()
407
{
408
 
409
    ?>
410
  </div>
411
 </div>
412
</body>
413
</html>
414
<noscript><plaintext>
415
<?php
416
}
417
// ------------------------- SQL QUERIES TO CREATE TABLES ------------------ //
418
function create_tables()
419
{
420
    global $HTTP_POST_VARS, $HTTP_SERVER_VARS, $errors;
421
 
422
    $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
423
    $gallery_dir = strtr(dirname($PHP_SELF), '\\', '/');
424
    $gallery_url_prefix = 'http://' . $HTTP_SERVER_VARS['HTTP_HOST'] . $gallery_dir . (substr($gallery_dir, -1) == '/' ? '' : '/');
425
 
426
    $db_schema = 'sql/schema.sql';
427
    $sql_query = fread(fopen($db_schema, 'r'), filesize($db_schema));
428
 
429
    $db_basic = 'sql/basic.sql';
430
    $sql_query .= fread(fopen($db_basic, 'r'), filesize($db_basic));
431
    // Insert the admin account
432
    $sql_query .= "INSERT INTO CPG_users VALUES (1, 1, 'YES', '" . $HTTP_POST_VARS['admin_username'] . "', '" . $HTTP_POST_VARS['admin_password'] . "', NOW(), NOW(), '', '', '', '', '', '', '');\n";
433
    // Set configuration values for image package
434
    $sql_query .= "REPLACE INTO CPG_config VALUES ('thumb_method', '" . $HTTP_POST_VARS['thumb_method'] . "');\n";
435
    $sql_query .= "REPLACE INTO CPG_config VALUES ('impath', '" . $HTTP_POST_VARS['impath'] . "');\n";
436
    $sql_query .= "REPLACE INTO CPG_config VALUES ('ecards_more_pic_target', '" . $gallery_url_prefix . "');\n";
437
    // Test write permissions for main dir
438
    if (!is_writable('.')) {
439
        $sql_query .= "REPLACE INTO CPG_config VALUES ('default_dir_mode', '0777');\n";
440
        $sql_query .= "REPLACE INTO CPG_config VALUES ('default_file_mode', '0666');\n";
441
    }
442
    // Update table prefix
443
    $sql_query = preg_replace('/CPG_/', $HTTP_POST_VARS['table_prefix'], $sql_query);
444
 
445
    $sql_query = remove_remarks($sql_query);
446
    $sql_query = split_sql_file($sql_query, ';');
447
 
448
    foreach($sql_query as $q) {
449
        if (!mysql_query($q)) {
450
            $errors .= "mySQL Error: " . mysql_error() . "on query '$q'<br /><br />";
451
            return;
452
        }
453
    }
454
}
455
// ---------------------- CONFIGURATION FILE TEMPLATE ---------------------- //
456
function build_cfg_file()
457
{
458
    global $DFLT, $HTTP_POST_VARS;
459
 
460
    $silly_safe_mode = test_silly_safe_mode() ? "// Silly safe mode\ndefine('SILLY_SAFE_MODE', 1);\n\n" : '';
461
 
462
    return <<<EOT
463
<?php
464
// Coppermine configuration file
465
$silly_safe_mode
466
// MySQL configuration
467
\$CONFIG['dbserver'] =                         '{$HTTP_POST_VARS['dbserver']}';        // Your database server
468
\$CONFIG['dbuser'] =                         '{$HTTP_POST_VARS['dbuser']}';        // Your mysql username
469
\$CONFIG['dbpass'] =                         '{$HTTP_POST_VARS['dbpass']}';                // Your mysql password
470
\$CONFIG['dbname'] =                         '{$HTTP_POST_VARS['dbname']}';        // Your mysql database name
471
 
472
 
473
// MySQL TABLE NAMES PREFIX
474
\$CONFIG['TABLE_PREFIX'] =                '{$HTTP_POST_VARS['table_prefix']}';
475
?>
476
EOT;
477
}
478
 
479
function write_config_file()
480
{
481
    global $errors, $DFLT;
482
 
483
    test_im();
484
    detect_img_package();
485
 
486
    $config = build_cfg_file();
487
    @unlink($DFLT['cfg_f']);
488
    if ($fd = @fopen($DFLT['cfg_f'], 'wb')) {
489
        fwrite($fd, $config);
490
        fclose($fd);
491
    } else {
492
        $errors .= "<hr /><br />Unable to write config file '{$DFLT['cfg_f']}'<br /><br />";
493
    }
494
}
495
 
496
function lock_install()
497
{
498
    global $notes, $DFLT;
499
 
500
    if ($fd = @fopen($DFLT['lck_f'], 'wb')) {
501
        fwrite($fd, 'locked');
502
        fclose($fd);
503
    } else {
504
        $notes .= "<br /><br /><b>Warning :</b> the installer could not create the '{$DFLT['lck_f']}' file. In order to secure your installation, you need to delete the 'install.php' file from your server !<br /><br />";
505
    }
506
}
507
// --------------------------------- MAIN CODE ----------------------------- //
508
// Disable magic_quotes_runtime if active to allow proper reading from .sql files.
509
set_magic_quotes_runtime(0);
510
// The defaults values
511
$table_prefix = $HTTP_POST_VARS['table_prefix'];
512
$DFLT = array('cfg_d' => 'include', // The config file dir
513
    'lck_f' => 'include/install.lock', // Name of install lock file
514
    'cfg_f' => 'include/config.inc.php', // The config file name
515
    'alb_d' => 'albums', // The album dir
516
    'upl_d' => 'userpics', // The uploaded pic dir
517
    'edit_d' => 'edit',
518
    'sql_d' => 'sql'
519
    );
520
 
521
$errors = '';
522
$notes = '';
523
 
524
if ($HTTP_GET_VARS['test_gd1']) { // GD1 test
525
    $im = imagecreate(1, 1);
526
    imagecolorallocate ($im, 255, 255, 255);
527
    imagejpeg($im, "{$DFLT['alb_d']}/{$DFLT['upl_d']}/gd1.jpg");
528
    header("Content-type: image/gif");
529
    fpassthru(fopen('images/spacer.gif'));
530
} elseif ($HTTP_GET_VARS['test_gd2']) { // GD2 test
531
    $im = imagecreatetruecolor(1, 1);
532
    imagejpeg($im, "{$DFLT['alb_d']}/{$DFLT['upl_d']}/gd2.jpg");
533
    header("Content-type: image/gif");
534
    fpassthru(fopen('images/spacer.gif'));
535
} elseif ($HTTP_GET_VARS['phpinfo'] && !file_exists($DFLT['lck_f'])) {
536
    phpinfo();
537
} else { // The installer
538
    html_header();
539
    html_logo();
540
    if (file_exists($DFLT['lck_f'])) {
541
        html_installer_locked();
542
    } elseif (count($HTTP_POST_VARS)) {
543
        test_sql_connection();
544
        test_admin_login();
545
        write_config_file();
546
        if ($errors == '') create_tables();
547
        if ($errors != '')
548
            html_input_config($errors);
549
        else {
550
            lock_install();
551
            html_install_success($notes);
552
        }
553
    } else {
554
        test_fs();
555
        if ($errors != '')
556
            html_prereq_errors($errors);
557
        else {
558
            html_input_config();
559
        }
560
    }
561
    html_footer();
562
}
563
 
564
?>