From 8d6b9966074231525556cc92483a19bb0c35a09a Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Mon, 17 Aug 2026 11:35:41 +0200 Subject: [PATCH] Add NC Connector timer status helper --- include/nc_connector_system.inc.php | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 include/nc_connector_system.inc.php diff --git a/include/nc_connector_system.inc.php b/include/nc_connector_system.inc.php new file mode 100644 index 0000000..6693803 --- /dev/null +++ b/include/nc_connector_system.inc.php @@ -0,0 +1,62 @@ + array('file', '/dev/null', 'r'), + 1 => array('pipe', 'w'), + 2 => array('pipe', 'w'), + ); + $process = @proc_open($command, $spec, $pipes); + if (!is_resource($process)) + { + return ''; + } + $stdout = stream_get_contents($pipes[1]); + stream_get_contents($pipes[2]); + fclose($pipes[1]); + fclose($pipes[2]); + $exit = proc_close($process); + return $exit === 0 ? trim((string)$stdout) : ''; +} + +function bratonien_tools_nc_connector_system_status() +{ + $timer = 'bratonien-nc-connector.timer'; + $next_raw = bratonien_tools_nc_connector_systemctl_value(array('show', $timer, '--property=NextElapseUSecRealtime', '--value')); + $next_timestamp = 0; + if ($next_raw !== '' && strtolower($next_raw) !== 'n/a') + { + $parsed = strtotime($next_raw); + if ($parsed !== false) + { + $next_timestamp = (int)$parsed; + } + } + + $active = bratonien_tools_nc_connector_systemctl_value(array('is-active', $timer)); + $enabled = bratonien_tools_nc_connector_systemctl_value(array('is-enabled', $timer)); + + return array( + 'timer_name' => $timer, + 'timer_active' => $active === 'active', + 'timer_enabled' => $enabled === 'enabled', + 'next_run_raw' => $next_raw, + 'next_run_timestamp' => $next_timestamp, + 'next_run_label' => $next_timestamp > 0 ? date('d.m.Y H:i:s', $next_timestamp) : ($next_raw !== '' ? $next_raw : 'Nicht verfügbar'), + 'legacy_runtime_exists' => is_dir('/opt/piwigo-sync'), + 'legacy_config_exists' => is_dir('/etc/piwigo-sync'), + 'legacy_service_exists' => is_file('/etc/systemd/system/piwigo-sync.service'), + 'legacy_timer_exists' => is_file('/etc/systemd/system/piwigo-sync.timer'), + ); +}