APLIKASI LATIHAN · sengaja mengandung kelemahan untuk praktik audit. Jangan memakai kata sandi asli Anda.
SIAUDIT / Kode Sumber

Kode Sumber

Kode SIAUDIT apa adanya. Label FK 1.4 menandai bagian yang berkaitan dengan butir kriteria.

app/tampilan.php 203 baris · SHA-256 3cd6d478d105 · SIAUDIT v1.4.2
1<?php
2// SIAUDIT — kerangka tampilan: kepala/kaki halaman, menu, ikon, dan halaman eror.
3
4function e(?string $s): string
5{
6 return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8');
7}
8
9function token(): string
11 $_SESSION['token'] ??= bin2hex(random_bytes(16));
12 return '<input type="hidden" name="token" value="' . $_SESSION['token'] . '">';
15function cekToken(): void
17 if (!hash_equals($_SESSION['token'] ?? '', $_POST['token'] ?? '')) throw new RuntimeException('Token formulir tidak valid. Muat ulang halaman.');
20function ikon(string $n): string
22 $p = [
23 'beranda' => '<path d="M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6h-6v6H4a1 1 0 0 1-1-1z"/>',
24 'tugas' => '<rect x="5" y="4" width="14" height="17" rx="2"/><path d="M9 3h6v3H9zM9 11h6M9 15h4"/>',
25 'kunci' => '<circle cx="8" cy="15" r="4"/><path d="m10.8 12.2 9.2-9.2M17 6l3 3M14.5 8.5l2 2"/>',
26 'log' => '<path d="M8 6h13M8 12h13M8 18h13M3.5 6h.01M3.5 12h.01M3.5 18h.01"/>',
27 'pengguna' => '<circle cx="9" cy="8" r="4"/><path d="M2 21a7 7 0 0 1 14 0M16 3.6a4 4 0 0 1 0 8.8M22 21a7 7 0 0 0-4.5-6.5"/>',
28 'reset' => '<path d="M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5"/>',
29 'kode' => '<path d="m8 6-6 6 6 6M16 6l6 6-6 6M14 4l-4 16"/>',
30 'peta' => '<path d="M9 4 3 6v14l6-2 6 2 6-2V4l-6 2zM9 4v14M15 6v14"/>',
31 'keluar' => '<path d="M15 4h4a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-4M10 17l5-5-5-5M15 12H3"/>',
32 'masuk' => '<path d="M9 4H5a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1h4M14 17l5-5-5-5M19 12H8"/>',
33 'daftar' => '<circle cx="9" cy="8" r="4"/><path d="M2 21a7 7 0 0 1 14 0M19 8v6M16 11h6"/>',
34 'perisai' => '<path d="M12 3 4 6v6c0 5 3.4 8.2 8 9 4.6-.8 8-4 8-9V6z"/><path d="m9 12 2 2 4-4"/>',
35 'awas' => '<path d="M12 3 2 20h20zM12 10v4M12 17h.01"/>',
36 'gembok' => '<rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/>',
37 'surel' => '<rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/>',
38 'cek' => '<path d="m5 12 5 5L20 7"/>',
39 'silang' => '<path d="M6 6l12 12M18 6 6 18"/>',
40 'info' => '<circle cx="12" cy="12" r="9"/><path d="M12 11v6M12 7.5h.01"/>',
41 'hapus' => '<path d="M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13"/>',
42 'menu' => '<path d="M4 6h16M4 12h16M4 18h16"/>',
43 'panah' => '<path d="M5 12h14M13 6l6 6-6 6"/>',
44 'kalender' => '<rect x="3" y="5" width="18" height="16" rx="2"/><path d="M3 10h18M8 3v4M16 3v4"/>',
45 'temuan' => '<circle cx="11" cy="11" r="7"/><path d="m20 20-4-4M11 8v3M11 14h.01"/>',
46 ];
47 return '<svg class="ikon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' . ($p[$n] ?? '') . '</svg>';
50function logo(): string
52 return '<svg class="logo" viewBox="0 0 40 40" aria-hidden="true"><defs><linearGradient id="lg" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#38bdf8"/><stop offset="1" stop-color="#2563eb"/></linearGradient></defs>'
53 . '<rect width="40" height="40" rx="11" fill="url(#lg)"/><path d="M20 8.5 11 12v7c0 6 4 9.6 9 10.8 5-1.2 9-4.8 9-10.8v-7z" fill="#fff" opacity=".95"/>'
54 . '<path d="m15.8 19.6 3 3 5.6-5.8" fill="none" stroke="#2563eb" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/></svg>';
57function pita(): string
59 return '<div class="pita">' . ikon('awas') . '<span><b>APLIKASI LATIHAN</b> · sengaja mengandung kelemahan untuk praktik audit. <b>Jangan memakai kata sandi asli Anda.</b></span></div>';
62function htmlAwal(string $judul, string $kelas = ''): void
64 echo '<!doctype html><html lang="id"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">'
65 . '<meta name="robots" content="noindex, nofollow"><title>' . e($judul) . ' · SIAUDIT</title>'
66 . '<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 40 40\'%3E%3Crect width=\'40\' height=\'40\' rx=\'11\' fill=\'%232563eb\'/%3E%3Cpath d=\'M20 8.5 11 12v7c0 6 4 9.6 9 10.8 5-1.2 9-4.8 9-10.8v-7z\' fill=\'white\'/%3E%3C/svg%3E">'
67 . '<link rel="stylesheet" href="gaya.css?v=' . VERSI . '"></head><body class="' . $kelas . '">' . pita();
70function tautanKode(): string
72 $f = 'public/' . basename($_SERVER['SCRIPT_NAME']);
73 return '<a href="kode.php?f=' . e($f) . '">' . ikon('kode') . 'Lihat kode halaman ini</a>';
76function inisial(string $nama): string
78 $kata = preg_split('/\s+/', trim($nama));
79 return strtoupper(substr($kata[0], 0, 1) . substr($kata[1] ?? '', 0, 1));
82function menu(string $aktif): string
84 $p = pengguna();
85 $grup = $p ? ['Utama' => ['index.php' => ['beranda', 'Beranda'], 'ganti-sandi.php' => ['kunci', 'Ganti Kata Sandi']]]
86 : ['Akun' => ['login.php' => ['masuk', 'Masuk'], 'daftar.php' => ['daftar', 'Daftar Akun']]];
87 if ($p && in_array($p['peran'], ['admin', 'operator'], true)) $grup['Administrasi']['log-aktivitas.php'] = ['log', 'Log Aktivitas'];
88 if ($p && $p['peran'] === 'admin') {
89 $grup['Administrasi']['pengguna.php'] = ['pengguna', 'Data Pengguna'];
90 $grup['Administrasi']['reset.php'] = ['reset', 'Reset Data Latihan'];
91 }
92 $grup['Untuk Auditor'] = ['kode.php' => ['kode', 'Kode Sumber'], 'peta.php' => ['peta', 'Peta Butir FK']];
93 $h = '';
94 foreach ($grup as $judul => $isi) {
95 $h .= '<div class="menu-judul">' . $judul . '</div>';
96 foreach ($isi as $url => [$ik, $label]) {
97 $h .= '<a href="' . $url . '" class="' . ($url === $aktif ? 'aktif' : '') . '">' . ikon($ik) . '<span>' . $label . '</span></a>';
98 }
99 }
100 return $h;
103function kepala(string $judul, string $aktif = '', string $sub = ''): void
105 htmlAwal($judul);
106 $p = pengguna();
107 echo '<div class="kerangka"><input type="checkbox" id="menu-buka" hidden><label for="menu-buka" class="tirai"></label>'
108 . '<aside class="sisi"><a class="merek" href="index.php">' . logo() . '<span>SIAUDIT<small>Sistem Informasi Audit</small></span></a>'
109 . '<nav class="menu">' . menu($aktif) . '</nav>';
110 if ($p) {
111 echo '<div class="profil"><span class="avatar">' . e(inisial($p['nama'])) . '</span><span class="profil-nama">' . e($p['nama'])
112 . '<small>' . e(ucfirst($p['peran'])) . ' · ' . e($p['unit']) . '</small></span>'
113 . '<a href="keluar.php" class="tombol-ikon" title="Keluar">' . ikon('keluar') . '</a></div>';
114 }
115 echo '</aside><div class="utama"><header class="atas"><label for="menu-buka" class="tombol-menu" aria-label="Menu">' . ikon('menu') . '</label>'
116 . '<div><div class="remah">SIAUDIT / ' . e($judul) . '</div><h1>' . e($judul) . '</h1>' . ($sub ? '<p class="sub">' . $sub . '</p>' : '') . '</div></header><main class="isi">';
119function kaki(): void
121 echo '</main><footer class="kaki"><span>SIAUDIT v' . VERSI . ' · Instansi Contoh · Bahan latihan Sosialisasi Audit Keamanan SPBE</span>'
122 . tautanKode() . '</footer></div></div></body></html>';
125function kepalaAuth(string $judul): void
127 htmlAwal($judul, 'hal-auth');
128 echo '<div class="auth"><section class="auth-merek"><div class="auth-merek-isi">' . logo()
129 . '<h2>SIAUDIT</h2><p>Sistem Informasi Audit Keamanan SPBE<br>Instansi Contoh</p><ul>'
130 . '<li>' . ikon('tugas') . 'Penugasan audit dan jadwal tim</li>'
131 . '<li>' . ikon('perisai') . 'Kertas kerja EDK, EIK, dan EFK</li>'
132 . '<li>' . ikon('temuan') . 'Rekam jejak temuan dan tindak lanjut</li></ul></div>'
133 . '<div class="auth-merek-kaki"><a href="kode.php">' . ikon('kode') . 'Kode sumber</a><a href="peta.php">' . ikon('peta') . 'Peta butir FK</a><span>v' . VERSI . '</span></div>'
134 . '</section><section class="auth-form"><div class="auth-kartu">';
137function kakiAuth(): void
139 echo '</div><div class="auth-kaki">' . tautanKode() . '</div></section></div></body></html>';
142function pesan(string $jenis, string $html): string
144 $ik = ['sukses' => 'cek', 'galat' => 'silang', 'awas' => 'awas', 'info' => 'info'][$jenis] ?? 'info';
145 return '<div class="pesan pesan-' . $jenis . '">' . ikon($ik) . '<div>' . $html . '</div></div>';
148function tanggal(string $ymd, bool $tahun = true): string
150 $bulan = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des'];
151 [$y, $m, $d] = explode('-', $ymd);
152 return (int)$d . ' ' . $bulan[(int)$m] . ($tahun ? " $y" : '');
155function lencanaJenis(string $jenis): string
157 $k = ['Aplikasi Web' => 'biru', 'Aplikasi Mobile' => 'ungu', 'Sistem Penghubung Layanan' => 'toska'][$jenis] ?? 'abu';
158 return '<span class="lencana lencana-' . $k . '">' . e($jenis) . '</span>';
161function lencanaTahap(int $t): string
163 $k = $t === 5 ? 'hijau' : ($t >= 3 ? 'biru' : ($t >= 1 ? 'kuning' : 'abu'));
164 return '<span class="lencana lencana-' . $k . '">' . e(TAHAP[$t]) . '</span>';
167function halamanTolak(): void
169 kepala('Akses Ditolak');
170 echo '<div class="kartu kosong">' . ikon('gembok') . '<h2>Akses ditolak</h2><p>Halaman ini hanya untuk peran tertentu.</p><a class="tombol" href="index.php">Kembali ke Beranda</a></div>';
171 kaki();
174// Halaman rincian eror yang tampil saat MODE_DEBUG aktif
175function halamanDebug(Throwable $e): void
177 [$sql, $param] = $GLOBALS['kueri_terakhir'] ?? ['', []];
178 foreach ($param as $v) {
179 $pos = strpos($sql, '?');
180 if ($pos !== false) $sql = substr_replace($sql, "'" . str_replace("'", "''", (string)$v) . "'", $pos, 1);
181 }
182 $baris = is_file($e->getFile()) ? file($e->getFile()) : [];
183 $awal = max(1, $e->getLine() - 5);
184 $kutipan = '';
185 for ($i = $awal; $i <= min(count($baris), $e->getLine() + 5); $i++) {
186 $kutipan .= '<div class="' . ($i === $e->getLine() ? 'sorot' : '') . '"><span>' . $i . '</span>' . e(rtrim($baris[$i - 1])) . '</div>';
187 }
188 $lingkungan = [
189 'Versi PHP' => PHP_VERSION, 'Server' => $_SERVER['SERVER_SOFTWARE'] ?? '-', 'Sistem operasi' => php_uname('s') . ' ' . php_uname('r'),
190 'Basis data' => realpath(DIR_DATA) . '/siaudit.sqlite', 'Zona waktu' => date_default_timezone_get(), 'Waktu server' => date('Y-m-d H:i:s'),
191 'URL' => ($_SERVER['REQUEST_METHOD'] ?? '') . ' ' . ($_SERVER['REQUEST_URI'] ?? ''),
192 ];
193 if (!headers_sent()) header('Content-Type: text/html; charset=utf-8');
194 echo '<!doctype html><html lang="id"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Eror · SIAUDIT</title>'
195 . '<link rel="stylesheet" href="gaya.css?v=' . VERSI . '"></head><body class="hal-debug">' . pita() . '<div class="debug">'
196 . '<div class="debug-kepala"><span class="debug-label">Uncaught ' . e(get_class($e)) . '</span><h1>' . e($e->getMessage()) . '</h1>'
197 . '<code>' . e($e->getFile()) . ':' . $e->getLine() . '</code></div>'
198 . '<section><h2>Kode sumber</h2><pre class="debug-kode">' . $kutipan . '</pre></section>';
199 if ($sql) echo '<section><h2>Kueri SQL terakhir</h2><pre class="debug-sql">' . e($sql) . '</pre></section>';
200 echo '<section><h2>Jejak pemanggilan</h2><pre>' . e($e->getTraceAsString()) . '</pre></section><section><h2>Lingkungan</h2><table>';
201 foreach ($lingkungan as $k => $v) echo '<tr><th>' . e($k) . '</th><td>' . e($v) . '</td></tr>';
202 echo '</table></section><p class="debug-kaki">SIAUDIT v' . VERSI . ' · MODE_DEBUG = true · <a href="index.php">Kembali ke Beranda</a></p></div></body></html>';