Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //this will test and validate your filezilla exported sites ie filezilla.xml file run this in the dir filezilla.xml is ie
- //'php verify.php filezilla.xml' or
- //'php verify.php filezilla.xml verify' to validate ftp details
- //an html file called filezilla_status will contain the ftp info
- $xml_file = $argv[1];
- if(isset($argv[1] && $argv[1] == "verify")){
- $test_ftp = true;
- }else{
- $test_ftp = false;
- }
- $xml_host_key = "*FILEZILLA3*SERVERS*SERVER*HOST";
- $xml_port_key = "*FILEZILLA3*SERVERS*SERVER*PORT";
- $xml_user_key = "*FILEZILLA3*SERVERS*SERVER*USER";
- $xml_pass_key = "*FILEZILLA3*SERVERS*SERVER*PASS";
- $xml_name_key = "*FILEZILLA3*SERVERS*SERVER*NAME";
- $story_array = array();
- $counter = 0;
- class xml_story{
- var $host, $port,$user,$pass, $valid;
- }
- function startTag($parser, $data){
- global $current_tag;
- $current_tag .= "*$data";
- }
- function endTag($parser, $data){
- global $current_tag;
- $tag_key = strrpos($current_tag, '*');
- $current_tag = substr($current_tag, 0, $tag_key);
- }
- function contents($parser, $data){
- global $current_tag, $xml_host_key, $xml_port_key, $counter, $story_array,$xml_user_key,$xml_pass_key,$xml_name_key;
- switch($current_tag){
- case $xml_host_key:
- $story_array[$counter] = new xml_story();
- $story_array[$counter]->host = $data;
- break;
- case $xml_port_key:
- $story_array[$counter]->port = $data;
- //$counter++;
- break;
- case $xml_user_key:
- $story_array[$counter]->user = $data;
- // $counter++;
- break;
- case $xml_pass_key:
- $story_array[$counter]->pass = $data;
- $story_array[$counter]->plain_txt_pass = base64_decode($data);
- // $counter++;
- break;
- case $xml_name_key:
- $story_array[$counter]->name = $data;
- $counter++;
- break;
- }
- }
- function get_percentage($total, $number)
- {
- if ( $total > 0 ) {
- return round($number / ($total / 100),2);
- } else {
- return 0;
- }
- }
- function test_ftp($vals){
- $ftp_server = $vals->host;
- $ftp_user = $vals->user;
- $ftp_pass = $vals->plain_txt_pass;
- $result = null;
- // set up a connection or die
- $conn_id = ftp_connect($ftp_server);
- if(is_resource($conn_id)){
- // try to login
- if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
- // echo "Connected as $ftp_user@$ftp_server\n";
- $result="valid";
- } else {
- // echo "Couldn't connect as $ftp_user\n";
- $result="invalid";
- }
- // close the connection
- ftp_close($conn_id);
- }else{
- $result="invalid";
- }
- return $result;
- }
- $xml_parser = xml_parser_create();
- xml_set_element_handler($xml_parser, "startTag", "endTag");
- xml_set_character_data_handler($xml_parser, "contents");
- $fp = fopen($xml_file, "r") or die("Could not open file");
- $data = fread($fp, filesize($xml_file)) or die("Could not read file");
- if(!(xml_parse($xml_parser, $data, feof($fp)))){
- die("Error on line " . xml_get_current_line_number($xml_parser));
- }
- xml_parser_free($xml_parser);
- fclose($fp);
- $html =
- '<html>
- <head>
- <title>Filezilla Parser</title>
- </head>
- <body bgcolor="#FFFFFF">
- <table width="1001" border="1">
- <tr>
- <td width="47"><strong>NO</strong></td>
- <td width="185"><strong>Name</strong></td>
- <td width="229"><strong>Host</strong></td>
- <td width="221"><strong>User Name</strong></td>
- <td width="125"><strong>Password</strong></td>
- <td width="154"><strong>Port</strong></td>
- <td><strong>Status</strong></td>
- </tr>';
- for($x=0;$x<count($story_array);$x++){
- echo get_percentage(count($story_array), $x) ."\n";
- if($test_ftp == true){
- $story_array[$x]->valid = test_ftp($story_array[$x]);
- }else{
- $story_array[$x]->valid = "Unknown";
- }
- $html .= "
- <tr>
- <td height='38'></td>
- <td>" . $story_array[$x]->name . " </td>
- <td>" . $story_array[$x]->host . "</td>
- <td>" . $story_array[$x]->user . "</td>
- <td>" . $story_array[$x]->plain_txt_pass . "</td>
- <td>" . $story_array[$x]->port . "</td>
- <td>" . $story_array[$x]->valid . "</td>
- </tr>";
- }
- $html .=
- '</table>
- </body>
- </html>';
- //echo $html;
- file_put_contents('filezilla_status.html',$html);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement