#!/usr/bin/perl
# addapp.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";

&headerstta($text{'index_addapp'}, "", "addapp",undef,1,1,$text{headpage_rigth} ); 
print "<hr><p>\n";
if ( $config{'is_ldapcache'} ne "true" ) { &footCacheHere; exit }
&foreign_require("proc", "proc-lib.pl");
$ldapcache_server=1;
&connect_cache();
&ReadParse();
 
 $type_cmd = $in{ttacmd};
 $appname=$in{appname};
 $grp_apps=$in{grpapps};
 $obj_descrip=$in{descrip};
 $aliasapp=$in{aliasapp};
 $maxsess=$in{maxsess};

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

 if (!$appname)  { &footHere; exit }  ;
    $alias=$aliasapp;
    %h_app=&list_apps();
    if ( $h_app{$aliasapp}->{'alias'} eq $aliasapp ) {
         $err_msg=$aliasapp.": ".$text{'list_err'};
         &footHere;
         exit;
    }
    $grp_name="";
    $grp_descrip="";
    $dn_grpapps="";
    $ens_grpapps="";
    %h_grpapps=&list_grpapps();
    if ( $h_grpapps{$grp_apps}->{'alias'} eq $grp_apps ) {
         $dn_grpapps=$h_grpapps{$grp_apps}->{obj};
         $ens_grpapps=$h_grpapps{$grp_apps}->{ens};
         $grp_name=$h_grpapps{$grp_apps}->{name};
         $grp_descrip=$h_grpapps{$grp_apps}->{descrip};
    } else {
         $err_msg="grp_apps: ".$text{'list_errno'};
         &footHere;
         exit;
    }
    if ( $dn_grpapps eq "" ) {
         $dn_app = "ou=$appname";
         $ens_app ="cn=$appname";
    } else {
         $dn_app = "ou=$appname,$dn_grpapps";
         $ens_app ="$ens_grpapps/cn=$appname";
    }
    $dnldap = "default";
    $default_obj="cn=$config{ldapcache_defaultobj}"; 

    $ldapcache_server=1;
    &connect_cache ();
    @tta3tier=&set_tta3tier($default_obj,$dn_app,$dnldap,"add","app");
    if ( &cache_obj(\%tta3tier) ne 0 ) { 
         &html_errshow("ldap");
         &footHere; exit;
    };
    if ( $config{ldapcache2_server}.length gt 0 ) {
             $ldapcache_server=2;
             &connect_cache ();
             if ( &cache_obj(\%tta3tier) ne 0 ) { &err_replication() }
    }
    $lin_app=$aliasapp."::".$appname."::".$grp_apps."::".$dn_app."::".$ens_app."::".$maxsess."::".$obj_descrip."::";
    &lock_file($config{'app_list'});
    open(FILEAPPS, ">>$config{'app_list'}");
         print FILEAPPS "$lin_app\n";
    close (FILEAPPS);
    &unlock_file($config{'app_list'});
    $str=$text{'user_made'}.$appname." ->  ".$grp_name;
    &additional_log('addapp.cgi', "app", $str);
    &webmin_log($config{'app_list'}, "app", "write",$lin_app);
    print "<tr><p><b>".$text{'user_made'}.$appname." ->  ".$grp_name."</b></tr>\n";
    print "<tr></tr>\n";
 &footHere;
 exit;

