Auto commit: 2025-10-08T06:10:35.241Z

This commit is contained in:
Flatlogic Bot 2025-10-08 06:10:35 +00:00
parent b1030df0f7
commit cf8c53640a
11 changed files with 785 additions and 20 deletions

View File

@ -8,8 +8,13 @@ require_once 'partials/header.php';
<div class="container-fluid">
<div class="d-flex justify-content-between align-items-center">
<h1 class="h3 mb-0 text-gray-800"><?php echo $page_title; ?></h1>
<button class="btn btn-primary"><i data-feather="plus" class="mr-2"></i>Create Account</button>
<h1 class="h3 mb-0 text-gray-800"><?php echo htmlspecialchars($page_title); ?></h1>
<div>
<a href="index.php" class="btn btn-secondary mr-2">
<i data-feather="arrow-left" class="mr-1"></i> Kembali
</a>
<button class="btn btn-primary"><i data-feather="plus" class="mr-2"></i>Create Account</button>
</div>
</div>
<hr>
<p>PPPoE/Hotspot account management page content goes here.</p>

View File

@ -7,7 +7,13 @@ require_once 'partials/header.php';
?>
<div class="container-fluid">
<h1 class="h3 mb-4 text-gray-800"><?php echo $page_title; ?></h1>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0 text-gray-800"><?php echo htmlspecialchars($page_title); ?></h1>
<a href="index.php" class="btn btn-secondary">
<i data-feather="arrow-left" class="mr-2"></i>Kembali ke Dashboard
</a>
</div>
<p>Billing page content goes here.</p>
</div>

View File

@ -5,6 +5,47 @@ define('DB_NAME', 'app_30953');
define('DB_USER', 'app_30953');
define('DB_PASS', 'e45f2778-db1f-450c-99c6-29efb4601472');
// --- Encryption Settings ---
// WARNING: Changing this key will make all existing encrypted data unreadable.
// For production, use a key from a secure source like an environment variable.
define('ENCRYPTION_KEY', 'def0000068fcf8f7483bde1c8a45b53289f734814842116f7238e4375290654f27a845b20d3435324d83a335e86c45000a7649364e4358612743677d6a336e3c');
define('ENCRYPTION_CIPHER', 'aes-256-cbc');
/**
* Encrypts a string.
*
* @param string $plaintext The string to encrypt.
* @return string The encrypted string (base64 encoded).
*/
function encrypt($plaintext) {
$ivlen = openssl_cipher_iv_length(ENCRYPTION_CIPHER);
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext_raw = openssl_encrypt($plaintext, ENCRYPTION_CIPHER, ENCRYPTION_KEY, OPENSSL_RAW_DATA, $iv);
$hmac = hash_hmac('sha256', $ciphertext_raw, ENCRYPTION_KEY, true);
return base64_encode($iv . $hmac . $ciphertext_raw);
}
/**
* Decrypts a string.
*
* @param string $ciphertext_base64 The base64 encoded ciphertext.
* @return string|false The decrypted string, or false on failure.
*/
function decrypt($ciphertext_base64) {
$c = base64_decode($ciphertext_base64);
$ivlen = openssl_cipher_iv_length(ENCRYPTION_CIPHER);
$iv = substr($c, 0, $ivlen);
$hmac = substr($c, $ivlen, 32);
$ciphertext_raw = substr($c, $ivlen + 32);
$original_plaintext = openssl_decrypt($ciphertext_raw, ENCRYPTION_CIPHER, ENCRYPTION_KEY, OPENSSL_RAW_DATA, $iv);
$calcmac = hash_hmac('sha256', $ciphertext_raw, ENCRYPTION_KEY, true);
if (hash_equals($hmac, $calcmac)) {
return $original_plaintext;
}
return false;
}
function db() {
static $pdo;
if (!$pdo) {
@ -14,4 +55,4 @@ function db() {
]);
}
return $pdo;
}
}

47
db/migrate.php Normal file
View File

