]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - configurator.php
New php utility to aid in the configuration of index.php by using an html form to...
[SourceForge/phpwiki.git] / configurator.php
1 <?php printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n", 'iso-8859-1'); ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
5 <head>
6 <!-- $Id: configurator.php,v 1.1 2002-02-22 07:12:09 carstenklapp Exp $ -->
7 <head>
8 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
9 </head>
10 <body>
11
12 <h1>Configuration tool for PhpWiki 1.3.x</h1>
13
14 <p>This tool is provided for testing purposes only. It's not finished so don't try to use it to configure your server yet.</p>
15
16 <?php
17 /**
18  * The Configurator is a php script to aid in the configuration of PhpWiki.
19  * Parts of this file are based on PHPWeather's configurator.php file.
20  * http://sourceforge.net/projects/phpweather/
21  *
22  * TO CHANGE THE CONFIGURATION OF YOUR PHPWIKI, DO *NOT* MODIFY THIS FILE!
23  * more instructions go here
24  * 
25  * An index.php will be generated for you which you can also modify later if you wish.
26  */
27
28
29 //////////////////////////////
30 // begin configuration options
31
32
33
34 $copyright = '
35 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam = array(
36 "Steve Wainstead", "Clifford A. Adams", "Lawrence Akka", 
37 "Scott R. Anderson", "Jon Åslund", "Neil Brown", "Jeff Dairiki",
38 "Stéphane Gourichon", "Jan Hidders", "Arno Hollosi", "John Jorgensen",
39 "Antti Kaihola", "Jeremie Kass", "Carsten Klapp", "Marco Milanesi",
40 "Grant Morgan", "Jan Nieuwenhuizen", "Aredridel Niothke", 
41 "Pablo Roca Rozas", "Sandino Araico Sánchez", "Joel Uckelman", 
42 "Reini Urban", "Tim Voght");
43
44 This file is part of PhpWiki.
45
46 PhpWiki is free software; you can redistribute it and/or modify
47 it under the terms of the GNU General Public License as published by
48 the Free Software Foundation; either version 2 of the License, or
49 (at your option) any later version.
50
51 PhpWiki is distributed in the hope that it will be useful,
52 but WITHOUT ANY WARRANTY; without even the implied warranty of
53 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
54 GNU General Public License for more details.
55
56 You should have received a copy of the GNU General Public License
57 along with PhpWiki; if not, write to the Free Software
58 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
59 ';
60
61
62
63 $preamble = '
64   This is the starting file for PhpWiki. All this file does is set
65   configuration options, and at the end of the file it includes() the
66   file lib/main.php, where the real action begins.
67
68   This file is divided into six parts: Parts Zero, One, Two, Three,
69   Four and Five. Each one has different configuration settings you can
70   change; in all cases the default should work on your system,
71   however, we recommend you tailor things to your particular setting.
72 ';
73
74
75
76 $properties['part0'] =
77 new part('Part Zero', false, '
78 Part Zero: If PHP needs help in finding where you installed the
79 rest of the PhpWiki code, you can set the include_path here.');
80
81
82
83 $properties['PHP include_path'] =
84 new iniset('include_path', false, "
85 NOTE: phpwiki uses the PEAR library of php code for SQL database
86 access. Your PHP is probably already configured to set
87 include_path so that PHP can find the pear code. If not (or if you
88 change include_path here) make sure you include the path to the
89 PEAR code in include_path. (To find the PEAR code on your system,
90 search for a file named 'PEAR.php'. Some common locations are:
91 <pre>
92   Unixish systems:
93     /usr/share/php
94     /usr/local/share/php
95   Mac OS X:
96     /System/Library/PHP
97 </pre>
98 The above examples are already included by PhpWiki. You shouldn't
99 have to change this unless you see a WikiFatalError:
100 <pre>
101     lib/FileFinder.php:82: Fatal[256]: DB.php: file not found
102 </pre>
103 Define the include path for this wiki: pear plus the phpwiki path
104 <pre>
105 $include_path = '.:/Apache/php/pear:/prog/php/phpwiki';
106 </pre>
107 Windows needs ';' as path delimiter. cygwin, mac and unix ':'
108 <pre>
109 if (substr(PHP_OS,0,3) == 'WIN') {
110     $include_path = implode(';',explode(':',$include_path));
111 } elseif (substr(PHP_OS,0,6) == 'CYGWIN') {
112     $include_path = '.:/usr/local/lib/php/pear:/usr/src/php/phpwiki';
113 } else {
114     ;
115 }</pre>");
116
117
118
119 $properties['partnull'] =
120 new part('Part Null', "
121 define ('PHPWIKI_VERSION', '1.3.2-jeffs-hacks');
122 require \"lib/prepend.php\";
123 rcs_id('$Id: configurator.php,v 1.1 2002-02-22 07:12:09 carstenklapp Exp $');
124 ", "
125 Part Null: Don't touch this!");
126
127
128 $properties['partone'] =
129 new part('Part One', "///////////////////////////////////////////////////////////////////
130 ", "
131
132 Part One:
133 Authentication and security settings:
134 ");
135
136
137
138 $properties['Wiki Name'] =
139 new defines('WIKI_NAME', ''/*'PhpWiki'*/, "
140 The name of your wiki.
141 This is used to generate a keywords meta tag in the HTML templates,
142 in bookmark titles for any bookmarks made to pages in your wiki,
143 and during RSS generation for the title of the RSS channel.");
144
145
146
147 $properties['Reverse DNS'] =
148 new defines_boolean('ENABLE_REVERSE_DNS',
149                     array('true'  => 'perform additional reverse dns lookups',
150                           'false' => 'just record the address as given by the httpd server'), "
151 If set, we will perform reverse dns lookups to try to convert the
152 users IP number to a host name, even if the http server didn't do
153 it for us.");
154
155
156
157 $properties['Admin Username'] =
158 new defines('ADMIN_USER', "", "
159 Username and password of administrator.
160 Set these to your preferences. For heaven's sake
161 pick a good password!");
162 $properties['Admin Password'] =
163 new defines('ADMIN_PASSWD', "", "");
164
165
166
167 $properties['ZIPdump Authentication'] =
168 new defines_boolean('ZIPDUMP_AUTH', 
169                     array('false' => 'everyone',
170                           'true'  => 'only admin'), "
171 If true, only the admin user can make zip dumps, else zip dumps
172 require no authentication.");
173
174
175
176 $properties['Strict Mailable Pagedumps'] =
177 new defines_boolean('STRICT_MAILABLE_PAGEDUMPS', 
178                     array('false' => 'binary',
179                           'true'  => 'quoted-printable'), "
180 If you define this to true, (MIME-type) page-dumps (either zip dumps,
181 or \"dumps to directory\" will be encoded using the quoted-printable
182 encoding.  If you're actually thinking of mailing the raw page dumps,
183 then this might be useful, since (among other things,) it ensures
184 that all lines in the message body are under 80 characters in length.
185
186 Also, setting this will cause a few additional mail headers
187 to be generated, so that the resulting dumps are valid
188 RFC 2822 e-mail messages.
189
190 Probably, you can just leave this set to false, in which case you get
191 raw ('binary' content-encoding) page dumps.");
192
193
194
195 $properties['Maximum Upload Size'] =
196 new defines_numeric('MAX_UPLOAD_SIZE', "16 * 1024 * 1024", "
197 The maximum file upload size.");
198
199
200
201 $properties['Minor Edit Timeout'] =
202 new defines_numeric('MINOR_EDIT_TIMEOUT', "7 * 24 * 3600", "
203 If the last edit is older than MINOR_EDIT_TIMEOUT seconds, the
204 default state for the \"minor edit\" checkbox on the edit page form
205 will be off.");
206
207
208
209
210
211
212
213
214
215
216 // MORE CONFIG OPTIONS GO IN HERE
217
218
219
220 $properties['Character Set'] =
221 new defines('CHARSET', 'iso-8859-1', "
222 Select a valid charset name to be inserted into the xml/html pages, 
223 and to reference links to the stylesheets (css). For more info see: 
224 http://www.iana.org/assignments/character-sets. Note that PhpWiki 
225 has been extensively tested only with the latin1 (iso-8859-1) 
226 character set.
227
228 If you change the default from iso-8859-1 PhpWiki may not work 
229 properly and it will require code modifications. However, character 
230 sets similar to iso-8859-1 may work with little or no modification 
231 depending on your setup. The database must also support the same 
232 charset, and of course the same is true for the web browser. (Some 
233 work is in progress hopefully to allow more flexibility in this 
234 area in the future).");
235
236
237
238 $properties['Language'] =
239 new selection('LANG',
240               array('C'  => 'English',
241                     'nl' => 'Nederlands',
242                     'es' => 'Español',
243                     'fr' => 'Français',
244                     'de' => 'Deutsch',
245                     'sv' => 'Svenska',
246                     'it' => 'Italiano'), "
247 Select your language/locale - default language is \"C\" for English.
248 Other languages available:<pre>
249 English \"C\"  (English    - HomePage)
250 Dutch   \"nl\" (Nederlands - ThuisPagina)
251 Spanish \"es\" (Español    - PáginaPrincipal)
252 French  \"fr\" (Français   - Accueil)
253 German  \"de\" (Deutsch    - StartSeite)
254 Swedish \"sv\" (Svenska    - Framsida)
255 Italian \"it\" (Italiano   - PaginaPrincipale)
256 </pre>
257 If you set \$LANG to the empty string, your systems default language
258 (as determined by the applicable environment variables) will be
259 used.
260
261 Note that on some systems, apprently using these short forms for
262 the locale won't work. On my home system 'LANG=de' won't result in
263 german pages. Somehow the system must recognize the locale as a
264 valid locale before gettext() will work, i.e., use 'de_DE', 'nl_NL'.");
265
266
267
268 // MORE CONFIG OPTIONS GO IN HERE
269
270
271
272 // end of configuration options
273 ///////////////////////////////
274 // begin class definitions
275
276 /**
277  * A basic property.
278  *
279  * Produces a string in the form "$name = value;"
280  * e.g.:
281  * $InlineImages = "png|jpg|gif";
282  */
283 class property {
284
285     var $config_item_name;
286     var $default_value;
287     var $description;
288
289     function property($config_item_name, $default_value, $description) {
290         $this->config_item_name = $config_item_name;
291         $this->description = $description;
292         $this->default_value = $default_value;
293     }
294
295     function get_config_item_name() {
296         return $this->config_item_name;
297     }
298
299     function get_description() {
300         return $this->description;
301     }
302
303     function get_config_line($posted_value) {
304         return "\n\$" . $this->get_config_item_name() . " = \"" . $posted_value . "\";";
305     }
306     function get_config($posted_value) {
307         $d = str_replace("<pre>", "", $this->get_description());
308         $d = str_replace("</pre>", "", $d);
309         $d = str_replace("\n", "\n// ", $d) . $this->get_config_line($posted_value) ."\n";
310         return $d;
311     }
312
313     function get_instructions($title) {
314         $i = "<p><b><h3>" . $title . "</h3></b></p>\n    <p>" . str_replace("\n\n", "</p><p>", $this->get_description()) . "</p>\n";
315         return "<tr>\n<td>\n" . $i . "</td>\n";
316     }
317
318     function get_html() {
319         return "<input type=\"text\" name=\"" . $this->get_config_item_name() . "\" value=\"" . $this->default_value . "\">";
320     }
321 }
322
323 class selection extends property {
324     function get_html() {
325         $output = '<select name="' . $this->get_config_item_name() . "\">\n";
326         /* The first option is the default */
327         while(list($option, $label) = each($this->default_value)) {
328             $output .= "  <option value=\"$option\">$label</option>\n";
329         }
330         $output .= "    </select>\n  </td>\n";
331         return $output;
332     }
333 }
334
335
336 class defines extends property {
337     function get_config_line($posted_value) {
338         if ($this->description)
339             $n = "\n";
340         if ($posted_value == '')
341             return "${n}//define('".$this->get_config_item_name()."', \"\");";
342         else
343             return "${n}define('".$this->get_config_item_name()."', '$posted_value');";
344     }
345 }
346
347 class defines_numeric extends property {
348     function get_config_line($posted_value) {
349         if ($this->description)
350             $n = "\n";
351         if ($posted_value == '')
352             return "${n}//define('".$this->get_config_item_name()."', 0);";
353         else
354             return "${n}define('".$this->get_config_item_name()."', $posted_value);";
355     }
356 }
357
358 class iniset extends property {
359     function get_config_line($posted_value) {
360         if ($posted_value)
361             return "\nini_set('".$this->get_config_item_name()."', '$posted_value');";
362         else
363             return "\n//ini_set('".$this->get_config_item_name()."', '\$".$this->get_config_item_name()."');";
364     }
365 }
366
367 class defines_boolean extends property {
368     function get_config_line($posted_value) {
369         if ($this->description)
370             $n = "\n";
371         return "${n}define('".$this->get_config_item_name()."', $posted_value);";
372     }
373     function get_html() {
374         $output = '<select name="' . $this->get_config_item_name() . "\">\n";
375         /* The first option is the default */
376         list($option, $label) = each($this->default_value);
377         $output .= "  <option value=\"$option\" selected>$label</option>\n";
378         /* There can only be two options */
379         list($option, $label) = each($this->default_value);
380         $output .= "  <option value=\"$option\">$label</option>\n";
381         $output .= "</select>\n  </td>\n";
382         return $output;
383     }
384 }
385
386 class part extends property {
387     function get_config($posted_value) {
388         $separator = "\n/////////////////////////////////////////////////////////////////////";
389         return $separator . str_replace("\n", "\n// ", $this->get_description()) ."\n$this->default_value";
390     }
391     function get_instructions($title) {
392         $i = "<h2>".$this->get_config_item_name()."</h2>\n$this->description\n";
393         return "<tr>\n<td colspan=\"2\" bgcolor=\"#eee\">\n" .$i ."</td></tr>\n";
394     }
395     function get_html() {
396         return "";
397     }
398 }
399
400 // end of class definitions
401 /////////////////////////////
402 // begin auto generation code
403
404 if ($action == 'make_config') {
405
406   $timestamp = date ('dS of F, Y H:i:s');
407
408     $config = "<?php
409 /* This is a local configuration file for PhpWiki.
410  * It was automatically generated by the configurator script
411  * on the $timestamp.
412  */
413
414 /*$copyright*/
415
416 /////////////////////////////////////////////////////////////////////
417 /*$preamble*/
418 ";
419
420     $posted = $GLOBALS['HTTP_POST_VARS'];
421
422     echo "<hr /><pre>\n";
423     print_r($GLOBALS['HTTP_POST_VARS']);
424     echo "</pre><hr />\n";
425
426     /*
427
428     */
429
430     foreach($properties as $option_name => $a) {
431         $posted_value = $posted[$a->config_item_name];
432         $config .= $properties[$option_name]->get_config($posted_value);
433     }
434
435     $diemsg = "The configurator.php is provided for testing purposes only.\nYou can't use this file with your PhpWiki server yet!!";
436     $config .= "\ndie(\"$diemsg\");";
437     $config .= "\n?>\n";
438
439     /* We first check if the config-file exists. */
440     if (file_exists('defaults.php')) {
441         /* We make a backup copy of the file */
442         $new_filename = 'defaults.' . time() . '.php';
443         if (@copy('defaults.php', $new_filename)) {
444             $fp = @fopen('defaults.php', 'w');
445         }
446     } else {
447         $fp = @fopen('defaults.php', 'w');
448     }
449
450     if ($fp) {
451         fputs($fp, $config);
452         fclose($fp);
453         echo "<p>The configuration was written to <code><b>defaults.php</b></code>. A backup was made to <code><b>$new_filename</b></code>.</p>\n";
454     } else {
455         echo "<p>A configuration file could <b>not</b> be written. You should copy the above configuration to a file, and manually save it as <code><b>defaults.php</b></code>.</p>\n";
456     }
457
458     echo "<hr />\n<p>Here's the configuration file based on your answers:</p>\n<pre>\n";
459     echo htmlentities($config);
460     echo "</pre>\n<hr />\n";
461
462     echo "<!--If she can stand it, I can. Play it!-->\n";
463     echo "<p>Would you like to <a href=\"configurator.php\">play again</a>?</p>\n";
464
465     } else {
466         /* No action has been specified - we make a form. */
467
468         echo '
469         <form action="configurator.php" method="post">
470         <table border="1" cellpadding="4" cellspacing="0">
471         <input type="hidden" name="action" value="make_config">
472         ';
473
474         while(list($property, $obj) = each($properties)) {
475             echo $obj->get_instructions($property);
476             if ($h = $obj->get_html())
477                 echo "<td>".$h."</td>\n";
478         }
479
480         echo '
481             </table>
482             <p><input type="submit" value="Make config-file"> <input type="reset" value="Clear"></p>
483             </form>
484             ';
485
486     }
487 ?>
488 </body>
489 </html>