Skip to content

Commit

Permalink
#727 Переписал процесс добавления / удаления пользователя для ssh.
Browse files Browse the repository at this point in the history
  • Loading branch information
boffart committed Jul 25, 2024
1 parent da3e039 commit bf3b00a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Core/System/Configs/SSHConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ private function getCreateSshUser(): string
shell_exec("$bbPath addgroup -S '$sshLogin' $sshLogin");
// Adding a user to the group 'root'
shell_exec("$bbPath addgroup -S '$sshLogin' root");

$cat = Util::which('cat');
$cut = Util::which('cut');
$sed = Util::which('sed');
$chown = Util::which('chown');
$currentGroupId = trim(shell_exec("$cat /etc/passwd | grep '^$sshLogin:' | $cut -f 3 -d ':'"));
shell_exec("$sed -i 's/$sshLogin:x:$currentGroupId:/$sshLogin:x:0:/g' /etc/passwd");
shell_exec("$chown -R $sshLogin:$sshLogin $homeDir");
}
return $sshLogin;
}
Expand Down
8 changes: 6 additions & 2 deletions src/Core/System/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public static function sendAdminNotification(string $subject, array $messages, b
{
// Prevent sending the same message twice.
$di = Di::getDefault();
if(!$di){
return;
}
$managedCache = $di->getShared(ManagedCacheProvider::SERVICE_NAME);
$cacheKey = 'sendAdminNotification:' . md5($subject . implode('', $messages));
$cacheTime = 3600 * 24; // 1 day
Expand All @@ -96,7 +99,7 @@ public static function sendAdminNotification(string $subject, array $messages, b
}

// Check if the notification system is available (e.g., PHP Mailer is configured and working).
if (!Notifications::checkConnection(Notifications::TYPE_PHP_MAILER)) {
if (!self::checkConnection(self::TYPE_PHP_MAILER)) {
return;
}

Expand All @@ -106,7 +109,8 @@ public static function sendAdminNotification(string $subject, array $messages, b
foreach ($messages as $message) {
$text .= '<br>' . Util::translate($message, false);
}
$text = $text . '<br><br>' . SystemMessages::getInfoMessage("The MikoPBX connection information");
$text .= '<br><br>' . SystemMessages::getInfoMessage("The MikoPBX connection information");
$text = str_replace(PHP_EOL, '<br>', $text);

// Get the admin email address from PbxSettings.
$adminMail = PbxSettings::getValueByKey(PbxSettingsConstants::SYSTEM_NOTIFICATIONS_EMAIL);
Expand Down

0 comments on commit bf3b00a

Please sign in to comment.