#!/usr/bin/perl
# addgrpapps.cgi
# ...  Servicios de Tarantella.

require './tarantella-lib.pl';
do "ldap-lib.pl";
 
&header($text{'index_addgrpapps'}, "", "");
print "<hr><p>\n";
if ( $config{'is_ldapcache'} ne "true" ) { &footCacheHere; exit }
&foreign_require("proc", "proc-lib.pl");
$ldapcache_server=1;
&connect_cache();
&ReadParse();
 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><b>$text{'titidx_adgrpapps'} $grpappsname </b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<center>\n";

 $type_cmd = $in{ttacmd};
 $grpappsname=$in{grpappsname};
 $grp_grpapps=$in{grpapps};
 $obj_descrip=$in{descrip};
 $aliasgrpapps=$in{aliasgrpapps};

 if (!$grpappsname)  { &footHere; exit }  ;
    $grp_name="";
    $grp_descrip="";
    $dn_grpapps="";
    $ens_grpapps="";
    foreach $grpapps (&list_grpapps()) {
         if ( $grpapps->{'alias'} eq $grp_grpapps ) {
            $dn_grpapps=$grpapps->{obj};
            $ens_grpapps=$grpapps->{ens};
            $grp_name=$grpapps->{name};
            $grp_descrip=$grpapps->{descrip};
            last;
         }
    }
    if ( $dn_grpapps eq "" ) {
         $dn = "ou=$grpappsname";
         $ens = "ou=$grpappsname";
    } else {
         $dn = "ou=$grpappsname,$dn_grpapps";
         $ens = "$ens_grpapps/ou=$grpappsname";
    }
    $dnldap = "default";
    $default_obj="cn=$config{ldapcache_defaultobj}";  
    $ldapcache_server=1;
    &connect_cache ();
    @tta3tier=&set_tta3tier($default_obj,$dn,$dnldap,"add","grpapps");
    if ( &cache_obj(\%tta3tier) ne 0 ) { &footHere; exit }  ;
    if ( $config{ldapcache2_server}.length gt 0 ) {
             $ldapcache_server=2;
             &connect_cache ();
             if ( &cache_obj(\%tta3tier) ne 0 ) { &err_replication() }
    }
    $lin_grpapps=$aliasgrpapps."::".$grpappsname."::"."$dn"."::"."$ens"."::".$obj_descrip;
    &lock_file($config{'grpapps_list'});
    open(FILEAPPS, ">>$config{'grpapps_list'}");
     print FILEAPPS "$lin_grpapps\n";
    close (FILEAPPS);
    $str=$text{'user_made'}.$grpappsname." ->  ".$grp_name;
    &additional_log('addgrpapps.cgi', undef, $str);
    &webmin_log($config{'grpapps_list'}, undef, "write");
    &unlock_file($config{'grpapps_list'});
    print "<tr><p><b>".$text{'user_made'}.$grpappsname." ->  ".$grp_name."</b></tr>\n";
    print "<tr></tr>\n";
 &footHere;
 exit;

