add method getSyslog
authorStricted <info@stricted.de>
Sun, 28 Jun 2015 06:35:07 +0000 (08:35 +0200)
committerStricted <info@stricted.de>
Sun, 28 Jun 2015 06:35:07 +0000 (08:35 +0200)
speedport.class.php
tests/syslog.php [new file with mode: 0644]

index 87d4c1c7bfc74a45254acae399ec8a7cb07ef04b..d54dd2140f17b1c5feeac6b24e5d588f74a6a269 100644 (file)
@@ -59,7 +59,7 @@ class speedport {
        
        /**
         * login into the router with the given password
-        *
+        * 
         * @param       string  $password
         * @return      boolean
         */
@@ -88,7 +88,7 @@ class speedport {
        
        /**
         * logout
-        *
+        * 
         * @return      array
         */
        public function logout () {
@@ -106,7 +106,7 @@ class speedport {
        
        /**
         * reboot the router
-        *
+        * 
         * @return      array
         */
        public function reboot () {
@@ -121,7 +121,7 @@ class speedport {
        
        /**
         * change dsl connection status
-        *
+        * 
         * @param       string  $status
         */
        public function changeConnectionStatus ($status) {
@@ -139,7 +139,7 @@ class speedport {
        
        /**
         * return the given json as array
-        *
+        * 
         * the following paths are known to be valid:
         * /data/dsl.json
         * /data/interfaces.json
@@ -162,9 +162,9 @@ class speedport {
         * /data/filterlist.json
         * /data/bonding_tr181.json
         * /data/letinfo.json
-        *
+        * 
         * /data/Status.json (No login needed)
-        *
+        * 
         * @param       string  $file
         * @return      array
         */
@@ -183,9 +183,27 @@ class speedport {
                return $json;
        }
        
+       /**
+        * get the router syslog
+        * 
+        * @return      array
+        */
+       public function getSyslog() {
+               $path = 'data/Syslog.json';
+               $fields = array('exporttype' => '0');
+               $cookie = 'challengev='.$this->challenge.'; '.$this->session;
+               $data = $this->sentRequest($path, $fields, $cookie);
+               
+               if (empty($data['body'])) {
+                       throw new Exception('unable to get syslog data');
+               }
+               
+               return explode("\n", $data['body']);
+       }
+       
        /**
         * sends the request to router
-        *
+        * 
         * @param       string  $path
         * @param       array   $fields
         * @param       string  $cookie
@@ -224,17 +242,15 @@ class speedport {
                $body = preg_replace("/(\r\n)|(\r)/", "\n", $body);
                $body = preg_replace('/\'/i', '"', $body);
                $body = preg_replace("/},\n\n]/", "}\n]", $body);
-               $body = preg_replace('/\s+/', ' ', $body);
-               $body = preg_replace("/\[ \]/i", '[ {} ]', $body);
-               $body = preg_replace("/}, ]/", "} ]", $body);
-               $body = preg_replace("/\n/", " ", $body);
+               $body = preg_replace("/\[\s+\]/i", '[ {} ]', $body);
+               $body = preg_replace("/},\n\s+]/", "} ]", $body);
                
                return array('header' => $this->parse_headers($header), 'body' => $body);
        }
        
        /**
         * parse the curl return header into an array
-        *
+        * 
         * @param       string  $response
         * @return      array
         */
diff --git a/tests/syslog.php b/tests/syslog.php
new file mode 100644 (file)
index 0000000..6e16be4
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+require_once('config.php');
+print_r($sp->getSyslog());
+$sp->logout();