Advertisement
Guest User

Untitled

a guest
Oct 7th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. class OperazioniFTP {
  2.  
  3. var $host = null;
  4. var $username = null;
  5. var $password = null;
  6.  
  7. var $new_password = null ;
  8. var $new_retype_password = null;
  9.  
  10.  
  11. private $ftp_db_user = null;
  12. private $ftp_db_pass = null;
  13. private $ftp_db_name = null;
  14. private $ftp_db_host = "localhost";
  15.  
  16. protected $conn_id = null;
  17.  
  18. function __construct() {
  19. var_dump($this->ftp_db_pass);
  20. var_dump($this->ftp_db_user);
  21.  
  22. // $this->db_connect();
  23. }
  24. function recupera_credenziali_proftpd() {
  25. $handle = file_get_contents('/etc/proftpd/sql.conf');
  26. $handle = preg_replace('/\s\s+/', ' ' ,$handle);
  27. $array_configurations =explode("\n",$handle);
  28. foreach ($array_configurations as $conf_line) {
  29. $array_esploso = explode(" ",$conf_line);
  30. if($array_esploso[0] == "SQLConnectInfo"){
  31. // $string = $array_esploso[1];
  32. // var_dump($string);
  33. list($database, $host)=explode("@", $array_esploso[1]);
  34. $array_esploso['database']=$database;
  35. $array_esploso['host']=$host;
  36. $array_esploso['username']=$array_esploso[2];
  37. $array_esploso['password']=$array_esploso[3];
  38.  
  39. unset($array_esploso[1]);
  40. unset($array_esploso[2]);
  41. unset($array_esploso[3]);
  42.  
  43. }
  44.  
  45. if($array_esploso[0] == "SQLUserInfo"){
  46. $array_esploso['table'] = $array_esploso[1];
  47. unset($array_esploso[1]);
  48. }
  49. $output_array[array_shift($array_esploso)] = $array_esploso;
  50. }
  51.  
  52. print_r($output_array);
  53. $this->ftp_db_user = $output_array['SQLConnectInfo']['username'];
  54. $this->ftp_db_pass = $output_array['SQLConnectInfo']['password'];
  55. $this->ftp_db_name = $output_array['SQLConnectInfo']['database'];
  56. $this->ftp_db_host = $output_array['SQLConnectInfo']['host'];
  57. $this->ftp_db_table = $output_array['SQLUserInfo']['table'];
  58.  
  59. // var_dump($this->ftp_db_pass);
  60. return true;
  61. }
  62.  
  63. function db_connect(){
  64.  
  65. $user = $this->ftp_db_user;
  66. $pass = $this->ftp_db_pass;
  67. $host = $this->ftp_db_host;
  68. $database = $this->ftp_db_name;
  69. $table = $this->ftp_db_table;
  70. $mysqli = new mysqli($host, $user, $pass, $database);
  71. if ($mysqli->connect_error) {
  72. die('Connect Error (' . $mysqli->connect_errno . ') '
  73. . $mysqli->connect_error);
  74. }
  75.  
  76. }
  77.  
  78.  
  79. function ftp_check(){
  80. // Connect
  81. $this->conn_id = ftp_connect($this->host);
  82.  
  83. // Open a session to an external ftp site
  84. $login_result = ftp_login ($this->conn_id, $this->username, $this->password);
  85.  
  86. // Check open
  87. // return ((!$this->conn_id) || (!$login_result)) ? false : true ;
  88. return ((!$this->conn_id) || (!$login_result)) ? false : $this->cambia_password() ;
  89. }
  90.  
  91. protected function cambia_password(){
  92. $SQL = "UPDATE `ftp`.`web1` SET `crypassword` = ENCRYPT('".$this->new_password."') WHERE `userid` = '".$this->username."' LIMIT 1";
  93. // echo $SQL;
  94. //return true;
  95. }
  96. function __destruct() {
  97. ftp_close($this->conn_id);
  98. }
  99.  
  100. }
  101.  
  102. $azione = new OperazioniFTP();
  103.  
  104. $azione->username=$_GET['username'];
  105. $azione->password=$_GET['actual_password'];
  106. $azione->host="localhost";
  107. $azione->recupera_credenziali_proftpd();
  108. $azione->new_password = (!$_GET['new_password']) ? die("ko,nuova password mancante") : $_GET['new_password'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement