2 require_once('ISpeedport.class.php');
3 require_once('lib/exception/RouterException.class.php');
4 require_once('SpeedportHybrid.class.php');
7 * @author Jan Altensen (Stricted)
8 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
9 * @copyright 2015 Jan Altensen (Stricted)
11 class Speedportw724v
extends SpeedportHybrid
implements ISpeedport
{
13 * login into the router with the given password
15 * @param string $password
18 public function login ($password) {
19 /* this is experimental, i dont have a speedport w724v so i cant test this
20 * feel free to test it and report if it dosent work
22 $path = 'data/Login.json';
23 $this->hash
= md5($password);
24 $fields = array('password' => $this->hash
, 'password_shadowed' => $this->hash
, 'showpw' => 0);
25 $data = $this->sentRequest($path, $fields);
26 $json = $this->getValues($data['body']);
28 if (isset($json['login']) && $json['login'] == 'success') {
29 if (isset($data['header']['Set-Cookie']) && !empty($data['header']['Set-Cookie'])) {
30 $this->cookie
= $data['header']['Set-Cookie'];
33 throw new RouterException('unable to get the session cookie from the router');
47 protected function getToken () {
48 // TODO: check if this is needed
52 * sends the request to router
55 * @param mixed $fields
56 * @param string $cookie
57 * @param integer $count
60 protected function sentRequest ($path, $fields, $cookie = false, $count = 0) {
61 $data = parent
::sentRequest($path, $fields, $cookie, $count);
62 $header = $data['header'];
63 $body = $data['body'];
66 $body = preg_replace("/(\r\n)|(\r)/", "\n", $body);
67 $body = preg_replace('/\'/i', '"', $body);
68 $body = preg_replace("/\[\s+\]/i", '[ {} ]', $body);
69 $body = preg_replace("/},\s+]/", "}\n]", $body);
72 if (strpos($path, '.json') !== false) {
73 $json = json_decode($body, true);
75 if (is_array($json)) {
80 return array('header' => $header, 'body' => $body);