diff --git a/public_html/admin/index.php b/public_html/admin/index.php index c4b4259..7c2cbe6 100644 --- a/public_html/admin/index.php +++ b/public_html/admin/index.php @@ -242,9 +242,7 @@ if ($action) { $search = strtolower(trim($_GET['search'] ?? '')); $skipDomains = ['sensor','binary_sensor','button','update','select','number', 'device_tracker','event','image','person','zone','tts','conversation', - 'assist_satellite','input_button','media_player','scene','water_heater', - 'alarm_control_panel','automation','script','calendar','notify', - 'weather','camera','siren','remote','todo','lawn_mower']; + 'assist_satellite','input_button']; $skipKeywords = ['pre_release','_record','_ftp_','_push_','_hub_ringtone', '_siren_on','_email_on','_manual_record','_infrared_', 'do_not_disturb','matter_server','zerotier','mariadb', @@ -489,25 +487,26 @@ if ($action) { $arcCounts = []; foreach ($arcStats as $r) $arcCounts[$r['status']] = (int)$r['cnt']; $cronLast = []; - $cronLog = '/home/jarvis.orbishosting.com/logs/cron.log'; + $cronLog = '/var/log/jarvis/cron.log'; if (file_exists($cronLog)) { - $lines = array_filter(explode("\n", shell_exec("grep -a 'facts\\|stats\\|calendar' " . escapeshellarg($cronLog) . " | tail -60"))); + $lines = array_filter(explode("\n", shell_exec("grep -a 'facts\\|stats\\|calendar\\|intent' " . escapeshellarg($cronLog) . " | tail -60"))); foreach ($lines as $line) { if (preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\].*facts/i', $line, $m)) $cronLast['facts_collector'] = $m[1]; if (preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\].*stats/i', $line, $m)) $cronLast['stats_cache'] = $m[1]; - if (preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\].*calendar/i', $line, $m)) $cronLast['calendar_sync'] = $m[1]; + if (preg_match('/^\\[(\\d{2}{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\].*calendar/i', $line, $m)) $cronLast['calendar_sync'] = $m[1]; + if (preg_match('/^\\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\\].*intent/i', $line, $m)) $cronLast['kb_intent_generator'] = $m[1]; } } if (empty($cronLast['stats_cache'])) { $row = JarvisDB::query('SELECT MAX(updated_at) as t FROM api_cache WHERE cache_key IN ("weather","news")'); if (!empty($row[0]['t'])) $cronLast['stats_cache'] = $row[0]['t']; } - $deployLog = '/home/jarvis.orbishosting.com/logs/deploy.log'; + $deployLog = '/var/log/jarvis/deploy.log'; if (file_exists($deployLog)) { $last = shell_exec("grep -a '\\[' " . escapeshellarg($deployLog) . " | tail -1"); if (preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\]/', trim($last), $m)) $cronLast['jarvis_deploy'] = $m[1]; } - $wdLog = '/home/jarvis.orbishosting.com/logs/watchdog.log'; + $wdLog = '/var/log/jarvis/watchdog.log'; if (file_exists($wdLog)) $cronLast['jarvis_watchdog'] = date('Y-m-d H:i:s', filemtime($wdLog)); $bkLog = '/var/backups/jarvis/backup.log'; if (file_exists($bkLog)) { @@ -520,9 +519,9 @@ if ($action) { break; case 'worker_action': - $wType = $data['worker_type'] ?? ''; - $wId = $data['worker_id'] ?? ''; - $wAction = $data['action'] ?? ''; + $wType = $_REQUEST['worker_type'] ?? ''; + $wId = $_REQUEST['worker_id'] ?? ''; + $wAction = $_REQUEST['waction'] ?? $_REQUEST['action'] ?? ''; if ($wType === 'agent' && $wAction === 'update') { JarvisDB::execute('INSERT INTO agent_commands (agent_id,command_type,command_data,status) VALUES (?,?,?,?)', [$wId,'update','{}','pending']); @@ -535,39 +534,61 @@ if ($action) { j(json_decode(curl_exec($ch),true)?:['error'=>'reactor unreachable']); } elseif ($wType === 'cron' && $wAction === 'run') { $scripts = [ - 'facts_collector'=>[true, '/home/jarvis.orbishosting.com/api/endpoints/facts_collector.php'], - 'stats_cache' =>[true, '/home/jarvis.orbishosting.com/api/endpoints/stats_cache.php'], - 'calendar_sync' =>[true, '/home/jarvis.orbishosting.com/api/endpoints/calendar_sync.php'], - 'jarvis_deploy' =>[false,'/usr/local/bin/jarvis-deploy.sh'], - 'jarvis_watchdog'=>[false,'/usr/local/bin/jarvis-watchdog.sh'], + 'facts_collector' =>[true, '/var/www/jarvis/api/endpoints/facts_collector.php'], + 'stats_cache' =>[true, '/var/www/jarvis/api/endpoints/stats_cache.php'], + 'calendar_sync' =>[true, '/var/www/jarvis/api/endpoints/calendar_sync.php'], + 'kb_intent_generator' =>[true, '/var/www/jarvis/api/endpoints/kb_intent_generator.php'], + 'jarvis_deploy' =>[false,'/usr/local/bin/jarvis-deploy.sh'], + 'jarvis_watchdog' =>[false,'/usr/local/bin/jarvis-watchdog.sh'], ]; if (isset($scripts[$wId])) { [$isPhp,$path] = $scripts[$wId]; $cmd = $isPhp - ? '/usr/local/lsws/lsphp85/bin/lsphp '.escapeshellarg($path).' >> /home/jarvis.orbishosting.com/logs/cron.log 2>&1 &' - : escapeshellcmd($path).' >> /home/jarvis.orbishosting.com/logs/deploy.log 2>&1 &'; + ? '/usr/bin/php8.3 '.escapeshellarg($path).' >> /var/log/jarvis/cron.log 2>&1 &' + : escapeshellcmd($path).' >> /var/log/jarvis/deploy.log 2>&1 &'; shell_exec($cmd); j(['ok'=>true,'msg'=>ucwords(str_replace('_',' ',$wId)).' triggered']); } else { bad('Unknown cron worker'); } } elseif ($wType === 'daemon' && $wId === 'arc_reactor' && $wAction === 'restart') { - shell_exec('bash -c "mkdir -p /home/jarvis.orbishosting.com/logs; systemctl restart jarvis-arc 2>/dev/null || (pkill -f reactor.py 2>/dev/null; sleep 1; cd /opt/jarvis-arc && source venv/bin/activate && nohup python3 reactor.py >> /home/jarvis.orbishosting.com/logs/arc_reactor.log 2>&1 &)"'); - j(['ok'=>true,'msg'=>'Arc Reactor restarting']); + shell_exec('systemctl restart jarvis-arc 2>&1'); + k(['ok'=>true,'msg'=>'Arc Reactor restarting via systemd']); } elseif ($wType === 'daemon' && $wId === 'arc_reactor' && $wAction === 'setup') { - $setupLog = '/home/jarvis.orbishosting.com/logs/arc_reactor.log'; - $cmd = 'bash -c "'. - 'mkdir -p /opt/jarvis-arc /home/jarvis.orbishosting.com/logs && '. - 'cp /var/www/jarvis/deploy/reactor.py /opt/jarvis-arc/reactor.py && '. - 'cp /var/www/jarvis/deploy/requirements.txt /opt/jarvis-arc/requirements.txt && '. - 'if [ ! -d /opt/jarvis-arc/venv ]; then python3 -m venv /opt/jarvis-arc/venv; fi && '. - '/opt/jarvis-arc/venv/bin/pip install -q -r /opt/jarvis-arc/requirements.txt && '. - 'pkill -f reactor.py 2>/dev/null; sleep 1 && '. - 'cd /opt/jarvis-arc && source venv/bin/activate && '. - 'nohup python3 reactor.py >> '.$setupLog.' 2>&1 &'. - '" >> '.$setupLog.' 2>&1'; - shell_exec($cmd); - j(['ok'=>true,'msg'=>'Arc Reactor setup started — check log in ~30s then restart']); + $log = '/var/log/jarvis/arc-setup.log'; + $cmd = implode(' && ', [ + 'mkdir -p /opt/jarvis-arc /var/log/jarvis', + 'cp /var/www/jarvis/deploy/reactor.py /opt/jarvis-arc/reactor.py', + 'cp /var/www/jarvis/deploy/requirements.txt /opt/jarvis-arc/requirements.txt', + '[ ! -f /opt/jarvis-arc/venv/bin/activate ] && python3 -m venv /opt/jarvis-arc/venv || true', + '/opt/jarvis-arc/venv/bin/pip install -q -r /opt/jarvis-arc/requirements.txt', + 'cp /var/www/jarvis/deploy/jarvis-arc.service /etc/systemd/system/jarvis-arc.service', + 'systemctl daemon-reload', + 'systemctl enable jarvis-arc', + 'systemctl restart jarvis-arc', + ]); + shell_exec("($cmd) >> " . escapeshellarg($log) . " 2>&1 &"); + k(['ok'=>true,'msg'=>'Arc Reactor setup started — check ' . $log]); + } elseif ($wType === 'agent' && $wAction === 'update_status') { + $ag = JarvisDB::single('SELECT version, status FROM registered_agents WHERE agent_id=?', [$wId]); + j(['ok'=>true,'version'=>$ag['version']??null,'status'=>$ag['status']??'unknown']); } else { bad('Invalid worker action'); } break; + case 'intent_gen_log': + $logFile = '/var/log/jarvis/cron.log'; + $since = max(0, (int)($_GET['since'] ?? 0)); + if (!file_exists($logFile)) { j(['lines'=>[],'next_line'=>0]); } + $allLines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $total = count($allLines); + // snapshot=1 just returns the current line count (call BEFORE triggering run) + if (!empty($_GET['snapshot'])) { j(['next_line'=>$total]); } + // Return only KB Intent Generator lines from position $since onward + $out = []; + for ($i = $since; $i < $total; $i++) { + if (stripos($allLines[$i], 'KB Intent Generator') !== false) { + $out[] = $allLines[$i]; + } + } + j(['lines'=>$out, 'next_line'=>$total]); + case 'arc_status': $ch = curl_init('http://127.0.0.1:7474/status'); curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>5, CURLOPT_CONNECTTIMEOUT=>3]); @@ -1442,6 +1463,7 @@ select.filter-sel:focus{border-color:var(--cyan)} +