@ -0,0 +1,47 @@
<?php
require_once __DIR__ . '/config.php';
try {
// Connect to MySQL server without specifying a database
$pdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
// Create the database if it doesn't exist
$pdo->exec("CREATE DATABASE IF NOT EXISTS " . DB_NAME . ";");
$pdo->exec("USE " . DB_NAME . ";");
echo "Database '" . DB_NAME . "' created or already exists.\n";
// Packages table
$pdo->exec("CREATE TABLE IF NOT EXISTS packages (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
price INT NOT NULL,
duration_days INT NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=INNODB;");
echo "Migration successful: 'packages' table created or already exists.\n";
// Routers table
$pdo->exec("CREATE TABLE IF NOT EXISTS routers (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
ip_address VARCHAR(45) NOT NULL,
username VARCHAR(255) NOT NULL,
password TEXT NOT NULL, -- Encrypted
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY ip_address (ip_address)
) ENGINE=INNODB;");
echo "Migration successful: 'routers' table created or already exists.\n";
} catch (PDOException $e) {
die("Migration failed: " . $e->getMessage());
}

View File

@ -0,0 +1,214 @@
<?php
/**
* RouterOS API client implementation.
*
* @author Denis Basta
* @copyright 2008-2013 Denis Basta
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version 1.6
*/
class RouterosAPI
{
public $debug = false; // Show debug information
public $connected = false; // Connection status
public $port = 8728; // RouterOS API port
public $timeout = 3; // Connection timeout
public $attempts = 5; // Connection attempts
public $delay = 3; // Delay between connection attempts
private $socket; // Socket resource
private $error_no; // Error number
private $error_str; // Error string
/**
* Connect to RouterOS
*
* @param string $ip Hostname (IP or domain) of the RouterOS server
* @param string $login The RouterOS username
* @param string $password The RouterOS password
*
* @return boolean Connection status
*/
public function connect($ip, $login, $password)
{
for ($ATTEMPT = 1; $ATTEMPT <= $this->attempts; $ATTEMPT++) {
$this->connected = false;
$this->debug('Connection attempt #' . $ATTEMPT . ' to ' . $ip . ':' . $this->port . '...');
$this->socket = @fsockopen($ip, $this->port, $this->error_no, $this->error_str, $this->timeout);
if ($this->socket) {
socket_set_timeout($this->socket, $this->timeout);
$this->write('/login');
$RESPONSE = $this->read(false);
if (isset($RESPONSE[0]) && $RESPONSE[0] == '!done') {
if (preg_match_all('/[^=]+/i', $RESPONSE[1], $MATCHES)) {
if ($MATCHES[0][0] == 'ret' && strlen($MATCHES[0][1]) == 32) {
$this->write('/login', false);
$this->write('=name=' . $login, false);
$this->write('=response=00' . md5(chr(0) . $password . pack('H*', $MATCHES[0][1])));
$RESPONSE = $this->read(false);
if (isset($RESPONSE[0]) && $RESPONSE[0] == '!done') {
$this->connected = true;
break;
}
}
}
}
fclose($this->socket);
}
sleep($this->delay);
}
if ($this->connected) {
$this->debug('Connected successfully to ' . $ip . ':' . $this->port);
} else {
$this->debug('Error connecting to ' . $ip . ':' . $this->port);
}
return $this->connected;
}
/**
* Disconnect from RouterOS
*/
public function disconnect()
{
fclose($this->socket);
$this->connected = false;
$this->debug('Disconnected');
}
/**
* Parse response from RouterOS
*
* @param array $response Response data
*
* @return array Parsed data
*/
public function parseResponse($response)
{
if (is_array($response)) {
$PARSED = array();
$CURRENT = null;
$singlevalue = null;
foreach ($response as $x) {
if (in_array($x, array('!fatal', '!re', '!trap'))) {
if ($x == '!re') {
$CURRENT =& $PARSED[];
} else {
$CURRENT =& $PARSED[$x][];
}
} elseif ($x != '!done') {
if (preg_match_all('/[^=]+/i', $x, $MATCHES)) {
if ($MATCHES[0][0] == 'ret') {
$singlevalue = $MATCHES[0][1];
}
$CURRENT[$MATCHES[0][0]] = (isset($MATCHES[0][1]) ? $MATCHES[0][1] : '');
}
}
}
if (empty($PARSED) && !is_null($singlevalue)) {
$PARSED = $singlevalue;
}
return $PARSED;
} else {
return array();
}
}
/**
* Read data from RouterOS
*
* @param boolean $parse Parse the data?
*
* @return array Data array
*/
public function read($parse = true)
{
$RESPONSE = array();
$line = '';
while (true) {
$BYTE = fread($this->socket, 1);
$line .= $BYTE;
if ($BYTE == "\0") {
$RESPONSE[] = $line;
if (substr($line, -5) == "!done\0") {
break;
}
$line = '';
}
}
if ($parse) {
return $this->parseResponse($RESPONSE);
} else {
return $RESPONSE;
}
}
/**
* Write (send) data to RouterOS
*
* @param string $command A string with the command to send
* @param boolean $param2 If we are sending a command, or a parameter
*
* @return void
*/
public function write($command, $param2 = true)
{
if ($command) {
$data = explode("\n", $command);
foreach ($data as $com) {
$com = trim($com);
fwrite($this->socket, $this->encodeLength(strlen($com)) . $com);
$this->debug('<<< ' . $com);
}
if (gettype($param2) == 'integer') {
fwrite($this->socket, $this->encodeLength(strlen('.tag=' . $param2)) . '.tag=' . $param2 . "\0");
$this->debug('<<< .tag=' . $param2);
} elseif (gettype($param2) == 'boolean') {
fwrite($this->socket, ($param2 ? '' : "\0"));
}
}
}
/**
* Encode length of the string
*
* @param integer $length Length of the string
*
* @return string Encoded length
*/
private function encodeLength($length)
{
if ($length < 0x80) {
return chr($length);
}
if ($length < 0x4000) {
return chr(($length >> 8) | 0x80) . chr($length & 0xFF);
}
if ($length < 0x200000) {
return chr(($length >> 16) | 0xC0) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
}
if ($length < 0x10000000) {
return chr(($length >> 24) | 0xE0) . chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
}
return chr(0xF0) . chr(($length >> 24) & 0xFF) . chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF);
}
/**
* Print debug information
*
* @param string $text Debug text
*
* @return void
*/
private function debug($text)
{
if ($this->debug) {
echo $text . "\n";
}
}
}

