4 * @author Jan Altensen (Stricted)
5 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
6 * @copyright 2015 Jan Altensen (Stricted)
25 protected $cookie = '';
31 protected $token = '';
34 * inititalize this class
38 public function __construct ($url = 'http://speedport.ip/') {
40 $this->checkRequirements();
44 * check php requirements
46 protected function checkRequirements () {
50 * get the values from array
55 protected function getValues($array) {
57 foreach ($array as $item) {
58 if (!isset($item['vartype']) ||
!isset($item['varid']) ||
!isset($item['varvalue'])) continue;
60 // thank you telekom for this piece of shit
61 if ($item['vartype'] == 'template') {
62 if (is_array($item['varvalue'])) {
63 $data[$item['varid']][] = $this->getValues($item['varvalue']);
66 // i dont know if we need this
67 $data[$item['varid']] = $item['varvalue'];
71 if (is_array($item['varvalue'])) {
72 $data[$item['varid']] = $this->getValues($item['varvalue']);
75 $data[$item['varid']] = $item['varvalue'];
84 * sends the request to router
87 * @param mixed $fields
88 * @param string $cookie
89 * @param integer $count
92 protected function sentRequest ($path, $fields, $cookie = false, $count = 0) {
93 $url = $this->url
.$path.'?lang=en';
95 curl_setopt($ch, CURLOPT_URL
, $url);
97 if (!empty($fields)) {
98 if (is_array($fields)) {
99 curl_setopt($ch, CURLOPT_POST
, count($fields));
100 curl_setopt($ch, CURLOPT_POSTFIELDS
, http_build_query($fields));
103 curl_setopt($ch, CURLOPT_POST
, $count);
104 curl_setopt($ch, CURLOPT_POSTFIELDS
, $fields);
108 if ($cookie === true) {
109 curl_setopt($ch, CURLOPT_COOKIE
, $this->cookie
);
112 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, true);
113 curl_setopt($ch, CURLOPT_HEADER
, true);
115 $result = curl_exec($ch);
117 $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE
);
118 $header = substr($result, 0, $header_size);
119 $body = substr($result, $header_size);
122 // check if response is empty
124 throw new RouterException('empty response');
127 return array('header' => $this->parse_headers($header), 'body' => $body);
131 * parse the curl return header into an array
133 * @param string $response
136 private function parse_headers($response) {
138 $header_text = substr($response, 0, strpos($response, "\r\n\r\n"));
140 $header_text = explode("\r\n", $header_text);
141 foreach ($header_text as $i => $line) {
143 $headers['http_code'] = $line;
146 list ($key, $value) = explode(': ', $line);
147 $headers[$key] = $value;