webMasterYoda Posted April 11, 2007 Share Posted April 11, 2007 Hi ppl. I have a problem. I am using a PHP script for hot-spot internet accounting. It is connecting to MikroTik's FTP from which it aquires certain file which contains info about hot-spot users internet usage. But, after reconstruction of our network sript stopped working. It's still connecting to FTP server, but cannot get directory and file list. BTW it is working in passive mode. I am sure about this, because I tested it with another FTP client from the server which is hosting this script. So, the solution is to force script to connect to MikroTiks FTP server in passive mode. But I am unable to get this done due to my poor knowledge of PHP scripting. Here is 2 main files which are important for PHP script config.php ------------ <?php //----------------------------------------------------------------------------------- $company = "KulaWireless"; $website_title = "KulaWireless Hu2T"; $website = "www.kulawireless.net"; $website_url = "http://".$website; $website_logo = "$website_url/themes/ExtraLite/images/logo.gif"; //----------------------------------------------------------------------------------- $ftp_server = "10.5.53.1"; $ftp_user_name = "user"; $ftp_user_pass = "password"; $ftp_file = "myprotok_kw5.txt"; //----------------------------------------------------------------------------------- global $status; //----------------------------------------------------------------------------------- $local_file = "./temp/xuserdata.dat"; $local_tmpf = "./temp/xtmp.dat"; //----------------------------------------------------------------------------------- global $user_name; global $user_pass; global $user_upload_limit; global $user_download_limit; global $user_upload; global $user_download; global $form_user; global $form_pass; //----------------------------------------------------------------------------------- # Messages $msg_invalid_user_or_pass = "Invalid username or password!"; $msg_both_parameter = "You must type both parameters!"; #Don't change $msg_footnote. It is fully forbidden. $msg_footnote = "Hu2T v0.0.3 engine's code is Copyright © 2005 by TuXzA. All Rights Reserved. Hu2T is Mikrotik Hostspot user used traffic monitor."; $msg_ftp_cnt_error = "There was a problem. Please try later or contact with system administrator." ; $msg_ftp_cnt_ok = "Successfully connected to database."; //----------------------------------------------------------------------------------- ?> main.php ------------ <?php //----------------------------------------------------------------------------------- $ftp_con = ftp_connect($ftp_server); $ftp_log_res = @ftp_login($ftp_con, $ftp_user_name, $ftp_user_pass); if (@ftp_get($ftp_con, $local_file, $ftp_file, FTP_BINARY)) { $status = $msg_ftp_cnt_ok; } else { $status = $msg_ftp_cnt_error; } @ftp_close($ftp_con); //----------------------------------------------------------------------------------- $ujsor = 0; $filebe = fopen($local_file, "r"); $fileki = fopen($local_tmpf, "w"); $text=fread($filebe,filesize($local_file)); for ($i=1 ; $i<filesize($local_file); $i++) if ((($text[$i-1]!=="\x20") && ($text[$i]=="\x20"))||($text[$i]!=="\x20")) { if ($ujsor>3) fwrite($fileki,$text[$i]); if ($text[$i]=="\x0A") $ujsor++; } fclose($fileki); fclose($filebe); //----------------------------------------------------------------------------------- $filebe = fopen($local_tmpf, "r"); $text=fread($filebe,filesize($local_tmpf)); $text.="\x0A\x0A"; $i=0; do { $userdata=''; while (!(($text[$i]=="\x0A") && ($text[$i+1]=="\x0A"))) { if ($text[$i]=="\x0A") $i++; else if ($text[$i]=="\x2D"); else $userdata.="$text[$i]"; $i++; } $i++; // print ($userdata); //-----------xxxxxxxxxxx $xm=1; $xa=1; $xb=1; $xc=1; $xd=1; $userdata1=$userdata; $userdata=str_replace("macaddress", "mcaddress", $userdata); if (strcmp($userdata1,$userdata)==0) $xm=0; $userdata1=$userdata; $userdata=str_replace("limitbytesin", "xxxxxa", $userdata); if (strcmp($userdata1,$userdata)==0) $xa=0; $userdata1=$userdata; $userdata=str_replace("limitbytesout", "xxxxxb", $userdata); if (strcmp($userdata1,$userdata)==0) $xb=0; $userdata1=$userdata; $userdata=str_replace("bytesin", "xxxxxc", $userdata); if (strcmp($userdata1,$userdata)==0) $xc=0; $userdata1=$userdata; $userdata=str_replace("bytesout", "xxxxxd", $userdata); if (strcmp($userdata1,$userdata)==0) $xd=0; // print ($userdata); //-----------xxxxxxxxxxx $upoz1 = strpos($userdata, 'name'); $upoz2 = strpos($userdata, 'password'); $uservag= array ('name=','"'); $user_name=str_replace($uservag, "", substr($userdata,$upoz1,$upoz2-$upoz1-1)); $ppoz1 = strpos($userdata, 'password'); if ($xm==1) $ppoz2 = strpos($userdata, 'mcaddress'); else $ppoz2 = strpos($userdata, 'profile'); $passvag= array ('password=','"'); $user_pass=str_replace($passvag, "", substr($userdata,$ppoz1,$ppoz2-$ppoz1-1)); $ulpoz1 = strpos($userdata, 'xxxxxa'); $ulpoz2 = strpos($userdata, 'xxxxxb'); $ullimitvag= array ('xxxxxa','='); $user_upload_limit=str_replace($ullimitvag, "", substr($userdata,$ulpoz1,$ulpoz2-$ulpoz1)); $user_upload_limit/=1024*1024; $dlpoz1 = strpos($userdata, 'xxxxxb'); $dlpoz2 = strpos($userdata, 'uptime'); $dllimitvag= array ('xxxxxb','='); $user_download_limit=str_replace($dllimitvag, "", substr($userdata,$dlpoz1,$dlpoz2-$dlpoz1)); $user_download_limit/=1024*1024; $bipoz1 = strpos($userdata, 'xxxxxc'); $bipoz2 = strpos($userdata, 'xxxxxd'); $bivag= array ('xxxxxc','='); $user_upload=str_replace($bivag, "", substr($userdata,$bipoz1,$bipoz2-$bipoz1)); $user_upload/=1024*1024; $bopoz1 = strpos($userdata, 'xxxxxd'); $bopoz2 = strpos($userdata, 'packetsin'); $bovag= array ('xxxxxd','='); $user_download=str_replace($bovag, "", substr($userdata,$bopoz1,$bopoz2-$bopoz1)); $user_download/=1024*1024; } while( !(($user_name==$form_user)|| ($i == filesize($local_tmpf)) ) ); fclose($filebe); //----------------------------------------------------------------------------------- ?> So, can someone help me? I really cant this done without your help. Thanx inadvance. Link to comment https://forums.phpfreaks.com/topic/46589-problem-with-script-connecting-to-ftp-using-passive-mode/ Share on other sites More sharing options...
electricblue Posted April 11, 2007 Share Posted April 11, 2007 Have you tried ftp_pasv? Link to comment https://forums.phpfreaks.com/topic/46589-problem-with-script-connecting-to-ftp-using-passive-mode/#findComment-226787 Share on other sites More sharing options...
webMasterYoda Posted April 11, 2007 Author Share Posted April 11, 2007 Hi electric. Thanks for your answer. Yes I tried, but I am not sure I putted the tag on the right place. As I said, my knowledge of PHP scripting is very poor. I know that "ftp_pasv" tag is important for this, but I dunno where and how to put it. That is the real problem. Dont laugh on me. Yes I am PHP noob. Link to comment https://forums.phpfreaks.com/topic/46589-problem-with-script-connecting-to-ftp-using-passive-mode/#findComment-226795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.