3 * @author Jan Altensen (Stricted)
4 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
5 * @copyright 2015-2016 Jan Altensen (Stricted)
9 * get uptime based on last reboot
13 public function getUptime () {
14 $lastReboot = $this->getLastReboot();
16 $dtF = new DateTime("@0");
17 $dtT = new DateTime("@".$lastReboot);
19 return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');
23 * return the given json as array
28 public function getData ($file) {
29 if ($file != 'Status') $this->checkLogin();
31 $path = 'data/'.$file.'.json';
33 $data = $this->sendRequest($path, $fields, true);
39 * get the router syslog
43 public function getSyslog() {
44 $data = $this->getData('SystemMessages');
45 $data = $this->getValues($data);
47 if (isset($data['addmessage'])) {
48 return $data['addmessage'];
56 * get Last Reboot time
60 public function getLastReboot () {
61 $response = $this->sendRequest("data/Reboot.json");
62 $response = $this->getValues($response);
64 $lastReboot = time() - strtotime($response['reboot_date']." ".$response['reboot_time']);
70 * reset the router to Factory Default
75 public function resetToFactoryDefault () {
78 $path = 'data/resetAllSetting.json';
79 $fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'password' => $this->hash
, 'reset_all' => 'true');
80 $data = $this->sendRequest($path, $fields, true);
87 * check if firmware is actual
91 public function checkFirmware () {
94 $path = 'data/checkfirmware.json';
95 $fields = array('checkfirmware' => 'true');
96 $data = $this->sendRequest($path, $fields, true);
106 public function reboot () {
109 $path = 'data/Reboot.json';
110 $fields = array('csrf_token' => $this->token
, 'reboot_device' => 'true');
111 $data = $this->sendEncryptedRequest($path, $fields, true);
112 $data = $this->getValues($data['body']);
114 if ($data['status'] == 'ok') {
115 // reset challenge and session
116 $this->challenge
= '';
119 $this->derivedk
= '';
121 // throw an exception because router is unavailable for other tasks
122 // like $this->logout() or $this->checkLogin
123 throw new RebootException('Router Reboot');