*
*
*/
- const VERSION = '1.0.2';
+ const VERSION = '1.0.3';
/**
* password-challenge
$path = 'data/Login.json';
$fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'challengev' => 'null');
$data = $this->sentRequest($path, $fields);
- $data = json_decode($data['body'], true);
- $data = $this->getValues($data);
+ $data = $this->getValues($data['body']);
if (isset($data['challengev']) && !empty($data['challengev'])) {
return $data['challengev'];
}
else {
- throw new RouterExeption('unable to get the challenge from the router');
+ throw new RouterException('unable to get the challenge from the router');
}
}
$this->hash = hash('sha256', $this->challenge.':'.$password);
$fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'password' => $this->hash);
$data = $this->sentRequest($path, $fields);
- $json = json_decode($data['body'], true);
- $json = $this->getValues($json);
+ $json = $this->getValues($data['body']);
if (isset($json['login']) && $json['login'] == 'success') {
$this->cookie = $this->getCookie($data);
// check if challenge or session is empty
if (empty($this->challenge) || empty($this->cookie)) {
if ($exception === true) {
- throw new RouterExeption('you musst be logged in to use this method');
+ throw new RouterException('you musst be logged in to use this method');
}
return false;
$path = 'data/SecureStatus.json';
$fields = array();
$data = $this->sentRequest($path, $fields, true);
+ $data = $this->getValues($data['body']);
- if (empty($data['body'])) {
- throw new RouterExeption('unable to get SecureStatus data');
- }
-
- $json = json_decode($data['body'], true);
- $json = $this->getValues($json);
-
- if ($json['loginstate'] != 1) {
+ if ($data['loginstate'] != 1) {
if ($exception === true) {
- throw new RouterExeption('you musst be logged in to use this method');
+ throw new RouterException('you musst be logged in to use this method');
}
return false;
$path = 'data/Login.json';
$fields = array('csrf_token' => $this->token, 'logout' => 'byby');
- $this->sentRequest($path, $fields, true);
- if ($this->checkLogin(false) === false) {
+ $data = $this->sentRequest($path, $fields, true);
+ $data = $this->getValues($data['body']);
+ if ((isset($data['status']) && $data['status'] == 'ok') && $this->checkLogin(false) === false) {
// reset challenge and session
$this->challenge = '';
$this->cookie = '';
$path = 'data/Reboot.json';
$fields = array('csrf_token' => $this->token, 'reboot_device' => 'true');
$data = $this->sentEncryptedRequest($path, $fields, true);
+ $data = $this->getValues($data['body']);
- $json = json_decode($data['body'], true);
- $json = $this->getValues($json);
-
- if ($json['status'] == 'ok') {
+ if ($data['status'] == 'ok') {
// throw an exception because router is unavailable for other tasks
// like $this->logout() or $this->checkLogin
throw new RebootException('Router Reboot');
if ($status == 'online' || $status == 'offline') {
$fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'password' => $this->hash, 'req_connect' => $status);
$data = $this->sentRequest($path, $fields, true);
+ $data = $this->getValues($data['body']);
- $json = json_decode($data['body'], true);
- $json = $this->getValues($json);
-
- if ($json['status'] == 'ok') {
+ if ($data['status'] == 'ok') {
return true;
}
else {
}
}
else {
- throw new RouterExeption();
+ throw new RouterException();
}
}
$fields = array();
$data = $this->sentRequest($path, $fields, true);
- if (empty($data['body'])) {
- throw new RouterExeption('unable to get '.$file.' data');
- }
-
- $json = json_decode($data['body'], true);
-
- return $json;
+ return $data['body'];
}
/**
$fields = array('exporttype' => $type);
$data = $this->sentRequest($path, $fields, true);
- if (empty($data['body'])) {
- throw new RouterExeption('unable to get export data');
- }
-
return explode("\n", $data['body']);
}
$path = 'data/modules.json';
$fields = array('csrf_token' => $this->token, 'lte_reconn' => '1');
$data = $this->sentEncryptedRequest($path, $fields, true);
- $json = json_decode($data['body'], true);
- return $json;
+ return $data['body'];
}
/**
$path = 'data/resetAllSetting.json';
$fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'password' => $this->hash, 'reset_all' => 'true');
$data = $this->sentRequest($path, $fields, true);
- $json = json_decode($data['body'], true);
- return $json;
+ return $data['body'];
}
$fields = array('checkfirmware' => 'true');
$data = $this->sentRequest($path, $fields, true);
- if (empty($data['body'])) {
- throw new RouterExeption('unable to get checkfirmware data');
- }
-
- $json = json_decode($data['body'], true);
-
- return $json;
+ return $data['body'];
}
/**
$body = substr($result, $header_size);
curl_close($ch);
+ // check if response is empty
+ if (empty($body)) {
+ throw new RouterException('empty response');
+ }
+
// check if body is encrypted (hex instead of json)
if (ctype_xdigit($body)) {
$body = $this->decrypt($body);
$body = preg_replace("/\[\s+\]/i", '[ {} ]', $body);
$body = preg_replace("/},\s+]/", "}\n]", $body);
+ // decode json
+ if (strpos($url, '.json') !== false) {
+ $body = json_decode($body, true);
+ }
+
return array('header' => $this->parse_headers($header), 'body' => $body);
}
$fields = array();
$data = $this->sentRequest($path, $fields, true);
- if (empty($data['body'])) {
- throw new RouterExeption('unable to get csrf_token');
- }
-
$a = explode('csrf_token = "', $data['body']);
$a = explode('";', $a[1]);
return $a[0];
}
else {
- throw new RouterExeption('unable to get csrf_token');
+ throw new RouterException('unable to get csrf_token');
}
}
}
if (empty($cookie)) {
- throw new RouterExeption('unable to get the session cookie from the router');
+ throw new RouterException('unable to get the session cookie from the router');
}
return $cookie;