From 5e44cffa0fe42cb2bf5645490c3d1703b39e0303 Mon Sep 17 00:00:00 2001 From: Stricted Date: Sun, 28 Jun 2015 08:35:07 +0200 Subject: [PATCH] add method getSyslog --- speedport.class.php | 42 +++++++++++++++++++++++++++++------------- tests/syslog.php | 4 ++++ 2 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 tests/syslog.php diff --git a/speedport.class.php b/speedport.class.php index 87d4c1c..d54dd21 100644 --- a/speedport.class.php +++ b/speedport.class.php @@ -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 index 0000000..6e16be4 --- /dev/null +++ b/tests/syslog.php @@ -0,0 +1,4 @@ +getSyslog()); +$sp->logout(); -- 2.20.1