From: sven d. <sv...@us...> - 2003-12-04 10:09:02
|
Update of /cvsroot/twiki/twiki/bin In directory sc8-pr-cvs1:/tmp/cvs-serv5960/bin Modified Files: installpasswd passwd register Log Message: moved over code from register to TWiki/User.pm Index: installpasswd =================================================================== RCS file: /cvsroot/twiki/twiki/bin/installpasswd,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** installpasswd 3 Dec 2003 13:03:07 -0000 1.10 --- installpasswd 4 Dec 2003 10:08:56 -0000 1.11 *************** *** 111,115 **** # OK - password may be changed my $oldCryptPassword = "$wikiName\:$oldcrypt"; ! TWiki::User::htpasswdAddUser( $oldCryptPassword, $theCryptPassword ); # OK - password changed --- 111,115 ---- # OK - password may be changed my $oldCryptPassword = "$wikiName\:$oldcrypt"; ! TWiki::User::htpasswdUpdateUser( $oldCryptPassword, $theCryptPassword ); # OK - password changed Index: passwd =================================================================== RCS file: /cvsroot/twiki/twiki/bin/passwd,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -r1.13 -r1.14 *** passwd 3 Dec 2003 13:17:44 -0000 1.13 --- passwd 4 Dec 2003 10:08:58 -0000 1.14 *************** *** 1,3 **** ! #!/usr/bin/perl -wT # # TWiki Collaboration Platform, http://TWiki.org/ --- 1,3 ---- ! add#!/usr/bin/perl -wT # # TWiki Collaboration Platform, http://TWiki.org/ *************** *** 136,140 **** # OK - password may be changed my $oldCryptPassword = "$wikiName\:$oldcrypt"; ! TWiki::User::htpasswdAddUser( $oldCryptPassword, $theCryptPassword ); # OK - password changed --- 136,140 ---- # OK - password may be changed my $oldCryptPassword = "$wikiName\:$oldcrypt"; ! TWiki::User::htpasswdUpdateUser( $oldCryptPassword, $theCryptPassword ); # OK - password changed Index: register =================================================================== RCS file: /cvsroot/twiki/twiki/bin/register,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -r1.40 -r1.41 *** register 23 Nov 2003 17:13:36 -0000 1.40 --- register 4 Dec 2003 10:08:58 -0000 1.41 *************** *** 36,46 **** use TWiki::Net; use TWiki::Plugins; ! ! if( $TWiki::OS eq "WINDOWS" ) { ! require MIME::Base64; ! import MIME::Base64 qw( encode_base64 ); ! require Digest::SHA1; ! import Digest::SHA1 qw( sha1 ); ! } &main(); --- 36,40 ---- use TWiki::Net; use TWiki::Plugins; ! use TWiki::User; &main(); *************** *** 102,106 **** if( ( $wikiName ) && ( ( &TWiki::Store::topicExists( $webName, $wikiName ) ) ! || ( htpasswdExistUser( $wikiName ) ) ) ) { # PTh 20 Jun 2000: changed to getOopsUrl --- 96,100 ---- if( ( $wikiName ) && ( ( &TWiki::Store::topicExists( $webName, $wikiName ) ) ! || ( TWiki::User::htpasswdExistUser( $wikiName ) ) ) ) { # PTh 20 Jun 2000: changed to getOopsUrl *************** *** 150,154 **** # generate user entry and add to .htpasswd file if( ! $remoteUser ) { ! htpasswdAddUser( htpasswdGeneratePasswd( $wikiName, $passwordA ) ); } --- 144,148 ---- # generate user entry and add to .htpasswd file if( ! $remoteUser ) { ! TWiki::User::htpasswdAddUser( TWiki::User::htpasswdGeneratePasswd( $wikiName, $passwordA ) ); } *************** *** 218,222 **** # add user to TWikiUsers topic ! my $userTopic = addUserToTWikiUsersTopic( $wikiName, $remoteUser ); # write log entry --- 212,216 ---- # add user to TWikiUsers topic ! my $userTopic = TWiki::User::addUserToTWikiUsersTopic( $wikiName, $remoteUser ); # write log entry *************** *** 235,341 **** } - sub htpasswdGeneratePasswd - { - my ( $user, $passwd ) = @_; - - # Original code by David Levy, Internet Channel, 1997, - # found at http://world.inch.com/Scripts/htpasswd.pl.html - - # Generate SHA1 passwords on Windows - like 'htpasswd -s' - if ( $TWiki::OS eq "WINDOWS" ) { - my $userEntry; - $userEntry = $user . ':{SHA}' . encode_base64( sha1( $passwd ) ); - chomp $userEntry; # Chop unwanted newline - return $userEntry; - } - # Use 'crypt' on all other platforms (assumed to be Unix/Linux) - srand( $$|time ); - my @saltchars = ( 'a'..'z', 'A'..'Z', '0'..'9', '.', '/' ); - my $salt = $saltchars[ int( rand( $#saltchars+1 ) ) ]; - $salt .= $saltchars[ int( rand( $#saltchars+1 ) ) ]; - my $passwdcrypt = crypt( $passwd, $salt ); - return "$user\:$passwdcrypt"; - } - - sub htpasswdExistUser - { - my ( $user ) = @_; - - if( ! $user ) { - return ""; - } - - my $text = &TWiki::Store::readFile( $TWiki::htpasswdFilename ); - - if( $text =~ /^${user}:/gm ) { # mod_perl: don't use /o - return "1"; - } - return ""; - } - - sub htpasswdAddUser - { - my ( $userEntry ) = @_; - - # can't use `htpasswd $wikiName` because htpasswd doesn't understand stdin - # simply add name to file, but this is a security issue - my $text = &TWiki::Store::readFile( $TWiki::htpasswdFilename ); - ##TWiki::writeDebug "User entry is :$userEntry: before newline"; - $text .= "$userEntry\n"; - &TWiki::Store::saveFile( $TWiki::htpasswdFilename, $text ); - } - - sub addUserToTWikiUsersTopic - { - my ( $wikiName, $remoteUser ) = @_; - my $today = &TWiki::getGmDate(); - my $topicName = $TWiki::wikiUsersTopicname; - my( $meta, $text ) = &TWiki::Store::readTopic( $TWiki::mainWebname, $topicName ); - my $result = ""; - my $status = "0"; - my $line = ""; - my $name = ""; - my $isList = ""; - # add name alphabetically to list - foreach( split( /\n/, $text) ) { - $line = $_; - # TODO: I18N fix here once basic auth problem with 8-bit user names is - # solved - $isList = ( $line =~ /^\t\*\s[A-Z][a-zA-Z0-9]*\s\-/go ); - if( ( $status == "0" ) && ( $isList ) ) { - $status = "1"; - } - if( $status == "1" ) { - if( $isList ) { - $name = $line; - $name =~ s/(\t\*\s)([A-Z][a-zA-Z0-9]*)\s\-.*/$2/go; - if( $wikiName eq $name ) { - # name is already there, do nothing - return $topicName; - } elsif( $wikiName lt $name ) { - # found alphabetical position - if( $remoteUser ) { - $result .= "\t* $wikiName - $remoteUser - $today\n"; - } else { - $result .= "\t* $wikiName - $today\n"; - } - $status = "2"; - } - } else { - # is last entry - if( $remoteUser ) { - $result .= "\t* $wikiName - $remoteUser - $today\n"; - } else { - $result .= "\t* $wikiName - $today\n"; - } - $status = "2"; - } - } - - $result .= "$line\n"; - } - &TWiki::Store::saveTopic( $TWiki::mainWebname, $topicName, $result, $meta, "", 1 ); - return $topicName; - } # EOF --- 229,232 ---- |