View File

@ -7,7 +7,13 @@ require_once 'partials/header.php';
?>
<div class="container-fluid">
<h1 class="h3 mb-4 text-gray-800"><?php echo $page_title; ?></h1>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0 text-gray-800"><?php echo htmlspecialchars($page_title); ?></h1>
<a href="index.php" class="btn btn-secondary">
<i data-feather="arrow-left" class="mr-2"></i>Kembali ke Dashboard
</a>
</div>
<p>Monitoring page content goes here.</p>
</div>

View File

@ -1,5 +1,6 @@
<?php
require_once 'auth.php';
require_once 'db/config.php';
// Restrict access to Administrators
if ($_SESSION['user']['role'] !== 'Administrator') {
@ -7,19 +8,167 @@ if ($_SESSION['user']['role'] !== 'Administrator') {
exit;
}
$page_title = 'Paket Layanan';
$pdo = db();
$feedback = [];
$edit_package = null;
// Handle Edit Request
if (isset($_GET['edit_id'])) {
$stmt = $pdo->prepare("SELECT * FROM packages WHERE id = ?");
$stmt->execute([$_GET['edit_id']]);
$edit_package = $stmt->fetch();
}
// Handle Delete Request
if (isset($_POST['delete_id'])) {
try {
$stmt = $pdo->prepare("DELETE FROM packages WHERE id = ?");
$stmt->execute([$_POST['delete_id']]);
$feedback = ['type' => 'success', 'message' => 'Paket berhasil dihapus.'];
} catch (PDOException $e) {
$feedback = ['type' => 'danger', 'message' => 'Gagal menghapus paket: ' . $e->getMessage()];
}
}
// Handle Add/Update Request
if (isset($_POST['save_package'])) {
$name = $_POST['name'];
$price = $_POST['price'];
$duration_days = $_POST['duration_days'];
$description = $_POST['description'];
$id = $_POST['id'];
// Basic validation
if (empty($name) || !is_numeric($price) || !is_numeric($duration_days)) {
$feedback = ['type' => 'danger', 'message' => 'Nama, Harga, dan Durasi harus diisi dengan benar.'];
} else {
try {
if (empty($id)) { // Add new
$stmt = $pdo->prepare("INSERT INTO packages (name, price, duration_days, description) VALUES (?, ?, ?, ?)");
$stmt->execute([$name, $price, $duration_days, $description]);
$feedback = ['type' => 'success', 'message' => 'Paket baru berhasil ditambahkan.'];
} else { // Update existing
$stmt = $pdo->prepare("UPDATE packages SET name = ?, price = ?, duration_days = ?, description = ? WHERE id = ?");
$stmt->execute([$name, $price, $duration_days, $description, $id]);
$feedback = ['type' => 'success', 'message' => 'Paket berhasil diperbarui.'];
// Redirect to clear edit state
header("Location: packages.php");
exit;
}
} catch (PDOException $e) {
$feedback = ['type' => 'danger', 'message' => 'Operasi gagal: ' . $e->getMessage()];
}
}
}
// Fetch all packages for display
$packages = $pdo->query("SELECT * FROM packages ORDER BY name ASC")->fetchAll();
$page_title = 'Paket Layanan';
require_once 'partials/header.php';
?>
<div class="container-fluid">
<div class="d-flex justify-content-between align-items-center">
<h1 class="h3 mb-0 text-gray-800"><?php echo $page_title; ?></h1>
<button class="btn btn-primary"><i data-feather="plus" class="mr-2"></i>Add Package</button>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0 text-gray-800"><?php echo htmlspecialchars($page_title); ?></h1>
<a href="index.php" class="btn btn-secondary">
<i data-feather="arrow-left" class="mr-2"></i>Kembali ke Dashboard
</a>
</div>
<?php if (!empty($feedback)): ?>
<div class="alert alert-<?php echo htmlspecialchars($feedback['type']); ?>">
<?php echo htmlspecialchars($feedback['message']); ?>
</div>
<?php endif; ?>
<!-- Add/Edit Form Card -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary"><?php echo $edit_package ? 'Edit Paket' : 'Tambah Paket Baru'; ?></h6>
</div>
<div class="card-body">
<form action="packages.php" method="POST">
<input type="hidden" name="id" value="<?php echo htmlspecialchars($edit_package['id'] ?? ''); ?>">
<div class="form-row">
<div class="form-group col-md-4">
<label for="name">Nama Paket</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($edit_package['name'] ?? ''); ?>" required>
</div>
<div class="form-group col-md-2">
<label for="price">Harga (Rp)</label>
<input type="number" class="form-control" id="price" name="price" value="<?php echo htmlspecialchars($edit_package['price'] ?? ''); ?>" required>
</div>
<div class="form-group col-md-2">
<label for="duration_days">Durasi (Hari)</label>
<input type="number" class="form-control" id="duration_days" name="duration_days" value="<?php echo htmlspecialchars($edit_package['duration_days'] ?? ''); ?>" required>
</div>
</div>
<div class="form-group">
<label for="description">Deskripsi</label>
<textarea class="form-control" id="description" name="description" rows="2"><?php echo htmlspecialchars($edit_package['description'] ?? ''); ?></textarea>
</div>
<button type="submit" name="save_package" class="btn btn-primary">
<i data-feather="save" class="mr-2"></i>Simpan
</button>
<?php if ($edit_package): ?>
<a href="packages.php" class="btn btn-secondary">Batal</a>
<?php endif; ?>
</form>
</div>
</div>
<!-- Packages List Card -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Daftar Paket</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Nama</th>
<th>Harga</th>
<th>Durasi</th>
<th>Deskripsi</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php if (empty($packages)): ?>
<tr>
<td colspan="5" class="text-center">Belum ada paket yang ditambahkan.</td>
</tr>
<?php else: ?>
<?php foreach ($packages as $pkg): ?>
<tr>
<td><?php echo htmlspecialchars($pkg['name']); ?></td>
<td>Rp <?php echo number_format($pkg['price'], 0, ',', '.'); ?></td>
<td><?php echo htmlspecialchars($pkg['duration_days']); ?> hari</td>
<td><?php echo htmlspecialchars($pkg['description']); ?></td>
<td>
<a href="packages.php?edit_id=<?php echo $pkg['id']; ?>" class="btn btn-sm btn-warning">
<i data-feather="edit-2"></i>
</a>
<form action="packages.php" method="POST" onsubmit="return confirm('Yakin ingin menghapus paket ini?');" class="d-inline">
<input type="hidden" name="delete_id" value="<?php echo $pkg['id']; ?>">
<button type="submit" class="btn btn-sm btn-danger">
<i data-feather="trash-2"></i>
</button>
</form>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>Service package management page content goes here.</p>
</div>
<?php require_once 'partials/footer.php'; ?>
<?php require_once 'partials/footer.php'; ?>

View File

@ -1,5 +1,7 @@
<?php
require_once 'auth.php';
require_once 'db/config.php';
require_once 'includes/routeros_api.class.php';
// Restrict access to Administrators
if ($_SESSION['user']['role'] !== 'Administrator') {
@ -8,18 +10,297 @@ if ($_SESSION['user']['role'] !== 'Administrator') {
}
$page_title = 'Routers';
$errors = [];
$success = '';
$API = new RouterosAPI();
$API->debug = false;
// Handle Test Connection (AJAX)
if (isset($_GET['action']) && $_GET['action'] == 'test_connection') {
header('Content-Type: application/json');
$id = $_GET['id'] ?? 0;
$stmt = db()->prepare("SELECT * FROM routers WHERE id = ?");
$stmt->execute([$id]);
$router = $stmt->fetch();
if ($router) {
$password = decrypt($router['password']);
if ($API->connect($router['ip_address'], $router['username'], $password)) {
$API->write('/system/resource/print');
$resource = $API->read();
$API->disconnect();
echo json_encode(['success' => true, 'message' => 'Connection successful!', 'data' => $resource[0]]);
} else {
echo json_encode(['success' => false, 'message' => 'Connection failed. Check IP, username, and password.']);
}
} else {
echo json_encode(['success' => false, 'message' => 'Router not found.']);
}
exit;
}
// Handle form submissions (Add/Edit)
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = $_POST['id'] ?? null;
$name = trim($_POST['name']);
$ip_address = trim($_POST['ip_address']);
$username = trim($_POST['username']);
$password = $_POST['password'];
$description = trim($_POST['description']);
if (empty($name)) $errors[] = 'Router name is required.';
if (empty($ip_address) || !filter_var($ip_address, FILTER_VALIDATE_IP)) $errors[] = 'A valid IP address is required.';
if (empty($username)) $errors[] = 'Username is required.';
if (empty($id) && empty($password)) $errors[] = 'Password is required for a new router.';
if (empty($errors)) {
if ($id) { // Update
if (!empty($password)) {
$encrypted_password = encrypt($password);
$stmt = db()->prepare("UPDATE routers SET name = ?, ip_address = ?, username = ?, password = ?, description = ? WHERE id = ?");
$stmt->execute([$name, $ip_address, $username, $encrypted_password, $description, $id]);
} else {
$stmt = db()->prepare("UPDATE routers SET name = ?, ip_address = ?, username = ?, description = ? WHERE id = ?");
$stmt->execute([$name, $ip_address, $username, $description, $id]);
}
$success = "Router updated successfully!";
} else { // Insert
$encrypted_password = encrypt($password);
$stmt = db()->prepare("INSERT INTO routers (name, ip_address, username, password, description) VALUES (?, ?, ?, ?, ?)");
try {
$stmt->execute([$name, $ip_address, $username, $encrypted_password, $description]);
$success = "Router added successfully!";
} catch (PDOException $e) {
if ($e->errorInfo[1] == 1062) { // Duplicate entry
$errors[] = "A router with this IP address already exists.";
} else {
$errors[] = "Database error: " . $e->getMessage();
}
}
}
}
}
// Handle Delete
if (isset($_GET['action']) && $_GET['action'] == 'delete') {
$id = $_GET['id'] ?? 0;
$stmt = db()->prepare("DELETE FROM routers WHERE id = ?");
$stmt->execute([$id]);
header('Location: routers.php?deleted=true');
exit;
}
if(isset($_GET['deleted'])) {
$success = "Router deleted successfully!";
}
// Fetch all routers
$routers = db()->query("SELECT * FROM routers ORDER BY name ASC")->fetchAll();
// Fetch router for editing
$edit_router = null;
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
$id = $_GET['id'] ?? 0;
$stmt = db()->prepare("SELECT * FROM routers WHERE id = ?");
$stmt->execute([$id]);
$edit_router = $stmt->fetch();
}
require_once 'partials/header.php';
?>
<div class="container-fluid">
<div class="d-flex justify-content-between align-items-center">
<h1 class="h3 mb-0 text-gray-800"><?php echo $page_title; ?></h1>
<button class="btn btn-primary"><i data-feather="plus" class="mr-2"></i>Add Router</button>
<h1 class="h3 mb-0 text-gray-800"><?php echo htmlspecialchars($page_title); ?></h1>
<a href="index.php" class="btn btn-secondary"><i data-feather="arrow-left" class="mr-1"></i> Kembali</a>
</div>
<hr>
<p>Router management page content goes here.</p>
<?php if (!empty($errors)):
foreach ($errors as $error):
?><div class="alert alert-danger"><p class="mb-0"><?php echo $error; ?></p></div><?php
endforeach;
endif; ?>
<?php if ($success):
?><div class="alert alert-success"><?php echo $success; ?></div><?php
endif; ?>
<div class="row">
<div class="col-md-4">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary"><?php echo $edit_router ? 'Edit Router' : 'Add New Router'; ?></h6>
</div>
<div class="card-body">
<form action="routers.php" method="POST">
<input type="hidden" name="id" value="<?php echo $edit_router['id'] ?? ''; ?>">
<div class="form-group">
<label for="name">Router Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($edit_router['name'] ?? ''); ?>" required>
</div>
<div class="form-group">
<label for="ip_address">IP Address</label>
<input type="text" class="form-control" id="ip_address" name="ip_address" value="<?php echo htmlspecialchars($edit_router['ip_address'] ?? ''); ?>" required>
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" name="username" value="<?php echo htmlspecialchars($edit_router['username'] ?? ''); ?>" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" <?php echo $edit_router ? '' : 'required'; ?> >
<?php if ($edit_router):
?><small class="form-text text-muted">Leave blank to keep the current password.</small><?php
endif; ?>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" id="description" name="description" rows="3"><?php echo htmlspecialchars($edit_router['description'] ?? ''); ?></textarea>
</div>
<button type="submit" class="btn btn-primary"><?php echo $edit_router ? 'Update Router' : 'Add Router'; ?></button>
<?php if ($edit_router):
?><a href="routers.php" class="btn btn-secondary">Cancel Edit</a><?php
endif; ?>
</form>
</div>
</div>
</div>
<div class="col-md-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Router List</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>IP Address</th>
<th>Username</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($routers as $router):
?><?php /* Check if $routers is empty before rendering rows */ if (!empty($routers)) { ?><?php // This check is redundant if the loop condition is correct, but kept for clarity if needed
?><tr >
<td><?php echo htmlspecialchars($router['name']); ?></td>
<td><?php echo htmlspecialchars($router['ip_address']); ?></td>
<td><?php echo htmlspecialchars($router['username']); ?></td>
<td>
<button class="btn btn-info btn-sm test-connection" data-id="<?php echo $router['id']; ?>" title="Test Connection">
<i data-feather="zap"></i>
</button>
<a href="routers.php?action=edit&id=<?php echo $router['id']; ?>" class="btn btn-warning btn-sm" title="Edit">
<i data-feather="edit-2"></i>
</a>
<a href="#" class="btn btn-danger btn-sm delete-router" data-id="<?php echo $router['id']; ?>" title="Delete">
<i data-feather="trash-2"></i>
</a>
</td>
</tr><?php } ?><?php endforeach; ?>
<?php if (empty($routers)):
?><td colspan="4" class="text-center">No routers found. Add one to get started.</td><?php
endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Delete Confirmation Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Confirm Delete</h5>
<button type="button" class="close" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this router?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<a href="#" id="confirmDelete" class="btn btn-danger">Delete</a>
</div>
</div>
</div>
</div>
<!-- Test Connection Modal -->
<div class="modal fade" id="testResultModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Connection Test Result</h5>
<button type="button" class="close" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<div class="modal-body" id="testResultBody">
<!-- Result will be injected here -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php require_once 'partials/footer.php'; ?>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Delete modal
const deleteButtons = document.querySelectorAll('.delete-router');
const confirmDelete = document.getElementById('confirmDelete');
deleteButtons.forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
const id = this.dataset.id;
confirmDelete.href = `routers.php?action=delete&id=${id}`;
new bootstrap.Modal(document.getElementById('deleteModal')).show();
});
});
// Test connection
const testButtons = document.querySelectorAll('.test-connection');
const testResultBody = document.getElementById('testResultBody');
const testResultModal = new bootstrap.Modal(document.getElementById('testResultModal'));
testButtons.forEach(button => {
button.addEventListener('click', function() {
const id = this.dataset.id;
testResultBody.innerHTML = '<p>Testing connection...</p>';
testResultModal.show();
fetch(`routers.php?action=test_connection&id=${id}`)
.then(response => response.json())
.then(data => {
let content = `<h6>${data.message}</h6>`;
if (data.success && data.data) {
content += '<pre class="bg-light p-2 rounded"><code class="json">';
content += `Board Name: ${data.data['board-name']}\n`;
content += `Version: ${data.data['version']}\n`;
content += `Uptime: ${data.data['uptime']}`;
content += '</code></pre>';
}
testResultBody.innerHTML = content;
})
.catch(error => {
testResultBody.innerHTML = '<p class="text-danger">An error occurred while testing the connection.</p>';
console.error('Error:', error);
});
});
});
});
</script>

