ftp.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. function salt($alg) {
  3. $salt=NULL;
  4. $n_char_to_remove=1;
  5. $max_blowfish_salt_length=22;
  6. $DEFAULT_SHA_ROUNDS =5000;
  7. $chararr=array('Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','0','1','2','3','4','5','6','7','8','9','/','.');
  8. if($alg="blowfish")
  9. $n_char_to_remove+=2; //tolgo dall'array "." e "/"
  10. else
  11. $n_char_to_remove+=0;
  12. for ($i=0;$i<$max_blowfish_salt_length;$i++){
  13. $salt .=$chararr[rand(0,count($chararr)-$n_char_to_remove)];
  14. }
  15. if ($alg="sha256")
  16. $init='$5$rounds='.$DEFAULT_SHA_ROUNDS;
  17. elseif ($alg="sha512")
  18. $init='$6$rounds='.$DEFAULT_SHA_ROUNDS;
  19. elseif ($alg="blowfish")
  20. $init='$2a$07';
  21. return $init.'$'.$salt;
  22. }
  23. //info mysql
  24. require_once('config/ftp.php');
  25. global $sock;
  26. $sock=mysql_connect($host,$user,$passwd);
  27. mysql_select_db($db);
  28. //fine sql
  29. $cosa="ftp";
  30. require_once('include/template.php');
  31. require_once('include/log.php');
  32. require_once('include/strenght_box.php');
  33. printHead($title_page);
  34. printLangSelector($lang);
  35. if ($_POST["ph"]==""){
  36. printPasswordStrenght();
  37. }
  38. printTitle($title);
  39. //printMessage($msgServiceOffline);
  40. //exit;
  41. if ($_POST["ph"]==""){
  42. printForm($form_user, $cosa, $lang);
  43. } else if ($_POST["ph"]=="1" AND $_POST["npwd"]==$_POST["npwd2"]) {
  44. $f=getLogFd();
  45. $p_sha256=$p_crypt=NULL;
  46. $host = gethostname();
  47. $user = $_POST["user"];
  48. $opwd = $_POST["opwd"];
  49. $npwd = $_POST["npwd"];
  50. $user_e = mysql_real_escape_string($user,$sock);
  51. writeLog($f,"[Info] === user: $user_e, chpw START ".$cosa.".php ===");
  52. $pw_query = "SELECT password_crypt
  53. FROM ftp_accounts
  54. JOIN hosts_urls USING (url_id)
  55. JOIN hosts USING (host_id)
  56. WHERE username = '$user_e'
  57. AND hostname = '$host'
  58. AND ftp = 'Y'";
  59. $r = mysql_query($pw_query);
  60. if (mysql_num_rows($r) != 0) {
  61. $pw_arr = mysql_fetch_row($r);
  62. if ($pw_arr[0]!=NULL) {
  63. $p_crypt=crypt($opwd,$pw_arr[0]);
  64. }
  65. if (strlen($_POST["npwd"])<6) {
  66. writeLog($f,"[INFO] user: $user_e, password troppo corta");
  67. closeLogFd($f);
  68. printMessage($msgShortPassword);
  69. } else {
  70. $n_sha=hash('sha256', $npwd);
  71. $n_crypt=crypt($npwd,salt('sha256'));
  72. $uq="UPDATE ftp_accounts
  73. SET password_sha256 = '$n_sha',
  74. password_crypt = '$n_crypt'
  75. WHERE username = '$user_e'";
  76. mysql_query($uq);
  77. if (mysql_affected_rows()==1) {
  78. writeLog($f,"[Ok] user: $user_e, update succesful");
  79. closeLogFd($f);
  80. printMessage($msgPasswordChanged);
  81. } else {
  82. //echo "problemi nell update\n";
  83. writeLog($f,"[Error] user: $user_e, db update error");
  84. closeLogFd($f);
  85. printMessage($msgPasswordNotChanged);
  86. }
  87. }
  88. } else {
  89. writeLog($f,"[Info] user: $user_e, credenziali errate");
  90. closeLogFd($f);
  91. printMessage($msgPasswordNotChanged);
  92. }
  93. } else {
  94. //echo "le 2 pw nuove non combaciano\n";
  95. printMessage($msgFailedConfirm);
  96. }
  97. printFooter();
  98. ?>