add experimental portforwarding stuff
authorStricted <info@stricted.de>
Mon, 27 Jul 2015 18:38:36 +0000 (20:38 +0200)
committerStricted <info@stricted.de>
Mon, 27 Jul 2015 18:38:36 +0000 (20:38 +0200)
SpeedportHybrid.class.php
lib/trait/Firewall.class.php [new file with mode: 0644]

index bbd91462c635aa203bc8338e5e2b505920d61ecd..ab8ce95733f69b8cc3e26929c3c4beb07b14affc 100644 (file)
@@ -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 (file)
index 0000000..2d43ffd
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+/**
+ * @author      Jan Altensen (Stricted)
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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
+       }
+}