smeserver-webshare/root/etc/e-smith/events/actions/webshare-rebuild-htpasswd

65 lines
2.3 KiB
Plaintext
Raw Permalink Normal View History

#!/usr/bin/perl -w
use esmith::ConfigDB;
use Apache::Htpasswd;
my $db = esmith::ConfigDB->open_ro("WebShare");
my @WebShare = $db->get_all_by_prop( type => 'WebShare' );
my $MultiAccessWebshare = $db->get_prop( "MultiAccess", "WebShareName" ) || "";
my %MultiWebshares = split( /,/, $db->get_prop( "MultiAccess", "WebShares" ) || "" );
foreach my $WebShare (@WebShare) {
my $ws = $WebShare->key;
my $rec = $db->get("$ws");
system( "/bin/rm -f /home/e-smith/db/webshare/htpasswd.$ws > /dev/null 2>&1" );
system( "/bin/touch", "/home/e-smith/db/webshare/htpasswd.$ws" );
my %Users = split( /,/, $rec->prop("Users") || "" );
if ( "%Users" ne "" ) {
foreach my $Users ( sort %Users ) {
my @user = split( /:/, $Users );
my $userName = $user[0];
my $password = $user[1];
#------------------------------------------------------------
# Create the MultiAccessWebshare account
#------------------------------------------------------------
if ( ( "$MultiAccessWebshare" eq "$ws" )
&& ( "%MultiWebshares" ne "" ) )
{
my $foo =
new Apache::Htpasswd(
"/home/e-smith/db/webshare/htpasswd.$MultiAccessWebshare");
$foo->htDelete("$userName");
$foo->{'USEMD5'} = "MD5";
$foo->htpasswd( "$userName", "$password" );
foreach my $MultiWebshares ( sort %MultiWebshares ) {
my $foo1 =
new Apache::Htpasswd(
"/home/e-smith/db/webshare/htpasswd.$MultiWebshares");
$foo1->htDelete("$userName");
$foo->{'USEMD5'} = "MD5";
$foo1->htpasswd( "$userName", "$password" );
}
}
else {
#------------------------------------------------------------
# Create the webshare account
#------------------------------------------------------------
my $foo = new Apache::Htpasswd("/home/e-smith/db/webshare/htpasswd.$ws");
$foo->htDelete("$userName");
$foo->{'USEMD5'} = "MD5";
$foo->htpasswd( "$userName", "$password" );
}
}
}
}
exit(0)