|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) MIKO LLC - All Rights Reserved |
|
4
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited |
|
5
|
|
|
* Proprietary and confidential |
|
6
|
|
|
* Written by Nikolay Beketov, 5 2020 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace MikoPBX\Core\Asterisk\Configs; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
use MikoPBX\Core\System\Util; |
|
14
|
|
|
use MikoPBX\Modules\Config\ConfigClass; |
|
15
|
|
|
|
|
16
|
|
|
class HttpConf extends ConfigClass |
|
17
|
|
|
{ |
|
18
|
|
|
protected string $description = 'http.conf'; |
|
19
|
|
|
|
|
20
|
|
|
protected function generateConfigProtected(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$enabled = ($this->generalSettings['AJAMEnabled'] === '1') ? 'yes' : 'no'; |
|
23
|
|
|
$conf = "[general]\n" . |
|
24
|
|
|
"enabled={$enabled}\n" . |
|
25
|
|
|
"bindaddr=0.0.0.0\n" . |
|
26
|
|
|
"bindport={$this->generalSettings['AJAMPort']}\n" . |
|
27
|
|
|
"prefix=asterisk\n" . |
|
28
|
|
|
"enablestatic=yes\n\n"; |
|
29
|
|
|
|
|
30
|
|
|
if ( ! empty($this->generalSettings['AJAMPortTLS'])) { |
|
31
|
|
|
$keys_dir = '/etc/asterisk/keys'; |
|
32
|
|
|
Util::mwMkdir($keys_dir); |
|
33
|
|
|
$WEBHTTPSPublicKey = $this->generalSettings['WEBHTTPSPublicKey']; |
|
34
|
|
|
$WEBHTTPSPrivateKey = $this->generalSettings['WEBHTTPSPrivateKey']; |
|
35
|
|
|
|
|
36
|
|
|
if ( ! empty($WEBHTTPSPublicKey) && ! empty($WEBHTTPSPrivateKey)) { |
|
37
|
|
|
$s_data = "{$WEBHTTPSPublicKey}\n{$WEBHTTPSPrivateKey}"; |
|
38
|
|
|
} else { |
|
39
|
|
|
// Генерируем сертификат ssl. |
|
40
|
|
|
$data = Util::generateSslCert(); |
|
41
|
|
|
$s_data = implode("\n", $data); |
|
42
|
|
|
} |
|
43
|
|
|
$conf .= "tlsenable=yes\n" . |
|
44
|
|
|
"tlsbindaddr=0.0.0.0:{$this->generalSettings['AJAMPortTLS']}\n" . |
|
45
|
|
|
"tlscertfile={$keys_dir}/ajam.pem\n" . |
|
46
|
|
|
"tlsprivatekey={$keys_dir}/ajam.pem\n"; |
|
47
|
|
|
Util::fileWriteContent("{$keys_dir}/ajam.pem", $s_data); |
|
48
|
|
|
} |
|
49
|
|
|
Util::fileWriteContent($this->config->path('asterisk.astetcdir') . '/http.conf', $conf); |
|
50
|
|
|
} |
|
51
|
|
|
} |