#!/usr/bin/perl
# cache_modobj.cgi
# Modify Tarantella Services Users

require './tarantella-lib.pl';
&ReadParse();

if (!$in{dn}) { &redirect("cache_selobj.cgi?form=modobj"); }
&header($text{'index_modldapcache'}, "", "modldapcache");
print "<hr><p>\n";
if ( $config{'is_ldapcache'} ne "true" ) { &footCacheHere; exit }

   $grpdn=$in{dn};
   $dn_obj=$in{dn};

   $grpdn=~s/,$config{ldapcache_base}//; 
   do "ldap-lib.pl";
   $ldapcache_server=1;
   &connect_cache();
   # loading variables
   $entry = $conncache->browse ($dn_obj);
   if ($err = $conncache->getErrorCode ()) {
              print "<hr>\n";
              print "<b> mod ($dn_obj): $err:".$conncache->getErrorString ()."</b>\n";
              print "<hr>\n";
              &footHere; exit ;
   }
   $tta3tier_domain = $entry->{tta3tierdomain}[0];
   $tta3tier_login = $entry->{tta3tierlogin}[0];
   $tta3tier_password = $entry->{tta3tierpassword}[0];
   $tta3tier_stringcmd = $entry->{tta3tierstringcmd}[0];
   $tta3tier_title = $entry->{tta3tiertitle}[0];
   $tta3tier_oudn = $entry->{tta3tieroudn}[0];
   $tta3tier_appkey1 = $entry->{tta3tierappkey1}[0];
   $tta3tier_appkey2 = $entry->{tta3tierappkey2}[0];
   $tta3tier_appkey3 = $entry->{tta3tierappkey3}[0];
   $tta3tier_appkey4 = $entry->{tta3tierappkey4}[0];
   $tta3tier_appkey5 = $entry->{tta3tierappkey5}[0];
   $tta3tier_appkey6 = $entry->{tta3tierappkey6}[0];
   $userou=$entry->{tta3tieroudn}[0];

   $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};
         &connect ;
         $entry = $conn->browse($dn);
         if ($err = $conn->getErrorCode ()) {
                 print "<hr>\n";
                 print "<b> mod ($dn): $err:".$conn->getErrorString ()."</b>\n";
                 print "<hr>\n";
         } else {
            $mail = $entry->{mail}[0];
            $sn = $entry->{sn}[0];
            $displayname = $entry->{displayname}[0];
            $lin_user="$sn -- $displayname";
         }
    } else { 
            $lin_user="DEFAULT";
    }
    if ($OuName) {
        $CnName=$OuName;
        $CnName=~s/$userou//g; 
        $objType="app";
        $objDescrip=&scan_objdescrip($objType,$OuName,$userou);
        if ( "$objDescrip" eq  "" ) {
           $objType="grpapps";
           $objDescrip=&scan_objdescrip($objType,$OuName,$userou);
        }
        if ( "$objDescrip" eq  "" ) {
           $objType="host";
           $CnName=$OuName;
           $CnName=~s/ou=/cn=/g; 
           $objDescrip=&scan_objdescrip($objType,$CnName,$userou);
        }
        if ( "$objDescrip" eq  "" ) {
           $objType="grphosts";
           $objDescrip=&scan_objdescrip($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 "   Chek_fields(obj)\n"; 
 print "*******************************************************************/\n";
 print "function Chek_fields(obj) {\n"; 
 if ( $config{'is_ldapcache'} eq "true" ) { &script_cache_chek; }; 
 print "     return true;\n"; 
 print "}\n"; 
if ( $config{'is_ldapcache'} eq "true" ) { &htmlCacheaShowPassw }
 print "//-->\n"; 
 print "</SCRIPT>\n"; 
 print "\n"; 
 print "<table width=100% border>\n";

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

 print "<form METHOD=POST name=modldapcache ACTION=\"modobj.cgi\" onSubmit=\"return Chek_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=\"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 "<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"; 
 
 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_grpappsobjname'}</b>","fgrpappsobjname"),"&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";   

if ( $config{'is_ldapcache'} eq "true" ) { $formObj="modldapcache";$msgObj=$text{'obj_params'};&htmlCacheapp(msgObj) }
 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;


