1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* MikoPBX - free phone system for small business |
4
|
|
|
* Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
17
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace MikoPBX\Core\Workers\Libs\WorkerPrepareAdvices; |
21
|
|
|
|
22
|
|
|
use MikoPBX\Common\Models\PbxSettings; |
23
|
|
|
use Phalcon\Di\Injectable; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class CheckSSHConfig |
27
|
|
|
* This class is responsible for checking external changes ssh root password. |
28
|
|
|
* |
29
|
|
|
* @package MikoPBX\Core\Workers\Libs\WorkerPrepareAdvices |
30
|
|
|
*/ |
31
|
|
|
class CheckSSHConfig extends Injectable |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Checks the password in case it was changed by an unauthorized means. |
36
|
|
|
* |
37
|
|
|
* @return array An array containing warning messages. |
38
|
|
|
* |
39
|
|
|
*/ |
40
|
|
|
public function process(): array |
41
|
|
|
{ |
42
|
|
|
$messages = []; |
43
|
|
|
$password = PbxSettings::getValueByKey('SSHPassword'); |
44
|
|
|
$hashString = PbxSettings::getValueByKey('SSHPasswordHashString'); |
45
|
|
|
$hashFile = PbxSettings::getValueByKey('SSHPasswordHash'); |
46
|
|
|
if($hashString !== md5($password)){ |
47
|
|
|
// The password has been changed in an unusual way. |
48
|
|
|
$messages['error'][] = ['messageTpl'=>'adv_SSHPasswordMismatchStringsHash']; |
49
|
|
|
} |
50
|
|
|
if($hashFile !== md5_file('/etc/passwd')){ |
51
|
|
|
// The system password does not match what is set in the configuration file. |
52
|
|
|
$messages['error'][] = ['messageTpl'=>'adv_SSHPasswordMismatchFilesHash']; |
53
|
|
|
} |
54
|
|
|
return $messages; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
} |