2 require_once('lib/exception/RebootException.class.php');
3 require_once('lib/exception/RouterException.class.php');
4 require_once('CryptLib/CryptLib.php');
5 require_once('Speedport.class.php');
6 require_once('ISpeedport.class.php');
7 require_once('lib/trait/Connection.class.php');
8 require_once('lib/trait/CryptLib.class.php');
9 require_once('lib/trait/Login.class.php');
10 require_once('lib/trait/Firewall.class.php');
11 require_once('lib/trait/Network.class.php');
12 require_once('lib/trait/Phone.class.php');
13 require_once('lib/trait/System.class.php');
16 * @author Jan Altensen (Stricted)
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @copyright 2015 Jan Altensen (Stricted)
20 class SpeedportHybrid
extends Speedport
implements ISpeedport
{
33 const VERSION
= '1.0.4';
36 * check php requirements
38 protected function checkRequirements () {
39 if (!extension_loaded('curl')) {
40 throw new Exception("The PHP Extension 'curl' is missing.");
42 else if (!extension_loaded('json')) {
43 throw new Exception("The PHP Extension 'json' is missing.");
45 else if (!extension_loaded('pcre')) {
46 throw new Exception("The PHP Extension 'pcre' is missing.");
48 else if (!extension_loaded('ctype')) {
49 throw new Exception("The PHP Extension 'ctype' is missing.");
51 else if (!extension_loaded('hash')) {
52 throw new Exception("The PHP Extension 'hash' is missing.");
54 else if (!in_array('sha256', hash_algos())) {
55 throw new Exception('SHA-256 algorithm is not Supported.');
60 * sends the encrypted request to router
63 * @param mixed $fields
64 * @param string $cookie
67 protected function sentEncryptedRequest ($path, $fields, $cookie = false) {
68 $count = count($fields);
69 $fields = $this->encrypt(http_build_query($fields));
70 return $this->sentRequest($path, $fields, $cookie, $count);
74 * sends the request to router
77 * @param mixed $fields
78 * @param string $cookie
79 * @param integer $count
82 protected function sentRequest ($path, $fields, $cookie = false, $count = 0) {
83 $data = parent
::sentRequest($path, $fields, $cookie, $count);
84 $header = $data['header'];
85 $body = $data['body'];
86 // check if body is encrypted (hex instead of json)
87 if (ctype_xdigit($body)) {
88 $body = $this->decrypt($body);
92 $body = preg_replace("/(\r\n)|(\r)/", "\n", $body);
93 $body = preg_replace('/\'/i', '"', $body);
94 $body = preg_replace("/\[\s+\]/i", '[ {} ]', $body);
95 $body = preg_replace("/},\s+]/", "}\n]", $body);
98 if (strpos($path, '.json') !== false) {
99 $json = json_decode($body, true);
101 if (is_array($json)) {
106 return array('header' => $header, 'body' => $body);