# 🧪 Panduan Test Local — Tunnel SaaS v2

Cheatsheet cepat untuk uji coba semua komponen di localhost
sebelum deploy ke hosting.

---

## 📋 Prerequisites

- ✅ Laragon **Start All** (Apache + PHP aktif)
- ✅ Browser modern (Chrome / Firefox / Edge)
- ✅ Editor (VS Code / Notepad++) untuk edit file PHP

---

## 🗺️ Peta URL Local

### Komponen Utama

```
http://localhost/
  ├── tunnel/                          ← Project v1 (tradisional)
  ├── tunnel-saas/
  │   ├── server/render.php            ← Endpoint SaaS
  │   ├── client/                       ← Client proxy
  │   ├── admin/                        ← Admin panel
  │   ├── panduan-saas.html            ← Panduan visual
  │   └── DEPLOY-CPANEL.txt
  └── (file Laragon lainnya)
```

### Quick Access

| Buka di Browser | Untuk |
|---|---|
| `localhost/tunnel-saas/admin/` | Login admin (passwd: `admin123`) |
| `localhost/tunnel-saas/client/` | Test proxy → server → render |
| `localhost/tunnel-saas/server/render.php` | Health check endpoint |
| `localhost/tunnel-saas/panduan-saas.html` | Baca panduan visual |
| `localhost/tunnel/` | Compare ke v1 lama |

---

## 🎯 Skenario Test Lengkap (15 menit)

### Skenario 1: Health Check Server

**Tujuan**: Pastikan server SaaS hidup.

```
URL: http://localhost/tunnel-saas/server/render.php
Expected: "Invalid API key"
```

✅ Sukses kalau muncul pesan itu (artinya endpoint aktif, butuh key).
❌ Kalau 404/500: cek `.htaccess` dan PHP error log Laragon.

---

### Skenario 2: Login Admin & Tambah Client

**Tujuan**: Setup client via admin panel.

#### 2a. Login
```
1. Buka: http://localhost/tunnel-saas/admin/
2. Password: admin123
3. Klik Masuk → Dashboard muncul
```

#### 2b. Tambah Client
```
1. Sidebar → 🔑 API Keys & Client
2. Isi form:
   - Nama: Test Client Local
   - Host: *
3. Klik "Generate Key & Simpan"
4. Key muncul di flash hijau, juga di tabel
5. Klik tombol "Copy" di baris key
```

#### 2c. Pasang Key di Client
Edit `c:\laragon\www\tunnel-saas\client\index.php`:

```php
$SERVER_URL = 'http://localhost/tunnel-saas/server/render.php';
$API_KEY    = 'PASTE_KEY_HASIL_COPY_DI_SINI';
```

Save.

#### 2d. Test Client
```
URL: http://localhost/tunnel-saas/client/
Expected: Homepage direktori APK muncul
```

---

### Skenario 3: Test Routing Lengkap

**Tujuan**: Cek semua URL bersih jalan via proxy.

Test satu per satu, semua harus status 200:

| URL Client | Yang Diharapkan |
|---|---|
| `localhost/tunnel-saas/client/` | Homepage |
| `localhost/tunnel-saas/client/aplikasi-axis` | Halaman brand |
| `localhost/tunnel-saas/client/about` | Tentang Kami |
| `localhost/tunnel-saas/client/contact` | Hubungi Kami |
| `localhost/tunnel-saas/client/privacy` | Kebijakan Privasi |
| `localhost/tunnel-saas/client/sitemap.xml` | XML sitemap |
| `localhost/tunnel-saas/client/robots.txt` | Robots.txt |
| `localhost/tunnel-saas/client/img/aplikasi-axis.png` | Banner PNG |
| `localhost/tunnel-saas/client/amp/aplikasi-axis` | Versi AMP |

---

### Skenario 4: Edit Brand List via Admin

**Tujuan**: Update list.txt lewat UI.

```
1. Admin → 📝 Brand List
2. Textarea muncul dengan isi list.txt saat ini
3. Tambah brand baru di baris baru, mis:
   testapk satu
   testapk dua
   testapk tiga
4. Klik "💾 Simpan & Sync ke AMP"
5. Flash hijau muncul: "List.txt disimpan: N entri"
6. Buka client:
   localhost/tunnel-saas/client/testapk-satu
   Halaman brand TESTAPK SATU muncul ✓
```

---

### Skenario 5: Jalankan Keyword Updater

**Tujuan**: Auto-tambah keyword trending.

```
1. Admin → 🔍 Keyword Updater
2. (Opsional) Edit seeds.txt kalau mau
3. Klik "🚀 Run Keyword Update"
4. Konfirmasi → tunggu 1-3 menit
5. Output script muncul di kotak hitam
6. Buka tab "Brand List" → jumlah baris bertambah
7. Test brand baru di client
```

---

### Skenario 6: Test Settings Geo & Audit

**Tujuan**: Aktifkan/nonaktifkan fitur via admin.

```
1. Admin → ⚙️ Settings
2. Edit Target URL: https://my-affiliate.com/{brand}
3. Centang/uncheck:
   - Aktifkan Geo Cloaking
   - Block Rich Results Test
4. Klik "💾 Simpan"
5. Refresh client → setting berlaku
```

