connect($mikrotikIP, $username, $password)) { function getDateInt($date) { $monthArray = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]; $days = substr($date, 4, 2); $month = substr($date, 0, 3); $year = substr($date, 7, 4); $monthInt = array_search(strtolower($month), $monthArray) + 1; $month = str_pad($monthInt, 2, "0", STR_PAD_LEFT); return intval($year . $month . $days); } function getTimeInt($time) { $hours = intval(substr($time, 0, 2)); $minutes = intval(substr($time, 3, 2)); return ($hours * 60) + $minutes; } // Ambil tanggal dan waktu dari MikroTik $systemClock = $API->comm('/system/clock/print')[0]; $date = $systemClock['date']; $time = $systemClock['time']; $today = getDateInt($date); $curtime = getTimeInt($time); // Ambil pengguna hotspot dengan profil "1Hari" $users = $API->comm('/ip/hotspot/user/print'); foreach ($users as $user) { // Periksa apakah 'comment' ada dan tidak kosong if (!isset($user['comment']) || empty($user['comment'])) { // echo "User {$user['name']} does not have a valid comment.\n"; continue; // Lewati pengguna ini dan lanjutkan ke iterasi berikutnya } $comment = $user['comment']; $name = $user['name']; // Pastikan format komentar sesuai (contoh: "jan/20/2025 14:04:35") if (substr($comment, 3, 1) === "/" && substr($comment, 6, 1) === "/") { $expd = getDateInt($comment); $expt = getTimeInt(substr($comment, 12, 8)); if (($expd < $today && $expt < $curtime) || ($expd < $today && $expt > $curtime) || ($expd == $today && $expt < $curtime)) { // Set limit-uptime menjadi 1 detik // Cek apakah limit-uptime sudah 1s if (isset($user['limit-uptime']) && $user['limit-uptime'] === '1s') { // echo "User {$user['name']} already has limit-uptime set to 1s.\n"; continue; // Lewati pengguna ini jika limit-uptime sudah diatur ke 1s } // Set limit-uptime menjadi 1 detik $API->comm('/ip/hotspot/user/set', [ '.id' => $user['.id'], 'limit-uptime' => '1s' ]); // Hapus sesi aktif pengguna berdasarkan nama $activeSessions = $API->comm('/ip/hotspot/active/print', [ '?user' => $name ]); foreach ($activeSessions as $session) { $API->comm('/ip/hotspot/active/remove', [ '.id' => $session['.id'] ]); } // echo "Updated and removed active session for user: $name\n"; } } else { // echo "Invalid comment format for user: $name\n"; } } $API->disconnect(); } else { echo "Unable to connect to MikroTik!"; }