0

I am building a web application for my router, it will be my Bachelor's Thesis.

The bad thing is that I can't display my router's informations using my cURL function because I get bad router username and password error. I didn't found any problem at all:

The cURL function:

function myCurl($url, $post="")
{
    global $status;



$header = 'Authorization: Basic YWRtaW46YWRtaW4=';

$cookiepath_tmp = "c:/xampp/htdocs/wifi/cookie.txt";

$resp = array();

$ch = curl_init();

curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
curl_setopt($ch,CURLOPT_URL, trim($url));
curl_setopt($ch,CURLOPT_REFERER, trim($url));
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookiepath_tmp);
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookiepath_tmp);
curl_setopt($ch,CURLOPT_COOKIESESSION, true);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_MAXREDIRS, 10);
curl_setopt($ch,CURLOPT_ENCODING, "");
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
#curl_setopt($ch,CURLOPT_AUTOREFERER, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch,CURLOPT_TIMEOUT, 15);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch,CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_HTTPHEADER, array( 'Expect:' ) );
curl_setopt($ch,CURLOPT_VERBOSE, 1);
#curl_setopt($ch,CURLOPT_FAILONERROR, true);

if($post) { curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$post); }

$returned = curl_exec($ch);
$resp['returned'] = $returned;

$status=curl_getinfo($ch);
$resp['status'] = $status;
curl_close($ch);


return $resp;
}

I am trying to display the informations using PHP:

The PHP code:

<?php echo $success_msg; 
        $url = "http://192.168.0.1/session.cgi";
        $post = "REPORT_METHOD=xml&ACTION=login_plaintext&USER=admin&PASSWD=admin&CAPTCHA=";
        $data = myCurl($url, $post);

        #$url = "http://192.168.0.1/st_log.php";
        #$data = myCurl($url);
        echo $data['returned'];

        ?>

The error is:

Username or Password is incorrect.

However, The username and password admin are correct.

I have added the following code into myCurl function but still doesn't work:

$header = 'Authorization: Basic YWRtaW46YWRtaW4=';
YWRtaW46YWRtaW4= is the encoded username:password in Base64.

LAST EDIT: I set the CURLOPT_HEADER to true, and I got this text displayed:

HTTP/1.1 501 Not Implemented Server: Router Webserver Connection: close WWW-Authenticate: Basic realm="TP-LINK Wireless Lite N Router WR740N" Content-Type: text/html 

Any solution for this?

I really appreciate your help! Thank you!

toofast
  • 39
  • 2
  • 12

1 Answers1

0

I don't known what is your router (vendor / model) but most of them use HTTP basic authentication. And, when the authentication is empty or wrong you get a HTTP 401 error: Unauthorized, which could correspond to your error string.

So you should try to insert a HTTP authorization header in the cURL request:

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Community
  • 1
  • 1
jmlemetayer
  • 4,774
  • 1
  • 32
  • 46