bin/configure
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
permissions -rwxr-xr-x
RELEASE 4.2.0 freetown
colas@0
     1
#!/usr/bin/perl -w
colas@0
     2
#
colas@0
     3
# TWiki Enterprise Collaboration Platform, http://TWiki.org/
colas@0
     4
#
colas@0
     5
# Copyright (C) 2000-2007 TWiki Contributors.
colas@0
     6
#
colas@0
     7
# This program is free software; you can redistribute it and/or
colas@0
     8
# modify it under the terms of the GNU General Public License
colas@0
     9
# as published by the Free Software Foundation; either version 2
colas@0
    10
# of the License, or (at your option) any later version. For
colas@0
    11
# more details read LICENSE in the root of this distribution.
colas@0
    12
#
colas@0
    13
# This program is distributed in the hope that it will be useful,
colas@0
    14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
colas@0
    15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
colas@0
    16
#
colas@0
    17
# As per the GPL, removal of this notice is prohibited.
colas@0
    18
#
colas@0
    19
# Configuration script for TWiki. Once you have a basic webserver
colas@0
    20
# configuration that lets you access this script, the rest of the
colas@0
    21
# configuration process is done from here.
colas@0
    22
#
colas@0
    23
# The script works from the top down, by checking features of the
colas@0
    24
# environment before moving on. The sequence is:
colas@0
    25
# 1. Check the version of perl
colas@0
    26
# 2. Check we have the modules to run this script
colas@0
    27
# 3. Check the environment
colas@0
    28
# 4. Check we have the modules to load the rest of configure
colas@0
    29
# ... and so on. At any stage, the script reports any errors in the
colas@0
    30
# best way it can given the environment established so far.
colas@0
    31
# When the basic checks are complete, the script moves into the
colas@0
    32
# real configuration steps; setting configuration variables.
colas@0
    33
#
colas@0
    34
# This phase of the configure environment follows a Model-View-
colas@0
    35
# Controller pattern.
colas@0
    36
#
colas@0
    37
# Controller
colas@0
    38
# This script is the controller; it handles communication with the
colas@0
    39
# browser (and thus the user). Communication is very simple; this script
colas@0
    40
# is re-invoked with different 'action' parameters to determine what it does.
colas@0
    41
#
colas@0
    42
# Model
colas@0
    43
# The Model consists of a simple node tree, where each node represents a
colas@0
    44
# structural element in the *presentation* of the configuration (this may
colas@0
    45
# not be consistent with the structure of $TWiki:cfg, so beware). Each
colas@0
    46
# leaf node has an associated Type (in the Types subdirectory) that has
colas@0
    47
# collected model and view behaviours for the basic types.
colas@0
    48
# The Model is independent of the language used to represent the
colas@0
    49
# configuration. There is one parser/generator provided, TWikiCfg, but it
colas@0
    50
# would be trivial to add others.
colas@0
    51
#
colas@0
    52
# The View is a DOM document, generated as HTML by a set of UI classes.
colas@0
    53
# Because of some convoluted history, there are actually three sets of classes
colas@0
    54
# that generate views. They are all subclasses of TWiki::Configure::UI
colas@0
    55
#    UIs - are top-level and pluggable UI components. All the main screens are
colas@0
    56
#          implemented here.
colas@0
    57
#    Checkers - are specialised UIs designed to give checking support for
colas@0
    58
#          variable values. Checkers also include the read-only checking
colas@0
    59
#          UIs used for checking environment.
colas@0
    60
#    Types - provide some UI support in the form of type-specific prompters.
colas@0
    61
#          this is really an abuse of the Model, but it saves creating
colas@0
    62
#          decorator classes for all the Model types.
colas@0
    63
# HTML is generated for the model using Visitor pattern. Each node in the tree
colas@0
    64
# is visited in depth-first order.
colas@0
    65
#
colas@0
    66
use strict;
colas@0
    67
use warnings;
colas@0
    68
colas@0
    69
# This is absolutely essential for error reporting. We load it using
colas@0
    70
# an eval so we can report the problem.
colas@0
    71
eval "use CGI::Carp qw(fatalsToBrowser)";
colas@0
    72
if ($@) {
colas@0
    73
    print <<"REPORT";
colas@0
    74
Content-type: text/plain
colas@0
    75
colas@0
    76
Could not load CGI::Carp. Please install this module before continuing.
colas@0
    77
It can be downloaded from http://www.cpan.org
colas@0
    78
colas@0
    79
The error seen was:
colas@0
    80
$@
colas@0
    81
REPORT
colas@0
    82
    exit 1;
colas@0
    83
}
colas@0
    84
colas@0
    85
###########################################################
colas@0
    86
# VERY basic stuff required for configure to work. Any errors
colas@0
    87
# during this phase will throw a die, which will be picked up
colas@0
    88
