summaryrefslogtreecommitdiff
path: root/install.php
blob: d13f967107d8568d156164c692003d9aea26f3da (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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?php
/**
 *  Dokuwiki installation assistance
 *
 *  @author      Chris Smith <chris@jalakai.co.uk>
 */

if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__)).'/');
if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
if(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/');

if(!defined('DEBUG')) define('DEBUG', false);

// ------------------------------------------------------------------------------------
// important settings ...
// installation dependent local config file list
$config_files = array(
  'local' => DOKU_LOCAL.'local.php',
  'users' => DOKU_LOCAL.'users.auth.php',
  'auth'  => DOKU_LOCAL.'acl.auth.php'
);

// other installation dir/file permission requirements
$install_permissions = array(
  'data'      => 'data',
  'pages'     => 'data/pages',
  'attic'     => 'data/attic',
  'media'     => 'data/media',
  'meta'      => 'data/meta',
  'cache'     => 'data/cache',
  'locks'     => 'data/locks',
  'changelog' => 'data/changes.log'
);

// array use to verify unchanged dokuwiki.php files, 'version' => 'md5 hash'
$dokuwiki_php = DOKU_CONF.'dokuwiki.php';
$dokuwiki_hash = array(
  '2005-09-22' => 'e33223e957b0b0a130d0520db08f8fb7',
  '2006-03-05' => '51295727f79ab9af309a2fd9e0b61acc',
  '2006-03-09' => '51295727f79ab9af309a2fd9e0b61acc',
);

// language strings

// ------------------------------------------------------------------------------------
// initialise variables ...

$msg = array();
$error = array();
$debug = array();
$process_form = false;

// form variables with default values
$title       = "";
$location    = true;
$data        = "./data";
$changeslog  = true;
$acl         = true;
$superuser   = "";
$fullname    = "";
$email       = "";

// check for dokuwiki 
// (for now assume included with Dokuwiki install & resident in dokuwiki root folder)

// ------------------------------------------------------------------------------------
// check for virgin dokuwiki installation 
$virgin_install = true;

  // $config_files mustn't exist
  foreach ($config_files as $file) {
    if (@file_exists($file)) {
      $virgin_install = false;
      $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $file);
      $msg[] = "<span class=\"file\">$file</span> exists"; }
  }

  // main dokuwiki config file (conf/dokuwiki.php) must not have been modified
  $installation_hash = md5(@file_get_contents($dokuwiki_php));
  if (!in_array($installation_hash, $dokuwiki_hash)) {
    $virgin_install = false;
    $msg[] = "unrecognised or modified dokuwiki.php -- hash=$installation_hash";
  }
// ------------------------------------------------------------------------------------
// check for other basic installation & configuration details (to be nice)

$changeslog_exists = @file_exists(DOKU_INC.'data/changes.log');

if (!is_writable(DOKU_CONF)) {
  $file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', DOKU_CONF);
  $error[] = "<span class=\"file\">$file</span> must be writable by the web server.";
}

//-------------------------------------------------------------------------------------
// utility functions

