178 lines
6.7 KiB
Perl
Executable File
178 lines
6.7 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
# updateALLcache.cgi
|
|
# Update ALL cache... Services with Tarantella.
|
|
# STTA Rev. 1.3 Copyright (c) 2001-2004 Jesús Pérez Lorenzo --- license GNU GPL
|
|
# stta: (@#) 1.31051043346- [2004_01_29_102036]
|
|
|
|
require './stta-lib.pl';
|
|
&foreign_require("proc", "proc-lib.pl");
|
|
do "ldap-lib.pl"
|
|
&headerstta($text{'index_updateALLcache'}, "", "",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
|
|
print "<hr><p>\n";
|
|
#&ReadParse();
|
|
|
|
sub callbackSearch
|
|
{
|
|
my ( $conn, $entry) = @_;
|
|
|
|
if ( !defined($entry) ) { return };
|
|
$dn = $entry->dn;
|
|
@attrs = $entry->attributes; # Obtain attributes for this entry.
|
|
my (%users);
|
|
$users{dn} = $dn;
|
|
foreach my $var (@attrs) {
|
|
$attr = $entry->get_value( $var, asref => 1 );
|
|
if ( defined($attr) ) {
|
|
foreach my $value (@$attr) { $users{$var} = $value; }
|
|
}
|
|
}
|
|
$users{department} = $users{description};
|
|
$users[$numusrs++] = \%users;
|
|
$conn->pop_entry;
|
|
}
|
|
|
|
$ldap_server=1;
|
|
|
|
print "<table width=100% border>\n";
|
|
print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_updatecache'}</b></td> </tr>\n";
|
|
print "<tr $cb> <td><table width=100%>\n";
|
|
print "<center>\n";
|
|
|
|
# $profilename=$in{profilename};
|
|
|
|
# if (!$profilename) { &footHere; exit }
|
|
$nItems=0;
|
|
$temp_f = &tempname();
|
|
open(TEMPF, ">$temp_f");
|
|
%h_ou=&list_ous();
|
|
%h_grphost=&list_grphosts();
|
|
%h_host=&list_hosts();
|
|
%h_hostuser=&list_hostsuser();
|
|
%h_profcache=&list_profcache();
|
|
foreach $item (keys (%h_profcache)) {
|
|
$profilename=$h_profcache{$item}->{'alias'};
|
|
$nItems++;
|
|
# Getting Profile details
|
|
if ( $h_profcache{$profilename}->{'alias'} eq $profilename) {
|
|
$prof_alias=$h_profcache{$profilename}->{'alias'};
|
|
$prof_name=$h_profcache{$profilename}->{'name'};
|
|
$prof_hostusername=$h_profcache{$profilename}->{'hostusername'};
|
|
$prof_hostname=$h_profcache{$profilename}->{'hostname'};
|
|
$prof_grphost=$h_profcache{$profilename}->{'grphost'};
|
|
$prof_username=$h_profcache{$profilename}->{'username'};
|
|
$prof_userou=$h_profcache{$profilename}->{'ou'};
|
|
}
|
|
if ( !$prof_hostusername ) { &footHere; exit }
|
|
# Getting Password for HOST or HostGroup
|
|
if ( $h_hostsuser{$prof_hostusername}->{'username'} eq $prof_hostusername) {
|
|
$hostspassword=$h_hostuser{$prof_hostusername}->{'passwd'};
|
|
}
|
|
if ( !$hostspassword ) { &footHere; exit }
|
|
|
|
# If HostGroup ... Load Hosts ...
|
|
$numhosts=0;
|
|
@listhosts="";
|
|
|
|
if ($prof_grphost) {
|
|
if ( $h_grphost{$prof_grphost}->{'alias'} eq $prof_grphost) {
|
|
$ens_grphosts=$h_grphost{$prof_grphost}->{'ens'};
|
|
$dn_grphosts=$h_grphost{$prof_grphost}->{'obj'};
|
|
$grp_name=$h_grphost{$prof_grphost}->{'name'};
|
|
}
|
|
if ( !$ens_grphosts ) { &footHere; exit }
|
|
foreach $item (keys (%h_host)) {
|
|
if ( $h_host{$item}->{'grpalias'} eq $prof_grphost) {
|
|
push(@listhosts, { 'name' => $h_host{$item}->{'name'},
|
|
'ens' => $h_host{$item}->{'ens'},
|
|
'num' => scalar(@listhosts) });
|
|
$numhosts++;
|
|
}
|
|
}
|
|
}
|
|
if ($prof_hostname) {
|
|
if ( $h_host{$prof_hostname}->{'alias'} eq $prof_hostname) {
|
|
push(@listhosts, { 'name' => $h_host{$prof_hostname}->{'name'},
|
|
'ens' => $h_host{$prof_hostname}->{'ens'},
|
|
'num' => scalar(@listhosts) });
|
|
$numhosts++;
|
|
}
|
|
}
|
|
|
|
|
|
# If OU Group ... Load Users
|
|
|
|
$numusrs=0;
|
|
@listusers="";
|
|
|
|
if ($prof_userou) {
|
|
if ( $h_ou{$prof_userou}->{'alias'} eq $prof_userou) {
|
|
$dn_ou=$h_ou{$prof_userou}->{'obj'};
|
|
$ouname=$h_ou{$prof_userou}->{'name'};
|
|
$ens_ou=$h_ou{$prof_userou}->{'ens'};
|
|
$organizationname=$h_ou{$prof_userou}->{'name'};
|
|
}
|
|
if ( !$ens_ou ) { &footHere; exit }
|
|
|
|
&connect ();
|
|
$ldap_base="$dn_ou,$config{ldap_dnusers}";
|
|
$filter = "(cn=*)";
|
|
|
|
&additional_log("search ", undef, "$ldap_base\nsubtree\n$filter");
|
|
my $status_con = $ldapObj->search ( base => $ldap_base,
|
|
scope => "sub",
|
|
filter => "(cn=" . $filter . ")",
|
|
callback => \&callbackSearch
|
|
);
|
|
&ldap_logerr("search $ldap_base");
|
|
}
|
|
}
|
|
if ($prof_username) {
|
|
&connect ();
|
|
$ldap_base="$config{ldap_dnusers}";
|
|
$filter = "(cn=$prof_username)";
|
|
$entry = $conn->search ($ldap_base, "subtree", $filter );
|
|
|
|
&additional_log("search ", undef, "$ldap_base\nsubtree\n$filter");
|
|
my $status_con = $ldapObj->search ( base => $ldap_base,
|
|
scope => "sub",
|
|
filter => "(cn=" . $filter . ")",
|
|
callback => \&callbackSearch
|
|
);
|
|
&ldap_logerr("search $ldap_base");
|
|
&webmin_log("updateALLcache.cgi", "search_subtree", $filter);
|
|
}
|
|
if ($#users < 0) { &footHere; exit }
|
|
|
|
# Ready to write TTA passcache file ...
|
|
|
|
foreach $user (@users) {
|
|
$dn = $user->{dn};
|
|
if ($dn) {
|
|
$cn = $user->{cn};
|
|
$ou=$user->{department};
|
|
$ens_usr = ".../_ens/".$config{tta_base}."/$ens_ou/$cn";
|
|
$dn_usr = ".../_service/sco/tta/ldapcache/$dn";
|
|
# Scan for host in the same HostGroup ...
|
|
foreach $host (@listhosts) {
|
|
$host_name=$host->{name};
|
|
$enshost = $host->{ens};
|
|
if ($enshost ) {
|
|
$ens_host = ".../_ens/".$config{tta_base}."/$enshost";
|
|
print TEMPF "--person \"$dn_usr\" --resource \"$ens_host\" --resuser \"$prof_hostusername\" --respass \"$hostspassword\"\n";
|
|
print "<tr><td>$profilename: $cn -- $host_name -- $prof_hostusername</tr></td>\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
close(TEMPF);
|
|
$type_cmd="passcache";
|
|
# if (&run_tta_cmd($type_cmd,"",$temp_f)) {
|
|
print "<tr><td><b>".$text{'user_made'}." -> $text{'index_updatecache'} </b><td></tr>\n";
|
|
# }
|
|
# unlink($temp_f);
|
|
print "<tr></tr>\n";
|
|
&footHere;
|
|
exit;
|
|
|