# using CGI::Carp fatalsToBrowser
colas@0
    89
colas@0
    90
colas@0
    91
# Warnings are fatal
colas@0
    92
$SIG{'__WARN__'} = sub { die @_ };
colas@0
    93
colas@0
    94
eval 'require 5.00503';
colas@0
    95
die $@ if $@;
colas@0
    96
colas@0
    97
# We warn against running TWiki on an older Perl version then 5.8.4
colas@0
    98
# but we will not let configure die in this situation. The user
colas@0
    99
# may have updated many libraries and tweaked TWiki so let us give
colas@0
   100
# him a chance.
colas@0
   101
my $perlversion = $];
colas@0
   102
if ($perlversion < 5.006) {
colas@0
   103
    print STDERR <<HERE;
colas@0
   104
Your perl version is older than 5.6.0.
colas@0
   105
TWiki has only been successfully tested on Perl 5.6.X and 5.8.X,
colas@0
   106
and there have been reports that it does not run on 5.5.
colas@0
   107
Running TWiki with an older Perl version requires upgrading of modules and
colas@0
   108
tweaking of the TWiki code.
colas@0
   109
HERE
colas@0
   110
}
colas@0
   111
colas@0
   112
# Get web server's user and group info
colas@0
   113
use vars qw($WebServer_uid $WebServer_gid);
colas@0
   114
$WebServer_uid = $WebServer_gid = '';
colas@0
   115
colas@0
   116
eval {
colas@0
   117
    $WebServer_uid = getlogin() || getpwuid($>) || '';
colas@0
   118
};
colas@0
   119
colas@0
   120
eval {
colas@0
   121
    $WebServer_gid = join(',', map { lc(getgrgid( $_ )) } split( ' ', $( ));
colas@0
   122
};
colas@0
   123
if( $@ ) {
colas@0
   124
    # Try to use Cygwin's 'id' command - may be on the path, since Cygwin
colas@0
   125
    # is probably installed to supply ls, egrep, etc - if it isn't, give
colas@0
   126
    # up.
colas@0
   127
    # Run command without stderr output, to avoid CGI giving error.
colas@0
   128
    # Get names of primary and other groups.
colas@0
   129
    $WebServer_gid = lc(qx(sh -c '( id -un ; id -gn) 2>/dev/null' 2>nul ));
colas@0
   130
}
colas@0
   131
colas@0
   132
my $localLibFailure;
colas@0
   133
colas@0
   134
sub _loadBasicModule {
colas@0
   135
    my ($module) = @_;
colas@0
   136
colas@0
   137
    eval "use $module";
colas@0
   138
    if ($@) {
colas@0
   139
        my $reason = "Failed to load the perl module $module. The module ";
colas@0
   140
        # See if we can find the .pm on @INC
colas@0
   141
        my $foundAt = "could not be found. ";
colas@0
   142
        my $modpath = $module;
colas@0
   143
        if ($modpath =~ /^([\w:]+)/) {
colas@0
   144
            $modpath =~ s#::#/#g;
colas@0
   145
            $modpath .= '.pm';
colas@0
   146
            foreach my $path (@INC) {
colas@0
   147
                if (-e "$path/$modpath") {
colas@0
   148
                    $foundAt = "was found at $path/$modpath";
colas@0
   149
                    if (!-r $foundAt) {
colas@0
   150
                        $foundAt .=
colas@0
   151
                          ", but I don't have permission to read it.";
colas@0
   152
                    }
colas@0
   153
                    last;
colas@0
   154
                }
colas@0
   155
            }
colas@0
   156
        }
colas@0
   157
        $reason .= $foundAt;
colas@0
   158
colas@0
   159
        $reason .= <<HERE;
colas@0
   160
colas@0
   161
colas@0
   162
Please ensure that:
colas@0
   163
   1 $module is installed,
colas@0
   164
   2 that the module is available on the \@INC path,
colas@0
   165
   3 that the webserver user ($WebServer_uid) has permission to read the $modpath file.
colas@0
   166
HERE
colas@0
   167
colas@0
   168
        $reason .= <<HERE;
colas@0
   169
The detailed error seen was:
colas@0
   170
$@
colas@0
   171
HERE
colas@0
   172
        if ($localLibFailure) {
colas@0
   173
            $reason .= <<HERE;
colas@0
   174
colas@0
   175
NOTE that I was unable to load LocalLib.cfg because of the following error:
colas@0
   176
colas@0
   177
$localLibFailure
colas@0
   178
HERE
colas@0
   179
        }
colas@0
   180
        die $reason;
colas@0
   181
    }
colas@0
   182
}
colas@0
   183
colas@0
   184
foreach my $module ('FindBin',
colas@0
   185
                    'File::Spec',
colas@0
   186
                    'Config',
colas@0
   187
                    'CGI qw(:any)',
colas@0
   188
                   ) {
colas@0
   189
    _loadBasicModule($module);
colas@0
   190
}
colas@0
   191
colas@0
   192
# Capture DIE for stack *when debugging*
colas@0
   193
#$SIG{__DIE__} = sub { Carp::confess( $_[0] || '' ) };
colas@0
   194
colas@0
   195
###########################################################
colas@0
   196
# Establish the path to the TWiki library
colas@0
   197
colas@0
   198
# Set the working dir to the bin dir
colas@0
   199
no warnings;
colas@0
   200
$FindBin::Bin =~ /^(.*)$/;
colas@0
   201
use warnings;
colas@0
   202
chdir($1);
colas@0
   203
my @root = File::Spec->splitdir($1);
colas@0
   204
pop(@root);
colas@0
   205
my @script = File::Spec->splitdir($0);
colas@0
   206
my $scriptName = pop(@script);
colas@0
   207
$scriptName =~ s/.*[\/\\]//;  # Fix for Item3511, on Win XP
colas@0
   208
colas@0
   209
# Try to load the LocalLib.cfg optional overload
colas@0
   210
colas@0
   211
# Paths from LocalLib.cfg (preferred)
colas@0
   212
use vars qw( $twikiLibPath @localPerlLibPath );
colas@0
   213
colas@0
   214
eval 'require "setlib.cfg"';
colas@0
   215
colas@0
   216
if ($@) {
colas@0
   217
    # No joy. Remember the failure so we can report it later.
colas@0
   218
    $localLibFailure = $@;
colas@0
   219
    # Stick the root/lib on the path; there's a high probability we'll be
colas@0
   220
    # able to find the bits of TWiki::Configure that way. We will report
colas@0
   221
    # the setlib error later.
colas@0
   222
    unshift(@INC, File::Spec->catfile(@root, 'lib'));
colas@0
   223
}
colas@0
   224
colas@0
   225
# Load all the bits of the configure module that we explicitly use
colas@0
   226
# The loadBasicModule does some extra analysis on errors.
colas@0
   227
foreach my $module (
colas@0
   228
    'Cwd',
colas@0
   229
    'Data::Dumper',
colas@0
   230
    'File::Copy',
colas@0
   231
    'File::Temp',
colas@0
   232
    'TWiki::Configure::Checker',
colas@0
   233
    'TWiki::Configure::CSS',
colas@0
   234
    'TWiki::Configure::Item',
colas@0
   235
    'TWiki::Configure::JS',
colas@0
   236
    'TWiki::Configure::Load',
colas@0
   237
    'TWiki::Configure::Pluggable',
colas@0
   238
    'TWiki::Configure::Root',
colas@0
   239
    'TWiki::Configure::Section',
colas@0
   240
    'TWiki::Configure::Type',
colas@0
   241
    'TWiki::Configure::Types::BOOLEAN',
colas@0
   242
    'TWiki::Configure::Types::NUMBER',
colas@0
   243
    'TWiki::Configure::Types::SELECT',
colas@0
   244
    'TWiki::Configure::Types::STRING',
colas@0
   245
    'TWiki::Configure::TWikiCfg',
colas@0
   246
    'TWiki::Configure::UI',
colas@0
   247
    'TWiki::Configure::UIs::Section',
colas@0
   248
    'TWiki::Configure::Value',
colas@0
   249
    'TWiki::Configure::Valuer',
colas@0
   250
   ) {
colas@0
   251
    _loadBasicModule($module);
colas@0
   252
}
colas@0
   253
colas@0
   254
$| = 1;                  # no buffering on STDOUT
colas@0
   255
colas@0
   256
###########################################################
colas@0
   257
# From this point on we shouldn't have any more "fatal" (to configure)
colas@0
   258
# errors, so we can report errors in the browser (i.e. without using die)
colas@0
   259
colas@0
   260
# We are configuring $TWiki::cfg, so we need to be in package TWiki from
colas@0
   261
# now on.
colas@0
   262
package TWiki;
colas@0
   263
colas@0
   264
# We keep the actual config, and the default from TWiki.cfg, separate
colas@0
   265
use vars qw( %cfg $defaultCfg );
colas@0
   266
colas@0
   267
# Declared in TWiki to support checkers
colas@0
   268
use vars qw( $query );
colas@0
   269
colas@0
   270
# 'constants' used in TWiki.cfg
colas@0
   271
use vars qw( $TRUE $FALSE );
colas@0
   272
$TRUE = 1;
colas@0
   273
$FALSE = 0;
colas@0
   274
colas@0
   275
# Remember what we detected previously, for use by Checkers
colas@0
   276
if( $scriptName =~ /(\.\w+)$/ ) {
colas@0
   277
    $TWiki::cfg{DETECTED}{ScriptExtension} = $1;
colas@0
   278
}
colas@0
   279
colas@0
   280
# very basic tool
colas@0
   281
sub findFileOnPath {
colas@0
   282
    my $file = shift;
colas@0
   283
colas@0
   284
    $file =~ s(::)(/)g;
colas@0
   285
colas@0
   286
    foreach my $dir ( @INC ) {
colas@0
   287
        if ( -e "$dir/$file" ) {
colas@0
   288
            return "$dir/$file";
colas@0
   289
        }
colas@0
   290
    }
colas@0
   291
    return undef;
colas@0
   292
}
colas@0
   293
colas@0
   294
###########################################################
colas@0
   295
# Grope the OS. This duplicates a bit of code in TWiki.pm,
colas@0
   296
# but it has to be duplicated because we don't want to deal
colas@0
   297
# with loading TWiki just yet.
colas@0
   298
colas@0
   299
unless( $TWiki::cfg{DetailedOS} ) {
colas@0
   300
    $TWiki::cfg{DetailedOS} = $^O;
colas@0
   301
    unless( $TWiki::cfg{DetailedOS} ) {
colas@0
   302
        require Config;
colas@0
   303
        $TWiki::cfg{DetailedOS} = $Config::Config{osname};
colas@0
   304
    }
colas@0
   305
}
colas@0
   306
unless( $TWiki::cfg{OS} ) {
colas@0
   307
    if ($TWiki::cfg{DetailedOS} =~ /darwin/i) { # MacOS X
colas@0
   308
        $TWiki::cfg{OS} = 'UNIX';
colas@0
   309
    } elsif ($TWiki::cfg{DetailedOS} =~ /Win/i) {
colas@0
   310
        $TWiki::cfg{OS} = 'WINDOWS';
colas@0
   311
    } elsif ($TWiki::cfg{DetailedOS} =~ /vms/i) {
colas@0
   312
        $TWiki::cfg{OS} = 'VMS';
colas@0
   313
    } elsif ($TWiki::cfg{DetailedOS} =~ /bsdos/i) {
colas@0
   314
        $TWiki::cfg{OS} = 'UNIX';
colas@0
   315
    } elsif ($TWiki::cfg{DetailedOS} =~ /dos/i) {
colas@0
   316
        $TWiki::cfg{OS} = 'DOS';
colas@0
   317
    } elsif ($TWiki::cfg{DetailedOS} =~ /^MacOS$/i) { # MacOS 9 or earlier
colas@0
   318
        $TWiki::cfg{OS} = 'MACINTOSH';
colas@0
   319
    } elsif ($TWiki::cfg{DetailedOS} =~ /os2/i) {
colas@0
   320
        $TWiki::cfg{OS} = 'OS2';
colas@0
   321
    } else {
colas@0
   322
        $TWiki::cfg{OS} = 'UNIX';
colas@0
   323
    }
colas@0
   324
}
colas@0
   325
colas@0
   326
$query = new CGI;
colas@0
   327
colas@0
   328
my $url = $query->url();
colas@0
   329
my $action = $query->param('action') || 'Configure';
colas@0
   330
my $expertsMode = defined($query->param('expert'));
colas@0
   331
colas@0
   332
# Handle serving an image embedded in the configure page, before generating
colas@0
   333
# any other output
colas@0
   334
if( $action eq 'image' ) {
colas@0
   335
    # SMELL: this call is correct, but causes a perl error
colas@0
   336
    # on some versions of CGI.pm
colas@0
   337
    # print $query->header(-type => $query->param('type'));
colas@0
   338
    # So use this instead:
colas@0
   339
    print 'Content-type: '.$query->param('type')."\n\n";
colas@0
   340
    if( open(F, 'logos/'.$query->param('image' ))) {
colas@0
   341
        local $/ = undef;
colas@0
   342
        print <F>;
colas@0
   343
        close(F);
colas@0
   344
    }
colas@0
   345
    exit 0;
colas@0
   346
}
colas@0
   347
colas@0
   348
my @meta = (
colas@0
   349
    CGI::meta({ 'http-equiv'=>'Pragma', content=>'no-cache' }),
colas@0
   350
    CGI::meta({ 'http-equiv'=>'Cache-Control', content=>'no-cache' }),
colas@0
   351
    CGI::meta({ 'http-equiv'=>'Expires', content=>0 }),
colas@0
   352
    CGI::meta({ name=>'robots', content=>'noindex' }),
colas@0
   353
    CGI::Link( { -rel=>'icon',
colas@0
   354
                 -href=>$scriptName.'?action=image;image=favicon.ico;type=image/x-icon',
colas@0
   355
                 -type=>'image/x-icon' } ),
colas@0
   356
    CGI::Link(
colas@0
   357
        { -rel=>'shortcut icon',
colas@0
   358
          -href=>$scriptName.'?action=image;image=logos/favicon.ico;type=image/x-icon',
colas@0
   359
          -type=>'image/x-icon' } ),
colas@0
   360
    CGI::script( { language => 'JavaScript',
colas@0
   361
                   type => 'text/javascript' }, TWiki::Configure::JS::js1() ),
colas@0
   362
    CGI::style( { -type=>'text/css' }, TWiki::Configure::CSS::css()),
colas@0
   363
    CGI::script( { language => 'JavaScript',
colas@0
   364
                   type => 'text/javascript' },
colas@0
   365
                 TWiki::Configure::JS::js2() ),
colas@0
   366
   );
colas@0
   367
colas@0
   368
# Generate standard page header
colas@0
   369
my $hdr = CGI::start_html(
colas@0
   370
    -title => 'TWiki Configuration',
colas@0
   371
    -head => \@meta,
colas@0
   372
    -class => 'patternNoViewPage');
colas@0
   373
colas@0
   374
# XML header confuses IE, so strip it out. This is fixed in CGI.pm 3.06
colas@0
   375
# (and IE 7, but who's counting?)
colas@0
   376
if ($CGI::VERSION < 3.06) {
colas@0
   377
    $hdr =~ s/^<\?xml.*?>//s;
colas@0
   378
}
colas@0
   379
print CGI::header('text/html'). $hdr;
colas@0
   380
colas@0
   381
print <<'HERE';
colas@0
   382
<div id="patternScreen">
colas@0
   383
 <div id="patternPageShadow">
colas@0
   384
  <div id="patternPage">
colas@0
   385
   <div id="patternOuter">
colas@0
   386
    <div id="patternFloatWrap">
colas@0
   387
     <div id="patternMain">
colas@0
   388
      <div id="patternMainContents">
colas@0
   389
HERE
colas@0
   390
colas@0
   391
# use this script recursively to serve the icon image
colas@0
   392
print CGI::img({src=>$scriptName.'?action=image;image=T-logo-140x40-t.gif;type=image/gif', class=>'logo', alt=>'TWiki', width=>'140', height=>'40'});
colas@0
   393
colas@0
   394
my $stub = new TWiki::Configure::Item();
colas@0
   395
my $sanityUI = TWiki::Configure::UI::loadChecker('BasicSanity', $stub);
colas@0
   396
my ($sanityStatement, $badLSC) = $sanityUI->ui();
colas@0
   397
colas@0
   398
# This is the dispatcher; $action is the name of the action to perform,
colas@0
   399
# this is concatenated to _action to determine the name of the procedure.
colas@0
   400
# Dispatcher methods return a boolean to indicate whether to generate a
colas@0
   401
# link back to the main page at the end.
colas@0
   402
if ($sanityUI->insane() || $query->param('abort')) {
colas@0
   403
    print $sanityStatement;
colas@0
   404
} else {
colas@0
   405
colas@0
   406
    $action =~ s/\W//g;
colas@0
   407
    my $method = '_action'.$action;
colas@0
   408
colas@0
   409
    die "Undefined action $action" unless defined(&$method);
colas@0
   410
colas@0
   411
    no strict 'refs';
colas@0
   412
    my $reroute = &$method();
colas@0
   413
    use strict 'refs';
colas@0
   414
colas@0
   415
    if ($reroute) {
colas@0
   416
        print '<div>';
colas@0
   417
        print CGI::a( { href=>$scriptName.'?t='.time(),
colas@0
   418
                        rel => 'nofollow' },
colas@0
   419
                      'Return to configuration');
colas@0
   420
        print CGI::br();
colas@0
   421
        print "</div>\n";
colas@0
   422
    }
colas@0
   423
}
colas@0
   424
colas@0
   425
print <<'HERE';
colas@0
   426
</div><!--/patternMainContents-->
colas@0
   427
</div><!--/patternMain-->
colas@0
   428
</div><!--/patternFloatWrap-->
colas@0
   429
<div class="clear">&nbsp;</div>
colas@0
   430
</div><!--/patternOuter-->
colas@0
   431
</div><!--/patternPage-->
colas@0
   432
</div><!--/patternPageShadow-->
colas@0
   433
</div><!--/patternScreen-->
colas@0
   434
HERE
colas@0
   435
colas@0
   436
print CGI::end_html(),"\n";
colas@0
   437
colas@0
   438
###########################################################
colas@0
   439
# End of the main program; the rest is all subs
colas@0
   440
colas@0
   441
sub _checkLoadUI {
colas@0
   442
    my ($uiname, $root) = @_;
colas@0
   443
    my $ui = TWiki::Configure::UI::loadUI($uiname, $root);
colas@0
   444
    unless ($ui) {
colas@0
   445
        print "Could not load $uiname UI. Error was: <pre>$@</pre>";
colas@0
   446
        if ($@ =~ /Can't locate (\S+)/) {
colas@0
   447
            print <<HERE
colas@0
   448
You may be able to correct this error by installing the missing $1 module.
colas@0
   449
HERE
colas@0
   450
        }
colas@0
   451
    }
colas@0
   452
    return $ui;
colas@0
   453
}
colas@0
   454
colas@0
   455
# Action invoked by 'Next' button on the main screen
colas@0
   456
sub _actionNext {
colas@0
   457
    my $valuer = new TWiki::Configure::Valuer(
colas@0
   458
        $TWiki::defaultCfg, \%TWiki::cfg);
colas@0
   459
    my %updated;
colas@0
   460
    my $modified = $valuer->loadCGIParams($TWiki::query, \%updated);
colas@0
   461
colas@0
   462
    # create the root of the UI
colas@0
   463
    my $root = new TWiki::Configure::Root();
colas@0
   464
    my $ui;
colas@0
   465
    if (!TWiki::Configure::UI::authorised()) {
colas@0
   466
        print CGI::h2('Authorisation is required to save.');
colas@0
   467
        print CGI::div($modified.' configuration item'.
colas@0
   468
                         ($modified==1?' was':'s were').' changed');
colas@0
   469
        if ($modified) {
colas@0
   470
            print CGI::div(join(' ', keys %updated));
colas@0
   471
        }
colas@0
   472
        $ui = _checkLoadUI('AUTH', $root);
colas@0
   473
        return 1 unless $ui;
colas@0
   474
        print $ui->ui(1, 'Save');
colas@0
   475
    } else {
colas@0
   476
        # Load the specs from the .spec files and generate the UI template
colas@0
   477
        TWiki::Configure::TWikiCfg::load($root, 1);
colas@0
   478
colas@0
   479
        $ui = _checkLoadUI('UPDATE', $root);
colas@0
   480
        return 1 unless $ui;
colas@0
   481
        print $ui->ui($root, $valuer, \%updated);
colas@0
   482
    }
colas@0
   483
    return 1;
colas@0
   484
}
colas@0
   485
colas@0
   486
# Invoked by "find more extensions" button in the Extensions section
colas@0
   487
sub _actionFindMoreExtensions {
colas@0
   488
    my $root = new TWiki::Configure::Root();
colas@0
   489
    print CGI::h1( 'Find TWiki Extensions');
colas@0
   490
    print '<div class="patternContent"><div class="patternTopic">';
colas@0
   491
colas@0
   492
    my $ui = _checkLoadUI('EXTENSIONS',$root);
colas@0
   493
    return 1 unless $ui;
colas@0
   494
colas@0
   495
    print $ui->ui();
colas@0
   496
    return 1;
colas@0
   497
}
colas@0
   498
colas@0
   499
# Invoked when an extension is to be installed
colas@0
   500
sub _actionInstallExtension {
colas@0
   501
    my $root = new TWiki::Configure::Root();
colas@0
   502
    my $ui;
colas@0
   503
    if (!TWiki::Configure::UI::authorised()) {
colas@0
   504
        $ui = _checkLoadUI('AUTH', $root);
colas@0
   505
        return 1 unless $ui;
colas@0
   506
        print $ui->ui(0, 'Install '.($query->param('extension')||''));
colas@0
   507
    } else {
colas@0
   508
        $ui = _checkLoadUI('EXTEND', $root);
colas@0
   509
        return 1 unless $ui;
colas@0
   510
        print $ui->ui();
colas@0
   511
    }
colas@0
   512
    return 1;
colas@0
   513
}
colas@0
   514
colas@0
   515
# This is the default screen
colas@0
   516
sub _actionConfigure {
colas@0
   517
colas@0
   518
    $TWiki::Configure::UI::toterrors = 0;
colas@0
   519
    $TWiki::Configure::UI::totwarnings = 0;
colas@0
   520
colas@0
   521
    print CGI::h1( 'Configuration');
colas@0
   522
    print $sanityStatement;
colas@0
   523
colas@0
   524
    # The first three sections go without a root
colas@0
   525
    my $stub = new TWiki::Configure::Item();
colas@0
   526
    my $eui = TWiki::Configure::UI::loadChecker('Environment', $stub);
colas@0
   527
colas@0
   528
    # See if this platform has special detection or checking requirements
colas@0
   529
    # (most don't)
colas@0
   530
    $stub = new TWiki::Configure::Item();
colas@0
   531
    my $osui = TWiki::Configure::UI::loadChecker(
colas@0
   532
        $Config::Config{osname}, $stub);
colas@0
   533
colas@0
   534
    $stub = new TWiki::Configure::Item();
colas@0
   535
    my $cgiui = TWiki::Configure::UI::loadChecker('CGISetup', $stub);
colas@0
   536
colas@0
   537
    # Use a separate root for the _saveable_ sections
colas@0
   538
    my $root = new TWiki::Configure::Root();
colas@0
   539
    my $valuer = new TWiki::Configure::Valuer(
colas@0
   540
        $TWiki::defaultCfg, \%TWiki::cfg);
colas@0
   541
colas@0
   542
    # Load the config structures.
colas@0
   543
    TWiki::Configure::TWikiCfg::load($root, !$badLSC);
colas@0
   544
colas@0
   545
    if (!$badLSC) {
colas@0
   546
        print <<HERE;
colas@0
   547
<div class="patternContent">
colas@0
   548
 <div class="patternTopic">
colas@0
   549
  <p><strong>Use this page to set the configuration options for TWiki.
colas@0
   550
  Fill in the settings, and then press 'Next'.</strong></p>
colas@0
   551
  <div class="explanation">
colas@0
   552
   <ul>
colas@0
   553
    <li><b>If your TWiki site is already working</b>, continue to
colas@0
   554
     <a rel="nofollow" href="$TWiki::cfg{ScriptUrlPath}/view$TWiki::cfg{ScriptSuffix}/$TWiki::cfg{SystemWebName}/WebHome">
colas@0
   555
browse to the TWiki WebHome</a>.
colas@0
   556
     <ul>
colas@0
   557
      <li>You will now need to consider how you are going to manage
colas@0
   558
       authentication and access control. See the reference manual
colas@0
   559
       sections on <a rel="nofollow" href="$TWiki::cfg{ScriptUrlPath}/view$TWiki::cfg{ScriptSuffix}/$TWiki::cfg{SystemWebName}/TWikiUserAuthentication">
colas@0
   560
 authentication</a>
colas@0
   561
       and
colas@0
   562
       <a rel="nofollow" href="$TWiki::cfg{ScriptUrlPath}/view$TWiki::cfg{ScriptSuffix}/$TWiki::cfg{SystemWebName}/TWikiAccessControl">
colas@0
   563
        access control</a>, and the
colas@0
   564
       <a rel="nofollow" href="#" onclick="foldBlock('SecuritySetup'); return false;">Security Setup</a>
colas@0
   565
       section below.
colas@0
   566
      </li>
colas@0
   567
     </ul>
colas@0
   568
    </li>
colas@0
   569
    <li><b>To become an administrator</b> you need to first <a rel="nofollow" href="$TWiki::cfg{ScriptUrlPath}/view$TWiki::cfg{ScriptSuffix}/$TWiki::cfg{SystemWebName}/TWikiRegistration">
colas@0
   570
register</a> as a normal user first and then add your wikiname to the <a rel="nofollow" href="$TWiki::cfg{ScriptUrlPath}/view$TWiki::cfg{ScriptSuffix}/$TWiki::cfg{UsersWebName}/$TWiki::cfg{SuperAdminGroup}">
colas@0
   571
 $TWiki::cfg{SuperAdminGroup}</a> (follow the text in yellow).
colas@0
   572
    </li>
colas@0
   573
    <li>
colas@0
   574
     <b>If you are on a non-standard platform or environment</b> there are a lot of
colas@0
   575
     <a href="http://twiki.org/cgi-bin/view/TWiki/SupplementalDocument">supplemental documents</a>
colas@0
   576
     on TWiki.org describing how to
colas@0
   577
     <a href="http://twiki.org/cgi-bin/view/TWiki/InstallingTWiki">install</a>,
colas@0
   578
     <a href="http://twiki.org/cgi-bin/view/TWiki/UpgradingTWiki">upgrade</a>, 
colas@0
   579
     <a href="http://twiki.org/cgi-bin/view/TWiki/InternationalizationSupplement">internationalize</a> and 
colas@0
   580
     <a href="http://twiki.org/cgi-bin/view/TWiki/SecuringTWikiSite">secure</a>
colas@0
   581
     your installation.
colas@0
   582
    </li>
colas@0
   583
    <li>
colas@0
   584
      <b>If you get stuck</b> there is a lot of support available at the
colas@0
   585
      <a href="http://twiki.org/cgi-bin/view/Support/WebHome">TWiki:Support</a>
colas@0
   586
      forum and on
colas@0
   587
      <a href="http://twiki.org/cgi-bin/view/Codev/TWikiIRC">TWikiIRC</a>
colas@0
   588
      (irc.freenode.net, channel #twiki).
colas@0
   589
     </li>
colas@0
   590
    </ul>
colas@0
   591
   </div>
colas@0
   592
   <div class="remark">Explanation of colours and symbols:
colas@0
   593
    <ul style="margin-top:0;">
colas@0
   594
     <li>Settings marked <span class='mandatory'>like this</span> are required
colas@0
   595
      (they must have a value).</li>
colas@0
   596
     <li>Any <span class='error'>errors</span> in your configuration will be
colas@0
   597
      highlighted.</li>
colas@0
   598
     <li><span class='warn'>Warnings</span> are non-fatal, but are often a good
colas@0
   599
      indicator that something that is wrong.</li>
colas@0
   600
     <li>The little <span class='twikiAlert' title="Not here, stupid. In the table below!">&delta;</span> after an entry means that the current value is <b>not</b> the same as the default value. If you hover the cursor over the <span class='twikiAlert' title="Not here, stupid. In the table below!">&delta;</span>, a popup will show you what the default value is.</li>
colas@0
   601
     <li><b><font color="#f00">EXPERT</font></b> means a setting is for expert use only. You should not fiddle with it unless you know what you are doing, or at least have read all the documentation.
colas@0
   602
HERE
colas@0
   603
        if (!$expertsMode) {
colas@0
   604
            print <<HERE
colas@0
   605
 EXPERT options are hidden unless you click the <form><input type="submit" style="background-color:#eef" value="Yes, I've read all the documentation"/><input type="hidden" name="t" value="@{[time()]}" /><input type="hidden" name="expert" value="1" /></form> button.
colas@0
   606
HERE
colas@0
   607
}
colas@0
   608
        print <<HERE;
colas@0
   609
     </li>
colas@0
   610
    </ul>
colas@0
   611
   </div><!-- remark-->
colas@0
   612
  </div><!--explanation-->
colas@0
   613
HERE
colas@0
   614
    }
colas@0
   615
    print CGI::start_form({ name=>'update',
colas@0
   616
                            action=>$scriptName,
colas@0
   617
                            method=>"post" });
colas@0
   618
    # use time to make sure we never allow cacheing
colas@0
   619
    print CGI::hidden( 'time', time() );
colas@0
   620
colas@0
   621
    print '<div class="options" id="options">';
colas@0
   622
    print CGI::div(
colas@0
   623
        { class => 'optionHeader' },
colas@0
   624
        CGI::span(
colas@0
   625
            'Settings'
colas@0
   626
              . CGI::span(
colas@0
   627
                { class => 'twikiSmall' },
colas@0
   628
                'Click the buttons below to open each section'
colas@0
   629
              )
colas@0
   630
          )
colas@0
   631
          . '&nbsp;'
colas@0
   632
          . CGI::span(
colas@0
   633
            { class => 'twikiSmall' },
colas@0
   634
            CGI::a(
colas@0
   635
                {
colas@0
   636
                    href    => '#',
colas@0
   637
                    rel     => 'nofollow',
colas@0
   638
                    onclick => 'toggleAllOptions(true); return false;'
colas@0
   639
                },
colas@0
   640
                'Open all options'
colas@0
   641
            )
colas@0
   642
          )
colas@0
   643
    );
colas@0
   644
colas@0
   645
    print $eui->ui();
colas@0
   646
    print $osui->ui() if $osui;
colas@0
   647
    print $cgiui->ui() if $cgiui;
colas@0
   648
colas@0
   649
    # Load the UI for the configuration and whack it out
colas@0
   650
    my $ui = _checkLoadUI('Root', $root);
colas@0
   651
    return 1 unless $ui;
colas@0
   652
    $ui->{experts} = $expertsMode;
colas@0
   653
    print $ui->ui($root, $valuer);
colas@0
   654
colas@0
   655
    print "</div><!-- options -->\n";
colas@0
   656
colas@0
   657
    if ($TWiki::Configure::UI::toterrors ||
colas@0
   658
          $TWiki::Configure::UI::totwarnings) {
colas@0
   659
        my $mess = 'Total: '.$TWiki::Configure::UI::toterrors.' error'.
colas@0
   660
          ($TWiki::Configure::UI::toterrors==1?'':'s').', '.
colas@0
   661
            $TWiki::Configure::UI::totwarnings.' warning'.
colas@0
   662
              ($TWiki::Configure::UI::totwarnings==1?'':'s');
colas@0
   663
        print CGI::div($mess);
colas@0
   664
    }
colas@0
   665
colas@0
   666
    print CGI::p(CGI::submit(-class=>'twikiSubmit',
colas@0
   667
                             -name=>'action',
colas@0
   668
                             -value=>'Next',
colas@0
   669
                             -accesskey=>'N'));
colas@0
   670
colas@0
   671
    print "<a href=\"$TWiki::cfg{ScriptUrlPath}/view$TWiki::cfg{ScriptSuffix}/$TWiki::cfg{SystemWebName}/WebHome\">Cancel and return to TWiki WebHome</a>";
colas@0
   672
colas@0
   673
    print CGI::end_form();
colas@0
   674
colas@0
   675
    print <<DIVS;
colas@0
   676
 </div><!--/patternTopic-->
colas@0
   677
</div><!--/patternContent-->
colas@0
   678
DIVS
colas@0
   679
    return 0;
colas@0
   680
}
colas@0
   681
colas@0
   682
1;
colas@0
   683