1 rizwank 1.1 # Support functionality for the TWiki Collaboration Platform, http://TWiki.org/
2 #
3 #
4 # Jul 2004 - written by Martin "GreenAsJade" Gregory, martin@gregories.net
5
6 package TWikiCfg;
7
8 use strict;
9
10 use vars '$twikiLibPath'; # read from setlib.cfg
11
12 use vars '@storeSettings'; # read from TWiki.cfg
13
14 # default Twiki.cfg contents, set in BEGIN block far below...
15 use vars qw($InitialBlurb @ConfigFileScalars @ConfigFileOSScalars @ConfigFileArrays @SubstituteBackVars);
16
17 use vars qw(@ActiveSubstitutions);
18
19 use Data::Dumper;
20 use File::Copy;
21
22 rizwank 1.1 =begin twiki
23
24 ---+ WriteNewTWikiCfg
25
26 Create a new TWiki.cfg with the default settings in it
27
28 =cut
29
30 sub WriteNewTWikiCfg
31 {
32 my $NewFileName = (shift or "./TWiki.cfg");
33
34 if (-f $NewFileName)
35 {
36 print "Are you sure you want to overwrite $NewFileName?\n";
37 my $response = <STDIN>;
38 if ($response !~ m/[yY]/)
39 {
40 die "WriteNewTWikiCfg passed unacceptable file name $NewFileName - can't proceed (sorry!)\n";
41 }
42 }
43 rizwank 1.1 open(NEW_CONFIG, ">$NewFileName") or die "Couldn't open $NewFileName for write: $!\n";
44
45 printToNewConfig("$InitialBlurb\n\n");
46 printToNewConfig("# This file created by WriteNewTWikiCfg, which provided default values\n\n");
47
48 my $configVal;
49
50 # @ConfigFileContents is an array of hashrefs, one per config variable
51 for $configVal (@ConfigFileScalars) # so $$configVal is a hash with a record about one config variable...
52 {
53 printToNewConfig($$configVal{'comment'} . "\n");
54
55 printToNewConfig("\$$$configVal{varname} = $$configVal{default} ;\n");
56 }
57
58 printToNewConfig("# Here follow OS dependent settings...\n");
59
60 for $configVal (@ConfigFileOSScalars) # $$configVal is a hash with a record about one config variable...
61 {
62 printToNewConfig($$configVal{'comment'} . "\n");
63
64 rizwank 1.1 printToNewConfig("\$$$configVal{varname} = $$configVal{default} ;\n");
65 }
66
67 for $configVal (@ConfigFileArrays) # $$configVal is a hash with a record about one config variable...
68 {
69 printToNewConfig($$configVal{'comment'} . "\n");
70
71 printToNewConfig("\@$$configVal{varname} = $$configVal{default} ;\n");
72 }
73
74 printToNewConfig("\n1;\n");
75 }
76
77 =pod
78 ---+ UpgradeTWikiConfig
79
80 Create an upgraded twiki installation configuration file from an existing one
81 and a new distribution.
82
83 Writes TWiki.cfg.new by default.
84
85 rizwank 1.1 Dialogs with the user on STDIN/STDOUT.
86
87 =cut
88
89 sub UpgradeTWikiConfig
90 {
91
92 my $existingConfigInfo = shift or die "UpgradeTWikiConfig not passed any arguments!\n";
93
94 my $targetDir = (shift or '.');
95
96 my $newConfigFile = "$targetDir/lib/TWiki.cfg";
97
98 my $twikiCfgFile;
99
100 if (-f "$existingConfigInfo/setlib.cfg")
101 {
102 my ($setlibPath) = $existingConfigInfo;
103
104 # Find out from there where TWiki.cfg is
105
106 rizwank 1.1 require "$setlibPath/setlib.cfg";
107
108 print "\nGreat - found it OK, and it tells me that the rest of the config is in $twikiLibPath,\n";
109 print "so that's where I'll be looking!\n\n";
110
111 print "First, making a new copy of setlib.cfg in your new installation...\n";
112 copy("$setlibPath/setlib.cfg", "$targetDir/bin/setlib.cfg") or
113 die "Whoa - error copying $setlibPath/setlib.cfg to $targetDir/bin/setlib.cfg! $!\n";
114
115 print "...$setlibPath/setlib.cfg has been copied into $targetDir/bin\n";
116
117 print "Now reading the old TWiki.cfg and generating the new...\n\n";
118
119 if ($twikiLibPath =~ m|^[~/]|)
120 {
121 # absolute path in $twikiLibPath
122 $twikiCfgFile = "$twikiLibPath/TWiki.cfg";
123 }
124 else
125 {
126 # relative path in $twikiLibPath
127 rizwank 1.1 $twikiCfgFile = "$existingConfigInfo/$twikiLibPath/TWiki.cfg";
128 }
129 }
130 elsif (-f "$existingConfigInfo/TWiki.cfg")
131 {
132 $twikiCfgFile = "$existingConfigInfo/TWiki.cfg";
133 }
134 else
135 {
136 die "UpgradeTwikiConfig couldn't find either setlib.cfg or TWiki.cfg at $existingConfigInfo: seems like a bug, someone needs to check it's arguments!\n";
137 }
138
139 # read 'em in...
140 require $twikiCfgFile;
141
142 # and now we have the old definitions...
143 # ... write those out where we can, or new defaults where we can't
144
145 open(NEW_CONFIG, ">$newConfigFile") or die "Couldn't open $newConfigFile to write it: $!\n";
146
147 printToNewConfig( "$InitialBlurb\n\n");
148 rizwank 1.1
149 printToNewConfig( "# This file has been generated by UpgradeTwiki, taking values from
150 # $twikiLibPath/Twiki.cfg where they could be found, and using
151 # default values for the remainder.
152 #
153 ");
154
155 CLOSE_YOUR_EYES: # unless you have a strong stomach... symbolic refs ahead...
156 {
157 no strict 'refs';
158
159 my $configVal;
160 my $usedADefault = 0;
161
162 # Do scalars first...
163
164 # @ConfigFileScalars is an array of hashrefs, one per config variable
165 for $configVal (@ConfigFileScalars) # so $$configVal is a hash with a record about one config variable...
166 {
167 printToNewConfig( $$configVal{'comment'} . "\n");
168
169 rizwank 1.1 my $newValue;
170
171 # ... and so this thing vvvvvv is the value of that variable, as read from $twikiCfgFile...
172 if (!defined(${$$configVal{'varname'}}))
173 {
174 # and if it is not defined, then we need to give it the default value
175 $newValue = $$configVal{'default'};
176 my $newDef = "\$$$configVal{varname} = $newValue ;";
177 printToNewConfig("$newDef\n");
178 print "There wasn't a definition for \"\$$$configVal{varname}\" in the old configuration... \n ...using the default: ' $newValue '\n";
179 $usedADefault = 1;
180 }
181 else
182 {
183 # if it is defined, just write code to set the value to whatever it currently is
184 $newValue = ${$$configVal{'varname'}};
185 printToNewConfig( Data::Dumper->Dump([$newValue],[$$configVal{'varname'}]));
186 }
187
188 if (grep(/^\$$$configVal{'varname'}$/, @SubstituteBackVars))
189 {
190 rizwank 1.1 push(@ActiveSubstitutions, {'subst' => $newValue, 'varname' => "\$$$configVal{'varname'}"});
191 }
192 }
193
194 # There was a choice of either using regexes to parse out the user's code for all the variable settings
195 # as strings, and writing those _strings_ into the new cfg file, or
196 # using perl to parse the old cfg file ('require') and writing the _values_ into the new cfg file.
197 # Since really only perl can parse perl, I chose the latter.
198 # Unfortunately, the user needs actual code for OS dependent variables, since the wiki might be
199 # being read from more than one OS.
200
201 # This leaves me with the choice of letting them down by writing the 'require'd value, which
202 # won't work on other OSes, or writing the default OS dependent code and praying that they
203 # didn't change it, or if they did then they know how to do it again...
204 # I chose the latter (on guidance from Sven: blame him :-) )
205
206 printToNewConfig( "# Here follow OS dependent settings...\n");
207
208 for $configVal (@ConfigFileOSScalars) # $$configVal is a hash with a record about one config variable...
209 {
210 printToNewConfig( $$configVal{'comment'} . "\n");
211 rizwank 1.1
212 printToNewConfig( "\$$$configVal{varname} = $$configVal{default} ;\n");
213 }
214
215 # Now do Arrays ... exactly the same code, except for @ instead of $.
216
217 # We have to have this nonsense because pre-Cairo TWiki.cfgs had nuisance
218 # stuff in @storeSettings (in particular, they referred to $TWiki::dataDir)
219 # we need to get rid of that!
220
221 # All this question stuff is commented out at the moment because of course they are upgrading
222 # from a pre-Cairo release - there is no other sort.
223 # this is the kind of stuff that will have to be done post-Cairo.
224
225 # print "Are you upgrading from a pre-Cairo TWiki?\n";
226 #
227 # my $response = <STDIN>;
228 #
229 # my $keepDefaults = 0;
230 #
231 # if ($response !~ m/[nN]/)
232 rizwank 1.1 # {
233 # print "\nAh...\n\n";
234 # print "Well, your new TWiki.cfg file (\"$newConfigFile\") is going to have the new default \@storeSettings in it.
235 #
236 #\tUnless someone changed the values in your old configuration, this will be just fine.
237 #
238 #\tIf someone did make some changes, you're going to have to manually copy those over (sorry!).
239 #
240 #\tIf in doubt, look at \@storeSettings in $twikiCfgFile
241 #\tand compare to what I've put in $newConfigFile.
242 #
243 #";
244
245 my $keepDefaults = 1;
246 # }
247
248 for $configVal (@ConfigFileArrays)
249 {
250 printToNewConfig( $$configVal{'comment'} . "\n");
251
252 # ... and so this thing vvvvvv is the value of that variable, as read from $twikiCfgFile...
253 rizwank 1.1 if (!defined(@{$$configVal{'varname'}}) or $keepDefaults)
254 {
255 # and if it is not defined, then we need to give it the default value
256 printToNewConfig( "\@$$configVal{varname} = $$configVal{default} ;\n");
257 unless ($keepDefaults)
258 {
259 print "There wasn't a definition for \"\$$$configVal{varname}\" in the old configuration... \n ...using the default: '$$configVal{default} '\n (You may want to check that this default works for you, edit if not!)\n";
260 $usedADefault = 1;
261 }
262 }
263 else
264 {
265 # if it is defined, just write code to set the value to whatever it currently is
266
267 printToNewConfig( Data::Dumper->Dump([\@{$$configVal{'varname'}}],["*$$configVal{'varname'}"]));
268 }
269 }
270
271 printToNewConfig( "1;\n");
272
273 close NEW_CONFIG or die "Yuck - couldn't close TWiki.cfg.new!\n";
274 rizwank 1.1
275 if ($usedADefault)
276 {
277 print "(You may want to check that the defaults used above work for you, edit if not!)\n";
278 }
279 }
280
281 print "$targetDir/lib/TWiki.cfg created...\n";
282 }
283
284 # Here follow the default contents of TWiki.cfg
285
286 # There are many ways that capture of the default TWiki.cfg settings could be done:
287 # text in the DATA segment etc etc
288
289 # I chose this way because it doesn't need any regex parsing stuff....
290 # I like the robustness that this confers: perl checks at least some aspects of it at compile time!
291
292 # These variables are declared down here in a BEGIN block simply to get all this
293 # mess out of the way: nice code first, lots of data second.
294
295 rizwank 1.1 BEGIN {
296
297 $InitialBlurb = "# Module of TWiki Collaboration Platform -*-Perl-*-
298 #
299 # This is the configuration file for TWiki, usually held in 'lib' directory.
300 #
301 # See 'setlib.cfg' in 'bin' directory to configure non-standard location
302 # for 'lib' directory or Perl modules.
303 #
304 # Copyright (C) 1999-2004 Peter Thoeny, peter\@thoeny.com
305 #
306 # For licensing info read license.txt file in the TWiki root.
307 # This program is free software; you can redistribute it and/or
308 # modify it under the terms of the GNU General Public License
309 # as published by the Free Software Foundation; either version 2
310 # of the License, or (at your option) any later version.
311 #
312 # This program is distributed in the hope that it will be useful,
313 # but WITHOUT ANY WARRANTY; without even the implied warranty of
314 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
315 # GNU General Public License for more details, published at
316 rizwank 1.1 # http://www.gnu.org/copyleft/gpl.html
317 #
318 # Notes:
319 # - Latest version at http://twiki.org/
320 # - Installation instructions in \$dataDir/TWiki/TWikiDocumentation.txt
321 # - Customize variables in TWiki.cfg when installing TWiki.
322 # - Optionally create a new plugin or customize DefaultPlugin.pm for
323 # custom extensions of rendering rules.
324 # - Upgrading TWiki is easy as long as you only customize DefaultPlugin.pm.
325 # - Variables that can be accessed from topics (see details in
326 # TWikiDocumentation.html) :
327 # %TOPIC% name of current topic
328 # %WEB% name of current web
329 # %SCRIPTURL% base TWiki script URL (place of view, edit...)
330 # %SCRIPTURLPATH% like %SCRIPTURL%, but path only (cut protocol and domain)
331 # %SCRIPTSUFFIX% script suffix (empty by default, '.pl' if required)
332 # %PUBURL% public URL (root of attachment URL)
333 # %PUBURLPATH% path of public URL
334 # %ATTACHURL% attachment URL of current topic
335 # %ATTACHURLPATH% path of attachment URL of current topic
336 # %DATE% today's date
337 rizwank 1.1 # %WIKIVERSION% tool version
338 # %USERNAME% login user name
339 # %WIKIUSERNAME% wiki user name
340 # %MAINWEB% main web name (Main)
341 # %TWIKIWEB% TWiki system web name (TWiki)
342 # %HOMETOPIC% home topic name (WebHome)
343 # %NOTIFYTOPIC% notify topic name (WebNotify)
344 # %WIKIUSERSTOPIC% user list topic name (TWikiUsers)
345 # %WIKIPREFSTOPIC% site-level preferences topic name (TWikiPreferences)
346 # %WEBPREFSTOPIC% web preferences topic name (WebPreferences)
347 # %STATISTICSTOPIC statistics topic name (WebStatistics)
348 # %INCLUDE{...}
349 # %SEARCH{...}% inline search
350
351
352 # variables that need to be changed when installing on a new server:
353 # ==================================================================
354 # ---- Windows paths should normally be written as 'c:/foo' not 'c:\foo'
355 # ---- (which doesnt do what you may think it does). You can use '\'
356 # ---- without problems inside single quotes, e.g. 'c:\foo'.
357 ";
358 rizwank 1.1
359 @ConfigFileScalars =
360 (
361 { 'varname' => 'defaultUrlHost',
362 'default' => '"http://your.domain.com"',
363 'comment' => '# URL for TWiki host : (e.g. "http://myhost.com:123")'},
364 { 'varname' => 'scriptUrlPath',
365 'default' => ' "/twiki/bin"',
366 'comment' => '# %SCRIPTURLPATH% : cgi-bin URL path for TWiki:'},
367 { 'varname' => 'dispScriptUrlPath',
368 'default' => ' $scriptUrlPath',
369 'comment' => '# URL path to scripts used to render links. Change if using redirection to shorten URLs'},
370 { 'varname' => 'dispViewPath',
371 'default' => ' "/view"',
372 'comment' => '# URL path to view script used to render links, relative to $dispScriptUrlPath'},
373 { 'varname' => 'pubUrlPath',
374 'default' => ' "/twiki/pub"',
375 'comment' => '# %PUBURLPATH% : Public data URL path for TWiki (root of attachments) :'},
376 { 'varname' => 'pubDir',
377 'default' => ' "/home/httpd/twiki/pub"',
378 'comment' => '# Public data directory (file path not URL), must match $pubUrlPath :'},
379 rizwank 1.1 { 'varname' => 'templateDir',
380 'default' => ' "/home/httpd/twiki/templates"',
381 'comment' => '# Template directory :'},
382 { 'varname' => 'dataDir',
383 'default' => ' "/home/httpd/twiki/data"',
384 'comment' => '# Data (topic files) root directory (file path not URL):'},
385 { 'varname' => 'logDir',
386 'default' => ' "$dataDir"',
387 'comment' => '# Log directory for log files, debug and warning files. Default "$dataDir" :'},
388 { 'varname' => 'scriptSuffix',
389 'default' => ' ""',
390 'comment' => '# variables that might need to be changed:
391 # ==================================================================
392 # %SCRIPTSUFFIX% : Suffix of TWiki Perl scripts (e.g. ".pl") :'},
393 { 'varname' => 'uploadFilter',
394 'default' => ' "^(\.htaccess|.*\.(?:php[0-9s]?|phtm[l]?|pl|py|cgi))\$"',
395 'comment' => '# Regex security filter for uploaded (attached) files :
396 # (Matching filenames will have a ".txt" appended)
397 # WARNING: Be sure to update this list with any
398 # configuration or script filetypes that are
399 # automatically run by your web server'},
400 rizwank 1.1 { 'varname' => 'safeEnvPath',
401 'default' => '"/bin:/usr/bin"',
402 'comment' => '# Set ENV{"PATH"} explicitly for taint checks ( #!perl -T option ) :
403 # (Note: PATH environment variable is not changed if set to "")
404 # $safeEnvPath - safe operating system PATH setting for use by TWiki scripts.
405 #
406 # ---- Check notes for your operating system and use appropriate line as model
407 # ---- Comment out unused lines (put "#" at start) and uncomment required line.
408 # ---- All Windows paths use "/" not "\" for simplicity.
409 #
410 # As long as you use full pathnames for $egrepCmd and similar (below),
411 # this path value is used only to find a shell (or cmd.exe) and by RCS programs
412 # to find "diff".
413 #
414 # >> Unix or Linux - ensure "diff" and shell (Bourne or bash type) is found on
415 # this path.
416 # Separator is ":"
417 # >> Windows: Cygwin Perl and RCS - ensure "diff" and "bash" found on this path.
418 # Same format as Unix PATH, separator is ":" not ";". You must NOT use
419 # "c:/foo" type paths, because ":" is taken as separator, meaning that
420 # "c" is interpreted as a relative pathname, giving Perl "Insecure
421 rizwank 1.1 # directory in $ENV{PATH}" error on using "Diffs" link.
422 # Separator is ":"
423 # $safeEnvPath = "/bin"; # Cygwin - uncomment, no need to customise
424
425 # >> Windows: ActiveState Perl, with Cygwin RCS and PERL5SHELL set to
426 # "c:/cygwin/bin/bash.exe -c". Same format as the normal Windows PATH,
427 # separator is ":" not ";". Its best to avoid "c:/foo" type paths,
428 # because in some cases these can cause a Perl "Insecure directory
429 # in $ENV{PATH}" error on using "Diffs" link. Since this setting is
430 # for Cygwin RCS, the best alternative is to convert "c:/foo" to
431 # "/c/cygdrive/foo" - odd looking but it works! The Windows system directory
432 # (e.g. /cygdrive/c/winnt/system32) is required in this path for commands
433 # using pipes to work (e.g. using the "Index" link).
434 # NOTE: Customise this path based on your Cygwin and Windows directories
435 # Separator is ";"
436 # $safeEnvPath = "/cygdrive/c/YOURCYGWINDIR/bin;/cygdrive/c/YOURWINDOWSDIR/system32";
437
438 # >> Windows: ActiveState Perl, with non-Cygwin RCS, OR no PERL5SHELL setting.
439 # Windows PATH, separator is ";". The Windows system directory
440 # (e.g. c:\winnt\system32) is required in this path for commands using pipes
441 # to work (e.g. using the "Index" link). Must NOT use "/" in pathnames
442 rizwank 1.1 # as this upsets cmd.exe - single "\" is OK using Perl single-quoted string.
443 # FIXME: needs testing, not currently recommended.
444 # NOTE: Customise this path based on your RCS and Windows directories
445 # Separator is ";"
446 # $safeEnvPath = "c:\YOUR_RCSPROGDIR\bin;c:\YOURWINDOWSDIR\system32";'
447 },
448 { 'varname' => 'mailProgram',
449 'default' => ' "/usr/sbin/sendmail -t -oi -oeq"',
450 'comment' => '# Mail program used in case Net::SMTP is not installed.
451 # See also SMTPMAILHOST in TWikiPreferences.
452 # Windows: this setting is ignored, just use Net::SMTP.'},
453 { 'varname' => 'noSpamPadding',
454 'default' => ' ""',
455 'comment' => '# Prevent spambots from grabbing addresses, default "":
456 # e.g. set to "NOSPAM" to get "user@somewhereNOSPAM.com"'},
457 { 'varname' => 'mimeTypesFilename',
458 'default' => ' "$dataDir/mime.types"',
459 'comment' => '# Pathname of mime types file that maps file suffixes to MIME types :
460 # For Apache server set this to Apaches mime.types file pathname.
461 # Default "$dataDir/mime.types"'},
462 { 'varname' => 'rcsDir',
463 rizwank 1.1 'default' => ' "/usr/bin"',
464 'comment' => '# RCS directory (find out by "which rcs") :'},
465 { 'varname' => 'useRcsDir',
466 'default' => ' "0"',
467 'comment' => '# Store RCS history files in directory (RCS under content dir), default "0"
468 # Dont change this in a working installation, only change when initially setting up a TWiki installation
469 # You also need to create an RCS directory for each Web. TWiki will create RCS directories under pub for attachments historys.'},
470 { 'varname' => 'storeTopicImpl',
471 'default' => ' "RcsWrap"',
472 'comment' => '# Choice and configuration of Storage implementation
473 # Currently select either:
474 # RcsWrap - use RCS executables, see TWiki::Store::RcsWrap.pm for explanation of storeSettings
475 # RcsLite - use a 100% Perl simplified implementation of Perl (NOT yet ready for production use)'},
476 { 'varname' => 'lsCmd',
477 'default' => ' "/bin/ls"',
478 'comment' => '# NOTE: You might want to avoid c: at start of cygwin unix command for
479 # Windows, seems to cause a problem with pipe used in search
480 # Unix ls command : (deprecated since 01 Nov 2003)'},
481 { 'varname' => 'egrepCmd',
482 'default' => ' "/bin/egrep"',
483 'comment' => '# Unix egrep command :'},
484 rizwank 1.1 { 'varname' => 'fgrepCmd',
485 'default' => ' "/bin/fgrep"',
486 'comment' => '# Unix fgrep command :'},
487 { 'varname' => 'displayTimeValues',
488 'default' => ' "gmtime"',
489 'comment' => '
490 #display Time in the following timezones (this only effects the display of times, all internal storage is still in GMT)
491 # gmtime / servertime'},
492 { 'varname' => 'useLocale',
493 'default' => ' 0',
494 'comment' => '# internationalisation setup:
495 # ==================================================================
496 # See the output of the "testenv" script for help with these settings.
497
498 # Set $useLocale to 1 to enable internationalisation support for
499 # 8-bit character sets'},
500 { 'varname' => 'siteLocale',
501 'default' => ' "en_US.ISO-8859-1"',
502 'comment' => '# Site-wide locale - used by TWiki and external programs such as grep,
503 # and to specify the character set for the users web browser. The
504 # language part also prevents English plural handling for non-English
505 rizwank 1.1 # languages. Ignored if $useLocale is 0.
506 #
507 # Locale names are not standardised - check "locale -a" on your system to
508 # see what"s installed, and check this works using command line tools. You
509 # may also need to check what charsets your browsers accept - the
510 # "preferred MIME names" at http://www.iana.org/assignments/character-sets
511 # are a good starting point.
512 #
513 # WARNING: Topics are stored in site character set format, so data conversion of
514 # file names and contents will be needed if you change locales after
515 # creating topics whose names or contents include 8-bit characters.
516 #'},
517 { 'varname' => 'siteCharsetOverride',
518 'default' => ' ""',
519 'comment' => '#
520 # Examples only: (choose suitable locale + charset for your own site)
521 # $siteLocale = "de_AT.ISO-8859-15"; # Austria with ISO-8859-15 for Euro
522 # $siteLocale = "ru_RU.KOI8-R"; # Russia
523 # $siteLocale = "ja_JP.eucjp"; # Japan
524 # $siteLocale = "C"; # English only, no I18N features
525
526 rizwank 1.1 # Site character set override - set this only if you must match a specific
527 # locale (from "locale -a") whose character set is not supported by your
528 # chosen conversion module (i.e. Encode for Perl 5.8 or higher, or
529 # Unicode::MapUTF8 for other Perl versions). For example, the locale
530 # "ja_JP.eucjp" exists on your system but only "euc-jp" is supported by
531 # Unicode::MapUTF8, set $siteCharsetOverride to "euc-jp". Leave this as ""
532 # if you dont have this problem.'},
533 { 'varname' => 'localeRegexes',
534 'default' => ' 1',
535 'comment' => '# Set $localeRegexes to 0 to force explicit listing of national chars in
536 # regexes, rather than relying on locale-based regexes. Intended for Perl
537 # 5.6 or higher on platforms with broken locales: should only be set if
538 # you have locale problems with Perl 5.6 or higher.'},
539 { 'varname' => 'upperNational',
540 'default' => ' ""',
541 'comment' => '
542 # If a suitable working locale is not available (i.e. $useLocale is 0), OR
543 # you are using Perl 5.005 (with or without working locales), OR
544 # $localeRegexes is 0, you can use WikiWords with accented national
545 # characters by putting any "8-bit" accented national characters within
546 # these strings - i.e. $upperNational should contain upper case non-ASCII
547 rizwank 1.1 # letters. This is termed "non-locale regexes" mode.
548 #
549 # If "non-locale regexes" is in effect, WikiWord linking will work, but
550 # some features such as sorting of WikiWords in search results may not.
551 # These features depend on $useLocale, which can be set independently of
552 # $localeRegexes, so they will work with Perl 5.005 as long as
553 # $useLocale is set to 1 and you have working locales.
554 #
555 # Using the recommended setup of Perl 5.6.1 with working locales avoids the
556 # need to set these parameters.'},
557 { 'varname' => 'lowerNational',
558 'default' => ' ""',
559 'comment' => ''},
560 { 'varname' => 'keywordMode',
561 'default' => ' "-ko"',
562 'comment' => '
563 # variables that probably do not change:
564 # ==================================================================
565
566 # RCS keyword handling: change this to "" only if you want TWiki pages to
567 # include automatically-updated RCS ID keyword strings. Leave this as
568 rizwank 1.1 # "-ko" if you dont know what that means! Default setting ensures that
569 # contents of TWiki pages are not changed by RCS. RcsLite always works in
570 # "-ko" mode.
571 '},
572 { 'varname' => 'securityFilter',
573 'default' => ' "[\\\*\?\~\^\$\@\%\`\"\\\'\&\;\|\<\>\x00-\x1F]" ',
574 'comment' => '# Regex security filter for web name, topic name, user name :'},
575 { 'varname' => 'defaultUserName',
576 'default' => ' "guest"',
577 'comment' => '# Default user name, default "guest" :'},
578 { 'varname' => 'wikiToolName',
579 'default' => ' "TWiki"',
580 'comment' => '# Deprecated, replaced by %WIKITOOLNAME% preferences variable :'},
581 { 'varname' => 'wikiHomeUrl',
582 'default' => ' "http://your.domain.com/twiki"',
583 'comment' => '# Deprecated, here for compatibility :'},
584 { 'varname' => 'siteWebTopicName',
585 'default' => ' ""',
586 'comment' => '# Site Web.Topic name, e.g. "Main.TokyoOffice". Default "" :'},
587 { 'varname' => 'mainWebname',
588 'default' => ' "Main"',
589 rizwank 1.1 'comment' => '# %MAINWEB% : Name of Main web, default "Main" :'},
590 { 'varname' => 'twikiWebname',
591 'default' => ' "TWiki"',
592 'comment' => '# %TWIKIWEB% : Name of TWiki system web, default "TWiki" :'},
593 { 'varname' => 'debugFilename',
594 'default' => ' "$logDir/debug.txt"',
595 'comment' => '# Pathname of debug file :'},
596 { 'varname' => 'warningFilename',
597 'default' => ' "$logDir/warning.txt"',
598 'comment' => '# Pathname of warning file. Default "$logDir/warning.txt" :
599 # (no warnings are written if empty)'},
600 { 'varname' => 'htpasswdFormatFamily',
601 'default' => ' "htpasswd" ',
602 'comment' => '# Password file format/encoding method :
603 # htpasswd:plain, htpasswd:crypt, htpasswd:md5 (currently unsupported),
604 # htpasswd:sha1, htdigest:md5, none:
605 #default htpasswd:crypt;'},
606 { 'varname' => 'htpasswdFilename',
607 'default' => ' ($htpasswdFormatFamily eq "htpasswd") ? "$dataDir/.htpasswd" : "$dataDir/.htdigest" ' ,
608 'comment' => '# Pathname of user name/password file for authentication :'
609 },
610 rizwank 1.1 { 'varname' => 'authRealm',
611 'default' => ' "Enter your WikiName. (First name and last name, no space, no dots, capitalized, e.g. JohnSmith). Cancel to register if you do not have one."',
612 'comment' => '# Authentication "realm" (must be the same as in
613 # password file, MUST NOT contain colons):'},
614 { 'varname' => 'logFilename',
615 'default' => ' "$logDir/log%DATE%.txt"',
616 'comment' => '# Pathname of log file :'},
617 { 'varname' => 'remoteUserFilename',
618 'default' => ' "$dataDir/remoteusers.txt"',
619 'comment' => '# Pathname of remote users file that maps IP to user :'},
620 { 'varname' => 'wikiUsersTopicname',
621 'default' => ' "TWikiUsers"',
622 'comment' => '# %WIKIUSERSTOPIC% : Name of users list topic :'},
623 { 'varname' => 'userListFilename',
624 'default' => ' "$dataDir/$mainWebname/$wikiUsersTopicname.txt"',
625 'comment' => '# Pathname of WebUsers topic, used to map Intranet login name
626 # (e.g. "fsmith") to Wiki name (e.g. "FredSmith") :'},
627 { 'varname' => 'doMapUserToWikiName',
628 'default' => ' "0"',
629 'comment' => '# Map login name to Wiki name, default "1", set to "0" for .htpasswd authenticated sites :'},
630 { 'varname' => 'mainTopicname',
631 rizwank 1.1 'default' => ' "WebHome"',
632 'comment' => '# %HOMETOPIC% : Name of main topic in a web, default "WebHome" :'},
633 { 'varname' => 'notifyTopicname',
634 'default' => ' "WebNotify"',
635 'comment' => '# %NOTIFYTOPIC% : Name of topic for email notifications, default "WebNotify" :'},
636 { 'varname' => 'wikiPrefsTopicname',
637 'default' => ' "TWikiPreferences"',
638 'comment' => '# %WIKIPREFSTOPIC% : Name of site-level preferences topic, default "TWikiPreferences" :'},
639 { 'varname' => 'webPrefsTopicname',
640 'default' => ' "WebPreferences"',
641 'comment' => '# %WEBPREFSTOPIC% : Name of preferences topic in a web, default "WebPreferences" :'},
642 { 'varname' => 'statisticsTopicname',
643 'default' => ' "WebStatistics"',
644 'comment' => '# %STATISTICSTOPIC% : Name of statistics topic, default "WebStatistics" :'},
645 { 'varname' => 'statsTopViews',
646 'default' => ' "10"',
647 'comment' => '# Number of top viewed topics to show in statistics topic, default "10" :'},
648 { 'varname' => 'statsTopContrib',
649 'default' => ' "10"',
650 'comment' => '# Number of top contributors to show in statistics topic, default "10" :'},
651 { 'varname' => 'doDebugStatistics',
652 rizwank 1.1 'default' => ' "0"',
653 'comment' => '# Statistics debugging - write invalid logfile lines to debug log'},
654 { 'varname' => 'numberOfRevisions',
655 'default' => ' "3"',
656 'comment' => '# Show how many revision links, "0" for all, default "3" :'},
657 { 'varname' => 'editLockTime',
658 'default' => ' "3600"',
659 'comment' => '# Number of seconds a topic is locked during edit, default "3600" :'},
660 { 'varname' => 'superAdminGroup',
661 'default' => ' "TWikiAdminGroup"',
662 'comment' => '# Group of users that can use cmd=repRev
663 # or that ALWAYS have edit powers (set $doSuperAdminGroup=1)'},
664 { 'varname' => 'doKeepRevIfEditLock',
665 'default' => ' "1"',
666 'comment' => '
667 # flag variables that could change:
668 # ==================================================================
669 # values are "0" for no, or "1" for yes
670 # Keep same revision if topic is saved again within edit lock time. Default "1"'},
671 { 'varname' => 'doGetScriptUrlFromCgi',
672 'default' => ' "0"',
673 rizwank 1.1 'comment' => '# Build $scriptUrlPath from $query->url parameter. Default "0".
674 # Note that links are incorrect after failed authentication if "1"'},
675 { 'varname' => 'doRemovePortNumber',
676 'default' => ' "0"',
677 'comment' => '# Remove port number from URL. Default "0"'},
678 { 'varname' => 'doRemoveImgInMailnotify',
679 'default' => ' "1"',
680 'comment' => '# Remove IMG tags in mailnotify. Default "1"'},
681 { 'varname' => 'doRememberRemoteUser',
682 'default' => ' "0"',
683 'comment' => '# Remember remote user by matching the IP address
684 # in case REMOTE_USER is empty. Default "0"
685 # (Note: Does not work reliably with dynamic IP addresses)'},
686 { 'varname' => 'doPluralToSingular',
687 'default' => ' "1"',
688 'comment' => '# Change non existing plural topic name to singular,
689 # e.g. TestPolicies to TestPolicy. Default "1"'},
690 { 'varname' => 'doHidePasswdInRegistration',
691 'default' => ' "1"',
692 'comment' => '# Hide password in registration email'},
693 { 'varname' => 'doSecureInclude',
694 rizwank 1.1 'default' => ' "1"',
695 'comment' => '# Remove ".." from %INCLUDE% filename, to
696 # prevent includes of "../../file". Default "1"'},
697 { 'varname' => 'doLogTopicView',
698 'default' => ' "1"',
699 'comment' => '# Log topic views to $logFilename. Default "1"'},
700 { 'varname' => 'doLogTopicEdit',
701 'default' => ' "1"',
702 'comment' => '# Log topic edits to $logFilename. Default "1"'},
703 { 'varname' => 'doLogTopicSave',
704 'default' => ' "1"',
705 'comment' => '# Log topic saves to $logFilename. Default "1"'},
706 { 'varname' => 'doLogRename',
707 'default' => ' "1"',
708 'comment' => '# Log renames to $logFilename. Default "1". Added JET 22-Feb-01'},
709 { 'varname' => 'doLogTopicAttach',
710 'default' => ' "1"',
711 'comment' => '# Log view attach to $logFilename. Default "1"'},
712 { 'varname' => 'doLogTopicUpload',
713 'default' => ' "1"',
714 'comment' => '# Log file upload to $logFilename. Default "1"'},
715 rizwank 1.1 { 'varname' => 'doLogTopicRdiff',
716 'default' => ' "1"',
717 'comment' => '# Log topic rdiffs to $logFilename. Default "1"'},
718 { 'varname' => 'doLogTopicChanges',
719 'default' => ' "1"',
720 'comment' => '# Log changes to $logFilename. Default "1"'},
721 { 'varname' => 'doLogTopicSearch',
722 'default' => ' "1"',
723 'comment' => '# Log search to $logFilename. Default "1"'},
724 { 'varname' => 'doLogRegistration',
725 'default' => ' "1"',
726 'comment' => '# Log user registration to $logFilename. Default "1"'},
727 { 'varname' => 'disableAllPlugins',
728 'default' => ' "0"',
729 'comment' => '# Disable plugins. Set to "1" in case TWiki is non functional after
730 # installing a new plugin. This allows you to remove the plugin from
731 # the ACTIVEPLUGINS list in TWikiPreferences. Default "0"'},
732 { 'varname' => 'doSuperAdminGroup',
733 'default' => ' "1"',
734 'comment' => '# Enable super-powers to $superAdminGroup members
735 # see Codev.UnchangeableTopicBug'}
736 rizwank 1.1 );
737
738 @ConfigFileOSScalars =
739 (
740 { 'varname' => 'detailedOS',
741 'default' => '($OS ? $OS : ($^O ? $^O : (require Config, $Config::Config{"osname"})))',
742 'comment' => '#'},
743 { 'varname' => 'OS',
744 'default' => '$detailedOS;
745 if ($OS=~/darwin/i) { # MacOS X, suggested by Todd Jonker on Codev
746 $OS = "UNIX";
747 } elsif ($OS=~/Win/i) {
748 $OS = "WINDOWS";
749 } elsif ($OS=~/vms/i) {
750 $OS = "VMS";
751 } elsif ($OS=~/bsdos/i) {
752 $OS = "UNIX";
753 } elsif ($OS=~/dos/i) {
754 $OS = "DOS";
755 } elsif ($OS=~/^MacOS$/i) { # MacOS 9 or earlier
756 $OS = "MACINTOSH";
757 rizwank 1.1 } elsif ($OS=~/os2/i) {
758 $OS = "OS2";
759 } else {
760 $OS = "UNIX";
761 }
762 ',
763 'comment' => ''},
764 { 'varname' => 'rcsArg',
765 'default' => ' ($OS eq "WINDOWS") ? "-x,v" : ""',
766 'comment' => '# Initialise RCS file, ignored if empty string,
767 # needed on Windows for binary files. Added JET 22-Feb-01'},
768 { 'varname' => 'nullDev',
769 'default' => ' {
770 UNIX=>"/dev/null", OS2=>"", WINDOWS=>"NUL", DOS=>"NUL", MACINTOSH=>"", VMS=>""
771 }->{$OS}',
772 'comment' => '# null device /dev/null for unix, NUL for windows'},
773 { 'varname' => 'htpasswdEncoding',
774 'default' => ' ($OS eq "WINDOWS") ? "sha1" : "crypt" ' ,
775 'comment' => '#'
776 },
777 { 'varname' => 'endRcsCmd',
778 rizwank 1.1 'default' => ' ($OS eq "UNIX") ? " 2>&1" : ""',
779 'comment' => '# This should enable gathering of extra error information on most OSes. However, wont work on NT4 unless unix like shell is used'},
780 { 'varname' => 'cmdQuote',
781 'default' => ' ($OS eq "UNIX") ? "\\"" : "\'" ' ,
782 'comment' => '# Command quote \' for unix, \" for Windows'}
783 );
784
785 @ConfigFileArrays =
786 (
787 { 'varname' => 'storeSettings',
788 'default' => '
789 (
790 # RcsLite and Rcs
791 dataDir => $dataDir,
792 pubDir => $pubDir,
793 attachAsciiPath => "\.(txt|html|xml|pl)\$",
794 dirPermission => 0775,
795 useRcsDir => $useRcsDir,
796
797 # Rcs only
798 initBinaryCmd => "$rcsDir/rcs $rcsArg -q -i -t-none -kb %FILENAME% $endRcsCmd",
799 rizwank 1.1 tmpBinaryCmd => "$rcsDir/rcs $rcsArg -q -kb %FILENAME% $endRcsCmd",
800 ciCmd => "$rcsDir/ci $rcsArg -q -l -m$cmdQuote%COMMENT%$cmdQuote -t-none -w$cmdQuote%USERNAME%$cmdQuote %FILENAME% $endRcsCmd",
801 coCmd => "$rcsDir/co $rcsArg -q -p%REVISION% $keywordMode %FILENAME% $endRcsCmd",
802 histCmd => "$rcsDir/rlog $rcsArg -h %FILENAME% $endRcsCmd",
803 infoCmd => "$rcsDir/rlog $rcsArg -r%REVISION% %FILENAME% $endRcsCmd",
804 diffCmd => "$rcsDir/rcsdiff $rcsArg -q -w -B -r%REVISION1% -r%REVISION2% $keywordMode --unified=%CONTEXT% %FILENAME% $endRcsCmd",
805 breakLockCmd => "$rcsDir/rcs $rcsArg -q -l -M %FILENAME% $endRcsCmd",
806 ciDateCmd => "$rcsDir/ci -l $rcsArg -q -mnone -t-none -d$cmdQuote%DATE%$cmdQuote -w$cmdQuote%USERNAME%$cmdQuote %FILENAME% $endRcsCmd",
807 delRevCmd => "$rcsDir/rcs $rcsArg -q -o%REVISION% %FILENAME% $endRcsCmd",
808 unlockCmd => "$rcsDir/rcs $rcsArg -q -u %FILENAME% $endRcsCmd",
809 lockCmd => "$rcsDir/rcs $rcsArg -q -l %FILENAME% $endRcsCmd",
810 tagCmd => "$rcsDir/rcs $rcsArg -N%TAG%:%REVISION% %FILENAME% $endRcsCmd",
811 )',
812 'comment' => '# Settings for Rcs (standard RCS programs) and RcsLite (built-in)'}
813 );
814
815
816 @SubstituteBackVars =
817 qw(
818 $dataDir
819 $pubDir
820 rizwank 1.1 $logDir
821 $mainWebname
822 );
823
824 @ActiveSubstitutions = ();
825 };
826
827 sub printToNewConfig
828 {
829 my ($config) = @_;
830
831 my $subst;
832
833 # $subst is a hashref containing a string and the variable name (string) that should be substituted
834
835 $config =~ m"([^=]*=[\s]*)'(.*)'";
836
837 my ($defn, $expr) = ($1, $2);
838
839 if ($expr)
840 {
841 rizwank 1.1 for $subst (@ActiveSubstitutions)
842 {
843 # print "pTNC: testing $$subst{'subst'} $$subst{'varname'}\n";
844 $expr =~ s/$$subst{'subst'}/'.$$subst{'varname'}.'/g;
845 }
846
847 $config = "$defn'$expr';\n";
848
849 $config =~ s/''\.//g;
850 $config =~ s/\.''//g;
851 }
852
853
854 print NEW_CONFIG $config;
855 }
856
857 1;
858
859 =end twiki
860
861 __DATA__
|