Merge remote-tracking branch 'upstream/master'

This commit is contained in:
bergware
2025-04-24 23:20:18 +02:00

View File

@@ -27,6 +27,7 @@ $cli = empty($zip);
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/webGui/include/Wrappers.php";
require_once "$docroot/webGui/include/publish.php";
if (is_file('/boot/syslinux/syslinux.cfg')) {
$bootenv = '/boot/syslinux';
@@ -45,18 +46,21 @@ $pools = pools_filter($disks);
require_once "$docroot/webGui/include/CustomMerge.php";
function write(...$messages){
$com = curl_init();
curl_setopt_array($com,[
CURLOPT_URL => 'http://localhost/pub/diagnostics?buffer_length=1',
CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket',
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => true
]);
foreach ($messages as $message) {
curl_setopt($com, CURLOPT_POSTFIELDS, $message);
curl_exec($com);
publish('diagnostics', $message);
}
curl_close($com);
}
// Add error logging function
function log_error($message, $command = '') {
global $diag;
$error_log = "/$diag/logs/diagnostics.error.log";
$timestamp = date('Y-m-d H:i:s');
$log_message = "[$timestamp] $message";
if ($command) {
$log_message .= " (Command: $command)";
}
file_put_contents($error_log, $log_message . "\n", FILE_APPEND);
}
// Modify run function to include error logging
@@ -65,7 +69,10 @@ function run($cmd, &$save=null, $timeout=30) {
// output command for display
write($cmd);
// execute command with timeout of 30s
exec("timeout -s9 $timeout $cmd", $save);
exec("LC_ALL=en_US.UTF-8 timeout -s9 $timeout $cmd 2>&1", $save, $return_code);
if ($return_code !== 0) {
log_error("Command failed with return code $return_code", $cmd);
}
return implode("\n",$save);
}