From: Stricted Date: Thu, 30 Jul 2015 16:12:23 +0000 (+0200) Subject: revert getMissedCalls, getTakenCalls and getDialedCalls for test reasons X-Git-Tag: 1.0.5~12 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=87492136014cb8915f6c8d4a047ec095468299c4;p=GitHub%2FStricted%2Fspeedport-hybrid-php-api.git revert getMissedCalls, getTakenCalls and getDialedCalls for test reasons --- diff --git a/SpeedportHybrid.class.php b/SpeedportHybrid.class.php index ab8ce95..f8d6a0d 100644 --- a/SpeedportHybrid.class.php +++ b/SpeedportHybrid.class.php @@ -136,7 +136,11 @@ class SpeedportHybrid { // decode json if (strpos($url, '.json') !== false) { - $body = json_decode($body, true); + $json = json_decode($body, true); + + if (is_array($json)) { + $body = $json; + } } return array('header' => $this->parse_headers($header), 'body' => $body); diff --git a/lib/trait/Firewall.class.php b/lib/trait/Firewall.class.php index 2d43ffd..6dae731 100644 --- a/lib/trait/Firewall.class.php +++ b/lib/trait/Firewall.class.php @@ -76,6 +76,24 @@ trait Firewall { * udp_private_to * portuwudp_id = -1 */ + /* + var inputs = $("input[name^='tcp_public_'], input[name^='tcp_private_'], input[name^='udp_public_'], input[name^='udp_private_']"); + var updateToField = function() { + var field = $(this); + var prefix = field.is("[name^='tcp_']") ? "tcp" : "udp"; + var cont = field.closest("div[id^='template_add']"); + var pv = parseInt(cont.find("input[name^='"+prefix+"_public_from']").val()); + var pt = parseInt(cont.find("input[name^='"+prefix+"_public_to']").val()); + var pp = parseInt(cont.find("input[name^='"+prefix+"_private_dest']").val()); + var result = ""; + if (!isNaN(pv) && !isNaN(pt) && !isNaN(pp)) { + if (pv <= pt) { + result = pp + pt - pv; + } + } + cont.find("input[name^='"+prefix+"_private_to']").val(result); + }; + */ } /** diff --git a/lib/trait/Phone.class.php b/lib/trait/Phone.class.php index a30f940..dd90b28 100644 --- a/lib/trait/Phone.class.php +++ b/lib/trait/Phone.class.php @@ -108,15 +108,25 @@ trait Phone { * @return array */ public function getMissedCalls() { - $data = $this->getData('PhoneCalls'); - $data = $this->getValues($data); + $lines = $this->exportData('1'); + $calls = array(); + $c = count($lines) -2; - if (isset($data['addmissedcalls'])) { - return $data['addmissedcalls']; - } - else { - return array(); + foreach ($lines as $line) { + if (empty($line) || strpos($line, 'Date') !== false) continue; + + $exp = explode(' ', $line); + + $data = array(); + $data['id'] = $c; + $data['missedcalls_date'] = $exp[0]; + $data['missedcalls_time'] = $exp[1]; + $data['missedcalls_who'] = $exp[2]; + $c = $c -1; + $calls[] = $data; } + + return $calls; } /** @@ -125,15 +135,27 @@ trait Phone { * @return array */ public function getTakenCalls() { - $data = $this->getData('PhoneCalls'); - $data = $this->getValues($data); + $lines = $this->exportData('2'); + $calls = array(); + $c = count($lines) -2; - if (isset($data['addtakencalls'])) { - return $data['addtakencalls']; - } - else { - return array(); + foreach ($lines as $line) { + if (empty($line) || strpos($line, 'Date') !== false) continue; + + $exp = explode(' ', $line); + + $data = array(); + $data['id'] = $c; + $data['takencalls_date'] = $exp[0]; + $data['takencalls_time'] = $exp[1]; + $data['takencalls_who'] = $exp[2]; + $data['takencalls_duration'] = $exp[3]; + $c = $c -1; + $calls[] = $data; } + + return $calls; + } /** @@ -142,14 +164,40 @@ trait Phone { * @return array */ public function getDialedCalls() { - $data = $this->getData('PhoneCalls'); - $data = $this->getValues($data); + $lines = $this->exportData('3'); + $calls = array(); + $c = count($lines) -2; - if (isset($data['adddialedcalls'])) { - return $data['adddialedcalls']; - } - else { - return array(); + foreach ($lines as $line) { + if (empty($line) || strpos($line, 'Date') !== false) continue; + + $exp = explode(' ', $line); + + $data = array(); + $data['id'] = $c; + $data['dialedcalls_date'] = $exp[0]; + $data['dialedcalls_time'] = $exp[1]; + $data['dialedcalls_who'] = $exp[2]; + $data['dialedcalls_duration'] = $exp[3]; + $c = $c -1; + $calls[] = $data; } + + return $calls; + } + + /** + * export data from router + * + * @return array + */ + private function exportData ($type) { + $this->checkLogin(); + + $path = 'data/Syslog.json'; + $fields = array('exporttype' => $type); + $data = $this->sentRequest($path, $fields, true); + + return explode("\n", $data['body']); } }