204 lines
7.2 KiB
PHP
204 lines
7.2 KiB
PHP
<?php
|
|
// ubah string jadi array
|
|
$idArray = array_map('trim', explode(',', $SvId));
|
|
|
|
// buat placeholders (?, ?, ?)
|
|
$placeholders = implode(',', array_fill(0, count($idArray), '?'));
|
|
|
|
$sql = "SELECT uuid FROM data_server WHERE id IN ($placeholders)";
|
|
$stm = $pdo->prepare($sql);
|
|
$stm->execute($idArray);
|
|
|
|
$uuids = $stm->fetchAll(PDO::FETCH_COLUMN); // ambil langsung kolom uuid
|
|
$tenant_id = implode(',', $uuids); // gabungkan jadi string dipisah koma
|
|
|
|
// --- Panggil API pakai tenant_id ---
|
|
$oltData = [];
|
|
if ($tenant_id) {
|
|
$apiUrl = "http://manjapro.net:20263/api/v1/olt/?tenant_id=" . $tenant_id;
|
|
$ch = curl_init();
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_URL => $apiUrl,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_HTTPHEADER => ["accept: application/json"]
|
|
]);
|
|
$response = curl_exec($ch);
|
|
if (curl_errno($ch)) {
|
|
$apiError = curl_error($ch);
|
|
}
|
|
curl_close($ch);
|
|
$oltData = json_decode($response, true);
|
|
}
|
|
|
|
$oltVendor = [];
|
|
|
|
$apiUrl = "http://manjapro.net:20263/api/v1/olt-vendor/";
|
|
$ch = curl_init();
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_URL => $apiUrl,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_HTTPHEADER => ["accept: application/json"]
|
|
]);
|
|
$resvendor = curl_exec($ch);
|
|
if (curl_errno($ch)) {
|
|
$apiError = curl_error($ch);
|
|
}
|
|
curl_close($ch);
|
|
$oltVendor = json_decode($resvendor, true);
|
|
|
|
foreach ($oltVendor as $vendor) {
|
|
$vendorMap[$vendor['id']] = $vendor['nama_vendor'] . " (" . $vendor['model'] . ")" ;
|
|
}
|
|
// print_r($oltVendor);
|
|
|
|
?>
|
|
|
|
<section class="content">
|
|
<div class="container-fluid mt-4">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<div class="row">
|
|
<div class="col-sm-6">
|
|
<h3 class="card-title">List OLT</h3>
|
|
</div>
|
|
<div class="col-sm-6">
|
|
<ol class="float-sm-right mb-0">
|
|
<button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#modalTambah">Tambah</button>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
<!--<h3 class="card-title">List OLT</h3>-->
|
|
<!--<button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#modalTambah">Tambah</button>-->
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (!empty($apiError)): ?>
|
|
<div class="alert alert-danger">Gagal ambil data API: <?= htmlspecialchars($apiError) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<table id="example2" class="table table-bordered table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>No</th>
|
|
<th>Nama Perangkat</th>
|
|
<th>IP</th>
|
|
<th>Lokasi</th>
|
|
<th>Vendor</th>
|
|
<th>Port SNMP</th>
|
|
<th>Port Telnet</th>
|
|
<th>Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!empty($oltData) && is_array($oltData)): ?>
|
|
<?php $no=1; foreach($oltData as $olt): ?>
|
|
<tr>
|
|
<td><?= $no++; ?></td>
|
|
<td><?= htmlspecialchars($olt['name'] ?? '-') ?></td>
|
|
<td><?= htmlspecialchars($olt['ip'] ?? '-') ?></td>
|
|
<td><?= htmlspecialchars($olt['location'] ?? '-') ?></td>
|
|
<td><?= htmlspecialchars($vendorMap[$olt['vendor_id']] ?? '-') ?></td>
|
|
<td><?= htmlspecialchars($olt['snmp_port'] ?? '-') ?></td>
|
|
<td><?= htmlspecialchars($olt['telnet_port'] ?? '-') ?></td>
|
|
<td>
|
|
<?php if (($olt['status'] ?? '') === 'online'): ?>
|
|
<span class="badge badge-success">Online</span>
|
|
<?php elseif (($olt['status'] ?? '') === 'offline'): ?>
|
|
<span class="badge badge-danger">Offline</span>
|
|
<?php else: ?>
|
|
<span class="badge badge-secondary"><?= htmlspecialchars($olt['status'] ?? '-') ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<a href="#" class="btn btn-warning btn-sm">Edit</a>
|
|
<a href="#" class="btn btn-danger btn-sm">Hapus</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<tr><td colspan="6" class="text-center">Data tidak tersedia</td></tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Modal Tambah -->
|
|
<div class="modal fade" id="modalTambah" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<form method="post">
|
|
<div class="modal-content">
|
|
<div class="modal-header bg-primary">
|
|
<h5 class="modal-title">Tambah OLT</h5>
|
|
<button type="button" class="close" data-dismiss="modal">×</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<input type="hidden" name="tenant_id" value="<?= htmlspecialchars($tenant_id) ?>">
|
|
<div class="form-group">
|
|
<label>Nama</label>
|
|
<input type="text" name="name" class="form-control" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>IP</label>
|
|
<input type="text" name="ip" class="form-control" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Lokasi</label>
|
|
<input type="text" name="location" class="form-control">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Nama Vendor</label>
|
|
<select class="form-control">
|
|
<option value="">--PILIH--</option>
|
|
<?php foreach ($oltVendor as $row): ?>
|
|
<option value="<?= $row['id'] ?>">
|
|
<?= $row['nama_vendor'] ?> (<?= $row['model'] ?>)
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="submit" name="tambah" class="btn btn-primary">Simpan</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
// === Handle Tambah Data (POST ke API) ===
|
|
if (isset($_POST['tambah'])) {
|
|
$postData = [
|
|
"tenant_id" => $_POST['tenant_id'],
|
|
"name" => trim($_POST['name']),
|
|
"ip" => trim($_POST['ip']),
|
|
"snmp_community" => "public",
|
|
"telnet_user" => "root",
|
|
"telnet_pass" => "admin",
|
|
"vendor_id" => (int)$_POST['vendor_id'],
|
|
"location" => trim($_POST['location']),
|
|
"snmp_port" => 161,
|
|
"telnet_port" => 23
|
|
];
|
|
$ch = curl_init("http://manjapro.net:20263/api/v1/olt/");
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_POST => true,
|
|
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
|
|
CURLOPT_POSTFIELDS => json_encode($postData)
|
|
]);
|
|
$res = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
// setelah simpan redirect supaya tidak POST ulang
|
|
header("Location: ".$_SERVER['PHP_SELF']."?id=".urlencode($SvId));
|
|
exit;
|
|
}
|
|
?>
|