---

### Skenario 7: Test Multi-Client (Sim 2 Domain)

**Tujuan**: Pastikan beda host = beda canonical.

Browser PowerShell trick (simulasi host header):

```powershell
# Test sebagai "domain1.test"
Invoke-WebRequest "http://localhost/tunnel-saas/client/aplikasi-axis" `
  -Headers @{Host="domain1.test"} -UseBasicParsing |
  Select-String 'canonical'

# Test sebagai "domain2.test"
Invoke-WebRequest "http://localhost/tunnel-saas/client/aplikasi-axis" `
  -Headers @{Host="domain2.test"} -UseBasicParsing |
  Select-String 'canonical'
```

⚠️ Catatan: PowerShell tidak selalu kirim Host header custom.
Alternatif: setup virtual host (lihat bawah).

---

## 🌐 Setup Virtual Host (Opsional, untuk Test Realistis)

Kalau mau test seperti production dengan domain berbeda:

### 1. Edit Hosts File (sebagai Admin)

```
File: C:\Windows\System32\drivers\etc\hosts

Tambahkan:
127.0.0.1   client1.test
127.0.0.1   client2.test
127.0.0.1   admin.test
```

### 2. Setup Virtual Host Laragon

```
Klik kanan tray Laragon → Apache → sites-enabled
Buat file: client1.test.conf
```

Isi:
```apache
<VirtualHost *:80>
    ServerName client1.test
    DocumentRoot "C:/laragon/www/tunnel-saas/client"
    <Directory "C:/laragon/www/tunnel-saas/client">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
```

Restart Apache via Laragon.

### 3. Test
```
http://client1.test/aplikasi-axis
```

Canonical akan jadi `https://client1.test/aplikasi-axis` 🎉

---

## 🛠️ Troubleshooting Local

### Q: "Invalid API key" terus muncul di client
- Cek key di client/index.php sama dengan di admin
- Hard refresh (Ctrl+F5)
- Restart Apache (Laragon stop/start) untuk clear opcache

### Q: 404 Not Found di client URL bersih
- Cek mod_rewrite Laragon aktif
- Pastikan client/.htaccess ikut ter-upload (file hidden)

### Q: Banner image broken (404 di /img/)
- Cek ekstensi GD aktif di Laragon
- Test direct: `localhost/tunnel-saas/server/img.php?brand=aplikasi-axis`

### Q: Admin panel blank putih
- PHP error: cek `C:\laragon\bin\apache\...\logs\error.log`
- Pastikan PHP 7.4+ aktif

### Q: Keyword updater timeout
- Edit php.ini → max_execution_time = 600
- Restart Apache

### Q: Session admin keluar terus
- Cek folder sesi PHP writable
- Atau set di php.ini: session.save_path = "C:/temp"

---

## 📊 Cek Aktivitas Real-Time

### Tail Log Server (PowerShell)
```powershell
Get-Content c:\laragon\www\tunnel-saas\server\saas_access.log -Wait -Tail 10
```

### Tail Log Keyword
```powershell
Get-Content c:\laragon\www\tunnel\keyword_update.log -Wait -Tail 20
```

### Cek Apache Error
```powershell
Get-Content C:\laragon\bin\apache\httpd-*\logs\error.log -Tail 30
```

---

## ✅ Checklist Sebelum Deploy ke Hosting

- [ ] Login admin pakai password kuat (BUKAN `admin123`)
- [ ] Hapus key `testkey123` wildcard dari saas_config.php
- [ ] Setting config.php → target_url asli (bukan example.com)
- [ ] Setting config.php → owner_bypass_key acak panjang
- [ ] Test semua skenario di atas berhasil
- [ ] Backup list.txt + keys.json + config.php
- [ ] Test 1 client baru full cycle berhasil

---

## 🎯 Quick Commands

```powershell
# Health check semua endpoint
$urls = @(
  "http://localhost/tunnel-saas/admin/",
  "http://localhost/tunnel-saas/client/",
  "http://localhost/tunnel-saas/server/render.php",
  "http://localhost/tunnel-saas/client/aplikasi-axis"
)
$urls | ForEach-Object {
  try { $r = Invoke-WebRequest $_ -UseBasicParsing -ErrorAction Stop
        Write-Host "$_  → $($r.StatusCode)" -ForegroundColor Green }
  catch { Write-Host "$_  → ERROR" -ForegroundColor Red }
}
```

```powershell
# Clear semua cache (untuk fresh test)
Remove-Item c:\laragon\www\tunnel-saas\server\cache\img\* -Force -ErrorAction SilentlyContinue
Remove-Item c:\laragon\www\tunnel-saas\server\cache\geo\* -Force -ErrorAction SilentlyContinue
Write-Host "Cache cleared"
```

---

📘 **Untuk panduan visual interaktif**: buka `panduan-saas.html`
🛠️ **Untuk deploy ke cPanel**: buka `DEPLOY-CPANEL.txt`
🏗️ **Untuk arsitektur lengkap**: buka `README.txt`
