fix login logic again
[GitHub/Stricted/speedport-hybrid-php-api.git] / lib / trait / Connection.class.php
CommitLineData
9b926efe
S
1<?php
2/**
3 * @author Jan Altensen (Stricted)
4 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
dd76f288 5 * @copyright 2015-2016 Jan Altensen (Stricted)
9b926efe
S
6 */
7trait 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);
e94573dd 21 $data = $this->sendRequest($path, $fields, true);
9b926efe
S
22 $data = $this->getValues($data['body']);
23
24 if ($data['status'] == 'ok') {
25 return true;
26 }
9b926efe
S
27 }
28 else {
29 throw new RouterException('unknown status');
30 }
7ef0b760
S
31
32 return false;
9b926efe
S
33 }
34
35 /**
36 * change lte connection status
37 *
38 * @param string $status
39 * @return boolean
40 */
41 public function changeLTEStatus ($status) {
7ef0b760
S
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
9b926efe
S
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);
e94573dd 54 $data = $this->sendEncryptedRequest($path, $fields, true);
7ef0b760 55 $data = $this->getValues($data['body']);
9b926efe 56
7ef0b760
S
57 if ($data['status'] == 'ok') {
58 return true;
59 }
9b926efe
S
60 }
61 else {
62 throw new RouterException('unknown status');
63 }
7ef0b760
S
64
65 return false;
9b926efe
S
66 }
67
68 /**
69 * reconnect LTE
70 *
71 * @return array
72 */
73 public function reconnectLte () {
74 $this->checkLogin();
75
7ef0b760
S
76 /* we have to wait 400ms before we can send the request (idk whats wrong with the router) */
77 usleep(400);
78
9b926efe
S
79 $path = 'data/modules.json';
80 $fields = array('csrf_token' => $this->token, 'lte_reconn' => '1');
e94573dd 81 $data = $this->sendEncryptedRequest($path, $fields, true);
7ef0b760
S
82 if ($data['status'] == 'ok') {
83 return true;
84 }
9b926efe 85
7ef0b760 86 return false;
9b926efe 87 }
89d43347 88}