Skip to content

Commit

Permalink
fix: consider open_basedir
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Nov 19, 2024
1 parent 53d60a6 commit 050a019
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/OperatingSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public function getLinuxDistribution(): string
private function getFromEtcRelease(): string
{
$file = $this->rootFolder . '/etc/*-release';
foreach (glob($file) as $path) {
$filesFound = glob($file);
if (!$filesFound) {
return '';
}
foreach ($filesFound as $path) {
$content = file_get_contents($path);
preg_match('/^ID=(?<version>.*)$/m', $content, $matches);
if (isset($matches['version'])) {
Expand All @@ -102,26 +106,36 @@ public function getFromLsbRelease(): string

private function isDebian(): string
{
if (file_exists($this->rootFolder . '/etc/debian_version')) {
return 'Debian';
if ($this->isInOpenBasedir($this->rootFolder . '/etc/debian_version')) {
if (file_exists($this->rootFolder . '/etc/debian_version')) {
return 'Debian';
}
}
if (!$this->runSafe('type apt 2>/dev/null >/dev/null &')) {
if (!$this->runSafe('type apt')) {
return '';
}
return 'Debian';
}

private function isAlpine(): string
{
if (!$this->runSafe('type apk 2>/dev/null >/dev/null &')) {
if (!$this->runSafe('type apk')) {
return '';
}
return 'Alpine';
}

private function runSafe(string $command): string
{
$output = shell_exec($command . ' 2>/dev/null >/dev/null &');
$output = shell_exec($command . ' 2>/dev/null');
return (string) $output;
}

private function isInOpenBasedir(string $path): bool {
$openBasedir = ini_get('open_basedir');
if (empty($openBasedir) || strpos($openBasedir, $path) !== false) {
return true;
}
return false;
}
}

0 comments on commit 050a019

Please sign in to comment.