#!/usr/bin/perl
# tta_passwd.cgi
# Managing User Password for Services with Tarantella.
# 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();
 
 $dn = $in{dn};
 if (!$dn) { &redirect("tta_selusr.cgi?form=passwd"); }
 $username = $in{username};
 $filter = $in{filter};
 $base = $in{base};
 &headerstta($text{'index_passwd'}, "", "passwd",undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
 print "<hr><p>\n"; 
 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 "var ask_confpasscache=true;\n"; 
 print "/******************************************************************\n"; 
 print "   setPasswdDefault(formObj)\n"; 
 print "   If password is empty assign username as default value in the form.\n"; 
 print "*******************************************************************/\n"; 
 print "function setPasswdDefault(formObj) {\n"; 
 print "   if (emptyField(formObj.username)) {\n"; 
 print "      formObj.username.value=\"\";\n"; 
 print "      formObj.password.value=\"\";\n"; 
 print "      return\n"; 
 print "   }   \n"; 
 print "   username=StringClip(true,formObj.username.value);\n"; 
 print "   formObj.username.value=username;\n"; 
 print "   if (emptyField(formObj.password)) {\n"; 
 print "        formObj.password.value=username;\n"; 
 print "        setStatusBar(msg0);\n"; 
 print "   }\n"; 
 print "}\n"; 
 print "/******************************************************************\n"; 
 print "   showPasswd(formObj)\n"; 
 print "   Show Password value from form.\n"; 
 print "*******************************************************************/\n"; 
 print "function showPasswd(formObj) {\n"; 
 print "   alert(\"Password es:\"+formObj.password.value+\"\");\n"; 
 print "}\n"; 
 print "/******************************************************************\n"; 
 print "   showPasswCache(formObj)\n"; 
 print "   Show PasswordCache value from form.\n"; 
 print "*******************************************************************/\n"; 
 print "function showPasswCache(formObj) {\n"; 
 print "     if ( formObj.passwCache.checked ) {\n"; 
 print "        alert(\"Password es:\"+formObj.password.value+\"\");\n"; 
 print "     }\n"; 
 print "     else {\n"; 
 print "        alert(msg4);\n"; 
 print "     }   \n"; 
 print "}\n"; 
 print "/******************************************************************\n"; 
 print "   CheckPasswd(formObj)\n"; 
 print "   Check Password value from form.\n"; 
 print "*******************************************************************/\n"; 
 print "function CheckPasswd(formObj) {\n"; 
 print "   if ( formObj.passwordchk.value != formObj.password.value) {\n"; 
 print "        alert(msg1);\n"; 
 print "        formObj.passwordchk.value=\"\";\n"; 
 print "        formObj.passwordchk.focus();\n"; 
 print "   }  \n"; 
 print "}\n"; 
 print "\n"; 
 print "/******************************************************************\n"; 
 print "   Check_fields(obj)\n"; 
 print "*******************************************************************/\n"; 
 print "function Check_fields(obj) {\n"; 
 print "     if ( emptyField(obj.password) == true ) {\n"; 
 print "          alert(obj.password.name+\":\"+msg1+\"->\"+obj.password.value+\"<-\");\n"; 
 print "		    obj.password.focus();\n"; 
 print "          return false;\n"; 
 print "     }         \n"; 
 print "   if ( obj.passwordchk.value != obj.password.value) {\n"; 
 print "        alert(msg1);\n"; 
 print "        obj.passwordchk.value=\"\";\n"; 
 print "        obj.passwordchk.focus();\n"; 
 print "        return false;\n"; 
 print "     }\n"; 
 print "     if ( obj.passwCache.checked ) {\n"; 
 print "          obj.passwCache.value=true; \n"; 
 print "          if ( ask_confpasscache == true ) {\n"; 
 print "               alert(msg3);\n"; 
 print "               ask_confpasscache=false;\n"; 
 print "               return false;\n"; 
 print "          }  \n"; 
 print "     }\n"; 
 print "     else {\n"; 
 print "          obj.passwCache.value=false; \n"; 
 print "     }\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_passwd'}</b></td> </tr>\n";
 print "<tr $cb> <td><table align=left>\n";
 print "<form METHOD=POST name=changepassw ACTION=\"passwd.cgi\" onSubmit=\"return Check_fields(this)\">\n"; 
 if ( "$username" ne "*" ) {
     print "        <tr><td valign=top>",&hlink("<b>$text{'f_username'}</b>","fusername"),"&nbsp;",$in{'username'},"  ";
     print "        &nbsp; ",&hlink("<b>$text{'f_grupo'}</b>","fgrupo"),"&nbsp;  ",$in{'userou'} ,"\n";
 } else {
     print "        <tr><td valign=top><b>$text{'index_filter'}</b></td>";
     print "<td> [ $base - $filter ] ";

 }
 print "      </td></tr>\n";
 print "        <input TYPE=\"hidden\" NAME=\"username\" VALUE=\"",$in{'username'},"\">\n";
 print "        <input TYPE=\"hidden\" NAME=\"dn\" VALUE=\"",$in{'dn'},"\">\n";
 print "        <input TYPE=\"hidden\" NAME=\"userou\" VALUE=\"",$in{'userou'},"\">\n";
 print "        <input TYPE=\"hidden\" NAME=\"filter\" VALUE=\"",$in{'filter'},"\">\n";
 print "        <input TYPE=\"hidden\" NAME=\"base\" VALUE=\"",$in{'base'},"\">\n";
 if ( $config{'has_systemusers'} eq "true" && $dn eq "-" ) {
    
    $num_user=&get_num_user($in{username});
    print "	<tr><td>",&hlink("<b>$text{'sys_user'}</b>","fsysuser"),"&nbsp;</td>";
    print " <td>&nbsp; &nbsp; &nbsp; &nbsp;<input type=button onClick='javascript: window.open(\"/useradmin/edit_user.cgi?num=$num_user\", \"edituser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=400\");return false' value=\"$text{modify} $in{username}\">\n";
    print "&nbsp;&nbsp;&nbsp;&nbsp&nbsp;",&hlink("<b>$text{'sync_user'}</b>","fsyncuser"),"&nbsp;";
    print "<input type=\"checkbox\" name=\"syncuser\" value=\"true\" >&nbsp;</td></tr>\n";
    print "<tr><td><hr></td><td><hr></td></tr>\n";
 }
 if ( $config{'has_ldapusers'} eq "true" && $dn ne "-" ) {
       print "        <tr><td valign=top>",&hlink("<b>$text{'f_password'}</b>","fpassword"),"\n";
       print "	   <input TYPE=\"button\" NAME=\"?\" VALUE=\"?\" onClick=\"showPasswd(changepassw);\" >\n"; 
      
       print "	  <td valign=top> <input TYPE=\"password\" NAME=\"password\" VALUE=\"\" cols=\"22\" size=\"12\" ALIGN=left\n"; 
       print "			onChange=\"changepassw.passwordchk.value=''\" ></td></tr>\n"; 
       print "<!--			onChange=\"setPasswdDefault(changepassw)\" onFocus=\"setPasswdDefault(changepassw)\" > --> \n"; 
       print "	   <tr><td valign=top>",&hlink("<b>$text{'f_passwordchk'}</b>","fpasswordchk"),"\n";
       print "	   <td valign=top><input TYPE=\"password\" NAME=\"passwordchk\" VALUE=\"\" cols=\"22\" size=\"12\" ALIGN=left\n"; 
       print "  			   onChange=\"CheckPasswd(changepassw)\" ></td></tr>\n"; 
}
if ( $config{'is_ldapcache'} ne "true" ) {
   print "	<tr><td valign=top>",&hlink("<b>$text{'f_defpasswd3tier'}</b>","fdefpasswd3tier"),"\n"; 
   print "	   <input TYPE=\"button\" NAME=\"?\" VALUE=\"?\" onClick=\"showPasswCache(changepassw);\" >&nbsp;\n"; 
   print "	  <td valign=top> <input TYPE=\"checkbox\" NAME=\"passwCache\" VALUE=\"false\"></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;\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;



