#!/usr/bin/perl
# modou.cgi
# Modify Ou from STTA
# 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';
if ( $config{'has_ldapusers'} eq "true" || $config{'is_ldapcache'} eq "true" ) {
     do "ldap-lib.pl";
}
&headerstta($text{'index_moddou'}, "", "moddou",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
print "<hr><p>\n"; 
&foreign_require("proc", "proc-lib.pl");
&ReadParse();

$dn = $in{dn};
$type_cmd = $in{ttacmd};
$ouname=$in{ouname};
$webtop=$in{webtop};
$inherit=$in{inherit} || "0";
$conntype=$in{conntype};
$cdm=$in{cdm};
$descrip=$in{descrip};
$maxsess=$in{maxsess};
$aliasou=$in{userorg};
if (!$dn) {
   print "<hr><p>\n";
   &footer($config{'back_return'},$text{'index'});
   print "<p><p><p>\n";
   do "footer.pl";
   exit;
}

 print "<p>\n";
 print "<table width=100% border>\n";
 if ( !$ouname || !$dn)  { &footHere; exit }
 %h_ou=&list_ous();
 if ( $h_ou{$aliasou}->{'alias'} ne $aliasou ) {
         $err_msg=$text{'list_errno'};
         &footHere;
         exit;
 }
 $dn_ou=$h_ou{$aliasou}->{'obj'};
 $organizationname=$h_ou{$aliasou}->{'name'};
 $ens_ou=$h_ou{$aliasou}->{'ens'};

 print "<tr $tb> <td><font color='$revtext'><b>".&text('titidx_modou',$ouname,$organizationname)."</b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 if ( $config{'has_ldapusers'} eq "true" ) {
     $ldap_server=1;
     &connect ();
     if ( &mod_ou() eq 0 ) { 
        if ( $config{ldap2_server}.length gt 0 ) {
             $ldap_server=2;
             &connect ();
             if ( &mod_ou() ne 0 ) { &err_replication() }
        }
        print "<tr></tr><tr></tr>\n";
        print "<tr><p></p><p><b>".$text{'user_update'}."... LDAP ... </b></tr>\n";
     } else { &html_errshow("ldap")};
 }
 $| = 1;
 print "<tr><td><pre>\n";
 $ens_obj = "--name \"".$config{tta_base}."/$ens_ou\"";

 $temp_f = &tempname();
 open(TEMPF, ">$temp_f");
            print TEMPF "$ens_obj \\\n";
            print TEMPF "  --description \"$descrip\"\\\n";
            foreach $w (&list_webtops()) {
                  if ( $w->{'alias'} eq $webtop) {
                      print TEMPF "  --webtop  \"$w->{'obj'}\"\\\n";
                  }
            }
            if ( $inherit ne "" ) {print TEMPF "  --inherit  \"$inherit\"\\\n";}
            if ( $conntype ne "" ) { print TEMPF "  --conntype \"$conntype\"\\\n"; }
            if ( $cdm ne "" ) { print TEMPF "  --cdm \"$cdm\"\\\n"; }
            print TEMPF "  \n";
 close(TEMPF);
 if (&run_tta_cmd($type_cmd,$ens_obj,$temp_f)) { 
        print "</pre><tr><p><b>$text{'user_update'}... Tarantella </b></tr>\n";
 } else { &html_errshow("tta")};
 if ( $debug lt 2 )  { unlink($temp_f); }
 $lin_ou=$aliasou."::".$ouname."::"."$dn_ou"."::"."$ens_ou"."::".$maxsess."::".$in{descrip}."::";
 &out_objslist( "modify", "modou.cgi", "ou", "ou_list", $aliasou, $lin_ou, \%h_ou );
 # Default object para LDAP cache ...
 if ( $config{'is_ldapcache'} eq "true" && $in{tta3tier_login} ) { 
         $dnldap = "default";
         $default_obj="cn=$config{ldapcache_defaultobj}";
         $dn_cache=$dn_ou;
         $task="mod";
         $ldapcache_server=1;
         &connect_cache();
         $dn_wk=$default_obj.",".$dn_cache.",".$config{ldapcache_base};
	 $cur_entry=&sel_cache_obj($dn_wk,"cn=*");
         if ( !defined($cur_entry) || $cur_entry->dn ne $dn_wk) { $task="add"; };
         @tta3tier=&set_tta3tier($default_obj,$dn_cache,$dnldap,$task,"ou");
         if ( &cache_obj(\%tta3tier) eq 0 ) {
              if ( $config{ldapcache2_server}.length gt 0 ) {
                   $ldapcache_server=2;
                   &connect_cache ();
                   if ( &cache_obj(\%tta3tier) ne 0 ) { &err_replication() }
              }
         } else { &html_errshow("ldap")};
 } 
 print "<tr></tr>\n";
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;
