Skip to content

Commit

Permalink
Поправил возможную проблему передачи в trim значения null
Browse files Browse the repository at this point in the history
  • Loading branch information
boffart committed Oct 28, 2024
1 parent 32ddce4 commit 55b91a2
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Core/System/CloudProvisioning/CloudProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function updateHostName(string $hostname): void
*/
protected function updateSSHCredentials(string $sshLogin, string $hashSalt): void
{
$data = md5(shell_exec(Util::which('ifconfig')) . $hashSalt . time());
$data = md5(shell_exec(Util::which('ifconfig'))??'' . $hashSalt . time());
$this->updatePbxSettings(PbxSettings::SSH_LOGIN, $sshLogin);
$this->updatePbxSettings(PbxSettings::SSH_PASSWORD, $data);
$this->updatePbxSettings(PbxSettings::SSH_DISABLE_SSH_PASSWORD, '1');
Expand Down
2 changes: 1 addition & 1 deletion src/Core/System/Configs/SSHConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private function updateUserGroupId(string $sshLogin): void
$cut = Util::which('cut');
$sed = Util::which('sed');

$currentGroupId = trim(shell_exec("$cat /etc/passwd | grep '^$sshLogin:' | $cut -f 3 -d ':'"));
$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");
}
}
4 changes: 2 additions & 2 deletions src/Core/System/DockerEntrypoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private function changeWwwUserID(): void
$cut = Util::which('cut');
$chown = Util::which('chown');
$chgrp = Util::which('chgrp');
$currentUserId = trim(shell_exec("$grep '^$userID:' < /etc/shadow | $cut -d ':' -f 3"));
$currentUserId = trim(shell_exec("$grep '^$userID:' < /etc/shadow | $cut -d ':' -f 3")??'');
if ($currentUserId !== '' && !empty($newUserId) && $currentUserId !== $newUserId) {
SystemMessages::sysLogMsg(__METHOD__, " - Old $userID user id: $currentUserId; New $userID user id: $newUserId", LOG_DEBUG);
$commands[] = "$sed -i 's/$userID:x:$currentUserId:/$userID:x:$newUserId:/g' /etc/shadow*";
Expand All @@ -137,7 +137,7 @@ private function changeWwwUserID(): void
}
}

$currentGroupId = trim(shell_exec("$grep '^$userID:' < /etc/group | $cut -d ':' -f 3"));
$currentGroupId = trim(shell_exec("$grep '^$userID:' < /etc/group | $cut -d ':' -f 3")??'');
if ($currentGroupId !== '' && !empty($newGroupId) && $currentGroupId !== $newGroupId) {
SystemMessages::sysLogMsg(__METHOD__, " - Old $userID group id: $currentGroupId; New $userID group id: $newGroupId", LOG_DEBUG);
$commands[] = "$sed -i 's/$userID:x:$currentGroupId:/$userID:x:$newGroupId:/g' /etc/group";
Expand Down
4 changes: 2 additions & 2 deletions src/Core/System/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static function sslRehash(): void
$cutPath = Util::which('cut');

// Get OpenSSL directory and cert file
$openSslDir = trim(shell_exec("$openSslPath version -d | $cutPath -d '\"' -f 2"));
$openSslDir = trim(shell_exec("$openSslPath version -d | $cutPath -d '\"' -f 2")??'');
$certFile = "$openSslDir/certs/ca-certificates.crt";
$tmpFile = tempnam('/tmp', 'cert-');
$rawData = file_get_contents($certFile);
Expand All @@ -229,7 +229,7 @@ public static function sslRehash(): void
continue;
}
file_put_contents($tmpFile, $cert);
$hash = trim(shell_exec("$openSslPath x509 -subject_hash -noout -in '$tmpFile'"));
$hash = trim(shell_exec("$openSslPath x509 -subject_hash -noout -in '$tmpFile'")??'');
rename($tmpFile, "$openSslDir/certs/$hash.0");
}
if (file_exists($tmpFile)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/System/SystemConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function tryRestoreConf():void
$sort = Util::which('sort');
$find = Util::which('find');
$cut = Util::which('cut');
$lastBackUp = trim(shell_exec("$find $tmpMountDir/dev/*$backupDir -type f -printf '%T@ %p\\n' | $sort -n | $tail -1 | $cut -f2- -d' '"));
$lastBackUp = trim(shell_exec("$find $tmpMountDir/dev/*$backupDir -type f -printf '%T@ %p\\n' | $sort -n | $tail -1 | $cut -f2- -d' '")??'');
if (!empty($lastBackUp)) {
$rm = Util::which('rm');
$gzip = Util::which('gzip');
Expand Down
2 changes: 1 addition & 1 deletion src/Core/System/SystemMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static function echoResult(string $message, string $result = self::RESULT
*/
public static function getCountCols(): string
{
$len = 1 * trim(shell_exec('tput cols'));
$len = 1 * trim(shell_exec('tput cols')??'');

// If the count of columns is zero, set it to a default value of 80
if ($len === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/PBXCoreREST/Lib/System/UpgradeFromImageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static function getStorageUID(): string
$awk = Util::which('awk');
$storageDeviceFile = self::STORAGE_DEVICE;
$cmd = "$grep $($cat $storageDeviceFile) < /etc/fstab | $awk -F'[= ]' '{ print \$2}'";
return trim(shell_exec($cmd));
return trim(shell_exec($cmd)??'');
}

/**
Expand All @@ -166,7 +166,7 @@ private static function getCfUID(): string
$grep = Util::which('grep');
$awk = Util::which('awk');
$cmd = "$grep '/cf' < /etc/fstab | $awk -F'[= ]' '{ print \$2}'";
return trim(shell_exec($cmd));
return trim(shell_exec($cmd)??'');
}

/**
Expand Down

0 comments on commit 55b91a2

Please sign in to comment.