#!/usr/bin/perl
# modgrpapps.cgi
# Mod GRP apps ...  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";
}
&foreign_require("proc", "proc-lib.pl");

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

 $type_cmd = $in{ttacmd};
 $webtop=$in{webtop};
 $inherit=$in{inherit} || "0";
 $conntype=$in{conntype};
 $cmd=$in{cdm};
 $descrip=$in{descrip};
 $maxsess=$in{maxsess};
 $aliasgrpapps=$in{aliasgrpapps};
 $grpappsname=$in{grpappsname};

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


 if ( !$aliasgrpapps) { &footHere; exit }  ;
 $dn_grpapps="";
 $ens_grpapps="";
 $alias="";
 %h_grpapps=&list_grpapps();
 if ( $h_grpapps{$aliasgrpapps}->{'alias'} ne $aliasgrpapps ) {
         $err_msg=$text{'list_errno'};
         &footHere;
         exit;
 }
 $alias=$h_grpapps{$aliasgrpapps}->{alias};
 $dn_grpapps=$h_grpapps{$aliasgrpapps}->{obj};
 $ens_grpapps=$h_grpapps{$aliasgrpapps}->{ens};
 if ( $dn_grpapps eq "" ) {
       $dn_org = "ou=$grpappsname";
       $ens_org = "cn=$grpappsname";
 } else {
       $dn_org = $dn_grpapps;
       $ens_org = $ens_grpapps;
 }
 # Default object para LDAP cache ...
 $ens_obj = "--name \"".$config{tta_base}."/$ens_grpapps\"";

 $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 ( $cmd ne "" ) { print TEMPF "  --cmd \"$cmd\"\\\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); }
 if ( $config{'is_ldapcache'} eq "true" && $in{tta3tier_login} ) { 
         $obj_descrip=$in{descrip};
         $dnldap = "default";
         $dn_cache=$dn_org;
         $task="mod";
         $ldapcache_server=1;
         &connect_cache();
         $default_obj="cn=$config{ldapcache_defaultobj}";
         $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,"grpapps");
         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")};
 } 
 $lingrpapps=$aliasgrpapps."::".$grpappsname."::"."$dn_org"."::"."$ens_org"."::".$maxsess."::".$obj_descrip."::";
 &out_objslist( "modify", "modgrpapps.cgi", "grpapps", "grpapps_list", $aliasgrpapps, $lingrpapps, \%h_grpapps );
 print "<tr><p><b>".$text{'user_update'}.$aliasgrpapps." ->  ".$grpappsname."</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;
