Reputation: 91
I would like to get access to my router (Speedport w723v) with a php-script.
Actually I only need the cookievalue that will be appended to the URI after a successful login, e.g.: http://speedport.ip/auth/hcti_startseite.php?cookie=SessionID_R3,BxXQc7WSbiS
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "https://speedport.ip/");
curl_setopt( $ch, CURLOPT_REFERER, "https://speedport.ip/");
curl_setopt( $ch, CURLOPT_COOKIEFILE, "SessionID.txt");
curl_setopt( $ch, CURLOPT_COOKIEJAR, "SessionID.txt"); # SAME cookiefile.
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt( $ch, CURLOPT_POSTFIELDS, "Password=PASSWORD&Username=USERNAME");
curl_setopt( $ch, CURLOPT_HEADER, 1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$getinfo = curl_getinfo($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
var_dump($data);
var_dump($getinfo);
var_dump($errno);
var_dump($error);
curl_close ($ch);
Password and username are okay, the result thrown out by the script above looks as follows:
string(145) "HTTP/1.1 302
CACHE-CONTROL: no-cache
Content-Type: text/html
LOCATION: https://speedport.ip/pub/msgerrcode.php?cookie=
Content-Length: 0
"
array(26) {
["url"]=>
string(21) "https://speedport.ip/"
["content_type"]=>
string(9) "text/html"
["http_code"]=>
int(302)
["header_size"]=>
int(145)
["request_size"]=>
int(187)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(20)
["redirect_count"]=>
int(0)
["total_time"]=>
float(0.53)
["namelookup_time"]=>
float(0)
["connect_time"]=>
float(0)
["pretransfer_time"]=>
float(0.53)
["size_upload"]=>
float(34)
["size_download"]=>
float(0)
["speed_download"]=>
float(0)
["speed_upload"]=>
float(64)
["download_content_length"]=>
float(0)
["upload_content_length"]=>
float(34)
["starttransfer_time"]=>
float(0.53)
["redirect_time"]=>
float(0)
["redirect_url"]=>
string(47) "https://speedport.ip/pub/msgerrcode.php?cookie="
["primary_ip"]=>
string(12) "192.168.100.1"
["certinfo"]=>
array(0) {
}
["primary_port"]=>
int(443)
["local_ip"]=>
string(14) "192.168.100.106"
["local_port"]=>
int(50900)
}
int(0)
string(0) ""
The cookiefile (SessionID.txt) remains empty; I have tried all possible paths.
I have noticed the redirect, but have no idea how to continue.
What am I doing wrong?
Upvotes: 0
Views: 743
Reputation: 91
The Password needs to be base64 encoded, the URI was wrong - this succeeded finally:
$ch = curl_init();
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt( $ch, CURLOPT_URL, "https://speedport.ip/index/login.cgi");
curl_setopt( $ch, CURLOPT_REFERER, "https://speedport.ip/index/login.cgi");
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $filename);
curl_setopt( $ch, CURLOPT_COOKIEJAR, $filename);
curl_setopt( $ch, CURLOPT_POST, TRUE);
curl_setopt( $ch, CURLOPT_POSTFIELDS, "Password=".base64_encode(PASSWORD)."&Username=admin");
curl_setopt( $ch, CURLOPT_HEADER, 1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec( $ch);
note: Username is always "admin".
Now you can reconnect or read data like callers...
Remember to logout again with your SessionID, otherwise you will need to wait several minutes before you can login on https://speedport.ip
curl_setopt( $ch, CURLOPT_URL, "https://speedport.ip/auth/logout.cgi?cookie=SessionID_R3,".$sid);
$data .= curl_exec( $ch);
Hope this will help others. Haven't found anything on the internet for the W723V Type A (Huawei). BTW: Had a very (!) bad, long night with JDownloader and the malware distributed with it. Cannot recommend it anymore at all.
Upvotes: 1