fix: safeguard shell_exec with function_exists check in login and medical api

This commit is contained in:
DevSoftTech Server 2026-09-22 13:03:19 +05:30
parent 6e78e6010e
commit 4766c7c9fa
2 changed files with 40 additions and 36 deletions

View File

@ -6297,19 +6297,21 @@ class MedicalStoreApi extends BaseController
$ips = [];
// Attempt to detect local LAN IP on Windows / Linux
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$output = shell_exec('ipconfig');
if ($output) {
preg_match_all('/IPv4 Address[ .:]+([0-9.]+)/i', $output, $matches);
if (!empty($matches[1])) {
$ips = array_unique($matches[1]);
if (function_exists('shell_exec')) {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$output = @shell_exec('ipconfig');
if ($output) {
preg_match_all('/IPv4 Address[ .:]+([0-9.]+)/i', $output, $matches);
if (!empty($matches[1])) {
$ips = array_unique($matches[1]);
}
}
} else {
$output = @shell_exec("hostname -I 2>/dev/null");
if ($output) {
$parts = preg_split('/\s+/', trim($output));
if (!empty($parts)) $ips = array_unique($parts);
}
}
} else {
$output = shell_exec("hostname -I 2>/dev/null");
if ($output) {
$parts = preg_split('/\s+/', trim($output));
if (!empty($parts)) $ips = array_unique($parts);
}
}

View File

@ -167,33 +167,35 @@
<?php
// Detect server network interfaces for LAN QR generation
$detectedNetworkInterfaces = [];
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$netOutput = @shell_exec('ipconfig');
if ($netOutput) {
$netLines = explode("\n", $netOutput);
$curAdapter = '';
foreach ($netLines as $nLine) {
$nLine = trim($nLine);
if (preg_match('/^(adapter|Wireless LAN adapter|Ethernet adapter|Unknown adapter)\s+([^:]+):/i', $nLine, $adM)) {
$curAdapter = trim($adM[2]);
}
if (preg_match('/IPv4 Address[ .:]+([0-9.]+)/i', $nLine, $ipM)) {
$foundIp = trim($ipM[1]);
if ($foundIp !== '127.0.0.1') {
$label = $curAdapter ? ($foundIp . ' (' . $curAdapter . ')') : $foundIp;
$detectedNetworkInterfaces[$foundIp] = $label;
if (function_exists('shell_exec')) {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$netOutput = @shell_exec('ipconfig');
if ($netOutput) {
$netLines = explode("\n", $netOutput);
$curAdapter = '';
foreach ($netLines as $nLine) {
$nLine = trim($nLine);
if (preg_match('/^(adapter|Wireless LAN adapter|Ethernet adapter|Unknown adapter)\s+([^:]+):/i', $nLine, $adM)) {
$curAdapter = trim($adM[2]);
}
if (preg_match('/IPv4 Address[ .:]+([0-9.]+)/i', $nLine, $ipM)) {
$foundIp = trim($ipM[1]);
if ($foundIp !== '127.0.0.1') {
$label = $curAdapter ? ($foundIp . ' (' . $curAdapter . ')') : $foundIp;
$detectedNetworkInterfaces[$foundIp] = $label;
}
}
}
}
}
} else {
$netOutput = @shell_exec("hostname -I 2>/dev/null");
if ($netOutput) {
$parts = preg_split('/\s+/', trim($netOutput));
foreach ($parts as $foundIp) {
$foundIp = trim($foundIp);
if ($foundIp && $foundIp !== '127.0.0.1') {
$detectedNetworkInterfaces[$foundIp] = $foundIp . ' (LAN)';
} else {
$netOutput = @shell_exec("hostname -I 2>/dev/null");
if ($netOutput) {
$parts = preg_split('/\s+/', trim($netOutput));
foreach ($parts as $foundIp) {
$foundIp = trim($foundIp);
if ($foundIp && $foundIp !== '127.0.0.1') {
$detectedNetworkInterfaces[$foundIp] = $foundIp . ' (LAN)';
}
}
}
}