From: Stricted Date: Sat, 17 Jun 2017 12:36:57 +0000 (+0200) Subject: support new speedport login method X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5575d0177b3669ed808101e28fca40440a8c2be9;p=GitHub%2FStricted%2Fspeedport-hybrid-php-api.git support new speedport login method --- diff --git a/lib/trait/Login.class.php b/lib/trait/Login.class.php index 2e5d029..aee01b3 100644 --- a/lib/trait/Login.class.php +++ b/lib/trait/Login.class.php @@ -46,10 +46,16 @@ trait Login { $path = 'data/Login.json'; $this->hash = hash('sha256', $this->challenge.':'.$password); - $fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'password' => $this->hash); + $fields = array('csrf_token' => 'nulltoken', "challengev" => $this->challenge, 'showpw' => 0, 'password' => $this->hash); $data = $this->sendRequest($path, $fields); $json = $this->getValues($data['body']); + if (in_array("challenge", $json)) { + $fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'password' => $this->hash); + $data = $this->sendRequest($path, $fields); + $json = $this->getValues($data['body']); + } + if (isset($json['login']) && $json['login'] == 'success') { $this->cookie = $this->getCookie($data); @@ -69,7 +75,7 @@ trait Login { /** * Requests the password-challenge from the router. */ - private function getChallenge () { + private function getChallenge_old () { $path = 'data/Login.json'; $fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'challengev' => 'null'); $data = $this->sendRequest($path, $fields); @@ -83,6 +89,30 @@ trait Login { } } + /** + * Requests the password-challenge from the router. + */ + private function getChallenge () { + $path = 'html/content/overview/index.html'; + $fields = array(); + $data = $this->sendRequest($path, $fields, true); + + $a = explode('challenge = "', $data['body']); + + if (!isset($a[1])) { + return getChallenge_old(); + } + + $a = explode('";', $a[1]); + + if (isset($a[0]) && !empty($a[0])) { + return $a[0]; + } + else { + throw new RouterException('unable to get the challenge from the router'); + } + } + /** * check if we are logged in *