From 354e9cce54dc9e4da5ee7de270899df76516a19c Mon Sep 17 00:00:00 2001 From: ksainc Date: Tue, 3 Oct 2023 18:04:45 -0400 Subject: [PATCH] Improved Grandstream support --- appinfo/routes.php | 5 +++ lib/Controller/DataController.php | 53 ++++++++++++++++++++++++------- lib/Resources/Grandstream.tpl | 42 ++++++++++++------------ 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index fe07595..5aa5c66 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -28,6 +28,11 @@ 'url' => '/xml/{id}/', 'verb' => 'GET' ], + [ + 'name' => 'Data#grandstream', + 'url' => '/grandstream/{id}/{token}/phonebook.xml', + 'verb' => 'GET' + ], [ 'name' => 'Data#phone', 'url' => '/phone/{id}/', diff --git a/lib/Controller/DataController.php b/lib/Controller/DataController.php index 26e74e8..5fe9164 100644 --- a/lib/Controller/DataController.php +++ b/lib/Controller/DataController.php @@ -104,34 +104,65 @@ public function xml(string $id): DataResponse { } else { return new GeneratedResponse($this->DataService->generateXML($result), 'text/xml; charset=UTF-8'); } - + } /** * @NoAdminRequired * @NoCSRFRequired * @PublicPage */ - public function phone(string $id) { + public function device(string $id, string $token, array $meta, string $mime) { - // construct place holder - $meta = []; // evaluate, if token exists - if (empty($this->request->getParam('token'))) { + if (!isset($meta['token']) || empty($meta['token'])) { return null; } - // collect meta data - $meta['token'] = $this->request->getParam('token'); - $meta['address'] = $this->request->__get('server')['REMOTE_ADDR']; - $meta['agent'] = $this->request->__get('server')['HTTP_USER_AGENT']; - $meta['mac'] = \OCA\Data\Utile\Extractor::mac($meta['agent'], true); // authorize request $result = $this->DataService->authorize($id, $meta); // evaluate, result if ($result === false) { return null; } else { - return new GeneratedResponse($this->DataService->generateTemplate($result), 'text/xml; charset=UTF-8'); + return new GeneratedResponse($this->DataService->generateTemplate($result), $mime); + } + + } + /** + * @NoAdminRequired + * @NoCSRFRequired + * @PublicPage + */ + public function phone(string $id, string $token = '') { + + // evaluate, if token exists + if (empty($token)) { + return null; } + // collect meta data + $meta = []; + $meta['token'] = $token; + $meta['address'] = $this->request->__get('server')['REMOTE_ADDR']; + $meta['agent'] = $this->request->__get('server')['HTTP_USER_AGENT']; + $meta['mac'] = \OCA\Data\Utile\Extractor::mac($meta['agent'], true); + + return $this->device($id, $token, $meta, 'text/xml; charset=UTF-8'); + + } + /** + * @NoAdminRequired + * @NoCSRFRequired + * @PublicPage + */ + public function grandstream(string $id, string $token) { + + // collect meta data + $meta = []; + $meta['token'] = $token; + $meta['address'] = $this->request->__get('server')['REMOTE_ADDR']; + $meta['agent'] = $this->request->__get('server')['HTTP_USER_AGENT']; + $meta['mac'] = \OCA\Data\Utile\Extractor::mac($meta['agent'], true); + + return $this->device($id, $token, $meta, 'text/xml; charset=UTF-8'); } diff --git a/lib/Resources/Grandstream.tpl b/lib/Resources/Grandstream.tpl index b93bf9b..47b9e28 100644 --- a/lib/Resources/Grandstream.tpl +++ b/lib/Resources/Grandstream.tpl @@ -2,31 +2,31 @@ {{ section reiterate start }} {% if(isset($data)): %} -{% foreach ($data->Phone as $entry): %} -{% if($entry->Type == 'WORK' && $entry->SubType == 'VOICE' && !empty($entry->Number)): %} -{% $number = $entry->Number %} -{% break %} -{% elseif($entry->Type == 'CELL' && !empty($entry->Number)): %} -{% $number = $entry->Number %} -{% break %} -{% elseif($entry->Type == 'HOME' && $entry->SubType == 'VOICE' && !empty($entry->Number)): %} -{% $number = $entry->Number %} -{% break %} -{% elseif($entry->Type == 'CAR' && !empty($entry->Number)): %} -{% $number = $entry->Number %} -{% break %} -{% endif; %} -{% endforeach; %} -{% if(isset($number)): %} + {{ $data->Name->Last }} {{ $data->Name->First }} - - {{ $number }} - 1 + 0 + {% foreach ($data->Phone as $entry): %} + {% if($entry->Type == 'WORK' && $entry->SubType == 'VOICE' && !empty($entry->Number)): %} + + {{ $entry->Number }} + + {% elseif($entry->Type == 'HOME' && $entry->SubType == 'VOICE' && !empty($entry->Number)): %} + + {{ $entry->Number }} + + {% elseif($entry->Type == 'CELL' && !empty($entry->Number)): %} + + {{ $entry->Number }} + {% elseif($entry->Type == 'CAR' && !empty($entry->Number)): %} + + {{ $entry->Number }} + + {% endif; %} + {% endforeach; %} {% endif; %} -{% endif; %} {{ section reiterate end }} - \ No newline at end of file +