#!/usr/bin/perl
# update.cgi
# ...  Servicios de Tarantella.
# STTA Rev. 1.3 Copyright (c) 2001-2002 Jesús Pérez Lorenzo  --- license GNU GPL 

 require './stta-lib.pl';

do "ldap-lib.pl";

sub update_obj
{
     my ($status_con);
     $status_con = 0;
     local $passwd_coded="";
 
     if ( "$ldapcache_server" eq "1" ) {
         $str=$config{ldapcache_server};
     } elsif ( "$ldapcache_server" eq "2" ) {
         $str=$config{ldapcache2_server};
     }
     $entry = $conncache->browse ($dn);
     if ($err = $conncache->getErrorCode ()) {
             $status_con=-1;
             &ldapcache_logerr("browse $dn"); 
     } else {
             &cipher_text ( "code",$entry->{tta3tierpassword}[0], \$passwd_coded); 
             $entry->{tta3tierpassword} = [$passwd_coded]; 
             $entry->{tta3tiermaxsess} = [$maxsess];
             $entry->{tta3tierticketstatus} = ["no"];
             $entry->{tta3tierticketcounter} = [""];
             $entry->{tta3tierendticket} = [""];
             $entry->{tta3tierdoifendticket} = [""];
             $conncache->update ($entry);
             if ($err = $conncache->getErrorCode ()) { $status_con=-1; }
             &ldapcache_logerr("update $dn"); 
     }
     return $status_con;
}

&headerstta($text{'index_update'}, "", "",undef,1,1,$text{headpage_rigth} );
print "<hr><p>\n"; 
if ( $config{'is_ldapcache'} ne "true" ) { &footCacheHere; exit };   
&foreign_require("proc", "proc-lib.pl");
&ReadParse();

 $type_cmd = $in{ttacmd};
 print "<table width=100% border>\n";
 print "<tr $tb> <td><b>$text{'titidx_update'}</b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<center>\n";

$ldapcache_server=1;   
&connect_cache ();

 $method="subtree";
 $search_dn=$config{ldapcache_base};

 &additional_log("search ", undef, "$search_dn\n$method\n(cn=*)");
 $entry = $conncache->search ($search_dn, $method, "(cn=*)");  
 &ldapcache_logerr("search $search_dn");  

 $i = 0;
    while ($entry) {
        my (%all_elemen);
 
        $all_elemen{dn} = $entry->getDN ();
        $all_elemen{objectclass} = $entry->{objectclass}[0];
        if ( $all_elemen{objectclass} eq "ttacacheapp" ) {
           $all_elemen{objtype} = "cn";
           $all_elemen{objcnou} = $entry->{cn}[0];
           $all_elemen{description} = $entry->{tta3tiertitle}[0];
        } else {
           $all_elemen{objtype} = "ou";
           $all_elemen{objcnou} = $entry->{ou}[0];
           $all_elemen{description} = $entry->{description}[0];
        }
 
        $all_elemen[$i++] = \%all_elemen;
        $entry = $conncache->nextEntry ();
    }
if ($#all_elemen > 0) {
    $maxsess="9999";
    $i = 0;
    foreach $item (@all_elemen) {
       if ( $item->{objectclass} eq "ttacacheapp" ) {
           $ldapcache_server=1;   
           &connect_cache ();
           $dn=$item->{dn};
           if ( &update_obj() eq 0 ) {
                print "<tr> <td><b>$text{'user_update'} ($dn)</b></td> </tr>\n";
                if ($config{ldapcache2_server} ne "" ) {;
                    $ldapcache_server=2;
                    &connect_cache ();
                    &update_obj();
                }
           }
       }
       $i++;
   }
}
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;



