Profile Paket

disabled>
Saat ini radius hanya digunakan untuk Autentikasi saja, untuk limit masih di sisi mikrotik
Nama Profile Harus sama dengan yang ada di Mikrotik
Pilih Berulangkali jika user hotspot di tagihan setiap bulan
">
Isi jika menggunakan Aplikasi Agen Voucher
Contoh : 3H => 3 Jam , 1D => 1 Hari
{'groupname'}; $radiusPayload = [ 'groupnameold' => $groupnameold, 'data' => [ 'jenis' => $_POST['jenis'], 'groupname' => $groupname, 'profile' => $_POST['profile'] ?? '', 'use_limit' => $_POST['use_limit'] ?? '', 'rate_limit' => $_POST['rate_limit'] ?? '', 'session_time' => $_POST['session_time'] ?? '', 'ip_pool' => $_POST['ip_pool'] ?? '', 'idle_time' => $_POST['idle_time'] ?? '' ]]; // print_r($radiusPayload); $currentRadiusData = json_decode($paket['radius_data'], true); if ($radiusPayload['data'] != $currentRadiusData) { $changes['radius_data'] = json_encode($radiusPayload['data']); } // === TRANSAKSI DB === $pdo->beginTransaction(); // === Update Radius jika perlu === if (isset($changes['radius_data']) && !empty($_POST['radiuscek'])) { $radius = new CrudRadiusServer(); $radius->request('update_paket', 'PUT', $radiusPayload); } // === Update ke Database hanya jika ada perubahan === if (!empty($changes)) { $updateFields = []; foreach ($changes as $key => $value) { // Pastikan tidak ada field yang dilarang ikut if (!in_array($key, ['id_data_server', 'radiuscek', 'jenis', 'jenishs'])) { $updateFields[] = "$key = :$key"; } } if (!empty($updateFields)) { $sql = "UPDATE profile_paket SET " . implode(', ', $updateFields) . " WHERE id = :id"; $stmt = $pdo->prepare($sql); foreach ($changes as $key => $value) { if (!in_array($key, ['id_data_server', 'radiuscek', 'jenis', 'jenishs'])) { $stmt->bindValue(":$key", $value); } } $stmt->bindValue(':id', $page[1]); $stmt->execute(); } } // === Update ke Mikrotik === $stmt = $pdo->prepare("SELECT * FROM setting_mikrotik WHERE id_data_server = :id_data_server"); $stmt->execute([':id_data_server' => $_POST['ids']]); $servers = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($servers as $server) { $mikrotikName = $server['nama']; $API = new RouterosAPI(); $API->debug = false; if ($API->connect2($server['ip_address'], $server['username'], $server['password'], $server['port_api'])) { $profileFound = false; $poolFound = false; // === CEK PROFILE & UPDATE SCRIPT === $profileFound = true; // Default true (kalau jenis bukan PPPoE/Hotspot tidak perlu dicek) if (!empty($_POST['profile'])) { if ($_POST['jenis'] == 'PPPOE') { $profiles = $API->comm('/ppp/profile/print'); } elseif ($_POST['jenis'] == 'Hotspot') { $profiles = $API->comm('/ip/hotspot/user/profile/print'); } else { $profiles = []; // DHCP tidak cek profile } $profileFound = false; foreach ($profiles as $p) { if ($p['name'] === $newProfile) { $profileFound = true; // === UPDATE SCRIPT (HANYA HOTSPOT) === if ($_POST['jenis'] == 'Hotspot' && $newStatus == 1 && empty($_POST['radiuscek'])) { $interval = intervalFormat($_POST['durasi']); $onLoginScript = ':local nama $user; :local tanggal [/system clock get date]; :local waktu [/system clock get time]; :if ([/ip hotspot user get [find name=$nama] comment] = "") do={/ip hotspot user set [find name=$nama] comment="Login.$tanggal $waktu"; :log warning ("User " . $nama . " berhasil login.")} else={:log warning ("User " . $nama . " berhasil melakukan login ulang.")}; :if ([/system schedule find name=$nama] = "") do={/system schedule add name=$nama interval=' . $interval . ' on-event="/ip hotspot active remove [find user=$nama]; /ip hotspot user remove [find name=$nama]; /system schedule remove [find name=$nama]" start-date=$tanggal start-time=$waktu;}'; $API->comm('/ip/hotspot/user/profile/set', [ '.id' => $p['.id'], 'on-login' => $onLoginScript, ]); } break; } } if (!$profileFound) { $messages[] = "Profil $newProfile di $mikrotikName tidak ditemukan."; break; } } // === CEK IP POOL === if (!empty($_POST['ip_pool']) && $_POST['jenis'] == 'DHCP') { $poolcek = $API->comm('/ip/pool/print'); foreach ($poolcek as $pool) { if ($pool['name'] === $_POST['ip_pool']) { $poolFound = true; break; } } if (!$poolFound) { $messages[] = "IP Pool {$_POST['ip_pool']} di $mikrotikName tidak ditemukan."; break; } } $rollbackServers[] = $server; // Catat untuk rollback jika error } else { $messages[] = "Gagal terhubung ke MikroTik $mikrotikName."; break; } } if (empty($messages)) { $pdo->commit(); sweetAlert("Profile Paket berhasil diperbarui", "success", "?" . encrypt_url('profile_paket')); } else { $pdo->rollBack(); $message = implode("
", $messages); detailAlert($message, true); } } catch (PDOException $e) { $pdo->rollBack(); sweetAlert("Terjadi kesalahan: " . $e->getMessage(), "error"); } } ?>