/**
 * remove magic quotes recursivly
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function remove_magic_quotes(&$array) {
  foreach (array_keys($array) as $key) {
    if (is_array($array[$key])) {
      remove_magic_quotes($array[$key]);
    }else {
      $array[$key] = stripslashes($array[$key]);
    }
  }
}

function cleanText($var, $default, $regex, $msg) {
  global $error;

  $value = isset($_REQUEST[$var]) ? $_REQUEST[$var] : $default;

  if ($regex) {
    if (!preg_match($regex, $value)) {
      $error[] = "$var - illegal/unrecognised value";
    }
  }
  return $value;
}

function fileWrite($name, $filename, $data) {
  global $error;

  if (($fp = @fopen($filename, 'wb')) === false) {
    $filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $filename);
    $error[] = "Unable to create $name (<span class=\"file\">$filename</span>).  You will need to check directory/file permissions and create the file manually.";
    return false;
  }

  if (!empty($data)) { fwrite($fp, $data);  }
  fclose($fp);
  return true;
}

// ------------------------------------------------------------------------------------
// form processing ...
if (isset($_REQUEST['submit'])) {
  if (!$virgin_install) {
    $msg[] = "unable to apply updates, installation already modified";

  } else {
    // apply updates per form instructions
    $process_form = true;

    if (get_magic_quotes_gpc()) {
      if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST);
    }

    $title = cleanText('title', '', '');
    $location = isset($_REQUEST['location']);
    $data = cleanText('data', '', '');
    $changeslog = isset($_REQUEST['changeslog']);
    $acl = isset($_REQUEST['acl']);
    $superuser = cleanText('superuser','','/\S+/');
    $password = cleanText('password','','/\S+/');
    $confirm = cleanText('confirm','','/^'.preg_quote($password,'/').'$/');
    $fullname = cleanText('fullname','','');
    $email = cleanText('email','','');

    $debug = compact('title','location','data','changeslog','acl','superuser','password','confirm');

    if (empty($error)) {
      // all incoming data is ok ... lets do ...
      // create changes.log
      if (!$changeslog_exists) {
        $filename = realpath((empty($data) || ($data{0} != "/")) ? DOKU_INC.$data : $data).'/changes.log';
        fileWrite('changeslog',$filename, '');
      }

      // create local.php
      $output = "";
      if (!empty($title)) $output .= '$conf[\'title\'] = \''.addslashes($title)."';\n";
      if (!empty($data)) $output .= '$conf[\'data\'] = \''.$data."';\n";
      if ($acl) $output .= '$conf[\'useacl\'] = 1'.";\n";
      if (!empty($superuser)) $output .= '$conf[\'superuser\'] = \''.$superuser."';\n";

      if (!empty($output)) {
        $output = '<'.'?php
/*
 * Dokuwiki\'s Main Configuration File - Local Settings 
 * Auto-generated by install script 
 * Date: '.date('r').'
 */'."\n".$output;
           fileWrite('local configuration settings file',DOKU_LOCAL.'local.php',$output);
       }

      if ($acl) {
        // create users.auth.php
        // --- user:MD5password:Real Name:email:groups,comma,seperated
        $output = (!empty($superuser)) ? join(":",array($superuser, md5($password), $fullname, $email, 'users')) : "";
        $output = @file_get_contents(DOKU_CONF.'users.auth.php.dist')."\n$output\n";

        fileWrite('acl user file', DOKU_LOCAL.'users.auth.php', $output);

        // create acl.auth.php
        $output = @file_get_contents(DOKU_CONF.'acl.auth.php.dist');
        fileWrite('acl authorisations file', DOKU_LOCAL.'acl.auth.php', $output);
      }
    }
  }
}
//-------------------------------------------------------------------------------------

$show_form = !$process_form && $virgin_install && empty($error);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<title>Dokuwiki Installer</title>
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/

html {margin: 0; padding: 0;}
body {
  width: 90%;
  margin: 0 auto;
  font: 84% Verdana, Helvetica, Arial, sans-serif;
}

a {
  white-space: nowrap;
}

img {
  border: none;
}

.abbr {
  border-bottom: 2px dotted #444;
}

.alert .file {
  color: #a03333;
}

.error .file {
  color: #c33;
}

h1 img {
  vertical-align: middle;
}

form, fieldset {
  margin: 1em 0;
  padding: 0;
  border: none;
  width: 100%;
}

ul {
  font-size: 80%;
}

form .field {
  margin: 0.5em 0;
}

label {
  display: block;
}

label span {
  display: block;
}

label input.text {
  width: 95%;
}

#instructions {
  float: right;
  width: 34%;
}

#details {
  float: left;
  width: 58%;
}

#process {
  margin: 1.5em 0;
}

#debug, #footer {
  clear: both;
}

#acl, #files {
  border: 1px solid #ccc;
  padding: 0.5em 0 1em 0;
}

fieldset.dependent {
  margin-left: 2em;
}


/*]]>*/-->
</style>
<script type="text/javascript">
<!--//--><![CDATA[//><!--


//--><!]]>
</script>
</head>
<body>
<h1><img src="http://wiki.splitbrain.org/_media/wiki:dokuwiki-64.png" alt="" />Dokuwiki Installer</h1>
<div id="instructions">
  <p>This page assists in the installation and configuration of <a href="http://wiki.splitbrain.org">Dokuwiki</a>.</p>
  <p>Dokuwiki uses ordinary files for the storage of wiki pages and other information associated with those pages 
  (e.g. images, search indexes, old revisions, etc).  In order to operate successfully Dokuwiki <strong>must</strong>
  have write access to the directories that hold those files.  This installer is not capable of setting up directory 
  permissions, that normally needs to be done directly or if you are using hosting, through your hosting 
  control panel (e.g. cPanel).</p>
  <p>This installer will setup your Dokuwiki configuration for <span class="abbr" title="access control list">ACL</span>, 
  which in turn allows administrator login and access to Dokuwiki's admin menu for installing plugins, managing 
  users, managing access to wiki pages and alteration of configuration settings.  It isn't required for Dokuwiki to 
  operate, however it will make Dokuwiki easier to administer.</p>
  <p>Use these links for details concerning <a href="http://wiki.splitbrain.org/wiki:installation">installation instructions</a>
  and <a href="http://wiki.splitbrain.org/wiki:configuration">configuration settings</a>.</p>
