#!/usr/bin/perl
# cache_delobj.cgi
# Delete Objects Cache 
# 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 (!$in{dn}) { &redirect("cache_selobj.cgi?form=delobj"); }
&headerstta($text{'index_delldapcache'}, "","delldapcache" ,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" ); 
print "<hr><p>\n";
if ( $config{'is_ldapcache'} ne "true" ) { &footCacheHere; exit }

   do "ldap-lib.pl";

   $lnro=$in{lnro};
   $grpdn=$in{dn};
   $dn_obj=$in{dn};
   $grpdn=~s/,$config{ldapcache_base}//; 
   $dn_cache=$dn_obj;
   # loading variables
   $ldapcache_server=$in{ldapcacheserver} || "1";
   &connect_cache();
   if ( $lnro > -1 && $dn_cache !=~ /cn=/ ) {
     $OuName=$grpdn; 
     $userou="default";
     $objType="";
     @lindn = split(/,/, $in{dn}); 
     $NameUser=$lindn[0];
     $OuName=$grpdn; 
     $OuName=~s/$NameUser,//; 
     $NameUser=$default_obj;
   } else {
     if ( &load_tta3tier_vars($dn_cache) ne 0 ) {
              &html_errshow("ldap");
              &footHere; exit ;
     }
     $userou=$tta3tier_oudn;
     $objType="";
     @lindn = split(/,/, $in{dn}); 
     $NameUser=$lindn[0];
     $OuName=$grpdn; 
     $OuName=~s/$NameUser,//; 
     $default_obj="cn=$config{ldapcache_defaultobj}" ;
   }


   if ( "$NameUser" ne "$default_obj" ) {

         $dn="$NameUser,".$userou.",".$config{ldap_base};
         $ldap_server=1;
         # loading variables
         &connect();
         $cur_entry=&sel_ldap_obj($dn,"ou=*");
         if ( !defined($cur_entry)  || $cur_entry->dn ne $dn) {
                    $err_msg=" Error: $NameUser $userou\n";
                    &html_errshow("ldap");
                    &footHere; exit ;
         } 
         %entryObj=&get_ldap_obj($dn,$cur_entry);
         $mail = $entryObj{mail};
         $sn = $entryObj{sn};
         $displayname = $entryObj{displayname};
         $lin_user="$sn -- $displayname";
    } else { 
            $lin_user="DEFAULT";
    }
    if ($OuName) {
        $CnName=$OuName;
        if ( $origin ne "default") { $CnName=~s/$userou,//g; } 
        $objType="app";
        $objDescrip=&scan_objdescrip(2,$objType,$OuName,$userou);
        if ( "$objDescrip" eq  "" ) {
           $objType="grpapps";
           $objDescrip=&scan_objdescrip(2,$objType,$OuName,$userou);
        }
        if ( "$objDescrip" eq  "" ) {
           $objType="host";
           $CnName=$OuName;
           $objDescrip=&scan_objdescrip(2,$objType,$CnName,$userou);
        }
        if ( "$objDescrip" eq  "" ) {
           $objType="grphosts";
           $objDescrip=&scan_objdescrip(2,$objType,$CnName,$userou);
        }
        if ( "$objDescrip" ne  "" ) {
           if ( "$CnName" ne  "" ) {
              $lin_name="$objDescrip -- $CnName";
           } else { $lin_name="$objDescrip -- $OuName"; }
        } else { $objType=""; }
     }

 print "<SCRIPT SRC=\"global.js\">\n"; 
 print "</SCRIPT>\n"; 
 print "<SCRIPT LANGUAGE=\"JavaScript\">\n"; 
 print "<!--\n"; 
 print "/*  Strings for locales  */\n"; 
 print "var msg0=\"".$text{'msg_0'},"\";\n";
 print "var msg1=\"".$text{'msg_1'},"\";\n";
 print "var msg2=\"".$text{'msg_2'},"\";\n";
 print "var msg3=\"".$text{'msg_3'},"\";\n";
 print "var msg4=\"".$text{'msg_4'},"\";\n";
 print "var msg5=\"".$text{'msg_5'},"\";\n";
 print "var msg6=\"".$text{'msg_6'},"\";\n";
 print "var msg7=\"".$text{'msg_7'},"\";\n";
 print "/******************************************************************\n"; 
 print "   Check_fields(obj)\n"; 
 print "*******************************************************************/\n";
 print "function Check_fields(obj) {\n"; 
 print "     return true;\n"; 
 print "}\n"; 
 print "//-->\n"; 
 print "</SCRIPT>\n"; 
 print "\n"; 
 print "<table width=100% border>\n";

 print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_delldapcache'}</b>: $in{desc}</td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";

 print "<form METHOD=POST name=delldapcache ACTION=\"delobj.cgi\" onSubmit=\"return Check_fields(this)\">\n"; 
 print "  <input TYPE=\"hidden\" NAME=\"dn\" VALUE=\"",$dn_obj,"\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"grpdn\" VALUE=\"",$grpdn,"\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"desc\" VALUE=\"",$in{desc},"\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"NameUser\" VALUE=\"",$NameUser,"\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"lin_user\" VALUE=\"",$lin_user,"\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"lin_name\" VALUE=\"",$lin_name,"\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"objType\" VALUE=\"",$objType,"\">\n";
 print "  <input TYPE=\"hidden\" NAME=\"lnro\" VALUE=\"",$lnro,"\">\n";

 if ( $lnro ne  -1 && $dn_cache =~ /cn=/ ) {
     print "<tr><td valign=top><b>$text{'obj_origin'}</b>&nbsp;</td></tr>\n";
     print "   <tr><td valign=top>",&hlink("<b>$text{'f_obj'}</b>","fobj"),"&nbsp;</td>\n";
     print "<td valign=top><b>$NameUser  ---  $lin_user </b>&nbsp;</td></tr>\n";
     print "<tr><td valign=top><b>$text{'obj_target'}</b>&nbsp;</td></tr>\n"; 
} else {
    print "<tr> <td valig=top><b>$text{'titidx_delldapcache'}</b>\n";
    print "<td valign=top><b> <big> $in{desc}</big></b>&nbsp; -> $grpdn </td></tr>\n";   
}
 
 if ( "$objType" eq  "app" ) {
       print "   <tr><td valign=top>",&hlink("<b>$text{'f_appobjname'}</b>","fappobjname"),"&nbsp;</td>\n";
  } elsif ( "$objType" eq  "grpapps" ) {
       print "   <tr><td valign=top>",&hlink("<b>$text{'f_aliasgrpapps'}</b>","faliasgrpapps"),"&nbsp;</td>\n"
  } elsif ( "$objType" eq  "host" ) {
       print "   <tr><td valign=top>",&hlink("<b>$text{'f_hostname'}</b>","fhostname"),"&nbsp;</td>\n";
  } elsif ( "$objType" eq  "grphosts" ) {
       print "   <tr><td valign=top>",&hlink("<b>$text{'f_usergrphosts'}</b>","fusergrphosts"),"&nbsp;</td>\n"
  }
 print "<td valign=top><b>$lin_name </b>&nbsp;</td></tr>\n";   

 print "        <tr><td valign=top><input TYPE=\"submit\" NAME=\"",$text{'f_sendreq'},"\" VALUE=\"",$text{'f_sendreq'},"\">\n";
 print "        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"reset\" NAME=\"",$text{'f_cancelreq'},"\" VALUE=\"",$text{'f_cancelreq'},"\"></td></tr>\n";

 print "	</form>\n"; 
 print "<tr><tr></table></table><hr><p>\n"; 
 &footer($config{'back_return'},$text{'index'}); 
 print "<p><p><p>\n";
 do "footer.pl\n";
 exit;


