#!/usr/bin/perl
# modlinks.cgi
# ...  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';
&ReadParse();
if ( $config{'is_ldapcache'} eq "true" && $in{tta3tier_login} ) {
     do "ldap-lib.pl";
}

&headerstta($text{'index_modlink'}, "", "modlink",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
print "<hr><p>\n"; 

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

 $status_cmd=0;
 $descrip=$in{descrip};
 $maxsess=$in{maxsess};
 $aliaslink=$in{aliaslink};
 $linkname=$in{linkname};

 if ( !$aliaslink) { &footHere; exit }  ;
 $alias="";
 %h_links=&list_links();
 if ( $h_links{$aliaslink}->{'alias'} ne $aliaslink ) {
         $err_msg=$text{'list_errno'};
         &footHere;
         exit;
 }
 $dn_link="";
 $ens_link="";
 $alias=$h_links{$aliaslink}->{alias};
 $dn_link=$h_links{$aliaslink}->{obj};
 $ens_link=$h_links{$aliaslink}->{ens};
 if ( $dn_link eq "" ) {
       $dn_org = "ou=$linkname";
       $ens_org= "cn=$linkname";
 } else {
       $dn_org= $dn_link;
       $ens_org= $ens_link;
 }
 $ens_obj = "--name \"".$config{tta_base}."/$ens_org\"";
 #   if ( $tta_norun eq "true" ) { $type_cmd = "no_run $type_cmd"; };
 #   if (&run_tta_cmd($type_cmd,$ens_obj,$temp_f)) {
 # Default object para LDAP cache ...
 if ( $config{'is_ldapcache'} eq "true" && $in{tta3tier_login} ) { 
         $obj_descrip=$in{descrip};
         $dnldap = "default";
         $default_obj="cn=$config{ldapcache_defaultobj}";
         $dn_cache=$dn_org;
         $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,"link");
         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")};
 } 
 $linlink=$aliaslink."::".$linkname."::"."$dn_org"."::"."$ens_org"."::".$maxsess."::".$descrip."::";
 &out_objslist( "modify", "modlinks.cgi", "links", "links_list", $aliaslink, $linlink, \%h_links );
 print "<tr><p><b>".$text{'user_update'}.$aliaslink." ->  ".$linkname."</b></tr>\n";
 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;
