mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
Initial commit: JARVIS AI dashboard v2.3
- 4-tier chat: HA control → Ollama → Groq → Claude - Push-based agent system with heartbeat/metrics - Network monitoring, alerts, Proxmox, Home Assistant - Windows + Linux agent installers - Stats cache cron, facts collector, KB engine
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* JARVIS API Router
|
||||
*/
|
||||
require_once __DIR__ . '/../api/config.php';
|
||||
require_once __DIR__ . '/../api/lib/db.php';
|
||||
require_once __DIR__ . '/../api/lib/kb_engine.php';
|
||||
|
||||
session_start();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Content-Type, X-Session-Token');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(204); exit; }
|
||||
|
||||
$uri = $_SERVER['REQUEST_URI'] ?? '/';
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
$path = trim(parse_url($uri, PHP_URL_PATH), '/');
|
||||
$parts = explode('/', $path);
|
||||
|
||||
// Remove 'api' prefix if present
|
||||
if (($parts[0] ?? '') === 'api') array_shift($parts);
|
||||
$endpoint = $parts[0] ?? '';
|
||||
$action = $parts[1] ?? '';
|
||||
|
||||
// Auth check (except login and ping)
|
||||
if ($endpoint !== 'auth' && $endpoint !== 'agent') {
|
||||
$token = $_SESSION['jarvis_token'] ?? ($_SERVER['HTTP_X_SESSION_TOKEN'] ?? '');
|
||||
if (empty($token) || $token !== ($_SESSION['jarvis_token'] ?? '')) {
|
||||
$localIP = $_SERVER['REMOTE_ADDR'] ?? '';
|
||||
$isLocal = in_array($localIP, ['127.0.0.1', '::1', JARVIS_IP]);
|
||||
if (!$isLocal && $endpoint !== 'ping') {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'Unauthorized', 'code' => 401]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($endpoint !== 'auth') session_write_close(); // Skip for auth so login can write session token
|
||||
|
||||
$body = file_get_contents('php://input');
|
||||
$data = json_decode($body, true) ?? [];
|
||||
|
||||
switch ($endpoint) {
|
||||
case 'ping':
|
||||
echo json_encode(['status' => 'online', 'time' => date('c'), 'codename' => JARVIS_CODENAME]);
|
||||
break;
|
||||
case 'auth':
|
||||
require __DIR__ . '/../api/endpoints/auth.php';
|
||||
break;
|
||||
case 'chat':
|
||||
require __DIR__ . '/../api/endpoints/chat.php';
|
||||
break;
|
||||
case 'system':
|
||||
require __DIR__ . '/../api/endpoints/system.php';
|
||||
break;
|
||||
case 'network':
|
||||
require __DIR__ . '/../api/endpoints/network.php';
|
||||
break;
|
||||
case 'proxmox':
|
||||
require __DIR__ . '/../api/endpoints/proxmox.php';
|
||||
break;
|
||||
case 'ha':
|
||||
require __DIR__ . '/../api/endpoints/ha.php';
|
||||
break;
|
||||
case 'do':
|
||||
require __DIR__ . '/../api/endpoints/do_server.php';
|
||||
break;
|
||||
case 'alerts':
|
||||
require __DIR__ . '/../api/endpoints/alerts.php';
|
||||
break;
|
||||
case 'facts':
|
||||
require __DIR__ . '/../api/endpoints/facts_collector.php';
|
||||
break;
|
||||
case 'weather':
|
||||
require __DIR__ . '/../api/endpoints/weather.php';
|
||||
break;
|
||||
case 'news':
|
||||
require __DIR__ . '/../api/endpoints/news.php';
|
||||
break;
|
||||
case "agent":
|
||||
require __DIR__ . '/../api/endpoints/agent.php';
|
||||
break;
|
||||
default:
|
||||
http_response_code(404);
|
||||
echo json_encode(['error' => 'Unknown endpoint: ' . $endpoint]);
|
||||
}
|
||||
Reference in New Issue
Block a user