#!/usr/bin/perl
# passwd.cgi
# STTA Rev. 1.3 Copyright (c) 2001-2002 Jesús Pérez Lorenzo  --- license GNU GPL 

 require './stta-lib.pl';
do "ldap-lib.pl";
&ReadParse();

$dn = $in{dn};
if (!$dn) { &redirect("tta_selusr.cgi?form=passwd"); } 
$username=$in{username};
$password=$in{password};
if (!$password) { &redirect("tta_selusr.cgi?form=passwd"); } 
 &headerstta($text{'index_passwd'}, "", "passwd",undef,1,1,$text{headpage_rigth} );
 print "<hr><p>\n"; 
 print "<p>\n";
 print "<table width=100% border>\n";
   
 $organizationname="";
 $ens_ou="";
 $aliasou=$in{userou};
 %h_ou=&list_ous();
 if ( $h_ou{$aliasou}->{'alias'} ne $aliasou ) {
      $err_msg=$text{'list_err'};
      &footHere;
      exit;
 }
 $dn_ou=$h_ou{$aliasou}->{'obj'};
 $organizationname=$h_ou{$aliasou}->{'name'};
 $ens_ou=$h_ou{$aliasou}->{'ens'};
 print "<tr $tb> <td><b>".&text('titidx_passwd',$username,$organizationname)."</b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<center>\n";

 $ldap_server=1;
 &connect ();

 if ( &mod_usr_password() eq 0 ) {
        if ( $config{ldap2_server}.length gt 0 ) {
             $ldap_server=2;
             &connect ();
             if ( &mod_usr_password() ne 0 ) { &err_replication() }
        }
        $lin_user="mod::".$username."::".$password."::".$in{surname}."::".$dn;
        &lock_file($config{'ldap_log_name'});
        open(FILELDAPLOG, ">>$config{'ldap_log_name'}");
               print FILELDAPLOG "$lin_user\n";
        close (FILELDAPLOG);
        $str=$text{'user_update'}.$username." ($surname) ->  ".$dn;
        &additional_log('passwd.cgi', "passwd", $str);
        &webmin_log($config{'ldap_log_name'}, "passwd", "modify",$lin_user);
        &unlock_file($config{'ldap_log_name'});
        print "</pre><tr><p><b>$text{'user_update'}... LDAP </b></tr>\n";
 }
 print "<tr></tr>\n";
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;
