API for anonymous access

This commit is contained in:
Jamie Cameron
2008-04-11 23:39:05 +00:00
parent aa5d4099ab
commit 0eafb60ceb
2 changed files with 51 additions and 0 deletions

View File

@@ -47,3 +47,5 @@ Fixed the display of modules granted to groups.
Added a per-user option to opt out of forced password changes after a certain number of days.
A human-readable description of the password restrictions regular expression can be entered, for use in error messages.
Webmin users can now be given temporary passwords, which they are forced to change at the next login. Thanks to GE Medical Systems for supporting this feature.
---- Changes since 1.410 ----
Added an API function to allow easier anonymous module access setup.

View File

@@ -889,5 +889,54 @@ local $hash = &hash_session_id($sid);
return $sessiondb{$hash} ? $hash : $sid;
}
# setup_anonymous_access(path, module)
# Grants anonymous access to some path. By default, the user for other anonymous
# access will be used, or if there is none, a user named 'anonymous' will be
# created and granted access to the module.
sub setup_anonymous_access
{
local ($path, $mod) = @_;
# Find out what users and paths we grant access to currently
local %miniserv;
&get_miniserv_config(\%miniserv);
local @anon = split(/\s+/, $miniserv{'anonymous'});
local $found = 0;
local $user;
foreach my $a (@anon) {
local ($p, $u) = split(/=/, $a);
$found++ if ($p eq $path);
$user = $u;
}
return 1 if ($found); # Already setup
if (!$user) {
# Create a user if need be
$user = "anonymous";
local $uinfo = { 'name' => $user,
'pass' => '*LK*',
'modules' => [ $mod ],
};
&create_user($uinfo);
}
else {
# Make sure the user has the module
local ($uinfo) = grep { $_->{'name'} eq $user } &list_users();
if ($uinfo && &indexof($mod, @{$uinfo->{'modules'}}) < 0) {
push(@{$uinfo->{'modules'}}, $mod);
&modify_user($uinfo->{'name'}, $uinfo);
}
else {
print STDERR "Anonymous access is granted to user $user, but he doesn't exist!\n";
}
}
# Grant access to the user and path
push(@anon, "$path=$user");
$miniserv{'anonymous'} = join(" ", @anon);
&put_miniserv_config(\%miniserv);
&reload_miniserv();
}
1;