This patch should take a UserId? from Apache (using any Apache Auth scheme) and use that as the username, rather than asking a user to set their own name and password. This takes /LoginAndPasswordsFromApache to the next obvious step. You don't need that patch for this one, but I'm not positive how well this works without that one. I stole some of this patch from that one...
TravisCB?
Usage:
Bugs/Enhancements?:
--- wiki.pl 2006-07-27 09:11:53.000000000 -0700
+++ wikilogin3.pl 2006-07-27 09:13:58.000000000 -0700
@@ -436,12 +436,17 @@
undef $q->{'.cookies'}; # Clear cache if it exists (for SpeedyCGI)
%UserData = (); # Fix for persistent environments.
%UserCookie = $q->cookie($CookieName);
- $UserID = $UserCookie{'id'};
- $UserID =~ s/\D//g; # Numeric only
+ $UserID= '10000'.$ENV{'REMOTE_USER'};
+
+ if ( $UserID=~/^10000$/){
+ $UserID = $UserCookie{'id'};
+ $UserID =~ s/\D//g; # Numeric only
+ }
+ warn "Found UserID-> $UserID\n";
if ($UserID < 200) {
$UserID = 111;
} else {
- &LoadUserData($UserID);
+ &LoadUserData($UserID);
}
if ($UserID > 199) {
if (($UserData{'id'} != $UserCookie{'id'}) ||
@@ -2448,7 +2552,7 @@
$Section{'ts'} = $Now; # Updated every edit
$Section{'ip'} = $ENV{REMOTE_ADDR};
$Section{'id'} = $UserID;
- $Section{'username'} = &GetParam("username", "");
+ $Section{'username'} = &UserName();
$Section{'data'} = $data;
$Page{$name} = join($FS2, %Section);
}
@@ -2794,28 +2802,27 @@
}
sub UserIsAdmin {
- my (@pwlist, $userPassword);
-
+ my $userName=$ENV{REMOTE_USER};
+ return 0 unless $userName;
+ #ADminPass is just list of auth usernames
return 0 if ($AdminPass eq "");
- $userPassword = &GetParam("adminpw", "");
- return 0 if ($userPassword eq "");
+ return 0 if ($userName eq "");
foreach (split(/\s+/, $AdminPass)) {
next if ($_ eq "");
- return 1 if ($userPassword eq $_);
+ return 1 if ($userName eq $_);
}
return 0;
}
sub UserIsEditor {
- my (@pwlist, $userPassword);
-
+ my $userName=$ENV{REMOTE_USER};
+ return 0 unless $userName;
return 1 if (&UserIsAdmin()); # Admin includes editor
return 0 if ($EditPass eq "");
- $userPassword = &GetParam("adminpw", ""); # Used for both
- return 0 if ($userPassword eq "");
+ return 0 if ($userName eq "");
foreach (split(/\s+/, $EditPass)) {
next if ($_ eq "");
- return 1 if ($userPassword eq $_);
+ return 1 if ($userName eq $_);
}
return 0;
}
@@ -3365,7 +3372,7 @@
print T($EditNote) . '<br>'; # Allow translation
}
print $q->submit(-name=>'Save', -value=>T('Save')), "\n";
- $userName = &GetParam("username", "");
+ $userName = &UserName();
if ($userName ne "") {
print ' (', T('Your user name is'), ' ',
&GetPageLink($userName) . ') ';
@@ -3426,22 +3433,12 @@
print &GetFormStart();
print GetHiddenValue("edit_prefs", 1), "\n";
print '<b>' . T('User Information:') . "</b>\n";
- print '<br>' . Ts('Your User ID number: %s', $UserID) . "\n";
- print '<br>' . T('UserName:') . ' ', &GetFormText('username', "", 20, 50);
- print ' ' . T('(blank to remove, or valid page name)');
- print '<br>' . T('Set Password:') . ' ',
- $q->password_field(-name=>'p_password', -value=>'*',
- -size=>15, -maxlength=>50),
- ' ', T('(blank to remove password)'), '<br>(',
- T('Passwords allow sharing preferences between multiple systems.'),
- ' ', T('Passwords are completely optional.'), ')';
- if (($AdminPass ne '') || ($EditPass ne '')) {
- print '<br>', T('Administrator Password:'), ' ',
- $q->password_field(-name=>'p_adminpw', -value=>'*',
- -size=>15, -maxlength=>50),
- ' ', T('(blank to remove password)'), '<br>',
- T('(Administrator passwords are used for special maintenance.)');
- }
+
+ my $name=$UserID;
+ $name=~s/10000//;
+ print '<br>' . Ts('Your UserName is: %s', $name) . "\n";
+
+
if ($EmailNotify) {
print "<br>";
print &GetFormCheck('notify', 1,
@@ -3541,6 +3538,7 @@
return;
}
$username = &GetParam("p_username", "");
+ $username = $ENV{'REMOTE_USER'} if $username =~ /^\s*$/;
if ($FreeLinks) {
$username =~ s/^\[\[(.+)\]\]/$1/; # Remove [[ and ]] if added
$username = &FreeToNormal($username);
@@ -3697,17 +3695,24 @@
sub DoNewLogin {
# Consider warning if cookie already exists
# (maybe use "replace=1" parameter)
- &CreateUserDir();
- $SetCookie{'id'} = &GetNewUserId();
+
+ $UserID= '10000'.$ENV{'REMOTE_USER'};
+ if ($UserID=~/^10000$/){
+ $UserID=&GetNewUserId();
+ }
+ &CreateUserDir($UserID);
+ $SetCookie{'id'} = $UserID;
$SetCookie{'randkey'} = int(rand(1000000000));
$SetCookie{'rev'} = 1;
%UserCookie = %SetCookie;
- $UserID = $SetCookie{'id'};
# The cookie will be transmitted in the next header
%UserData = %UserCookie;
$UserData{'createtime'} = $Now;
$UserData{'createip'} = $ENV{REMOTE_ADDR};
&SaveUserData();
+
+ my $fname = "$DataDir/usermap";
+ &AppendStringToFile($fname, $UserID . ':' . $ENV{'REMOTE_USER'} . "\n");
}
sub DoEnterLogin {
@@ -3731,15 +3736,19 @@
my ($uid, $password, $success);
$success = 0;
- $uid = &GetParam("p_userid", "");
- $uid =~ s/\D//g;
- $password = &GetParam("p_password", "");
+ $uid= '10000'.$ENV{'REMOTE_USER'};
+ $password='apache_auth';
+ if ( $uid=~/^10000$/){
+ $uid = &GetParam("p_userid", "");
+ $uid =~ s/\D//g;
+ $password = &GetParam("p_password", "");
+ }
if (($uid > 199) && ($password ne "") && ($password ne "*")) {
$UserID = $uid;
&LoadUserData();
if ($UserID > 199) {
- if (defined($UserData{'password'}) &&
- ($UserData{'password'} eq $password)) {
+ if (defined($UserData{'password'}) &&
+ ($UserData{'password'} eq CryptPass($EditPass, $password))) {
$SetCookie{'id'} = $uid;
$SetCookie{'randkey'} = $UserData{'randkey'};
$SetCookie{'rev'} = 1;
@@ -3964,7 +4077,7 @@
&DoEdit($id, 0, $pgtime, $string, 1);
return;
}
- $user = &GetParam("username", "");
+ $user = &UserName();
# If the person doing editing chooses, send out email notification
if ($EmailNotify) {
&EmailNotify($id, $user) if &GetParam("do_email_notify", "") eq 'on';
@@ -5089,6 +5202,12 @@
print Ts('Recommended $StartUID setting is %s.', $maxID + 100) . '<br>';
print &GetCommonFooter();
}
+sub UserName {
+ my ($userName);
+ $userName = &GetParam("username", "");
+ $userName = ucfirst($ENV{'REMOTE_USER'}) if $userName =~ /^\s*$/;
+ return $userName;
+}
#END_OF_OTHER_CODE
&DoWikiRequest() if ($RunCGI && ($_ ne 'nocgi')); # Do everything.