Skip to content

Commit

Permalink
Improved Grandstream support
Browse files Browse the repository at this point in the history
  • Loading branch information
ksainc committed Oct 3, 2023
1 parent dfa3924 commit 354e9cc
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 32 deletions.
5 changes: 5 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}/',
Expand Down
53 changes: 42 additions & 11 deletions lib/Controller/DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

}

Expand Down
42 changes: 21 additions & 21 deletions lib/Resources/Grandstream.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
<AddressBook>
{{ 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)): %}

<Contact>
<LastName>{{ $data->Name->Last }}</LastName>
<FirstName>{{ $data->Name->First }}</FirstName>
<Phone>
<phonenumber>{{ $number }}</phonenumber>
<accountindex>1</accountindex>
<Primary>0</Primary>
{% foreach ($data->Phone as $entry): %}
{% if($entry->Type == 'WORK' && $entry->SubType == 'VOICE' && !empty($entry->Number)): %}
<Phone type="Work">
<phonenumber>{{ $entry->Number }}</phonenumber>
</Phone>
{% elseif($entry->Type == 'HOME' && $entry->SubType == 'VOICE' && !empty($entry->Number)): %}
<Phone type="Work">
<phonenumber>{{ $entry->Number }}</phonenumber>
</Phone>
{% elseif($entry->Type == 'CELL' && !empty($entry->Number)): %}
<Phone type="Home">
<phonenumber>{{ $entry->Number }}</phonenumber>
</Phone>
{% elseif($entry->Type == 'CAR' && !empty($entry->Number)): %}
<Phone type="Cell">
<phonenumber>{{ $entry->Number }}</phonenumber>
</Phone>
{% endif; %}
{% endforeach; %}
</Contact>
{% endif; %}
{% endif; %}
{{ section reiterate end }}
</AddressBook>
</AddressBook>

0 comments on commit 354e9cc

Please sign in to comment.