From: Stricted Date: Mon, 27 Jul 2015 18:38:36 +0000 (+0200) Subject: add experimental portforwarding stuff X-Git-Tag: 1.0.5~14 X-Git-Url: https://git.stricted.de/?p=GitHub%2FStricted%2Fspeedport-hybrid-php-api.git;a=commitdiff_plain;h=324305fd6644da62fc17fbe7c85b8bd2b8d6755e add experimental portforwarding stuff --- diff --git a/SpeedportHybrid.class.php b/SpeedportHybrid.class.php index bbd9146..ab8ce95 100644 --- a/SpeedportHybrid.class.php +++ b/SpeedportHybrid.class.php @@ -5,6 +5,7 @@ require_once('CryptLib/CryptLib.php'); require_once('lib/trait/Connection.class.php'); require_once('lib/trait/CryptLib.class.php'); require_once('lib/trait/Login.class.php'); +require_once('lib/trait/Firewall.class.php'); require_once('lib/trait/Network.class.php'); require_once('lib/trait/Phone.class.php'); require_once('lib/trait/System.class.php'); @@ -17,6 +18,7 @@ require_once('lib/trait/System.class.php'); class SpeedportHybrid { use Connection; use CryptLib; + use Firewall; use Login; use Network; use Phone; @@ -52,6 +54,8 @@ class SpeedportHybrid { private function getValues($array) { $data = array(); foreach ($array as $item) { + if (!isset($item['vartype']) || !isset($item['varid']) || !isset($item['varvalue'])) continue; + // thank you telekom for this piece of shit if ($item['vartype'] == 'template') { if (is_array($item['varvalue'])) { diff --git a/lib/trait/Firewall.class.php b/lib/trait/Firewall.class.php new file mode 100644 index 0000000..2d43ffd --- /dev/null +++ b/lib/trait/Firewall.class.php @@ -0,0 +1,91 @@ + + * @copyright 2015 Jan Altensen (Stricted) + */ +trait Firewall { + /** + * get all Portforwarding Entrys + * + * @return array + */ + public function getPortforwardingEntrys () { + $data = $this->getData('Portforwarding'); + $data = $this->getValues($data); + + //print_r($data); + + if (isset($data['addportuw'])) { + return $data['addportuw']; + } + else { + return array(); + } + } + + /** + * delete Portforwarding Entry + * + * @param integer $id + * + * @return array + */ + public function deletePortforwardingEntry ($id) { + $this->checkLogin(); + + $path = 'data/Portforwarding.json'; + $fields = array('csrf_token' => $this->token, + 'id_portforward' => $id, + 'deleteEntry' => 'delete' + ); + + $data = $this->sentRequest($path, $fields, true); + $data = $this->getValues($data['body']); + + if ($data['status'] == 'ok') { + return $data; + } + else { + throw new RouterException('can not delete Phone Book Entry'); + } + } + + /** + * add Portforwarding Entry + * + * @param string $name + * @param integer $device + */ + public function addPortforwardingEntry ($name, $device) { + // TODO: find a way to make this possible + /* fields: + * + * portuw_name + * portuw_device + * optvar_portuw_template = -1 + * tcp_public_from + * tcp_public_to + * tcp_private_dest + * tcp_private_to + * portuwtcp_id = -1 + * + * udp_public_from + * udp_public_to + * udp_private_dest + * udp_private_to + * portuwudp_id = -1 + */ + } + + /** + * edit Portforwarding Entry + * + * @param integer $id + * @param string $name + * @param integer $device + */ + public function editPortforwardingEntry ($id, $name, $device) { + // TODO: find a way to make this possible + } +}