From: Stricted Date: Thu, 2 Jul 2015 07:07:51 +0000 (+0200) Subject: fix login on firmware 050124.02.00.009 X-Git-Tag: 1.0.0~9 X-Git-Url: https://git.stricted.de/?p=GitHub%2FStricted%2Fspeedport-hybrid-php-api.git;a=commitdiff_plain;h=c2678616c9b2849615e47125722124ee2425a167 fix login on firmware 050124.02.00.009 --- diff --git a/speedport.class.php b/speedport.class.php index 39f26a9..4aa517d 100644 --- a/speedport.class.php +++ b/speedport.class.php @@ -64,7 +64,9 @@ class speedport { $fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'challengev' => 'null'); $data = $this->sentRequest($path, $fields); $data = json_decode($data['body'], true); - if ($data[1]['varid'] == 'challengev') { + $data = $this->getValues($data); + + if (isset($data['challengev']) && !empty($data['challengev'])) { $this->challenge = $data[1]['varvalue']; } } @@ -81,7 +83,8 @@ class speedport { $fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'password' => $this->hash); $data = $this->sentRequest($path, $fields); $json = json_decode($data['body'], true); - if ($json[15]['varid'] == 'login' && $json[15]['varvalue'] == 'success') { + $json = $this->getValues($json); + if (isset($json['login']) && $json['login'] == 'success') { if (isset($data['header']['Set-Cookie']) && !empty($data['header']['Set-Cookie'])) { preg_match('/^.*(SessionID_R3=[a-z0-9]*).*/i', $data['header']['Set-Cookie'], $match); if (isset($match[1]) && !empty($match[1])) { @@ -116,6 +119,7 @@ class speedport { // reset challenge and session $this->challenge = ''; $this->session = ''; + $this->token = ""; $json = json_decode($data['body'], true); @@ -149,7 +153,11 @@ class speedport { if ($status == 'online' || $status == 'offline') { $fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'password' => $this->hash, 'req_connect' => $status); $cookie = 'challengev='.$this->challenge.'; '.$this->session; - $this->sentRequest($path, $fields, $cookie); + $data = $this->sentRequest($path, $fields, $cookie); + + $json = json_decode($this->decrypt($data['body']), true); + + return $json; } else { throw new Exception(); @@ -329,7 +337,7 @@ class speedport { * @param string $data * @return array */ - public function decrypt ($data) { + private function decrypt ($data) { require_once 'CryptLib/CryptLib.php'; $factory = new CryptLib\Cipher\Factory(); $aes = $factory->getBlockCipher('rijndael-128'); @@ -353,7 +361,7 @@ class speedport { * @param array $data * @return string */ - public function encrypt ($data) { + private function encrypt ($data) { require_once 'CryptLib/CryptLib.php'; $factory = new CryptLib\Cipher\Factory(); $aes = $factory->getBlockCipher('rijndael-128'); @@ -369,6 +377,21 @@ class speedport { return bin2hex($mode->finish()); } + /** + * get the values from array + * + * @param array $array + * @return array + */ + private function getValues($array) { + $data = array(); + foreach ($array as $item) { + $data[$item['varid']] = $item['varvalue']; + } + + return $data; + } + /** * sends the request to router *