Update Voucher , Tiket , Dashboard
membuat perubahan dan update
This commit is contained in:
+10
-2
@@ -351,12 +351,20 @@ $stmt = $pdo->prepare("SELECT
|
||||
<div class="card-body">
|
||||
<div class="direct-chat-messages" style="height: 450px">
|
||||
<?php
|
||||
$stmt = $pdo->prepare("SELECT * FROM v_tiket_gangguan WHERE status = '1' $SqlDataId ORDER BY start_time DESC");
|
||||
$stmt = $pdo->prepare("SELECT * FROM v_tiket_gangguan WHERE status = '1' $SqlDataId ORDER BY level ASC, start_time DESC");
|
||||
$stmt->execute();
|
||||
while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
// Tentukan warna garis berdasarkan level
|
||||
if ($data['level'] == 1) {
|
||||
$borderColor = '#dc3545'; // Bootstrap danger
|
||||
} elseif ($data['level'] == 2) {
|
||||
$borderColor = '#ffc107'; // Bootstrap warning
|
||||
} else {
|
||||
$borderColor = '#0dcaf0'; // Bootstrap info
|
||||
}
|
||||
?>
|
||||
<a href="?<?php echo encrypt_url('tiket_buat') ?>">
|
||||
<div class="card p-2 text-dark" style="border-left: 8px solid red">
|
||||
<div class="card p-2 text-dark" style="border-left: 8px solid; border-left-color: <?= $borderColor; ?>;">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<p class="m-0 text-danger"><?php echo $data['jenis_tiket']; ?></p>
|
||||
|
||||
+345
-55
@@ -1,4 +1,10 @@
|
||||
<!-- Main content -->
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
?>
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
@@ -11,15 +17,225 @@
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<ol class="float-sm-right mb-0">
|
||||
<!--<a type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#staticBackdrop">Tambah</a>-->
|
||||
<a type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#staticBackdrop">Generate</a>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Modal Tambah -->
|
||||
<div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div class="modal-header bg-primary">
|
||||
<h5 class="modal-title" id="staticBackdropLabel">Generate Voucher</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Nama Server</label>
|
||||
<select class="form-control" name="ids" required>
|
||||
<option value="">Pilih</option>
|
||||
<?php
|
||||
$List = new Listdata();
|
||||
$List->set_list("data_server", $SqlDataWH);
|
||||
foreach ($List->get_list() as $key => $value): ?>
|
||||
<option value="<?php echo $value['id']; ?>"><?php echo $value['nama_server']; ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Mikrotik</label>
|
||||
<select class="form-control" name="idm" required>
|
||||
<option value="">Pilih</option>
|
||||
<?php
|
||||
$List = new Listdata();
|
||||
$List->set_list("setting_mikrotik", $SqlDataWHId);
|
||||
foreach ($List->get_list() as $key => $value): ?>
|
||||
<option value="<?php echo $value['id']; ?>"><?php echo $value['nama']; ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="row g-3">
|
||||
<div class="col-8">
|
||||
<div class="form-group">
|
||||
<label>Paket</label>
|
||||
<select class="form-control" name="idp" required>
|
||||
<option value="">Pilih</option>
|
||||
<?php
|
||||
$List = new Listdata();
|
||||
$List->set_list("profile_paket", $SqlDataWHId . "AND jenis_profile = 'Hotspot' AND status = 1");
|
||||
foreach ($List->get_list() as $key => $value): ?>
|
||||
<option value="<?php echo $value['id']; ?>"><?php echo $value['nama']; ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="form-group">
|
||||
<label>Jumlah</label>
|
||||
<div class="input-group mb-3">
|
||||
<input type="number" class="form-control" min="1" max="50" value="1" name="jumlah" id="jumlah" required>
|
||||
<span class="input-group-text" id="basic-addon2">Pcs</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<input type="submit" name="generate" class="btn btn-primary" value="Generate">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if (isset($_POST['generate'])) {
|
||||
try {
|
||||
// Mulai transaksi DB
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// Ambil data paket
|
||||
$stmt = $pdo->prepare("SELECT radius_data,durasi,nama_profile,harga_paket FROM profile_paket WHERE id = :idp");
|
||||
$stmt->execute([':idp' => $_POST['idp']]);
|
||||
$paket = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
// ====== KIRIM KE API MIKROTIK ======
|
||||
$stmt = $pdo->prepare("SELECT ip_address,username,password,port_api,radius_nas_data FROM setting_mikrotik WHERE id = :id");
|
||||
$stmt->execute([':id' => $_POST['idm']]);
|
||||
$mikrotik = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$dataMik = json_decode($mikrotik['radius_nas_data']);
|
||||
|
||||
if (!$paket) {
|
||||
throw new Exception("Paket tidak ditemukan.");
|
||||
}
|
||||
|
||||
$data = json_decode($paket['radius_data']);
|
||||
$kode = $data ? 'VR' : 'VM'; // VR = Radius, VM = MikroTik
|
||||
$jenis = $data ? 'sv-radius' : 'sv-mikrotik';
|
||||
$karakter = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
|
||||
$str = $paket['durasi'];
|
||||
$jumlah = intval($_POST['jumlah']);
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
// Validasi jumlah
|
||||
if ($jumlah < 1 || $jumlah > 200) {
|
||||
throw new Exception("Jumlah voucher harus antara 1-200.");
|
||||
}
|
||||
|
||||
// Generate voucher unik
|
||||
$voucherList = [];
|
||||
while (count($voucherList) < $jumlah) {
|
||||
$kodevoucher = $str . substr(str_shuffle($karakter), 0, 7) . $kode;
|
||||
|
||||
// Pastikan tidak duplikat di DB & array
|
||||
$cek = $pdo->prepare("SELECT COUNT(*) FROM ganerate_voucher WHERE voucher = :voucher");
|
||||
$cek->execute([':voucher' => $kodevoucher]);
|
||||
if ($cek->fetchColumn() == 0 && !in_array($kodevoucher, $voucherList)) {
|
||||
$voucherList[] = $kodevoucher;
|
||||
}
|
||||
}
|
||||
|
||||
// Kirim ke Radius atau MikroTik
|
||||
$successVoucher = [];
|
||||
$failVoucher = [];
|
||||
|
||||
if ($data) {
|
||||
// ====== KIRIM KE RADIUS ======
|
||||
$radius = new CrudRadiusServer();
|
||||
$apiResponse = $radius->request('add_user', 'POST', [
|
||||
'jenis' => 'Hotspot',
|
||||
'username' => $voucherList,
|
||||
'password' => $voucherList,
|
||||
'groupname' => $data->groupname,
|
||||
'nasgroupname' => $dataMik->data->{'nasgroupname'}
|
||||
]);
|
||||
|
||||
foreach ($apiResponse['results'] as $res) {
|
||||
if ($res['status'] === 'success') {
|
||||
$successVoucher[] = $res['username'];
|
||||
} else {
|
||||
$failVoucher[] = $res['username'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($successVoucher)) {
|
||||
throw new Exception("Tidak ada voucher yang berhasil dibuat di Radius.");
|
||||
}
|
||||
} else {
|
||||
|
||||
require('router_api/routeros_api.class.php');
|
||||
$API = new RouterosAPI();
|
||||
$API->debug = false;
|
||||
|
||||
if (!$API->connect2($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password'], $mikrotik['port_api'])) {
|
||||
throw new Exception("Gagal konek ke API MikroTik.");
|
||||
}
|
||||
|
||||
foreach ($voucherList as $vcr) {
|
||||
$result = $API->comm('/ip/hotspot/user/add', [
|
||||
"name" => $vcr,
|
||||
"password" => $vcr,
|
||||
"profile" => $paket['nama_profile'], // pastikan field profile ada di DB
|
||||
"server" => "all"
|
||||
]);
|
||||
|
||||
if (isset($result['!trap'])) {
|
||||
$failVoucher[] = $vcr;
|
||||
} else {
|
||||
$successVoucher[] = $vcr;
|
||||
}
|
||||
}
|
||||
|
||||
$API->disconnect();
|
||||
|
||||
if (empty($successVoucher)) {
|
||||
throw new Exception("Tidak ada voucher yang berhasil dibuat di MikroTik.");
|
||||
}
|
||||
}
|
||||
|
||||
// Insert ke DB hanya yang sukses
|
||||
$values = [];
|
||||
$params = [];
|
||||
foreach ($successVoucher as $voucher) {
|
||||
$values[] = "(?, ?, ?, ?, ?, ?, ?)";
|
||||
$params[] = $_POST['ids']; // id_data_server
|
||||
$params[] = $_POST['idm']; // id_setting_mikrotik
|
||||
$params[] = $_POST['idp']; // id_profile_paket
|
||||
$params[] = $voucher; // voucher
|
||||
$params[] = $paket['harga_paket']; // harga
|
||||
$params[] = $jenis; // jenis
|
||||
$params[] = $date; // create_time
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO ganerate_voucher
|
||||
(id_data_server, id_setting_mikrotik, id_profile_paket, voucher, harga, jenis, create_time)
|
||||
VALUES " . implode(", ", $values);
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
// Commit transaksi
|
||||
$pdo->commit();
|
||||
|
||||
$totalSuccess = count($successVoucher);
|
||||
$totalError = count($failVoucher);
|
||||
|
||||
sweetAlert("$totalSuccess voucher berhasil dibuat. Gagal: $totalError", "success");
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
// sweetAlert("Gagal membuat voucher: " . $e->getMessage(), "error");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- /.card-header -->
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-7">
|
||||
<div class="row">
|
||||
<div class="col-md-3 mb-2">
|
||||
|
||||
@@ -68,67 +284,101 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-5">
|
||||
<?php
|
||||
// Ambil semua data Mikrotik langsung
|
||||
$List = new Listdata();
|
||||
$List->set_list("setting_mikrotik", $SqlDataWHId);
|
||||
?>
|
||||
<h6 class="mt-2 mb-2">Mikrotik</h6>
|
||||
<select class="form-control" name="idmscript" id="idmscript">
|
||||
<?php foreach ($List->get_list() as $value):
|
||||
$radius_data = json_decode($value['radius_nas_data']);
|
||||
$dataUrl = encrypt_url(json_encode([
|
||||
'board' => $value['board_id'],
|
||||
'nasgroupname' => $radius_data->data->{'nasgroupname'}
|
||||
]));
|
||||
?>
|
||||
<option value="<?= htmlspecialchars($dataUrl) ?>">
|
||||
<?= htmlspecialchars($value['nama']) ?>
|
||||
</option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
|
||||
<h6 class="mt-2 mb-2">Login Page Script</h6>
|
||||
<div class="mb-3">
|
||||
<div class="text-right" style="margin-bottom: -33px; margin-right: 2px;">
|
||||
<a onclick="copyToClipboard('script-page')" class="btn btn-sm btn-light btn-icon" title="Copy">
|
||||
<i class="fa fa-copy"></i>
|
||||
</a>
|
||||
</div>
|
||||
<pre class="bg-light border rounded p-3 mb-2" id="script-page">
|
||||
Loading script...
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Buat script HTML dengan escape karakter agar aman
|
||||
function generateScript(dataUrl) {
|
||||
return `<div id="voucher-container"></div>;
|
||||
<script src="http://localhost/manjapro-project/voucherpay/cl-style.js?i=${dataUrl}"></script>`;
|
||||
}
|
||||
|
||||
// Update script ketika pilihan berubah
|
||||
function updateScript() {
|
||||
const selectedValue = document.getElementById('idmscript').value;
|
||||
const preElement = document.getElementById('script-page');
|
||||
preElement.textContent = generateScript(selectedValue);
|
||||
}
|
||||
|
||||
// Event: saat select berubah
|
||||
document.getElementById('idmscript').addEventListener('change', updateScript);
|
||||
|
||||
// Saat halaman pertama kali load
|
||||
window.addEventListener('DOMContentLoaded', updateScript);
|
||||
|
||||
// Tombol copy
|
||||
function copyToClipboard(preId) {
|
||||
const text = document.getElementById(preId).textContent
|
||||
.replace(/</g, "<").replace(/>/g, ">");
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
// console.log("Script berhasil disalin!");
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-md-7">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-5">
|
||||
<div class="row">
|
||||
<div class="col-md-3 mb-2">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<center>
|
||||
<p>Akumulasi Voucher</p>
|
||||
<p>Voucher List</p>
|
||||
</center>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-6">
|
||||
<!-- small box -->
|
||||
<div class="small-box bg-info" id="pendingBox">
|
||||
<div class="inner">
|
||||
<h4 id="jumtotalValue">0</h4>
|
||||
<p>Total Voucher</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="ion ion-android-wifi"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-6">
|
||||
<!-- small box -->
|
||||
<div class="small-box bg-warning" id="pendingBox">
|
||||
<div class="inner">
|
||||
<h4 id="jumbelumValue">0</h4>
|
||||
<p>Belum Aktif</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="ion ion-wifi"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-6">
|
||||
<!-- small box -->
|
||||
<div class="small-box bg-success" id="pendingBox">
|
||||
<div class="inner">
|
||||
<h4 id="jumsedangValue">0</h4>
|
||||
<p>Sedang Aktif</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="ion ion-android-wifi"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-6">
|
||||
<!-- small box -->
|
||||
<div class="small-box bg-danger" id="pendingBox">
|
||||
<div class="inner">
|
||||
<h4 id="jumsudahValue">0</h4>
|
||||
<p>Sudah Kedaluarsa</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="ion ion-wifi"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<table id="voucherTable" class="table table-striped table-bordered" style="zoom: 90%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Waktu</th>
|
||||
<th>Voucher</th>
|
||||
<th>Harga</th>
|
||||
<th>Biaya</th>
|
||||
<th>Saldo</th>
|
||||
<th>Status</th>
|
||||
<th>Aktif</th>
|
||||
<th>Expired</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -227,3 +477,43 @@
|
||||
// Panggil fungsi setDefaultMonth saat halaman dimuat
|
||||
window.onload = fetchDataAgen();
|
||||
</script>
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#voucherTable').DataTable({
|
||||
"processing": true,
|
||||
"serverSide": true,
|
||||
"responsive": true,
|
||||
"autoWidth": false,
|
||||
"ajax": {
|
||||
"url": "controller/voucher_auto.php",
|
||||
"type": "GET"
|
||||
},
|
||||
"pageLength": 25,
|
||||
"columns": [
|
||||
{ "data": 0 }, // create_time
|
||||
{ "data": 1 }, // voucher
|
||||
{ "data": 2 }, // harga
|
||||
{ "data": 3, "orderable": false }, // biaya (tidak bisa diurutkan)
|
||||
{ "data": 4, "orderable": false }, // saldo (tidak bisa diurutkan)
|
||||
{ "data": 5 }, // status_cek
|
||||
{ "data": 6 }, // active_time
|
||||
{ "data": 7 } // expaired_time
|
||||
],
|
||||
"order": [[0, "desc"]]
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
document.getElementById('jumlah').addEventListener('input', function () {
|
||||
let value = parseInt(this.value);
|
||||
|
||||
if (value > 50) {
|
||||
this.value = 50; // set max
|
||||
} else if (value < 1) {
|
||||
this.value = 1; // set min
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
+286
-111
@@ -41,17 +41,28 @@
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Radius Server</label>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="radiuscek" value="1" id="checkbox1-0">
|
||||
<label class="form-check-label" for="checkbox1">
|
||||
Menggunakan Radius
|
||||
</label>
|
||||
</div>
|
||||
<i class="text-danger"><small>Saat ini radius hanya digunakan untuk Autentikasi saja, untuk limit masih di sisi mikrotik</small></i>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Jenis Profile</label>
|
||||
<select class="form-control" name="jenis" data-select="jenis-select1" required>
|
||||
<option value="">Pilih</option>
|
||||
<option value="PPPOE">PPPOE</option>
|
||||
<option value="Hotspot">Hotspot</option>
|
||||
<option value="DHCP" id="group-dhcp">DHCP IP Address</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-group" id="group-jenis0">
|
||||
<label>Nama Profile Di Mikrotik</label>
|
||||
<input type="text" class="form-control" name="profile" required>
|
||||
<input type="text" class="form-control" name="profile">
|
||||
<i class="text-danger"><small>Nama Profile Harus sama dengan yang ada di Mikrotik</small></i>
|
||||
</div>
|
||||
<div class="form-group" id="group-jenis1">
|
||||
@@ -85,6 +96,26 @@
|
||||
<input type="text" class="form-control" name="durasi" placeholder="6H" id="durasi">
|
||||
<i class="text-danger">Contoh : 3H => 3 Jam , 1D => 1 Hari </i>
|
||||
</div>
|
||||
<div class="form-group" id="group-use">
|
||||
<label>Limit Pengguna / Device</label>
|
||||
<input type="text" class="form-control" name="use_limit">
|
||||
</div>
|
||||
<div class="form-group" id="group-pool">
|
||||
<label>IP Pool</label>
|
||||
<input type="text" class="form-control" name="ip_pool">
|
||||
</div>
|
||||
<div class="form-group" id="group-rate">
|
||||
<label>Rate Limit</label>
|
||||
<input type="text" class="form-control" name="rate_limit" placeholder="( Opsional )">
|
||||
</div>
|
||||
<div class="form-group" id="group-session">
|
||||
<label>Session Timeout</label>
|
||||
<input type="text" class="form-control" name="session_time" placeholder="( Opsional )">
|
||||
</div>
|
||||
<div class="form-group" id="group-idle">
|
||||
<label>Idle Timeout</label>
|
||||
<input type="text" class="form-control" name="idle_time" placeholder="( Opsional )">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -94,118 +125,213 @@
|
||||
<input type="submit" name="tambah" class="btn btn-primary" value="Tambah">
|
||||
</div>
|
||||
</form>
|
||||
<?php
|
||||
<?php
|
||||
if (isset($_POST['tambah'])) {
|
||||
try {
|
||||
// Ambil dan sanitasi data dari form
|
||||
$status = ($_POST['jenishs'] == 1) ? 1 : NULL;
|
||||
$nominal = preg_replace("/[^0-9]/", "", $_POST['harga']);
|
||||
$cekfee = preg_replace("/[^0-9]/", "", $_POST['fee']);
|
||||
$fee = (!empty($cekfee)) ? $cekfee : NULL;
|
||||
// === VALIDASI INPUT USER ===
|
||||
$requiredFields = ['ids', 'jenis', 'nama', 'harga'];
|
||||
foreach ($requiredFields as $field) {
|
||||
if (empty($_POST[$field])) {
|
||||
sweetAlert("Field " . $field. " tidak boleh kosong!", "error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Ambil server dari database
|
||||
// === SANITASI DAN INISIALISASI ===
|
||||
$status = ($_POST['jenishs'] == 1) ? 1 : NULL;
|
||||
$nominal = preg_replace("/[^0-9]/", "", $_POST['harga']);
|
||||
$cekfee = preg_replace("/[^0-9]/", "", $_POST['fee']);
|
||||
$fee = (!empty($cekfee)) ? $cekfee : NULL;
|
||||
|
||||
$groupname = preg_replace(
|
||||
'/\s+/',
|
||||
'-',
|
||||
strtolower(trim(preg_replace('/[^a-z0-9 ]/i', '', $_POST['jenis'] . ' ' .$_POST['nama'])))
|
||||
) . '-' . $SvId;
|
||||
|
||||
$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'] ?? '';
|
||||
|
||||
// === TRANSAKSI DATABASE UNTUK ROLLBACK JIKA GAGAL ===
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// Ambil semua server
|
||||
$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
|
||||
$rollbackServers = [];
|
||||
$messages = []; // pesan error
|
||||
|
||||
// === RADIUS PROCESS ===
|
||||
if (!empty($_POST['radiuscek']) && $_POST['radiuscek'] == 1) {
|
||||
$radius = new CrudRadiusServer();
|
||||
|
||||
$radiusPayload = [
|
||||
'jenis' => $_POST['jenis'],
|
||||
'groupname' => $groupname,
|
||||
'profile' => $profile,
|
||||
'use_limit' => $use_limit,
|
||||
'rate_limit' => $rate_limit,
|
||||
'session_time' => $session_time,
|
||||
'ip_pool' => $ip_pool,
|
||||
'idle_time' => $idle_time
|
||||
];
|
||||
|
||||
$radius->request('add_paket', 'POST', $radiusPayload);
|
||||
$radius_data = json_encode($radiusPayload);
|
||||
} else {
|
||||
$radius_data = '';
|
||||
}
|
||||
|
||||
// === LOOPING SERVER MIKROTIK ===
|
||||
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'];
|
||||
if ($API->connect2(
|
||||
$server['ip_address'],
|
||||
$server['username'],
|
||||
$server['password'],
|
||||
$server['port_api']
|
||||
)) {
|
||||
$profileName = $_POST['profile'] ?? '';
|
||||
$ipPool = $_POST['ip_pool'] ?? '';
|
||||
$profileFound = false;
|
||||
$poolFound = false;
|
||||
|
||||
// === CEK PROFILE ===
|
||||
if ($_POST['jenis'] == 'PPPOE') {
|
||||
// Cek profil PPPOE
|
||||
$profiles = $API->comm('/ppp/profile/print');
|
||||
$found = false;
|
||||
} elseif ($_POST['jenis'] == 'Hotspot') {
|
||||
$profiles = $API->comm('/ip/hotspot/user/profile/print');
|
||||
}
|
||||
|
||||
foreach ($profiles as $profile) {
|
||||
if ($profile['name'] === $profileName) {
|
||||
$found = true;
|
||||
if (!empty($profiles)) {
|
||||
foreach ($profiles as $p) {
|
||||
if ($p['name'] === $profileName) {
|
||||
$profileFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
$messages[] = "Profil PPPOE <b>$profileName</b> di <b>$mikrotikName</b> tidak ada.";
|
||||
}
|
||||
} else {
|
||||
// Cek profil Hotspot
|
||||
$profiles = $API->comm('/ip/hotspot/user/profile/print');
|
||||
$found = false;
|
||||
$profileId = null;
|
||||
$profileFound = true;
|
||||
}
|
||||
|
||||
foreach ($profiles as $profile) {
|
||||
if ($profile['name'] === $profileName) {
|
||||
$profileId = $profile['.id'];
|
||||
$found = true;
|
||||
break;
|
||||
// === CEK IP POOL (HANYA UNTUK DHCP & HOTSPOT) ===
|
||||
if (!empty($ipPool) && ($_POST['jenis'] == 'DHCP')) {
|
||||
$poolcek = $API->comm('/ip/pool/print');
|
||||
if (!empty($poolcek)) {
|
||||
foreach ($poolcek as $pool) {
|
||||
if ($pool['name'] === $ipPool) {
|
||||
$poolFound = 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 <b>$profileName</b> di <b>$mikrotikName</b> tidak aktif atau status tidak sesuai.";
|
||||
// }
|
||||
} else {
|
||||
$messages[] = "Profil Hotspot <b>$profileName</b> di <b>$mikrotikName</b> tidak ditemukan.";
|
||||
}
|
||||
} else {
|
||||
// Jika tidak perlu IP Pool, dianggap ditemukan
|
||||
$poolFound = true;
|
||||
}
|
||||
|
||||
// === VALIDASI PROFILE & IP POOL ===
|
||||
if (!$profileFound) {
|
||||
$messages[] = "Profil <b>$profileName</b> di <b>$mikrotikName</b> tidak ditemukan.";
|
||||
break; // gagal -> keluar loop
|
||||
}
|
||||
|
||||
if (!$poolFound) {
|
||||
$messages[] = "IP Pool <b>$ipPool</b> di <b>$mikrotikName</b> tidak ditemukan.";
|
||||
break; // gagal -> keluar loop
|
||||
}
|
||||
|
||||
// === JIKA HOTSPOT & STATUS AKTIF -> SET ON-LOGIN SCRIPT ===
|
||||
if ($_POST['jenis'] == 'Hotspot' && $status == 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,
|
||||
]);
|
||||
}
|
||||
|
||||
// Catat server yang berhasil untuk rollback jika ada error nanti
|
||||
$rollbackServers[] = $server;
|
||||
} else {
|
||||
$messages[] = "Gagal terhubung ke MikroTik <b>$mikrotikName</b>.";
|
||||
break; // gagal -> langsung keluar loop
|
||||
}
|
||||
}
|
||||
|
||||
// Cek pesan sebelum menyimpan ke database
|
||||
if (empty($messages)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO profile_paket
|
||||
(id_data_server, jenis_profile, nama_profile, durasi, nama, harga_paket, vi_agen, status)
|
||||
VALUES (:id_data_server, :jenis_profile, :nama_profile, :durasi, :nama, :harga_paket, :vi_agen, :status)");
|
||||
$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->execute();
|
||||
sweetAlert("Profile Paket Telah ditambahkan", "success");
|
||||
} else {
|
||||
// Menampilkan pesan error jika ada
|
||||
|
||||
// === CEK ERROR DAN ROLLBACK JIKA PERLU ===
|
||||
if (!empty($messages)) {
|
||||
// Rollback ke DB
|
||||
$pdo->rollBack();
|
||||
|
||||
// Rollback radius jika ada
|
||||
if (!empty($_POST['radiuscek']) && $_POST['radiuscek'] == 1) {
|
||||
$radius->request('delete_paket', 'DELETE', [
|
||||
'groupname' => $groupname
|
||||
]);
|
||||
}
|
||||
|
||||
// Rollback ke server yang sudah diproses
|
||||
foreach ($rollbackServers as $srv) {
|
||||
$API = new RouterosAPI();
|
||||
if ($API->connect2($srv['ip_address'], $srv['username'], $srv['password'], $srv['port_api'])) {
|
||||
if ($_POST['jenis'] == 'PPPOE') {
|
||||
$API->comm('/ppp/profile/remove', [
|
||||
'numbers' => $profileName
|
||||
]);
|
||||
} else {
|
||||
$API->comm('/ip/hotspot/user/profile/remove', [
|
||||
'numbers' => $profileName
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$message = implode("<br>", $messages);
|
||||
detailAlert($message, strpos($message, 'tidak ada') !== false || strpos($message, 'Gagal') !== false);
|
||||
detailAlert("Rollback! $message", true);
|
||||
return;
|
||||
}
|
||||
|
||||
// === SIMPAN KE DATABASE ===
|
||||
$stmt = $pdo->prepare("INSERT INTO profile_paket
|
||||
(id_data_server, jenis_profile, nama_profile, durasi, nama, harga_paket, vi_agen, status, radius_data)
|
||||
VALUES (:id_data_server, :jenis_profile, :nama_profile, :durasi, :nama, :harga_paket, :vi_agen, :status, :radius_data)");
|
||||
$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(':radius_data', $radius_data);
|
||||
$stmt->execute();
|
||||
|
||||
$pdo->commit(); // commit transaksi
|
||||
sweetAlert("Profile Paket Telah ditambahkan", "success");
|
||||
|
||||
} catch (PDOException $e) {
|
||||
// Menangani kesalahan dalam koneksi database atau query
|
||||
sweetAlert("Terjadi kesalahan: " . $e->getMessage(), "error");
|
||||
$pdo->rollBack();
|
||||
sweetAlert("Terjadi kesalahan DB: " . $e->getMessage(), "error");
|
||||
} catch (Exception $e) {
|
||||
// Menangani kesalahan umum
|
||||
$pdo->rollBack();
|
||||
sweetAlert("Terjadi kesalahan: " . $e->getMessage(), "error");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -229,7 +355,8 @@ if (isset($_POST['tambah'])) {
|
||||
<?php
|
||||
$apaket = mysqli_query($con,"SELECT * FROM profile_paket $SqlDataWHId ORDER BY nama ASC");
|
||||
while ($paket = mysqli_fetch_assoc($apaket))
|
||||
{
|
||||
{
|
||||
$data_radius = json_decode($paket['radius_data']);
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
@@ -258,7 +385,13 @@ if (isset($_POST['tambah'])) {
|
||||
</tr>
|
||||
<?php
|
||||
if (isset($_POST['hapus'.$paket['id']]))
|
||||
{
|
||||
{
|
||||
|
||||
$groupname = $data_radius->{'groupname'};
|
||||
$radius = new CrudRadiusServer();
|
||||
$radius->request('delete_paket', 'DELETE', [
|
||||
'groupname' => $groupname
|
||||
]);
|
||||
$iddata = $paket['id'];
|
||||
deleteAlert("profile_paket", $iddata);
|
||||
}
|
||||
@@ -280,8 +413,9 @@ if (isset($_POST['tambah'])) {
|
||||
<!-- /.content -->
|
||||
|
||||
<script>
|
||||
// Ambil semua elemen dropdown dalam modal
|
||||
// Ambil semua elemen dropdown & checkbox dalam modal
|
||||
const jenisSelects = document.querySelectorAll('[data-select]');
|
||||
const radiusCheckbox = document.querySelector('input[name="radiuscek"]');
|
||||
|
||||
// Sembunyikan semua grup pada awalnya
|
||||
document.querySelectorAll('[id^="group-"]').forEach(group => {
|
||||
@@ -292,60 +426,97 @@ document.querySelectorAll('[id^="group-"]').forEach(group => {
|
||||
function updateGroupVisibility() {
|
||||
const jenisSelect = document.querySelector('select[name="jenis"]');
|
||||
const jenishsSelect = document.querySelector('select[name="jenishs"]');
|
||||
const group0 = document.getElementById('group-jenis0');
|
||||
const group1 = document.getElementById('group-jenis1');
|
||||
const group2 = document.getElementById('group-jenis2');
|
||||
const group3 = document.getElementById('group-jenis3');
|
||||
const select2 = document.getElementById('jenis-select2');
|
||||
const groupdhcp = document.getElementById('group-dhcp');
|
||||
const radiusUse = document.getElementById('group-use');
|
||||
const radiusRate = document.getElementById('group-rate');
|
||||
const radiusSession = document.getElementById('group-session');
|
||||
const radiusIdle = document.getElementById('group-idle');
|
||||
const groupPool = document.getElementById('group-pool');
|
||||
const fee = document.getElementById('fee');
|
||||
const durasi = document.getElementById('durasi');
|
||||
|
||||
// Reset nilai input grup
|
||||
function resetGroup(group) {
|
||||
const input = group.querySelector('select, input');
|
||||
if (input) {
|
||||
input.value = '';
|
||||
// Helper untuk reset grup
|
||||
function resetGroup(group, resetValue = true) {
|
||||
if (resetValue) {
|
||||
const inputs = group.querySelectorAll('select, input');
|
||||
inputs.forEach(input => {
|
||||
if (input.type === 'checkbox' || input.type === 'radio') {
|
||||
input.checked = false;
|
||||
} else {
|
||||
input.value = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
group.style.display = 'none';
|
||||
}
|
||||
|
||||
// Tampilkan grup berdasarkan pilihan di dropdown
|
||||
// Reset semua grup dulu untuk menghindari tumpang tindih
|
||||
const allGroups = [
|
||||
group0, group1, group2, group3,
|
||||
groupdhcp, groupPool,
|
||||
radiusUse, radiusRate, radiusSession, radiusIdle
|
||||
];
|
||||
allGroups.forEach(g => resetGroup(g, false));
|
||||
|
||||
// Logic untuk dropdown jenis
|
||||
if (jenisSelect.value === "Hotspot") {
|
||||
group0.style.display = 'block';
|
||||
group1.style.display = 'block';
|
||||
group1.querySelector('select').required = true;
|
||||
} else {
|
||||
resetGroup(group1);
|
||||
} else if (jenisSelect.value === "PPPOE") {
|
||||
group0.style.display = 'block';
|
||||
} else if (jenisSelect.value === "DHCP") {
|
||||
groupPool.style.display = 'block';
|
||||
}
|
||||
|
||||
if (jenishsSelect) {
|
||||
// Logic untuk jenishs select
|
||||
if (jenisSelect.value === "Hotspot" && jenishsSelect.value === "1") {
|
||||
group2.style.display = 'block';
|
||||
group3.style.display = 'block';
|
||||
fee.required = true;
|
||||
durasi.required = true;
|
||||
} else {
|
||||
fee.required = false;
|
||||
durasi.required = false;
|
||||
if (jenishsSelect.value === "1") {
|
||||
group2.style.display = 'block';
|
||||
group3.style.display = 'block';
|
||||
jenishsSelect.required = true;
|
||||
fee.required = true;
|
||||
durasi.required = true;
|
||||
} else {
|
||||
resetGroup(group2);
|
||||
resetGroup(group3);
|
||||
jenishsSelect.required = false;
|
||||
fee.required = false;
|
||||
durasi.required = false;
|
||||
jenishsSelect.selectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Logic untuk checkbox radius
|
||||
if (radiusCheckbox.checked) {
|
||||
groupdhcp.style.display = 'block';
|
||||
|
||||
if (jenisSelect.value === "PPPOE") {
|
||||
radiusUse.style.display = 'block';
|
||||
radiusRate.style.display = 'block';
|
||||
} else if (jenisSelect.value === "Hotspot") {
|
||||
radiusUse.style.display = 'block';
|
||||
radiusSession.style.display = 'block';
|
||||
radiusRate.style.display = 'block';
|
||||
radiusIdle.style.display = 'block';
|
||||
} else if (jenisSelect.value === "DHCP") {
|
||||
radiusRate.style.display = 'block';
|
||||
groupPool.style.display = 'block';
|
||||
}
|
||||
} else {
|
||||
// Hanya reset grup radius & dhcp
|
||||
[radiusUse, radiusRate, radiusSession, radiusIdle, groupdhcp, groupPool].forEach(g => resetGroup(g));
|
||||
|
||||
// Jika jenisSelect saat ini DHCP, reset ke kosong supaya tidak memicu tampil lagi
|
||||
if (jenisSelect.value === "DHCP") {
|
||||
jenisSelect.selectedIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Cek apakah select sudah ada isinya dan update tampilan
|
||||
// Inisialisasi tampilan saat halaman diload
|
||||
function initializeGroupVisibility() {
|
||||
const jenisSelect = document.querySelector('select[name="jenis"]');
|
||||
const jenishsSelect = document.querySelector('select[name="jenishs"]');
|
||||
|
||||
if (jenisSelect.value) {
|
||||
updateGroupVisibility();
|
||||
}
|
||||
|
||||
if (jenishsSelect && jenishsSelect.value) {
|
||||
updateGroupVisibility();
|
||||
}
|
||||
updateGroupVisibility();
|
||||
}
|
||||
|
||||
// Tambahkan event listener untuk setiap dropdown
|
||||
@@ -353,6 +524,10 @@ jenisSelects.forEach(select => {
|
||||
select.addEventListener('change', updateGroupVisibility);
|
||||
});
|
||||
|
||||
// Inisialisasi tampilan grup pada load
|
||||
// Tambahkan event listener untuk checkbox radius
|
||||
radiusCheckbox.addEventListener('change', updateGroupVisibility);
|
||||
|
||||
// Jalankan inisialisasi
|
||||
initializeGroupVisibility();
|
||||
</script>
|
||||
|
||||
|
||||
+277
-140
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
$apaket = mysqli_query($con,"SELECT * FROM profile_paket WHERE id = '$page[1]'");
|
||||
$paket = mysqli_fetch_assoc($apaket);
|
||||
|
||||
$data = json_decode($paket['radius_data']);
|
||||
?>
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
@@ -26,7 +28,7 @@ $paket = mysqli_fetch_assoc($apaket);
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label>Nama Server</label>
|
||||
<select class="form-control" name="ids">
|
||||
<select class="form-control" name="ids" disabled>
|
||||
<?php
|
||||
$List = new Listdata();
|
||||
$List->set_list("data_server",$SqlDataWH);
|
||||
@@ -35,28 +37,43 @@ $paket = mysqli_fetch_assoc($apaket);
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Radius Server</label>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="radiuscek" value="1" id="checkbox1-0" <?= (empty($paket['radius_data'])) ? "" : "checked"; ?> disabled>
|
||||
<label class="form-check-label" for="checkbox1">
|
||||
Menggunakan Radius
|
||||
</label>
|
||||
</div>
|
||||
<i class="text-danger"><small>Saat ini radius hanya digunakan untuk Autentikasi saja, untuk limit masih di sisi mikrotik</small></i>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Jenis Profile</label>
|
||||
<select class="form-control" name="jenis" data-select="jenis-select1" required>
|
||||
<select class="form-control" name="jenis" data-select="jenis-select1" disabled>
|
||||
<option value="">Pilih</option>
|
||||
<option value="PPPOE" <?php if($paket['jenis_profile'] == 'PPPOE') { echo "selected";} ?>>PPPOE</option>
|
||||
<option value="Hotspot" <?php if($paket['jenis_profile'] == 'Hotspot') { echo "selected";} ?>>Hotspot</option>
|
||||
<option value="DHCP" id="group-dhcp" <?php if($paket['jenis_profile'] == 'DHCP') { echo "selected";} ?>>DHCP IP Address</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-group" id="group-jenis0">
|
||||
<label>Nama Profile Di Mikrotik</label>
|
||||
<input type="text" class="form-control" value="<?php echo $paket['nama_profile']; ?>" name="profile" required>
|
||||
<input type="text" class="form-control" value="<?php echo $paket['nama_profile']; ?>" name="profile">
|
||||
</div>
|
||||
<i class="text-danger"><small>Nama Profile Harus sama dengan yang ada di Mikrotik</small></i>
|
||||
<div class="form-group" id="group-jenis1">
|
||||
<label>Jenis Hotspot</label>
|
||||
<select class="form-control" name="jenishs" id="jenis-select2" data-select="jenis-select2">
|
||||
<select class="form-control" id="jenis-select2" name="jenishs" data-select="jenis-select2" disabled>
|
||||
<option value="">Pilih</option>
|
||||
<option value="1" <?php if($paket['status'] == '1') { echo "selected";} ?>>Sekali Pakai</option>
|
||||
<option value="0" <?php if($paket['status'] == NULL) { echo "selected";} ?>>Berulangkali</option>
|
||||
</select>
|
||||
<i class="text-danger"><small>Pilih <b>Berulangkali</b> jika user hotspot di tagihan setiap bulan</small></i>
|
||||
</div>
|
||||
<input type="hidden" name="ids" value="<?= $paket['id_data_server']; ?>">
|
||||
<input type="hidden" name="radiuscek" value="<?= (empty($paket['radius_data'])) ? "" : 1 ; ?>">
|
||||
<input type="hidden" name="jenis" value="<?= $paket['jenis_profile']; ?>">
|
||||
<input type="hidden" name="jenishs" value="<?= $paket['status']; ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
@@ -79,6 +96,26 @@ $paket = mysqli_fetch_assoc($apaket);
|
||||
<input type="text" class="form-control" name="durasi" value="<?php echo $paket['durasi']; ?>" placeholder="6H" id="durasi">
|
||||
<i class="text-danger">Contoh : 3H => 3 Jam , 1D => 1 Hari </i>
|
||||
</div>
|
||||
<div class="form-group" id="group-use">
|
||||
<label>Limit Pengguna / Device</label>
|
||||
<input type="text" class="form-control" name="use_limit" value="<?= $data->use_limit ?>">
|
||||
</div>
|
||||
<div class="form-group" id="group-pool">
|
||||
<label>IP Pool</label>
|
||||
<input type="text" class="form-control" name="ip_pool" value="<?= $data->ip_pool ?>">
|
||||
</div>
|
||||
<div class="form-group" id="group-rate">
|
||||
<label>Rate Limit</label>
|
||||
<input type="text" class="form-control" name="rate_limit" placeholder="( Opsional )" value="<?= $data->rate_limit ?>">
|
||||
</div>
|
||||
<div class="form-group" id="group-session">
|
||||
<label>Session Timeout</label>
|
||||
<input type="text" class="form-control" name="session_time" placeholder="( Opsional )" value="<?= $data->session_time ?>">
|
||||
</div>
|
||||
<div class="form-group" id="group-idle">
|
||||
<label>Idle Timeout</label>
|
||||
<input type="text" class="form-control" name="idle_time" placeholder="( Opsional )" value="<?= $data->idle_time ?>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -96,110 +133,161 @@ $paket = mysqli_fetch_assoc($apaket);
|
||||
<?php
|
||||
if (isset($_POST['edit'])) {
|
||||
try {
|
||||
// Ambil dan sanitasi data dari form
|
||||
$status = ($_POST['jenishs'] == 1) ? 1 : NULL;
|
||||
$nominal = preg_replace("/[^0-9]/", "", $_POST['harga']);
|
||||
$cekfee = preg_replace("/[^0-9]/", "", $_POST['fee']);
|
||||
$fee = (!empty($cekfee)) ? $cekfee : NULL;
|
||||
// === Validasi perubahan data ===
|
||||
$changes = [];
|
||||
$messages = [];
|
||||
$rollbackServers = [];
|
||||
|
||||
// Ambil server dari database
|
||||
$newNama = $_POST['nama'];
|
||||
$newProfile = $_POST['profile'];
|
||||
$newDurasi = $_POST['durasi'];
|
||||
$newHarga = preg_replace("/[^0-9]/", "", $_POST['harga']);
|
||||
$newFee = preg_replace("/[^0-9]/", "", $_POST['fee']);
|
||||
$newStatus = $_POST['status'] ?? NULL;
|
||||
|
||||
if ($newNama !== $paket['nama']) $changes['nama'] = $newNama;
|
||||
if ($newProfile !== $paket['nama_profile']) $changes['nama_profile'] = $newProfile;
|
||||
if ($newDurasi !== $paket['durasi']) $changes['durasi'] = $newDurasi;
|
||||
if ($newHarga != $paket['harga_paket']) $changes['harga_paket'] = $newHarga;
|
||||
if ($newFee != $paket['vi_agen']) $changes['vi_agen'] = $newFee;
|
||||
if ($newStatus != $paket['status']) $changes['status'] = $newStatus;
|
||||
|
||||
// === Radius Data ===
|
||||
$groupname = preg_replace('/\s+/', '-', strtolower(trim(preg_replace('/[^a-z0-9 ]/i', '', $_POST['jenis'] . ' ' . $newNama)))) . '-' . $SvId;
|
||||
$groupnameold = $data->{'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 <b>$profileName</b> di <b>$mikrotikName</b> 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 <b>$profileName</b> di <b>$mikrotikName</b> 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 <b>$profileName</b> di <b>$mikrotikName</b> 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 <b>$newProfile</b> di <b>$mikrotikName</b> 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 <b>{$_POST['ip_pool']}</b> di <b>$mikrotikName</b> tidak ditemukan.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$rollbackServers[] = $server; // Catat untuk rollback jika error
|
||||
} else {
|
||||
$messages[] = "Gagal terhubung ke MikroTik <b>$mikrotikName</b>.";
|
||||
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("<br>", $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'])) {
|
||||
|
||||
|
||||
<script>
|
||||
const jenisSelects = document.querySelectorAll('[data-select]');
|
||||
// Ambil semua elemen dropdown & checkbox dalam halaman
|
||||
const jenisSelects = document.querySelectorAll('[data-select]');
|
||||
const radiusCheckbox = document.querySelector('input[name="radiuscek"]');
|
||||
|
||||
// Sembunyikan semua grup pada awalnya
|
||||
document.querySelectorAll('[id^="group-"]').forEach(group => {
|
||||
// Sembunyikan semua grup pada awalnya
|
||||
document.querySelectorAll('[id^="group-"]').forEach(group => {
|
||||
group.style.display = 'none';
|
||||
});
|
||||
|
||||
// Fungsi untuk mengupdate tampilan grup
|
||||
function updateGroupVisibility() {
|
||||
const jenisSelect = document.querySelector('select[name="jenis"]');
|
||||
const jenishsSelect = document.querySelector('select[name="jenishs"]');
|
||||
const group0 = document.getElementById('group-jenis0');
|
||||
const group1 = document.getElementById('group-jenis1');
|
||||
const group2 = document.getElementById('group-jenis2');
|
||||
const group3 = document.getElementById('group-jenis3');
|
||||
const groupdhcp = document.getElementById('group-dhcp');
|
||||
const radiusUse = document.getElementById('group-use');
|
||||
const radiusRate = document.getElementById('group-rate');
|
||||
const radiusSession = document.getElementById('group-session');
|
||||
const radiusIdle = document.getElementById('group-idle');
|
||||
const groupPool = document.getElementById('group-pool');
|
||||
const fee = document.getElementById('fee');
|
||||
const durasi = document.getElementById('durasi');
|
||||
|
||||
// Helper untuk reset grup
|
||||
function resetGroup(group, resetValue = true) {
|
||||
if (resetValue) {
|
||||
const inputs = group.querySelectorAll('select, input');
|
||||
inputs.forEach(input => {
|
||||
if (input.type === 'checkbox' || input.type === 'radio') {
|
||||
input.checked = false;
|
||||
} else {
|
||||
input.value = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
group.style.display = 'none';
|
||||
});
|
||||
|
||||
// Fungsi untuk mengupdate tampilan grup
|
||||
function updateGroupVisibility() {
|
||||
const jenisSelect = document.querySelector('select[name="jenis"]');
|
||||
const jenishsSelect = document.querySelector('select[name="jenishs"]');
|
||||
const group1 = document.getElementById('group-jenis1');
|
||||
const group2 = document.getElementById('group-jenis2');
|
||||
const group3 = document.getElementById('group-jenis3');
|
||||
const select2 = document.getElementById('jenis-select2');
|
||||
const fee = document.getElementById('fee');
|
||||
const durasi = document.getElementById('durasi');
|
||||
|
||||
// Reset nilai input grup
|
||||
function resetGroup(group) {
|
||||
const input = group.querySelector('select, input');
|
||||
if (input) {
|
||||
input.value = '';
|
||||
}
|
||||
group.style.display = 'none';
|
||||
}
|
||||
|
||||
// Tampilkan grup berdasarkan pilihan di dropdown
|
||||
if (jenisSelect.value === "Hotspot") {
|
||||
group1.style.display = 'block';
|
||||
group1.querySelector('select').required = true;
|
||||
} else {
|
||||
resetGroup(group1);
|
||||
}
|
||||
|
||||
if (jenishsSelect) {
|
||||
if (jenishsSelect.value === "1") {
|
||||
group2.style.display = 'block';
|
||||
group3.style.display = 'block';
|
||||
jenishsSelect.required = true;
|
||||
fee.required = true;
|
||||
durasi.required = true;
|
||||
} else {
|
||||
resetGroup(group2);
|
||||
resetGroup(group3);
|
||||
jenishsSelect.required = false;
|
||||
fee.required = false;
|
||||
durasi.required = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tambahkan event listener untuk setiap dropdown
|
||||
jenisSelects.forEach(select => {
|
||||
select.addEventListener('change', updateGroupVisibility);
|
||||
});
|
||||
// Reset semua grup dulu
|
||||
const allGroups = [
|
||||
group0, group1, group2, group3,
|
||||
groupdhcp, groupPool,
|
||||
radiusUse, radiusRate, radiusSession, radiusIdle
|
||||
];
|
||||
allGroups.forEach(g => resetGroup(g, false));
|
||||
|
||||
// Memanggil fungsi untuk memperbarui tampilan berdasarkan nilai yang sudah ada
|
||||
jenisSelects.forEach(select => {
|
||||
if (select.value) {
|
||||
updateGroupVisibility({ target: select });
|
||||
// Tampilkan grup sesuai dropdown jenis
|
||||
if (jenisSelect.value === "Hotspot") {
|
||||
group0.style.display = 'block';
|
||||
group1.style.display = 'block';
|
||||
group1.querySelector('select').required = true;
|
||||
} else if (jenisSelect.value === "PPPOE") {
|
||||
group0.style.display = 'block';
|
||||
} else if (jenisSelect.value === "DHCP") {
|
||||
groupPool.style.display = 'block';
|
||||
}
|
||||
|
||||
// Tampilkan grup sesuai jenishs select
|
||||
if (jenisSelect.value === "Hotspot" && jenishsSelect.value === "1") {
|
||||
group2.style.display = 'block';
|
||||
group3.style.display = 'block';
|
||||
if (fee) fee.required = true;
|
||||
if (durasi) durasi.required = true;
|
||||
} else {
|
||||
if (fee) fee.required = false;
|
||||
if (durasi) durasi.required = false;
|
||||
}
|
||||
|
||||
// Tampilkan grup sesuai checkbox radius
|
||||
if (radiusCheckbox && radiusCheckbox.checked) {
|
||||
groupdhcp.style.display = 'block';
|
||||
|
||||
if (jenisSelect.value === "PPPOE") {
|
||||
radiusUse.style.display = 'block';
|
||||
radiusRate.style.display = 'block';
|
||||
} else if (jenisSelect.value === "Hotspot") {
|
||||
radiusUse.style.display = 'block';
|
||||
radiusSession.style.display = 'block';
|
||||
radiusRate.style.display = 'block';
|
||||
radiusIdle.style.display = 'block';
|
||||
} else if (jenisSelect.value === "DHCP") {
|
||||
radiusRate.style.display = 'block';
|
||||
groupPool.style.display = 'block';
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Hanya reset grup radius & dhcp
|
||||
[radiusUse, radiusRate, radiusSession, radiusIdle, groupdhcp, groupPool].forEach(g => resetGroup(g));
|
||||
|
||||
// Jika jenisSelect saat ini DHCP, reset ke kosong supaya tidak memicu tampil lagi
|
||||
if (jenisSelect.value === "DHCP") {
|
||||
jenisSelect.selectedIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Jalankan inisialisasi saat halaman sudah siap
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
updateGroupVisibility(); // Jalankan sekali saat halaman pertama kali dibuka
|
||||
});
|
||||
|
||||
// Tambahkan event listener untuk setiap dropdown
|
||||
jenisSelects.forEach(select => {
|
||||
select.addEventListener('change', updateGroupVisibility);
|
||||
});
|
||||
|
||||
// Tambahkan event listener untuk checkbox radius
|
||||
if (radiusCheckbox) {
|
||||
radiusCheckbox.addEventListener('change', updateGroupVisibility);
|
||||
}
|
||||
</script>
|
||||
|
||||
+439
-20
@@ -6,7 +6,7 @@
|
||||
<div class="card-header">
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<h3 class="card-title">Setting Mikrotik</h3>
|
||||
<h3 class="card-title">Setting Mikrotik <?=$SvId;?></h3>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<ol class="float-sm-right mb-0">
|
||||
@@ -35,26 +35,43 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>IP Address</label>
|
||||
<input type="text" class="form-control" name="ipa" required="required">
|
||||
<input type="text" class="form-control" name="ipa" value="172.0.0.1" required="required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Port API Mikrotik</label>
|
||||
<input type="text" class="form-control" name="pam" required="required">
|
||||
<input type="text" class="form-control" name="pam" value="0" required="required">
|
||||
<i class="text-danger">Isi Jika memiliki IP Public</i>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Port Remote Modem</label>
|
||||
<input type="text" class="form-control" name="prm" required="required">
|
||||
<input type="text" class="form-control" name="prm" value="0" required="required">
|
||||
<i class="text-danger">Isi Jika memiliki IP Public</i>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Tambahan</label>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="tunnel" value="1" id="checkbox1-0">
|
||||
<label class="form-check-label" for="checkbox1">
|
||||
Buatkan saya tunnel Port API Mikrotik dan Port Remote Modem
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="radius" value="1" id="checkbox2-0">
|
||||
<label class="form-check-label" for="checkbox2">
|
||||
Menggunakan radius server
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="card-body pb-0">
|
||||
<div class="form-group">
|
||||
<label>Username</label>
|
||||
<label>Username Mikrotik</label>
|
||||
<input type="text" class="form-control" name="usm" required="required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Password</label>
|
||||
<label>Password Mikrotik</label>
|
||||
<input type="text" class="form-control" name="psw" required="required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -156,8 +216,10 @@
|
||||
<form class="form-inline" method="post" enctype="multipart/form-data">
|
||||
<div class="row">
|
||||
<input type="submit" name="test<?php echo $server['id']; ?>" class="btn btn-primary btn-sm" value="Test">
|
||||
<a type="button" class="btn btn-secondary btn-sm ml-1" data-toggle="modal" data-target="#modal-edit<?php echo $server['id'];?>">Edit
|
||||
</a>
|
||||
<a type="button" class="btn btn-secondary btn-sm ml-1" data-toggle="modal" data-target="#modal-edit<?php echo $server['id'];?>">Edit</a>
|
||||
<?php if(!empty($server['radius_nas_data'])) { ?>
|
||||
<a type="button" class="btn btn-success btn-sm ml-1" data-toggle="modal" data-target="#modal-detail<?php echo $server['id'];?>">Nas Detail</a>
|
||||
<?php } ?>
|
||||
<input type="submit" name="hapus<?php echo $server['id'];?>" value="Hapus" class="btn btn-danger btn-sm ml-1" />
|
||||
</div>
|
||||
</form>
|
||||
@@ -278,6 +340,21 @@
|
||||
<label>Port Remote Modem</label>
|
||||
<input type="text" class="form-control" value="<?php echo $server['port_remote']; ?>" name="prm" required="required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Tambahan</label>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="tunnel" value="1" id="checkbox1-<?= $server['id']; ?>" <?= (!empty($server['radius_nas_data'])) ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="checkbox1">
|
||||
Buatkan saya tunnel Port API Mikrotik dan Port Remote Modem
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="radius" value="1" id="checkbox2-<?= $server['id']; ?>" <?= ($server['status_radius'] == 1) ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="checkbox2">
|
||||
Menggunakan radius server
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
@@ -319,6 +396,117 @@
|
||||
<?php
|
||||
if (isset($_POST['edit' . $server['id']])) {
|
||||
try {
|
||||
|
||||
// Jika data tunnel radius kosong tapi mau bikin tunnel & radius
|
||||
if (empty($server['radius_nas_data']) && $_POST['tunnel'] == 1) {
|
||||
|
||||
$tunnel = new CreateTunnel();
|
||||
$resultTun = $tunnel->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 );
|
||||
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END Modal Edit -->
|
||||
<!-- Modal DETAIL -->
|
||||
<?php $apiScript = json_decode($server['radius_nas_data'], true)?>
|
||||
<div class="modal fade" id="modal-detail<?php echo $server['id'];?>" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-success">
|
||||
<h5 class="modal-title" id="staticBackdropLabel">Detail Mikrotik</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
<h6 class="mb-2 ml-4"><i class="fa fa-network-wired mr-2"></i> OVPN / L2TP / SSTP / Radius Server</h6>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="card-body pb-0 pt-0">
|
||||
|
||||
|
||||
<div class="mb-3">
|
||||
<ul class="list-group list-group-flush">
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>Connect To</span>
|
||||
<span class="text-muted">tunnel.manjapro.net</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>User</span>
|
||||
<span class="text-primary fw-bold"><?= $apiScript['data']['name']; ?></span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>Password</span>
|
||||
<span class="text-danger fw-bold"><?= $apiScript['data']['password']; ?></span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>Port API Mikrotik</span>
|
||||
<span class="text-danger fw-bold"><?= $apiScript['data']['port-api']; ?></span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>Port Remote ONU</span>
|
||||
<span class="text-danger fw-bold"><?= $apiScript['data']['port-remote']; ?></span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>Port SSTP</span>
|
||||
<span class="text-muted">4433</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>Port OVPN</span>
|
||||
<span class="text-muted">1199</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>Protocol OVPN</span>
|
||||
<span class="text-muted">udp</span>
|
||||
</li>
|
||||
<?php if($server['status_radius'] == 1) { ?>
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>Address Radius</span>
|
||||
<span class="text-primary fw-bold">172.16.254.242</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>Protocol Radius</span>
|
||||
<span class="text-muted">udp</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between p-2">
|
||||
<span>Secret Radius</span>
|
||||
<span class="text-danger fw-bold"><?= $apiScript['data']['nas_secret']; ?></span>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<?php if($server['status_radius'] == 1) { ?>
|
||||
<h6 class="mt-2 mb-2">Script Radius Server</h6>
|
||||
<div class="mb-3">
|
||||
<div class="text-right" style="margin-bottom: -33px; margin-right: 2px;">
|
||||
<a onclick="copyToClipboard('script4-<?= $server['id']; ?>')" class="btn btn-sm btn-light btn-icon" title="Copy">
|
||||
<i class="fa fa-copy"></i>
|
||||
</a>
|
||||
</div>
|
||||
<pre class="bg-light border rounded p-3 mb-2" id="script4-<?= $server['id']; ?>">
|
||||
/radius
|
||||
add service=dhcp,hotspot,ppp address=172.16.254.242 protocol=udp secret=<?= $apiScript['data']['nas_secret']; ?> authentication-port=1812 accounting-port=1813 comment="Radius ManjaPro"
|
||||
/radius incoming
|
||||
set accept=yes port=3799
|
||||
/ip route
|
||||
add dst-address=172.16.254.242 gateway=172.18.1.100 check-gateway=ping distance=1 comment="Route to Radius Server"
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="card-body pb-0 pt-0">
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<h6 class="mb-2">Script OVPN</h6>
|
||||
<div class="mb-3">
|
||||
<div class="text-right" style="margin-bottom: -33px; margin-right: 2px;">
|
||||
<a onclick="copyToClipboard('script1-<?= $server['id']; ?>')" class="btn btn-sm btn-light btn-icon" title="Copy">
|
||||
<i class="fa fa-copy"></i>
|
||||
</a>
|
||||
</div>
|
||||
<pre class="bg-light border rounded p-3 mb-2" id="script1-<?= $server['id']; ?>">
|
||||
/interface ovpn-client
|
||||
add name=opvn-manjapro connect-to=tunnel.manjapro.net port=1199 mode=ip protocol=udp user=<?= $apiScript['data']['name']; ?> password=<?= $apiScript['data']['password']; ?> profile=default-encryption add-default-route=no route-nopull-yes disabled=no
|
||||
/ip firewall nat
|
||||
add chain=dstnat dst-address=<?= $apiScript['data']['remote-address']; ?> protocol=tcp dst-port=<?= $apiScript['data']['port-remote']; ?> action=dst-nat to-addresses=172.0.0.1 to-port=80 comment="Remote"
|
||||
/ip service
|
||||
set api port=<?= $apiScript['data']['port-api']; ?>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
||||
<?php if($server['status_radius'] == 0) { ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="card-body pb-0 pt-0">
|
||||
<?php } ?>
|
||||
|
||||
<h6 class="mt-2 mb-2">Script L2TP</h6>
|
||||
<div class="mb-3">
|
||||
<div class="text-right" style="margin-bottom: -33px; margin-right: 2px;">
|
||||
<a onclick="copyToClipboard('script2-<?= $server['id']; ?>')" class="btn btn-sm btn-light btn-icon" title="Copy">
|
||||
<i class="fa fa-copy"></i>
|
||||
</a>
|
||||
</div>
|
||||
<pre class="bg-light border rounded p-3 mb-2" id="script2-<?= $server['id']; ?>">
|
||||
/interface l2tp-client
|
||||
add name=l2tp-manjapro connect-to=tunnel.manjapro.net user=<?= $apiScript['data']['name']; ?> password=<?= $apiScript['data']['password']; ?> profile=default-encryption add-default-route=no disabled=no
|
||||
/ip firewall nat
|
||||
add chain=dstnat dst-address=<?= $apiScript['data']['remote-address']; ?> protocol=tcp dst-port=<?= $apiScript['data']['port-remote']; ?> action=dst-nat to-addresses=172.0.0.1 to-port=80 comment="Remote"
|
||||
/ip service
|
||||
set api port=<?= $apiScript['data']['port-api']; ?>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<h6 class="mt-2 mb-2">Script SSTP</h6>
|
||||
<div class="mb-3">
|
||||
<div class="text-right" style="margin-bottom: -33px; margin-right: 2px;">
|
||||
<a onclick="copyToClipboard('script3-<?= $server['id']; ?>')" class="btn btn-sm btn-light btn-icon" title="Copy">
|
||||
<i class="fa fa-copy"></i>
|
||||
</a>
|
||||
</div>
|
||||
<pre class="bg-light border rounded p-3 mb-2" id="script3-<?= $server['id']; ?>">
|
||||
/interface sstp-client
|
||||
add name=sstp-manjapro connect-to=tunnel.manjapro.net port=4433 proxy-port=4433 user=<?= $apiScript['data']['name']; ?> password=<?= $apiScript['data']['password']; ?> profile=default-encryption add-default-route=no disabled=no
|
||||
/ip firewall nat
|
||||
add chain=dstnat dst-address=<?= $apiScript['data']['remote-address']; ?> protocol=tcp dst-port=<?= $apiScript['data']['port-remote']; ?> action=dst-nat to-addresses=172.0.0.1 to-port=80 comment="Remote"
|
||||
/ip service
|
||||
set api port=<?= $apiScript['data']['port-api']; ?>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END Modal DETAIL -->
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -400,4 +771,52 @@ $('#syncBtn').on('click', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// Pilih semua checkbox dengan prefix "checkbox1-" dan "checkbox2-"
|
||||
document.querySelectorAll('[id^="checkbox1-"]').forEach(checkbox1 => {
|
||||
const serverId = checkbox1.id.split('-')[1]; // ambil ID unik dari checkbox1-xxx
|
||||
const checkbox2 = document.getElementById('checkbox2-' + serverId);
|
||||
|
||||
checkbox1.addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
checkbox2.checked = false; // kalau ceklis 1, hilangkan ceklis 2
|
||||
} else {
|
||||
checkbox2.checked = false;
|
||||
}
|
||||
});
|
||||
|
||||
checkbox2.addEventListener('change', function () {
|
||||
if (this.checked) {
|
||||
checkbox1.checked = true; // kalau ceklis 2, aktifkan ceklis 1
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// const checkbox1 = document.getElementById('checkbox1');
|
||||
// const checkbox2 = document.getElementById('checkbox2');
|
||||
|
||||
// checkbox1.addEventListener('change', function () {
|
||||
// if (checkbox1.checked) {
|
||||
// checkbox2.checked = false; // kalau ceklis 1, hilangkan ceklis 2
|
||||
// } else {
|
||||
// checkbox2.checked = false;
|
||||
// }
|
||||
// });
|
||||
|
||||
// checkbox2.addEventListener('change', function () {
|
||||
// if (checkbox2.checked) {
|
||||
// checkbox1.checked = true; // kalau ceklis 2, aktifkan ceklis 1
|
||||
// }
|
||||
// });
|
||||
</script>
|
||||
|
||||
<script>
|
||||
function copyToClipboard(id) {
|
||||
const text = document.getElementById(id).innerText;
|
||||
navigator.clipboard.writeText(text);
|
||||
}
|
||||
</script>
|
||||
|
||||
+68
-49
@@ -22,63 +22,82 @@
|
||||
<div class="card-body">
|
||||
<table id="example1" class="table table-bordered table-striped">
|
||||
<thead class="bg-warning">
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>Time</th>
|
||||
<th>Nama Server</th>
|
||||
<th>Jenis</th>
|
||||
<th>Keterangan</th>
|
||||
<th>Lokasi</th>
|
||||
<th>Koordinat</th>
|
||||
<th>URL Tracking</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>Time</th>
|
||||
<th>Nama Server</th>
|
||||
<th>Jenis</th>
|
||||
<th>Keterangan</th>
|
||||
<th>Lokasi</th>
|
||||
<th>Koordinat</th>
|
||||
<th>URL Tracking</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
<?php
|
||||
$no = 1;
|
||||
$aserver = mysqli_query($con,"SELECT * FROM v_tiket_gangguan WHERE status = '1' $SqlDataId");
|
||||
while ($server = mysqli_fetch_assoc($aserver)) {
|
||||
$stmt = $pdo->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 = '<a href="?'.encrypt_url('user_detail|'.$server['id_pelanggan']).'"><b>'.$server['nama_pelanggan'].'</b></a><br>'.$server['permasalahan'];
|
||||
} else {
|
||||
$ket = $server['permasalahan'];
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td style="max-width: 30px;"><?php echo $no; ?></td>
|
||||
<td style="max-width: 75px;"><?php echo $server['start_time']; ?></td>
|
||||
<td><?php echo $server['nama_server']; ?></td>
|
||||
<td><?php echo $server['jenis_tiket']; ?></td>
|
||||
<td style="max-width: 150px;"><?php echo $ket; ?></td>
|
||||
<td style="max-width: 150px;"><?php echo $server['lokasi']; ?></td>
|
||||
<td style="max-width: 150px;"><a href="https://www.google.com/maps/search/?api=1&query=<?php echo $server['latitude'].', '.$server['longitude']; ?>" target="_blank"><?php echo $server['latitude'].', '.$server['longitude']; ?></a></td>
|
||||
<td style="max-width: 150px;"><a href="<?= 'https://manjapro.net/tracking/' . $server['tiket_id']; ?>" target="_blank"><?= 'https://manjapro.net/tracking/' . $server['tiket_id']; ?></a></td>
|
||||
<td>
|
||||
<form method="post">
|
||||
<?php if(in_array("Ubah", $json_array[36]['sub_menu'])) { ?>
|
||||
<input type="submit" name="proses<?php echo $server['id'];?>" value="Proses Tiket" class="btn btn-primary btn-sm ml-1" />
|
||||
<?php } if(in_array("Hapus", $json_array[36]['sub_menu'])) { ?>
|
||||
<input type="submit" name="hapus<?php echo $server['id'];?>" value="Hapus" class="btn btn-danger btn-sm ml-1" />
|
||||
<?php } ?>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
if (isset($_POST['proses'.$server['id']])) {
|
||||
$waktu = date('Y-m-d H:i:s');
|
||||
$stmt = $pdo->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
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td class="align-middle" style="border-left: 8px solid <?php echo $borderColor; ?>;">
|
||||
<?php echo $no; ?>
|
||||
</td>
|
||||
<td style="max-width: 75px;"><?php echo $server['start_time']; ?></td>
|
||||
<td><?php echo $server['nama_server']; ?></td>
|
||||
<td><?php echo $server['jenis_tiket']; ?></td>
|
||||
<td style="max-width: 150px;"><?php echo $ket; ?></td>
|
||||
<td style="max-width: 150px;"><?php echo $server['lokasi']; ?></td>
|
||||
<td style="max-width: 150px;">
|
||||
<a href="https://www.google.com/maps/search/?api=1&query=<?php echo $server['latitude'].','.$server['longitude']; ?>" target="_blank">
|
||||
<?php echo $server['latitude'].', '.$server['longitude']; ?>
|
||||
</a>
|
||||
</td>
|
||||
<td style="max-width: 150px;">
|
||||
<a href="<?= 'https://manjapro.net/tracking/' . $server['tiket_id']; ?>" target="_blank">
|
||||
<?= 'https://manjapro.net/tracking/' . $server['tiket_id']; ?>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<form method="post">
|
||||
<?php if (in_array("Ubah", $json_array[36]['sub_menu'])) { ?>
|
||||
<input type="submit" name="proses<?php echo $server['id'];?>" value="Proses Tiket" class="btn btn-primary btn-sm mb-1" />
|
||||
<?php } if (in_array("Hapus", $json_array[36]['sub_menu'])) { ?>
|
||||
<input type="submit" name="hapus<?php echo $server['id'];?>" value="Hapus" class="btn btn-danger btn-sm" />
|
||||
<?php } ?>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
if (isset($_POST['proses'.$server['id']])) {
|
||||
$waktu = date('Y-m-d H:i:s');
|
||||
$stmt2 = $pdo->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++; } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -33,7 +33,7 @@ while ($tiap = $ambil->fetch_assoc()) {
|
||||
<div class="card-body">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label>Pilih Server</label>
|
||||
<select class="form-control" required="required" name="ids">
|
||||
@@ -46,7 +46,7 @@ while ($tiap = $ambil->fetch_assoc()) {
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label>Jenis Gangguan</label>
|
||||
<select id="jenis" class="form-control" name="jenis">
|
||||
@@ -57,6 +57,17 @@ while ($tiap = $ambil->fetch_assoc()) {
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<label>Level Gangguan</label>
|
||||
<select class="form-control" name="level" required>
|
||||
<option value="">Pilih Level</option>
|
||||
<option value="1">Tinggi</option>
|
||||
<option value="2">Sedang</option>
|
||||
<option value="3">Bawah</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="form-content"></div>
|
||||
</div>
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user