7552601dcff2dd923cfd3322a3c0ae012f34e343
[GitHub/Stricted/speedport-hybrid-php-api.git] / lib / trait / Connection.class.php
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-2016 Jan Altensen (Stricted)
6 */
7 trait Connection {
8 /**
9 * change dsl connection status
10 *
11 * @param string $status
12 * @return boolean
13 */
14 public function changeDSLStatus ($status) {
15 $this->checkLogin();
16
17 $path = 'data/Connect.json';
18
19 if ($status == 'online' || $status == 'offline') {
20 $fields = array('csrf_token' => 'nulltoken', 'showpw' => 0, 'password' => $this->hash, 'req_connect' => $status);
21 $data = $this->sendRequest($path, $fields, true);
22 $data = $this->getValues($data['body']);
23
24 if ($data['status'] == 'ok') {
25 return true;
26 }
27 }
28 else {
29 throw new RouterException('unknown status');
30 }
31
32 return false;
33 }
34
35 /**
36 * change lte connection status
37 *
38 * @param string $status
39 * @return boolean
40 */
41 public function changeLTEStatus ($status) {
42 $this->checkLogin();
43
44 /* we have to wait 400ms before we can send the request (idk whats wrong with the router) */
45 usleep(400);
46
47 $path = 'data/Modules.json';
48
49 if ($status == '0' || $status == '1' || $status == 'yes' || $status == 'no') {
50 if ($status == 'yes') $status = '1';
51 else if ($status == 'no') $status = '0';
52
53 $fields = array('csrf_token' => $this->token, 'use_lte' => $status);
54 $data = $this->sendEncryptedRequest($path, $fields, true);
55 $data = $this->getValues($data['body']);
56
57 if ($data['status'] == 'ok') {
58 return true;
59 }
60 }
61 else {
62 throw new RouterException('unknown status');
63 }
64
65 return false;
66 }
67
68 /**
69 * reconnect LTE
70 *
71 * @return array
72 */
73 public function reconnectLte () {
74 $this->checkLogin();
75
76 /* we have to wait 400ms before we can send the request (idk whats wrong with the router) */
77 usleep(400);
78
79 $path = 'data/modules.json';
80 $fields = array('csrf_token' => $this->token, 'lte_reconn' => '1');
81 $data = $this->sendEncryptedRequest($path, $fields, true);
82 if ($data['status'] == 'ok') {
83 return true;
84 }
85
86 return false;
87 }
88 }