Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. <?php
  2.  
  3. //this will test and validate your filezilla exported sites ie filezilla.xml file run this in the dir filezilla.xml is ie
  4. //'php verify.php filezilla.xml' or
  5. //'php verify.php filezilla.xml verify' to validate ftp details
  6. //an html file called filezilla_status will contain the ftp info
  7.  
  8. $xml_file = $argv[1];
  9. if(isset($argv[1] && $argv[1] == "verify")){
  10. $test_ftp = true;
  11. }else{
  12. $test_ftp = false;
  13. }
  14. $xml_host_key = "*FILEZILLA3*SERVERS*SERVER*HOST";
  15. $xml_port_key = "*FILEZILLA3*SERVERS*SERVER*PORT";
  16. $xml_user_key = "*FILEZILLA3*SERVERS*SERVER*USER";
  17. $xml_pass_key = "*FILEZILLA3*SERVERS*SERVER*PASS";
  18. $xml_name_key = "*FILEZILLA3*SERVERS*SERVER*NAME";
  19. $story_array = array();
  20. $counter = 0;
  21.  
  22. class xml_story{
  23. var $host, $port,$user,$pass, $valid;
  24. }
  25. function startTag($parser, $data){
  26. global $current_tag;
  27. $current_tag .= "*$data";
  28. }
  29. function endTag($parser, $data){
  30. global $current_tag;
  31. $tag_key = strrpos($current_tag, '*');
  32. $current_tag = substr($current_tag, 0, $tag_key);
  33. }
  34. function contents($parser, $data){
  35. global $current_tag, $xml_host_key, $xml_port_key, $counter, $story_array,$xml_user_key,$xml_pass_key,$xml_name_key;
  36. switch($current_tag){
  37. case $xml_host_key:
  38. $story_array[$counter] = new xml_story();
  39. $story_array[$counter]->host = $data;
  40. break;
  41. case $xml_port_key:
  42.  
  43. $story_array[$counter]->port = $data;
  44. //$counter++;
  45. break;
  46. case $xml_user_key:
  47.  
  48. $story_array[$counter]->user = $data;
  49. // $counter++;
  50. break;
  51. case $xml_pass_key:
  52.  
  53. $story_array[$counter]->pass = $data;
  54. $story_array[$counter]->plain_txt_pass = base64_decode($data);
  55. // $counter++;
  56. break;
  57. case $xml_name_key:
  58.  
  59. $story_array[$counter]->name = $data;
  60. $counter++;
  61. break;
  62.  
  63. }
  64. }
  65. function get_percentage($total, $number)
  66. {
  67. if ( $total > 0 ) {
  68. return round($number / ($total / 100),2);
  69. } else {
  70. return 0;
  71. }
  72. }
  73. function test_ftp($vals){
  74.  
  75. $ftp_server = $vals->host;
  76. $ftp_user = $vals->user;
  77. $ftp_pass = $vals->plain_txt_pass;
  78. $result = null;
  79. // set up a connection or die
  80. $conn_id = ftp_connect($ftp_server);
  81.  
  82. if(is_resource($conn_id)){
  83. // try to login
  84. if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
  85. // echo "Connected as $ftp_user@$ftp_server\n";
  86. $result="valid";
  87. } else {
  88. // echo "Couldn't connect as $ftp_user\n";
  89. $result="invalid";
  90. }
  91.  
  92. // close the connection
  93. ftp_close($conn_id);
  94. }else{
  95. $result="invalid";
  96. }
  97. return $result;
  98. }
  99.  
  100. $xml_parser = xml_parser_create();
  101. xml_set_element_handler($xml_parser, "startTag", "endTag");
  102. xml_set_character_data_handler($xml_parser, "contents");
  103. $fp = fopen($xml_file, "r") or die("Could not open file");
  104. $data = fread($fp, filesize($xml_file)) or die("Could not read file");
  105. if(!(xml_parse($xml_parser, $data, feof($fp)))){
  106. die("Error on line " . xml_get_current_line_number($xml_parser));
  107. }
  108. xml_parser_free($xml_parser);
  109. fclose($fp);
  110.  
  111. $html =
  112. '<html>
  113. <head>
  114. <title>Filezilla Parser</title>
  115. </head>
  116. <body bgcolor="#FFFFFF">
  117. <table width="1001" border="1">
  118. <tr>
  119. <td width="47"><strong>NO</strong></td>
  120. <td width="185"><strong>Name</strong></td>
  121. <td width="229"><strong>Host</strong></td>
  122. <td width="221"><strong>User Name</strong></td>
  123. <td width="125"><strong>Password</strong></td>
  124. <td width="154"><strong>Port</strong></td>
  125. <td><strong>Status</strong></td>
  126. </tr>';
  127.  
  128. for($x=0;$x<count($story_array);$x++){
  129.  
  130. echo get_percentage(count($story_array), $x) ."\n";
  131.  
  132. if($test_ftp == true){
  133. $story_array[$x]->valid = test_ftp($story_array[$x]);
  134. }else{
  135. $story_array[$x]->valid = "Unknown";
  136. }
  137.  
  138. $html .= "
  139. <tr>
  140. <td height='38'></td>
  141. <td>" . $story_array[$x]->name . " </td>
  142. <td>" . $story_array[$x]->host . "</td>
  143. <td>" . $story_array[$x]->user . "</td>
  144. <td>" . $story_array[$x]->plain_txt_pass . "</td>
  145. <td>" . $story_array[$x]->port . "</td>
  146. <td>" . $story_array[$x]->valid . "</td>
  147. </tr>";
  148. }
  149.  
  150. $html .=
  151. '</table>
  152. </body>
  153. </html>';
  154.  
  155. //echo $html;
  156.  
  157. file_put_contents('filezilla_status.html',$html);
  158. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement