Skip to content

Commit

Permalink
Item13081: Add the super user password to configure
Browse files Browse the repository at this point in the history
This is an initial pass - probably needs some re-thinking,   but without
it, the user is left without any way to use the web configuration tool.
  • Loading branch information
gac410 committed Nov 8, 2014
1 parent ffa59a9 commit 760c052
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions core/tools/configure
Expand Up @@ -135,10 +135,16 @@ if ( $params->{save} ) {
}

sub _prompt {
my ( $root, $keys, $default ) = @_;
my $vob = $root->getValueObject($keys);
if ( $vob && $vob->{desc} ) {
print "$vob->{desc}\n";
my ( $root, $keys, $default, $prompt ) = @_;

if ($prompt) {
print $prompt;
}
else {
my $vob = $root->getValueObject($keys);
if ( $vob && $vob->{desc} ) {
print "$vob->{desc}\n";
}
}
local $/ = "\n";
my $reply = '';
Expand All @@ -150,13 +156,37 @@ sub _prompt {
chomp($reply);
$reply ||= $default;
}
if ( $keys eq '{Password}' ) {
$reply = _setPassword( 'admin', $reply );
}
eval "\$Foswiki::cfg$keys='$reply'";
if ($@) {
print STDERR "Failed to set $keys: "
. Foswiki::Configure::Reporter::stripStacktrace($@);
}
}

sub _setPassword {
my ( $login, $passwd ) = @_;
my $salt = '$apr1$';
my @saltchars = ( '.', '/', 0 .. 9, 'A' .. 'Z', 'a' .. 'z' );
require Crypt::PasswdMD5;
foreach my $i ( 0 .. 7 ) {

# generate a salt not only from rand() but also mixing
# in the users login name: unecessary
$salt .= $saltchars[
(
int( rand( $#saltchars + 1 ) ) +
$i +
ord( substr( $login, $i % length($login), 1 ) ) )
% ( $#saltchars + 1 )
];
}
return Crypt::PasswdMD5::apache_md5_crypt( $passwd,
substr( $salt, 0, 14 ) );
}

sub _reply {
my $response = shift;

Expand Down Expand Up @@ -198,6 +228,8 @@ unless ( $Foswiki::cfg{isVALID} ) {
print STDERR "LocalSite.cfg load failed\n"
. Foswiki::Configure::Reporter::stripStacktrace($@);
Foswiki::Configure::Load::readConfig( 0, 0, 1 );
Foswiki::Configure::Load::setBootstrap();

print "** Enter values for critical configuration items.\n";
print
"** type a new value or hit return to accept the value in brackets.\n";
Expand All @@ -212,7 +244,17 @@ unless ( $Foswiki::cfg{isVALID} ) {
_prompt( $root, '{WorkingDir}', "$bin/../working" );
_prompt( $root, '{ToolsDir}', $bin );

Foswiki::Configure::Load::setBootstrap();
eval 'use Crypt::PasswdMD5';
unless ($@) {
_prompt( $root, '{Password}', undef,
"Enter a password for the 'admin' sudo account.\n" );
push( @{ $Foswiki::cfg{BOOTSTRAP} }, '{Password}' );
}
else {
print
"*** Unable to set password - Module Crypt::PasswdMD5 is not available\n";
}

$Foswiki::cfg{isVALID} = 1;
}

Expand Down

0 comments on commit 760c052

Please sign in to comment.