Commit | Line | Data |
---|---|---|
9b926efe S |
1 | <?php |
2 | /** | |
3 | * @author Jan Altensen (Stricted) | |
4 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
5 | * @copyright 2015 Jan Altensen (Stricted) | |
6 | */ | |
7 | trait System { | |
8 | /** | |
9 | * get uptime based on online (connection) time | |
10 | * | |
11 | * @return string | |
12 | */ | |
13 | public function getUptime () { | |
42e31077 | 14 | $data = $this->getData('Overview'); |
9b926efe S |
15 | $data = $this->getValues($data); |
16 | ||
17 | return $data['days_online']; | |
18 | } | |
19 | ||
20 | /** | |
21 | * return the given json as array | |
22 | * | |
23 | * @param string $file | |
24 | * @return array | |
25 | */ | |
26 | public function getData ($file) { | |
27 | if ($file != 'Status') $this->checkLogin(); | |
28 | ||
29 | $path = 'data/'.$file.'.json'; | |
30 | $fields = array(); | |
31 | $data = $this->sentRequest($path, $fields, true); | |
32 | ||
33 | return $data['body']; | |
34 | } | |
35 | ||
36 | /** | |
37 | * get the router syslog | |
38 | * | |
39 | * @return array | |
40 | */ | |
41 | public function getSyslog() { | |
42 | $data = $this->getData('SystemMessages'); | |
43 | $data = $this->getValues($data); | |
44 | ||
45 | if (isset($data['addmessage'])) { | |
46 | return $data['addmessage']; | |
47 | } | |
48 | else { | |
49 | return array(); | |
50 | } | |
51 | } | |
52 | ||
53 | /** | |
54 | * reset the router to Factory Default | |
55 | * not tested | |
56 | * | |
57 | * @return array | |
58 | */ | |
59 | public function resetToFactoryDefault () { | |
60 | $this->checkLogin(); | |
61 | ||
62 | $path = 'data/resetAllSetting.json'; | |
63 | $fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'password' => $this->hash, 'reset_all' => 'true'); | |
64 | $data = $this->sentRequest($path, $fields, true); | |
65 | ||
66 | return $data['body']; | |
67 | } | |
68 | ||
69 | ||
70 | /** | |
71 | * check if firmware is actual | |
72 | * | |
73 | * @return array | |
74 | */ | |
75 | public function checkFirmware () { | |
76 | $this->checkLogin(); | |
77 | ||
78 | $path = 'data/checkfirmware.json'; | |
79 | $fields = array('checkfirmware' => 'true'); | |
80 | $data = $this->sentRequest($path, $fields, true); | |
81 | ||
82 | return $data['body']; | |
83 | } | |
e9631169 S |
84 | |
85 | /** | |
86 | * reboot the router | |
87 | * | |
88 | * @return boolean | |
89 | */ | |
90 | public function reboot () { | |
91 | $this->checkLogin(); | |
92 | ||
93 | $path = 'data/Reboot.json'; | |
94 | $fields = array('csrf_token' => $this->token, 'reboot_device' => 'true'); | |
95 | $data = $this->sentEncryptedRequest($path, $fields, true); | |
96 | $data = $this->getValues($data['body']); | |
97 | ||
98 | if ($data['status'] == 'ok') { | |
99 | // reset challenge and session | |
100 | $this->challenge = ''; | |
101 | $this->cookie = ''; | |
102 | $this->token = ''; | |
103 | $this->derivedk = ''; | |
104 | ||
105 | // throw an exception because router is unavailable for other tasks | |
106 | // like $this->logout() or $this->checkLogin | |
107 | throw new RebootException('Router Reboot'); | |
108 | } | |
109 | ||
110 | return false; | |
111 | } | |
89d43347 | 112 | } |