diff --git a/.user.ini b/.user.ini deleted file mode 100644 index 28b2a5e..0000000 --- a/.user.ini +++ /dev/null @@ -1 +0,0 @@ -open_basedir=/www/wwwroot/bilspro/:/tmp/ \ No newline at end of file diff --git a/autentikasi/aut_akses.php b/autentikasi/aut_akses.php index 7f4cf10..c789a70 100644 --- a/autentikasi/aut_akses.php +++ b/autentikasi/aut_akses.php @@ -56,7 +56,7 @@ include 'config/tanggal_indo.php';
Lupa Password ?
- Kembali ke Halaman Utama + Kembali ke Halaman Utama
diff --git a/autentikasi/register.php b/autentikasi/register.php index 3bba11c..454fe87 100644 --- a/autentikasi/register.php +++ b/autentikasi/register.php @@ -212,7 +212,7 @@ include "config/tanggal_indo.php";
- Kembali ke Halaman Utama + Kembali ke Halaman Utama
diff --git a/controller/Param_crudRadiusServer.txt b/controller/Param_crudRadiusServer.txt new file mode 100644 index 0000000..ebc60c4 --- /dev/null +++ b/controller/Param_crudRadiusServer.txt @@ -0,0 +1,21 @@ +$api = new CrudRadiusServer(); + +// Tambah user +$api->request('add_user', 'POST', [ + 'username' => 'test123', + 'password' => 'pass123' +]); + +// Update user +$api->request('update_user', 'PUT', [ + 'username' => 'test123', + 'password' => 'newpass' +]); + +// Hapus user +$api->request('delete_user', 'DELETE', [ + 'username' => 'test123' +]); + +// Ambil semua user +$api->request('get_all', 'GET'); diff --git a/controller/createTunnel.php b/controller/createTunnel.php new file mode 100644 index 0000000..8561d03 --- /dev/null +++ b/controller/createTunnel.php @@ -0,0 +1,266 @@ +debug = false; + + // Connect ke MikroTik + if ($mikrotik->connect2('manjapro.net', 'apiapkmanjapro', 'apiapkmanjapro123321', '2887')) { + + // Ambil semua remote-address yang sudah dipakai + $secrets = $mikrotik->comm('/ppp/secret/print', [ + "?local-address" => "172.18.1.100" + ]); + + $maxIp = 0; + foreach ($secrets as $secret) { + if (isset($secret['remote-address']) && filter_var($secret['remote-address'], FILTER_VALIDATE_IP)) { + $ipParts = explode('.', $secret['remote-address']); + if (count($ipParts) == 4 && $ipParts[0] == '172' && $ipParts[1] == '18' && $ipParts[2] == '1') { + $lastOctet = (int)$ipParts[3]; + if ($lastOctet > $maxIp) { + $maxIp = $lastOctet; + } + } + } + } + + // Hitung remote-address baru + $nextIp = $maxIp + 1; + $remoteAddress = "172.18.1." . $nextIp; + + // Local address (bisa fix atau ambil dari pool) + $localAddress = "172.18.1.100"; + + // ============================== + // Ambil semua dst-port yang sudah digunakan + // ============================== + $natRules = $mikrotik->comm('/ip/firewall/nat/print'); + $usedPorts = []; + + foreach ($natRules as $rule) { + if (isset($rule['dst-port'])) { + $ports = explode(',', $rule['dst-port']); + foreach ($ports as $p) { + $usedPorts[] = (int)$p; + } + } + } + + // Cari 2 port yang bebas mulai dari 2000 + $startPort = 200; + $freePorts = []; + while (count($freePorts) < 2) { + if (!in_array($startPort, $usedPorts)) { + $freePorts[] = $startPort; + } + $startPort++; + if ($startPort > 9999) { // Batas port TCP + break; // Hindari infinite loop + } + } + + if (count($freePorts) < 2) { + return [ + 'status' => false, + 'message' => 'Tidak ada 2 port bebas yang tersedia' + ]; + } + + $port1 = $freePorts[0]; + $port2 = $freePorts[1]; + + // ============================== + // Generate user/pass + // ============================== + $secretUser = strtolower(preg_replace('/[^a-z0-9]/i', '', substr($Secret, 0, 12))) . "@manjapro.net"; + $secretPass = strtolower(substr(md5($secretUser), 0, 12)); + $nasSecret = substr(md5($secretUser), 0, 20); + + // Tambahkan PPP secret + $add = $mikrotik->comm('/ppp/secret/add', [ + "name" => $secretUser, + "password" => $secretPass, + "profile" => "default-encryption", + "local-address" => $localAddress, + "remote-address" => $remoteAddress, + "service" => "any", + "comment" => $Secret + ]); + + // Tambahkan 2 firewall NAT rules + $nat1 = $mikrotik->comm('/ip/firewall/nat/add', [ + "chain" => "dstnat", + "dst-address-list" => "IP-Public", + "dst-port" => $port1, + "protocol" => "tcp", + "action" => "dst-nat", + "to-addresses" => $remoteAddress, + "to-ports" => $port1, + "comment" => $Secret + ]); + + $nat2 = $mikrotik->comm('/ip/firewall/nat/add', [ + "chain" => "dstnat", + "dst-address-list" => "IP-Public", + "dst-port" => $port2, + "protocol" => "tcp", + "action" => "dst-nat", + "to-addresses" => $remoteAddress, + "to-ports" => $port2, + "comment" => $Secret + ]); + + $mikrotik->disconnect(); + + // Siapkan data response + $data = [ + "name" => $secretUser, + "password" => $secretPass, + "profile" => "default-encryption", + "local-address" => $localAddress, + "remote-address" => $remoteAddress, + "service" => "any", + "nas_secret" => $nasSecret, + "nasgroupname" => $nasGroup, + "port-api" => $port1, + "port-remote" => $port2 + ]; + + return json_encode( [ + 'status' => true, + 'message' => 'PPP secret dan NAT berhasil dibuat', + 'data' => $data + ] ); + } else { + return json_encode ([ + 'status' => false, + 'message' => 'Gagal terhubung ke MikroTik' + ]); + } + } + + public function deleteTunnel($Data) + { + $data = json_decode($Data); + + // Validasi data yang diterima + if (!isset($data->data->{'name'}) || !isset($data->data->{'port-api'}) || !isset($data->data->{'port-remote'})) { + http_response_code(400); + echo json_encode([ + 'success' => false, + 'message' => "Data tidak lengkap untuk menghapus tunnel" + ]); + return; + } + + $name = $data->data->{'name'}; + $portApi = $data->data->{'port-api'}; + $portRemote = $data->data->{'port-remote'}; + + $mikrotik = new RouterosAPI(); + $mikrotik->debug = false; + + // Connect ke MikroTik + if ($mikrotik->connect2('manjapro.net', 'apiapkmanjapro', 'apiapkmanjapro123321', 2887)) { + + try { + // Hapus PPP Secret + $pppSecrets = $mikrotik->comm('/ppp/secret/print', [ + "?name" => $name + ]); + + if (!empty($pppSecrets)) { + foreach ($pppSecrets as $secret) { + if (isset($secret['.id'])) { + $mikrotik->comm('/ppp/secret/remove', [ + ".id" => $secret['.id'] + ]); + } + } + } + + // Hapus NAT untuk port-api + $natApi = $mikrotik->comm('/ip/firewall/nat/print', [ + "?dst-port" => $portApi + ]); + + if (!empty($natApi)) { + foreach ($natApi as $rule) { + if (isset($rule['.id'])) { + $mikrotik->comm('/ip/firewall/nat/remove', [ + ".id" => $rule['.id'] + ]); + } + } + } + + // Hapus NAT untuk port-remote + $natRemote = $mikrotik->comm('/ip/firewall/nat/print', [ + "?dst-port" => $portRemote + ]); + + if (!empty($natRemote)) { + foreach ($natRemote as $rule) { + if (isset($rule['.id'])) { + $mikrotik->comm('/ip/firewall/nat/remove', [ + ".id" => $rule['.id'] + ]); + } + } + } + + $mikrotik->disconnect(); + + // Kirim respon sukses + http_response_code(200); + echo json_encode([ + 'success' => true, + 'message' => "Tunnel '$name' berhasil dihapus" + ]); + } catch (Exception $e) { + $mikrotik->disconnect(); + http_response_code(500); + echo json_encode([ + 'success' => false, + 'message' => "Gagal menghapus tunnel: " . $e->getMessage() + ]); + } + } else { + http_response_code(500); + echo json_encode([ + 'success' => false, + 'message' => "Gagal koneksi ke MikroTik" + ]); + } + } + +} + + + +// <===== CONTOH =====> + +// $tunnel = new CreateTunnel(); +// $result = $tunnel->addSecret('user123', 'pass123'); + +// if ($result['status']) { +// echo "✅ Berhasil: " . $result['remote-address']; +// } else { +// echo "❌ Gagal: " . $result['message']; +// } \ No newline at end of file diff --git a/controller/crudRadiusServer.php b/controller/crudRadiusServer.php new file mode 100644 index 0000000..bbc5378 --- /dev/null +++ b/controller/crudRadiusServer.php @@ -0,0 +1,55 @@ +baseUrl . "?action=" . urlencode($action); + + $ch = curl_init($url); + + $headers = [ + 'Content-Type: application/json', + 'Authorization: Bearer ' . $this->token + ]; + + // Set CURL options + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method)); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + // Jika ada data, kirim sebagai JSON + if (!empty($data)) { + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + } + + // Eksekusi request + $response = curl_exec($ch); + + if (curl_errno($ch)) { + // Return error sebagai array + return [ + 'success' => false, + 'error' => curl_error($ch) + ]; + } + + curl_close($ch); + + // Decode JSON response + $decoded = json_decode($response, true); + + // Jika JSON tidak valid + if (json_last_error() !== JSON_ERROR_NONE) { + return [ + 'success' => false, + 'error' => 'Invalid JSON response from API' + ]; + } + + return $decoded; + } +} diff --git a/controller/voucher_auto.php b/controller/voucher_auto.php new file mode 100644 index 0000000..121e15d --- /dev/null +++ b/controller/voucher_auto.php @@ -0,0 +1,110 @@ +query("SELECT COUNT(*) FROM ganerate_voucher WHERE $baseCondition"); + $totalRecords = $totalQuery->fetchColumn(); + + // Query data + search + $sql = "SELECT create_time, voucher, harga, status_cek, active_time, expaired_time, jenis + FROM ganerate_voucher + WHERE $baseCondition"; + $params = []; + + if (!empty($searchValue)) { + $sql .= " AND ( + create_time LIKE :search OR + voucher LIKE :search OR + status_cek LIKE :search OR + active_time LIKE :search OR + expaired_time LIKE :search + )"; + $params[':search'] = "%$searchValue%"; + } + + // Hitung total setelah filter + $filteredSql = str_replace( + "SELECT create_time, voucher, harga, status_cek, active_time, expaired_time, jenis", + "SELECT COUNT(*)", + $sql + ); + $stmtFiltered = $pdo->prepare($filteredSql); + $stmtFiltered->execute($params); + $filteredRecords = $stmtFiltered->fetchColumn(); + + // Tambahkan ORDER BY dan LIMIT + $sql .= " ORDER BY $orderColumn $orderColumnDir LIMIT :start, :length"; + $stmt = $pdo->prepare($sql); + + // Binding parameter + foreach ($params as $key => $value) { + $stmt->bindValue($key, $value); + } + $stmt->bindValue(':start', $start, PDO::PARAM_INT); + $stmt->bindValue(':length', $length, PDO::PARAM_INT); + + $stmt->execute(); + $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // Hitung biaya & saldo, lalu format angka + $data = []; + foreach ($rows as $row) { + $harga = floatval($row['harga']); + if ($row['jenis'] === 'api-pw') { + $biaya = $harga * $potongan; + } else { + $biaya = 0; // Tidak ada biaya jika bukan sv-radius + } + $saldo = $harga - $biaya; + + $data[] = [ + $row['create_time'], + $row['voucher'], + number_format($harga), // harga + number_format($biaya), // biaya + number_format($saldo), // saldo + $row['status_cek'], + $row['active_time'], + $row['expaired_time'], + ]; + } + + // Kirim response JSON ke DataTables + $response = [ + "draw" => $draw, + "recordsTotal" => $totalRecords, + "recordsFiltered" => $filteredRecords, + "data" => $data, + ]; + + header('Content-Type: application/json'); + echo json_encode($response); +} catch (Exception $e) { + // Tangani error + header('Content-Type: application/json'); + echo json_encode([ + "error" => $e->getMessage() + ]); +} diff --git a/dashboard.php b/dashboard.php index 829ceb6..aea0856 100644 --- a/dashboard.php +++ b/dashboard.php @@ -1,5 +1,5 @@ -
+
@@ -96,110 +133,161 @@ $paket = mysqli_fetch_assoc($apaket); {'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); - $messages = []; // Array untuk menyimpan pesan foreach ($servers as $server) { $mikrotikName = $server['nama']; $API = new RouterosAPI(); $API->debug = false; - // Koneksi ke MikroTik if ($API->connect2($server['ip_address'], $server['username'], $server['password'], $server['port_api'])) { - $profileName = $_POST['profile']; + $profileFound = false; + $poolFound = false; - if ($_POST['jenis'] == 'PPPOE') { - // Cek profil PPPOE - $profiles = $API->comm('/ppp/profile/print'); - $found = false; + // === CEK PROFILE & UPDATE SCRIPT === + $profileFound = true; // Default true (kalau jenis bukan PPPoE/Hotspot tidak perlu dicek) - foreach ($profiles as $profile) { - if ($profile['name'] === $profileName) { - $found = true; - break; - } - } - if (!$found) { - $messages[] = "Profil PPPOE $profileName di $mikrotikName tidak ada."; - } - } else { - // Cek profil Hotspot - $profiles = $API->comm('/ip/hotspot/user/profile/print'); - $found = false; - - foreach ($profiles as $profile) { - if ($profile['name'] === $profileName) { - $profileId = $profile['.id']; - $found = true; - break; - } - } - - if ($found) { - // Jika status sama dengan 1 - if ($status == 1) { - // Pastikan intervalFormat() sudah terdefinisi - $interval = intervalFormat($_POST['durasi']); - - // Skrip On Login yang akan dipasang - $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;}'; - - // Update skrip On Login - $API->comm('/ip/hotspot/user/profile/set', [ - '.id' => $profileId, - 'on-login' => $onLoginScript, - ]); - } else { - $messages[] = "Gagal Upload Script: Profil Hotspot $profileName di $mikrotikName tidak aktif atau status tidak sesuai."; - } + 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 { - $messages[] = "Profil Hotspot $profileName di $mikrotikName tidak ada."; + $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; } } - // Cek pesan sebelum menyimpan ke database if (empty($messages)) { - $stmt = $pdo->prepare("UPDATE profile_paket SET - id_data_server = :id_data_server, - jenis_profile = :jenis_profile, - nama_profile = :nama_profile, - durasi = :durasi, - nama = :nama, - harga_paket = :harga_paket, - vi_agen = :vi_agen, - status = :status - WHERE id = :id"); - $stmt->bindParam(':id_data_server', $_POST['ids']); - $stmt->bindParam(':jenis_profile', $_POST['jenis']); - $stmt->bindParam(':nama_profile', $_POST['profile']); - $stmt->bindParam(':durasi', $_POST['durasi']); - $stmt->bindParam(':nama', $_POST['nama']); - $stmt->bindParam(':harga_paket', $nominal); - $stmt->bindParam(':vi_agen', $fee); - $stmt->bindParam(':status', $status); - $stmt->bindParam(':id', $page[1]); - $stmt->execute(); - sweetAlert("Profile Paket Telah di Ubah", "success", "?".encrypt_url('profile_paket')); + $pdo->commit(); + sweetAlert("Profile Paket berhasil diperbarui", "success", "?" . encrypt_url('profile_paket')); } else { + $pdo->rollBack(); $message = implode("
", $messages); - detailAlert($message, strpos($message, 'tidak ada') !== false || strpos($message, 'Gagal') !== false); + detailAlert($message, true); } - } catch (PDOException $e) { - // Menangani kesalahan + $pdo->rollBack(); sweetAlert("Terjadi kesalahan: " . $e->getMessage(), "error"); } } @@ -207,67 +295,116 @@ if (isset($_POST['edit'])) { diff --git a/pages/setting_mikrotik.php b/pages/setting_mikrotik.php index 3355941..f605c36 100644 --- a/pages/setting_mikrotik.php +++ b/pages/setting_mikrotik.php @@ -6,7 +6,7 @@
-

Setting Mikrotik

+

Setting Mikrotik

    @@ -35,26 +35,43 @@
- +
- + + Isi Jika memiliki IP Public
- + + Isi Jika memiliki IP Public +
+
+ +
+ + +
+
+ + +
- +
- +
@@ -86,22 +103,64 @@ if (isset($_POST['tambah'])) { $user_remote = 'Test'; $last_remote = date('Y-m-d H:i:s'); + try { - // Misalkan $pdo adalah koneksi PDO yang sudah dibuat sebelumnya + // Cek apakah tunnel dibuat + if (!empty($_POST['tunnel']) && $_POST['tunnel'] == 1 || !empty($_POST['radius']) && $_POST['radius'] == 1) { + + $nasgroup = "server" . $SvId; + + $tunnel = new CreateTunnel(); + $resultTun = $tunnel->addTunnel($_POST['nmk'] . '_' . $_POST['ids'], $nasgroup); + $radius_nas_data = $resultTun; + + $decodedResult = json_decode($resultTun); + $nasname = $decodedResult->data->{"remote-address"} ?? null; + $shortname = strtok($decodedResult->data->{"name"}, '@'); + $nassecret = $decodedResult->data->{"nas_secret"} ?? null; + + //Add nas Radius Sevrver + if ($decodedResult->{'status'} == true && $_POST['radius'] == 1) { + $radius = new CrudRadiusServer(); + $radius->request('add_nas', 'POST', [ + 'nasname' => $nasname, + 'shortname' => $shortname, + 'secret' => $nassecret, + 'nasnamegroup' => $nasgroup + ]); + } + + $address = "tunnel.manjapro.net"; + $portApi = $decodedResult->data->{"port-api"} ?? null; + $portRm = $decodedResult->data->{"port-remote"} ?? null; + } else { + $radius_nas_data = ""; + + $address = $_POST['ipa']; + $portApi = $_POST['pam']; + $portRm = $_POST['prm']; + } + + // Tentukan status radius (aktif/tidak) + $status_radius = (!empty($_POST['radius']) && $_POST['radius'] == 1) ? 1 : 0; + + // Insert ke DB $stmt = $pdo->prepare("INSERT INTO setting_mikrotik - (id_data_server, nama, ip_address, port_api, port_remote, username, password, profile_remote, user_remote, last_remote) - VALUES (:id_data_server, :nama, :ip_address, :port_api, :port_remote, :username, :password, :profile_remote, :user_remote, :last_remote)"); + (id_data_server, nama, ip_address, port_api, port_remote, username, password, profile_remote, user_remote, last_remote, radius_nas_data, status_radius) + VALUES (:id_data_server, :nama, :ip_address, :port_api, :port_remote, :username, :password, :profile_remote, :user_remote, :last_remote, :radius_nas_data, :status_radius)"); $stmt->bindParam(':id_data_server', $_POST['ids']); $stmt->bindParam(':nama', $_POST['nmk']); - $stmt->bindParam(':ip_address', $_POST['ipa']); - $stmt->bindParam(':port_api', $_POST['pam']); - $stmt->bindParam(':port_remote', $_POST['prm']); + $stmt->bindParam(':ip_address', $address); + $stmt->bindParam(':port_api', $portApi); + $stmt->bindParam(':port_remote', $portRm); $stmt->bindParam(':username', $_POST['usm']); $stmt->bindParam(':password', $_POST['psw']); $stmt->bindParam(':profile_remote', $_POST['profile_remote']); $stmt->bindParam(':user_remote', $user_remote); $stmt->bindParam(':last_remote', $last_remote); + $stmt->bindParam(':radius_nas_data', $radius_nas_data); + $stmt->bindParam(':status_radius', $status_radius); if ($stmt->execute()) { sweetAlert("Data telah ditambah", "success"); @@ -111,6 +170,7 @@ sweetAlert("Error: " . $e->getMessage(), "error"); } } + ?>
@@ -156,8 +216,10 @@
@@ -278,6 +340,21 @@
+
+ +
+ > + +
+
+ > + +
+
@@ -319,6 +396,117 @@ addTunnel($_POST['nmk'] . '_' . $_POST['ids']); + $radius_nas_data = $resultTun; + + $decodedResult = json_decode($resultTun); + $nasname = $decodedResult->data->{"remote-address"} ?? null; + $shortname = strtok($decodedResult->data->{"name"}, '@'); + $nassecret = $decodedResult->data->{"nas_secret"} ?? null; + $nasgroup = "server" . $SvId; + + // Tambahkan NAS ke Radius jika diminta + if ($decodedResult->{'status'} == true && !empty($_POST['radius'])) { + $radius = new CrudRadiusServer(); + $radius->request('add_nas', 'POST', [ + 'nasname' => $nasname, + 'shortname' => $shortname, + 'secret' => $nassecret, + 'nasnamegroup' => $nasgroup + ]); + $status_radius = 1 ; + } else { + $status_radius = 0 ; + } + + $address = "tunnel.manjapro.net"; + $portApi = $decodedResult->data->{"port-api"} ?? null; + $portRm = $decodedResult->data->{"port-remote"} ?? null; + + } + // Jika data tunnel radius ada tapi tunnel & radius mau dihapus + elseif (!empty($server['radius_nas_data']) && empty($_POST['tunnel'])) { + + $nasnameip = json_decode($server['radius_nas_data']); + $nasipname = $nasnameip->data->{'remote-address'}; + + $radius = new CrudRadiusServer(); + $radius->request('delete_nas', 'DELETE', [ + 'nasname' => $nasipname + ]); + + $dtunnel = new CreateTunnel(); + $dresultTun = $dtunnel->deleteTunnel($server['radius_nas_data']); + + // hapus data tunnel di db setting mikrotik + $radius_nas_data = ""; + $status_radius = 0 ; + + $address = $_POST['ipa']; + $portApi = $_POST['pam']; + $portRm = $_POST['prm']; + + } + // Jika tetap pakai tunnel tapi radius dinonaktifkan + elseif (!empty($server['radius_nas_data']) && empty($_POST['radius'])) { + + $nasnameip = json_decode($server['radius_nas_data']); + $nasipname = $nasnameip->data->{'remote-address'}; + + $radius = new CrudRadiusServer(); + $radius->request('delete_nas', 'DELETE', [ + 'nasname' => $nasipname + ]); + + $radius_nas_data = $server['radius_nas_data']; + $status_radius = 0 ; + + $address = "tunnel.manjapro.net"; + $portApi = $nasnameip->data->{"port-api"}; + $portRm = $nasnameip->data->{"port-remote"}; + + } + // Jika sudah ada tunnel lalu mau pakai radius + elseif (!empty($server['radius_nas_data']) && $_POST['radius'] == 1) { + + $decodedResult = json_decode($server['radius_nas_data']); + $nasname = $decodedResult->data->{"remote-address"} ?? null; + $shortname = strtok($decodedResult->data->{"name"}, '@'); + $nassecret = $decodedResult->data->{"nas_secret"} ?? null; + $nasgroup = "server" . $SvId; + + $radius = new CrudRadiusServer(); + $radius->request('add_nas', 'POST', [ + 'nasname' => $nasname, + 'shortname' => $shortname, + 'secret' => $nassecret, + 'nasnamegroup' => $nasgroup + ]); + + $radius_nas_data = $server['radius_nas_data']; + $status_radius = 1 ; + + $address = "tunnel.manjapro.net"; + $portApi = $decodedResult->data->{"port-api"}; + $portRm = $decodedResult->data->{"port-remote"}; + + } + // Jika tidak menggunakan tunnel dan radius + else { + $radius_nas_data = ""; + $status_radius = ""; + + $address = $_POST['ipa']; + $portApi = $_POST['pam']; + $portRm = $_POST['prm']; + } + + // Misalkan $pdo adalah koneksi PDO yang sudah dibuat sebelumnya $stmt = $pdo->prepare("UPDATE setting_mikrotik SET id_data_server = :id_data_server, @@ -328,40 +516,223 @@ port_remote = :port_remote, username = :username, password = :password, - profile_remote = :profile_remote + profile_remote = :profile_remote, + radius_nas_data = :radius_nas_data, + status_radius = :status_radius WHERE id = :id"); // Mengikat parameter $stmt->bindParam(':id_data_server', $_POST['ids']); $stmt->bindParam(':nama', $_POST['nmk']); - $stmt->bindParam(':ip_address', $_POST['ipa']); - $stmt->bindParam(':port_api', $_POST['pam']); - $stmt->bindParam(':port_remote', $_POST['prm']); + $stmt->bindParam(':ip_address', $address); + $stmt->bindParam(':port_api', $portApi); + $stmt->bindParam(':port_remote', $portRm); $stmt->bindParam(':username', $_POST['usm']); $stmt->bindParam(':password', $_POST['psw']); $stmt->bindParam(':profile_remote', $_POST['profile_remote']); + $stmt->bindParam(':radius_nas_data', $radius_nas_data); + $stmt->bindParam(':status_radius', $status_radius); $stmt->bindParam(':id', $server['id']); // ID dari server yang ingin diupdate // Eksekusi statement if ($stmt->execute()) { + // Membuat Tunnel Radius sweetAlert("Data telah diubah", "success"); } } catch (PDOException $e) { // Menangani kesalahan - sweetAlert("Error: " . $e->getMessage(), "error"); + // sweetAlert("Error: " . $e->getMessage(), "error"); + echo $e->getMessage(); } } + // Hapus data Mikrotik if (isset($_POST['hapus'.$server['id']])) { + $dtunnel = new CreateTunnel(); + $dresultTun = $dtunnel->deleteTunnel($server['radius_nas_data']); + + $nasnameip = json_decode($server['radius_nas_data']); + $nasipname = $nasnameip->data->{'remote-address'}; + $radius = new CrudRadiusServer(); + $radius->request('delete_nas', 'DELETE', [ + 'nasname' => $nasipname + ]); + $iddata = $server['id']; deleteAlert("setting_mikrotik",$iddata ); + } ?>
+ + + + @@ -400,4 +771,52 @@ $('#syncBtn').on('click', function () { }); }); }); - \ No newline at end of file + + + + + + + diff --git a/pages/tiket_buat.php b/pages/tiket_buat.php index ee4f0a8..942c141 100644 --- a/pages/tiket_buat.php +++ b/pages/tiket_buat.php @@ -22,63 +22,82 @@
- - - - - - - - - - - + + + + + + + + + + + - query("SELECT * FROM v_tiket_gangguan WHERE status = '1' $SqlDataId ORDER BY level"); + while ($server = $stmt->fetch(PDO::FETCH_ASSOC)) { if ($server['jenis_tiket'] == 'Pelanggan') { $ket = ''.$server['nama_pelanggan'].'
'.$server['permasalahan']; } else { $ket = $server['permasalahan']; } - ?> - - - - - - - - - - - - prepare("UPDATE tiket_gangguan SET id_penyelesai_tiket = :idpenyet, sebelum_proses_time = :waktu, status = '2' WHERE id = :idtik"); - $stmt->bindParam(':waktu', $waktu); - $stmt->bindParam(':idpenyet', $UserId, PDO::PARAM_INT); - $stmt->bindParam(':idtik', $server['id'], PDO::PARAM_INT); - $stmt->execute(); - sweetAlert("Tiket akan di proses", "success", "?".encrypt_url('tiket_proses')); - } - if (isset($_POST['hapus'.$server['id']])) { - $iddata = $server['id']; - deleteAlert("tiket_gangguan", $iddata); - } - $no++; } ?> + + // Tentukan warna garis berdasarkan level + if ($server['level'] == 1) { + $borderColor = '#dc3545'; // Bootstrap danger + } elseif ($server['level'] == 2) { + $borderColor = '#ffc107'; // Bootstrap warning + } else { + $borderColor = '#0dcaf0'; // Bootstrap info + } + ?> + + + + + + + + + + + + prepare("UPDATE tiket_gangguan SET id_penyelesai_tiket = :idpenyet, sebelum_proses_time = :waktu, status = '2' WHERE id = :idtik"); + $stmt2->bindParam(':waktu', $waktu); + $stmt2->bindParam(':idpenyet', $UserId, PDO::PARAM_INT); + $stmt2->bindParam(':idtik', $server['id'], PDO::PARAM_INT); + $stmt2->execute(); + sweetAlert("Tiket akan di proses", "success", "?".encrypt_url('tiket_proses')); + } + if (isset($_POST['hapus'.$server['id']])) { + $iddata = $server['id']; + deleteAlert("tiket_gangguan", $iddata); + } + $no++; } ?>
NoTimeNama ServerJenisKeteranganLokasiKoordinatURL TrackingAction
NoTimeNama ServerJenisKeteranganLokasiKoordinatURL TrackingAction
-
- - - - - -
-
+ + + + + + + + + + +
+ + + + + +
+
diff --git a/pages/tiket_buat_baru.php b/pages/tiket_buat_baru.php index 6c0dd32..729b133 100644 --- a/pages/tiket_buat_baru.php +++ b/pages/tiket_buat_baru.php @@ -33,7 +33,7 @@ while ($tiap = $ambil->fetch_assoc()) {
-
+
-
+
+
+
+ + +
+
@@ -89,6 +100,7 @@ if (isset($_POST['tambah'])) { $lokasi = $result['alamat']; $latitude = $result['latitude']; $longitude = $result['longitude']; + $level = $_POST['level']; } else { $cekinput = false; } @@ -102,11 +114,12 @@ if (isset($_POST['tambah'])) { $lokasi = $_POST['tempat']; $latitude = NULL; $longitude = NULL; + $level = $_POST['level']; } - $stmt = $pdo->prepare("INSERT INTO tiket_gangguan (id_data_server, id_pelanggan, id_pembuat_tiket, jenis_tiket, permasalahan, start_time, status, lokasi, latitude, longitude) VALUES - (:idds, :idpel, :idpet, :jenis, :permasalahan, :timestart, '1', :lokasi, :latitude, :longitude)"); + $stmt = $pdo->prepare("INSERT INTO tiket_gangguan (id_data_server, id_pelanggan, id_pembuat_tiket, jenis_tiket, permasalahan, start_time, status, lokasi, latitude, longitude, level) VALUES + (:idds, :idpel, :idpet, :jenis, :permasalahan, :timestart, '1', :lokasi, :latitude, :longitude, :level)"); $stmt->bindParam(':idds', $idds, PDO::PARAM_INT); $stmt->bindParam(':idpel', $idpel, PDO::PARAM_INT); $stmt->bindParam(':idpet', $idpet, PDO::PARAM_INT); @@ -116,6 +129,7 @@ if (isset($_POST['tambah'])) { $stmt->bindParam(':lokasi', $lokasi); $stmt->bindParam(':latitude', $latitude); $stmt->bindParam(':longitude', $longitude); + $stmt->bindParam(':level', $level); $stmt->execute(); $lastId = $pdo->lastInsertId(); diff --git a/voucherpay/cl-style.js b/voucherpay/cl-style.js index 9fcdcd5..4570efd 100644 --- a/voucherpay/cl-style.js +++ b/voucherpay/cl-style.js @@ -4,13 +4,13 @@ const script = document.currentScript; if (script && script.src) { const url = new URL(script.src); - return url.searchParams.get("router_id"); + return url.searchParams.get("i"); } return null; } - const routerId = getRouterIdFromScriptSrc() || "unknown"; - console.log("Halaman login diakses dari MikroTik:", routerId); + const i = getRouterIdFromScriptSrc() || "unknown"; + console.log("Halaman login diakses dari MikroTik:", i); document.addEventListener("DOMContentLoaded", function () { const container = document.getElementById("voucher-container"); @@ -18,7 +18,7 @@ if (container) { const iframe = document.createElement("iframe"); iframe.id = "voucherFrame"; - iframe.src = "https://manjapro.net/voucherpay/?id=" + encodeURIComponent(routerId); + iframe.src = "http://localhost/manjapro-project/voucherpay/?i=" + encodeURIComponent(i); iframe.style.width = "100%"; iframe.style.border = "none"; iframe.style.display = "block"; diff --git a/voucherpay/index.php b/voucherpay/index.php index 1fe8576..ad725ca 100644 --- a/voucherpay/index.php +++ b/voucherpay/index.php @@ -1,12 +1,34 @@ {'board'}; +$radius_id = $params->nasgroupname; $stmt = $pdo->prepare("SELECT * FROM setting_mikrotik WHERE board_id = :board_id"); $stmt->bindParam(':board_id', $board_id, PDO::PARAM_STR); diff --git a/web/index.php b/web/index.php index 07e2bf0..eaee9b2 100644 --- a/web/index.php +++ b/web/index.php @@ -10,6 +10,7 @@ if ($jam >= 5 && $jam < 11) { $waktuSapa = "Selamat Malam"; } $pesantext = $waktuSapa.', Ada yang mau saya tanyakan terkait Apklikasi ManjaPro'; + ?> @@ -86,10 +87,10 @@ $pesantext = $waktuSapa.', Ada yang mau saya tanyakan terkait Apklikasi ManjaPro Harga