View File

@ -13,7 +13,13 @@ require_once 'partials/header.php';
?>
<div class="container-fluid">
<h1 class="h3 mb-4 text-gray-800"><?php echo $page_title; ?></h1>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0 text-gray-800"><?php echo htmlspecialchars($page_title); ?></h1>
<a href="index.php" class="btn btn-secondary">
<i data-feather="arrow-left" class="mr-2"></i>Kembali ke Dashboard
</a>
</div>
<p>Settings page content goes here.</p>
</div>

View File

@ -14,8 +14,13 @@ require_once 'partials/header.php';
<div class="container-fluid">
<div class="d-flex justify-content-between align-items-center">
<h1 class="h3 mb-0 text-gray-800"><?php echo $page_title; ?></h1>
<button class="btn btn-primary"><i data-feather="plus" class="mr-2"></i>Add Operator</button>
<h1 class="h3 mb-0 text-gray-800"><?php echo htmlspecialchars($page_title); ?></h1>
<div>
<a href="index.php" class="btn btn-secondary mr-2">
<i data-feather="arrow-left" class="mr-1"></i> Kembali
</a>
<button class="btn btn-primary"><i data-feather="plus" class="mr-2"></i>Add Operator</button>
</div>
</div>
<hr>
<p>Operator management page content goes here.</p>

View File

@ -8,8 +8,13 @@ require_once 'partials/header.php';
<div class="container-fluid">
<div class="d-flex justify-content-between align-items-center">
<h1 class="h3 mb-0 text-gray-800"><?php echo $page_title; ?></h1>
<button class="btn btn-primary"><i data-feather="plus" class="mr-2"></i>Create Voucher</button>
<h1 class="h3 mb-0 text-gray-800"><?php echo htmlspecialchars($page_title); ?></h1>
<div>
<a href="index.php" class="btn btn-secondary mr-2">
<i data-feather="arrow-left" class="mr-1"></i> Kembali
</a>
<button class="btn btn-primary"><i data-feather="plus" class="mr-2"></i>Create Voucher</button>
</div>
</div>
<hr>
<p>Voucher management page content goes here.</p>