#!/usr/bin/perl
# adddomain.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_adddomain'}, "", "adddomain",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();
 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><b>$text{'titidx_addomain'} $domainname </b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<center>\n";

 $type_cmd = $in{ttacmd};
 $domainname=$in{domainname};
 $grp_domains=$in{grpdomains};
 $obj_descrip=$in{descrip};
 $aliasdomain=$in{aliasdomain};
 $maxsess=$in{maxsess};

 if (!$domainname)  { &footHere; exit }  ;
    $alias=$aliasdomain;
    %h_domains=&list_domains();
    if ( $h_domains{$aliasdomain}->{'alias'} eq $aliasdomain ) {
         $err_msg="aliasdomain: ".$text{'list_err'};
         &footHere;
         exit;
    }
    $grp_name="";
    $grp_descrip="";
    $dn_grpdomain="";
    $ens_grpdomain="";
    if ( $h_domains{$grp_domains}->{'alias'} eq $grp_domains ) {
         $dn_grpdomain=$h_domains{$grp_domains}->{obj};
         $ens_grpdomain=$h_domains{$grp_domains}->{ens};
         $grp_descrip=$h_domains{$grp_domains}->{descrip};
         $grp_name=$h_domains{$grp_domains}->{name};
    } else {
         $err_msg="$grp_domains: ".$text{'list_errno'};
         &footHere;
         exit;
    }
    if ( $dn_grpdomain eq "" ) {
         $dn = "ou=$domainname";
         $ens= "ou=$domainname";
    } else {
         $dn = "ou=$domainname,$dn_grpdomain";
         $ens= "ou=$ens_grpdomain/ou=$domainname";
    }
    $dnldap = "default";
    $dn_org = $dn;
    $default_obj="cn=$config{ldapcache_defaultobj}";
    $ens_obj = "$ens,".$config{tta_base};
    $ldapcache_server=1;
    &connect_cache ();
    @tta3tier=&set_tta3tier($default_obj,$dn,$dnldap,"add","domain");
    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() }
    }
    &lock_file($config{'domain_list'});
    $lin_domain=$aliasdomain."::".$domainname."::"."$dn_org"."::"."$ens"."::".$maxsess."::".$obj_descrip."::";
    open(FILEDOMAINS, ">>$config{'domain_list'}");
           print FILEDOMAINS "$lin_domain\n";
    close (FILEDOMAINS);
    &unlock_file($config{'domain_list'});
    $str=$text{'user_made'}.$domainname." ->  ".$grp_name;
    &additional_log('adddomains.cgi', "domain", $str);
    &webmin_log($config{'domain_list'}, "domain", "write",$lin_domain);
    print "<tr><p><b>".$text{'user_made'}.$domainname." ->  ".$grp_name."</b></tr>\n";
    print "<tr></tr>\n";
 &footHere;
 exit;

