support new speedport login method
authorStricted <info@stricted.net>
Sat, 17 Jun 2017 12:36:57 +0000 (14:36 +0200)
committerStricted <info@stricted.net>
Sat, 17 Jun 2017 12:36:57 +0000 (14:36 +0200)
lib/trait/Login.class.php

index 2e5d029f2475e595476f85f182e9dcb721fc1c82..aee01b3279a648106f4a9fd65c39ead5adbdec42 100644 (file)
@@ -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
         *