</div>
<div id="details">  
<?php if (!$virgin_install) { ?>
  <p>Modified installation detected.</p>
  <ul class="alert">
<?php   foreach ($msg as $text) { ?>
    <li><?php echo $text?></li>
<?php   } ?>
  </ul>
  <p>For security reasons this script will only work with a new &amp; unmodified Dokuwiki installation. 
  You should either re-extract the files from the downloaded package or consult the complete 
  <a href="http://wiki.splitbrain.org/wiki:install">Dokuwiki installation instructions</a></p>
<?php } /* end if (!virgin_install) */ ?>
<?php if (!$process_form && !empty($error)) { ?>
  <p>One or more incorrect directory/file permissions were found.</p>
  <ul class="error">
<?php   foreach ($error as $text) { ?>
    <li><?php echo $text ?></li>
<?php   } ?>
  </ul>
  <p>In order to complete this installation the above directories and files need to have their 
    permissions altered as indicated. Please correct the above problems before trying again.</p>
<?php } /* end if (!$process_form && !empty($error)) */ ?>
<?php if ($process_form) { ?>
<?php   if (empty($error)) { ?>
  <p>Configuration updated successfully.</p>
  <p>Now that your initial dokuwiki configuration has been set you should delete this file to prevent its further use
  which may damage your dokuwiki installation and/or configuration.</p>
  <p>Use this link to visit your new <a href="doku.php" title="my new dokuWiki">wiki</a></p>
<?php   } else { ?>
  <p>The following errors were encountered ... </p>
  <ul class="error">
<?php     foreach ($error as $text) { ?>
    <li><?php echo $text?></li>
<?php     } ?>
  </ul>
  <p>return to <a href="install.php">installation form</a></p>
<?php   } ?>
<?php } ?>
<?php if ($show_form) { ?>
  <form action="" method="post">
    <fieldset id="wiki">
      <div class="field"><label><span> Wiki Name </span><input class="text" type="text" name="title" value="<?php echo $title ?>" /></label></div>
      <fieldset id="acl">
      <div class="field"><label><input class="checkbox" type="checkbox" name="acl" <?php echo(($acl ? 'checked="checked"' : ''));?> /> Enable ACL </label></div>
        <fieldset class="dependent">
          <div class="field"><label><span> Superuser </span><input class="text" type="text" name="superuser" value="<?php echo $superuser ?>" /></label></div>
          <div class="field"><label><span> Full name </span><input class="text" type="text" name="fullname" value="<?php echo $fullname ?>" /></label></div>
          <div class="field"><label><span> Email Address </span><input class="text" type="text" name="email" value="<?php echo $email ?>" /></label></div>
          <div class="field"><label><span> Superuser password </span><input class="text" type="password" name="password" /></label></div>
          <div class="field"><label><span> Confirm password </span><input class="text" type="password" name="confirm" /></label></div>
        </fieldset>
      </fieldset>
      <fieldset id="files">
        <div class="field"><label><input class="checkbox" type="checkbox" name="location" <?php echo(($location ? 'checked="checked"' : ''));?> />Use default wiki location</label></div>
        <fieldset class="dependent">
          <div class="field"><label><span> Wiki Location </span><input class="text" type="text" name="data" value="<?php echo $data ?>" /></label></div>
        </fieldset>
      </fieldset>
<?php if (!$changeslog_exists) { ?>
      <div class="field"><label><input class="checkbox" type="checkbox" name="changeslog" <?php echo(($changeslog ? 'checked="checked"' : ''));?> />Create changes.log file</label></div>
<?php } ?>
    </fieldset>
    <fieldset id="process">
      <input class="button" type="submit" name="submit" value="Process Configuration Changes" />
    </fieldset>
  </form>
<?php } ?>
</div><!-- #details -->
<?php if (DEBUG) { ?>
<div id="debug">
  <pre>
  <?php print_r($_REQUEST); print_r($debug); print_r($error); ?>
  </pre>
</div>
<?php } ?>
<div id="footer">
  <a href="http://wiki.splitbrain.org"><img src="lib/tpl/default/images/button-dw.png" alt="powered by dokuwiki" /></a>
  <a href="http://www.php.net"><img src="lib/tpl/default/images/button-php.gif" alt="powered by php" /></a>
</div>
</body>
</html>