Created At: 2026-06-14T16:22:43Z
Completed At: 2026-06-14T16:22:43Z
File Path: `file:///c:/Users/HP/Downloads/climate-system/climate-system/index.php`
Total Lines: 4089
Total Bytes: 174796
Showing lines 300 to 350
The following code has been modified to include a line number before every line, in the format: <line_number>: <original_line>. Please note that any changes targeting the original code should remove the line number, colon, and leading space.
300: }
301: 
302: // Router API Endpoint
303: $action = isset($_GET['action']) ? $_GET['action'] : '';
304: 
305: if (!empty($action)) {
306:     header('Content-Type: application/json');
307: 
308:     try {
309:         // A. Cek Otentikasi Sesi Admin untuk Aksi Modifikasi Database
310:         $protected_actions = ['save_historical', 'save_future', 'add_location', 'add_variable', 'add_period'];
311:         if (in_array($action, $protected_actions)) {
312:             if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
313:                 http_response_code(401);
314:                 echo json_encode(['success' => false, 'error' => 'Unauthorized: Sesi admin tidak ditemukan. Silakan login terlebih dahulu.']);
315:                 exit;
316:             }
317:         }
318: 
319:         // B. Endpoint Otentikasi Admin
320:         if ($action === 'login') {
321:             if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
322:                 echo json_encode(['error' => 'Metode request tidak valid.']);
323:                 exit;
324:             }
325:             $raw_input = file_get_contents('php://input');
326:             $input = json_decode($raw_input, true);
327:             $username = isset($input['username']) ? trim($input['username']) : '';
328:             $password = isset($input['password']) ? trim($input['password']) : '';
329: 
330:             if ($username === 'admin' && $password === 'admin') {
331:                 $_SESSION['admin_logged_in'] = true;
332:                 echo json_encode(['success' => true, 'message' => 'Login Admin berhasil!']);
333:             } else {
334:                 echo json_encode(['success' => false, 'error' => 'Username atau Password salah.']);
335:             }
336:             exit;
337:         }
338: 
339:         if ($action === 'logout') {
340:             unset($_SESSION['admin_logged_in']);
341:             session_destroy();
342:             echo json_encode(['success' => true, 'message' => 'Logout Admin berhasil!']);
343:             exit;
344:         }
345: 
346:         if ($action === 'check_auth') {
347:             $is_logged_in = isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true;
348:             echo json_encode(['success' => true, 'authenticated' => $is_logged_in]);
349:             exit;
350:         }
The above content does NOT show the entire file contents. If you need to view any lines of the file which were not shown to complete your task, call this tool again to view those lines.
