# 🚀 WEB-BASED INSTALLER - QUICK START

**Status:** ✅ READY | **Version:** 1.0.0

---

## ⚡ 5 MENIT SETUP

### **FILES YANG SUDAH DIBUAT:**

```
✅ dashboard/installer.php             (650 lines)  - Web UI untuk install
✅ api/controllers/InstallerController.php (400 lines) - API endpoints
✅ api/index.php                        (UPDATED)    - Router addition
✅ WEB_BASED_INSTALLER_GUIDE.md        (500+ lines) - Full documentation
```

### **YANG PERLU DIUPLOAD KE WEBHOST:**

```bash
# Priority 1: UPLOAD DULU
scp dashboard/installer.php user@tracker.lppmunud.id:/path/to/tracker/dashboard/

# Priority 2: UPLOAD CONTROLLER
scp api/controllers/InstallerController.php user@tracker.lppmunud.id:/path/to/tracker/api/controllers/

# Priority 3: ENSURE API ROUTER UPDATED
# Verify api/index.php sudah include InstallerController
# dan ada handleInstaller() method
```

---

## 🎯 CARA KERJA (3 LANGKAH)

### **LANGKAH 1: Admin Setup (Webhost)**
```bash
1. Upload 3 files ke webhost:
   - dashboard/installer.php
   - api/controllers/InstallerController.php
   - api/index.php (already updated)

2. Test: Open browser
   http://tracker.lppmunud.id/dashboard/installer.php
   
   Should see:
   ✅ Beautiful installer interface
   ✅ Download button
   ✅ System requirements list
   ✅ Step-by-step guide
```

### **LANGKAH 2: User Download (Target PC)**
```powershell
1. Buka browser di target PC
   http://tracker.lppmunud.id/dashboard/installer.php

2. Klik "Download Installer (PowerShell Script)"
   File: PCMonitor-Install.ps1 (~20KB)

3. File akan di-download otomatis
```

### **LANGKAH 3: User Install (Target PC)**
```powershell
1. Right-click PowerShell → Run as Administrator

2. Navigate ke download folder:
   cd C:\Users\YourName\Downloads

3. Allow script execution:
   Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

4. Run installer:
   .\PCMonitor-Install.ps1

   # Script akan:
   ✅ Validate admin privileges
   ✅ Check .NET 6.0 SDK
   ✅ Collect system info
   ✅ Download agent files (~50-100MB)
   ✅ Install as Windows Service
   ✅ Register dengan webhost
   ✅ Show agent ID
   ✅ Display dashboard link

5. Selesai! Agent muncul di dashboard dalam 30 detik
```

---

## 🔗 URLs & ENDPOINTS

### **For Users:**
```
http://tracker.lppmunud.id/dashboard/installer.php
└─ Beautiful installer interface
└─ Download PowerShell script here
```

### **For Developers (API):**
```
GET /api/installer?action=download-agent
└─ Download agent ZIP files
└─ Auth: Session + Admin required
└─ Response: Binary ZIP file

POST /api/installer?action=register-agent
└─ Register new agent
└─ Auth: None (uses system info)
└─ Input: System information (JSON)
└─ Response: agent_id

GET /api/installer?action=config
├─ Get installer configuration
├─ Auth: None (public)
└─ Response: JSON config

GET /api/installer?action=check&mac=MAC_ADDRESS
├─ Check if agent installed
├─ Auth: Optional
└─ Response: Installation status

GET /api/installer?action=progress&agent_id=AGENT_ID
├─ Get installation progress
├─ Auth: Optional
└─ Response: Progress status

GET /api/installer?action=requirements
├─ Get system requirements
├─ Auth: Optional
└─ Response: Requirements for installation
```

---

## ✨ FEATURES

### **Web Interface:**
- ✅ Beautiful, responsive design
- ✅ Step-by-step instructions
- ✅ System requirements checklist
- ✅ Direct download button
- ✅ Troubleshooting guide
- ✅ Video tutorial link
- ✅ Support contact info

### **PowerShell Installer Script:**
- ✅ Admin validation
- ✅ System requirements check (.NET 6.0)
- ✅ Automatic file download
- ✅ Service installation
- ✅ Auto-registration
- ✅ Status verification
- ✅ Error handling & logging

### **API Backend:**
- ✅ Download agent ZIP files
- ✅ Auto-register agents
- ✅ Configuration management
- ✅ Installation status check
- ✅ Progress tracking
- ✅ Requirements validation
- ✅ Audit logging

### **Database Integration:**
- ✅ Auto-insert into agents table
- ✅ Generate unique agent_id
- ✅ Track installation time
- ✅ Monitor agent status
- ✅ Audit trail logging

---

## 📊 INSTALLATION FLOW

```
┌─────────────────────────────────────────┐
│ User opens installer.php in browser     │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Download PowerShell script              │
│ (PCMonitor-Install.ps1)                 │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Right-click → Run as Administrator     │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Script validates system requirements    │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Collect system info (MAC, CPU, RAM)    │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Download agent files from webhost      │
│ (ZIP ~50-100MB)                        │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Extract & install to C:\Program Files\  │
│ PCMonitor                              │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Create Windows Service                  │
│ PCMonitorAgent (Automatic startup)     │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Register agent with webhost             │
│ (POST system info → get agent_id)      │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Verify service is running               │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Show success summary & agent ID        │
│ Display dashboard link                  │
└────────────────┬────────────────────────┘
                 ↓
┌─────────────────────────────────────────┐
│ Agent appears in dashboard within 30s   │
│ http://tracker.lppmunud.id/             │
│ dashboard/agents                        │
└─────────────────────────────────────────┘
```

---

## 🛠️ TROUBLESHOOTING

### **Error: "Not running as Administrator"**
```
❌ Problem: Script ran without admin privileges
✅ Solution: Right-click PowerShell → "Run as administrator"
```

### **Error: ".NET SDK not found"**
```
❌ Problem: .NET 6.0 not installed
✅ Solution: 
   1. Download: https://dotnet.microsoft.com/download
   2. Install SDK (not runtime)
   3. Restart PowerShell
   4. Run install again
   5. Verify: dotnet --version
```

### **Error: "Failed to download agent"**
```
❌ Problem: Network/firewall issue
✅ Solution:
   1. Test connectivity: ping tracker.lppmunud.id
   2. Try: curl http://tracker.lppmunud.id/api/installer?action=config
   3. Check firewall allows port 80/443
   4. Verify webhost API working
   5. Check logs: C:\Program Files\PCMonitor\logs\
```

### **Service won't start**
```
❌ Problem: Service failed
✅ Solution:
   1. Check: Get-Service -Name PCMonitorAgent
   2. Check logs: C:\Program Files\PCMonitor\logs\
   3. Try manual: cd "C:\Program Files\PCMonitor"
   4. Run: .\PCMonitorAgent.exe debug
   5. Check if .NET runtime available
```

### **Agent not in dashboard**
```
❌ Problem: Agent registered but not visible
✅ Solution:
   1. Wait 30-60 seconds for first heartbeat
   2. Refresh dashboard
   3. Check SQL: SELECT * FROM agents ORDER BY created_at DESC;
   4. Verify network connectivity from PC to webhost
   5. Check agent logs for API errors
```

---

## 📋 PRE-DEPLOYMENT CHECKLIST

- [ ] Files uploaded to webhost
  - [ ] dashboard/installer.php
  - [ ] api/controllers/InstallerController.php
  - [ ] api/index.php updated
  
- [ ] Webhost accessibility
  - [ ] Installer page loads: http://tracker.lppmunud.id/dashboard/installer.php
  - [ ] Download button works
  - [ ] Script downloads successfully
  
- [ ] Test on Windows 10/11 PC
  - [ ] Script runs with admin
  - [ ] System requirements validated
  - [ ] Download succeeds
  - [ ] Service starts
  - [ ] Registration works
  
- [ ] Database
  - [ ] agents table exists with all columns
  - [ ] agent_id generates correctly
  - [ ] New agents appear in table
  
- [ ] Dashboard
  - [ ] Agent appears in agents list
  - [ ] Correct system info displayed
  - [ ] Status shows "Active"
  
- [ ] Security
  - [ ] Only admin can download script
  - [ ] HTTPS/TLS enabled
  - [ ] Input validation working
  - [ ] Duplicate prevention working

---

## 🚀 DEPLOYMENT STEPS

### **1. Upload Files (5 min)**

```bash
# SSH to webhost
ssh user@tracker.lppmunud.id

# Navigate to tracker directory
cd /home/lppmunu1/public_html/tracker.lppmunud.id

# Upload files
scp dashboard/installer.php user@tracker.lppmunud.id:./dashboard/
scp api/controllers/InstallerController.php user@tracker.lppmunud.id:./api/controllers/
```

### **2. Verify Installation (5 min)**

```bash
# Check files exist
ls -la dashboard/installer.php
ls -la api/controllers/InstallerController.php

# Set permissions
chmod 644 dashboard/installer.php
chmod 644 api/controllers/InstallerController.php

# Test with browser
curl http://tracker.lppmunud.id/dashboard/installer.php
# Should see HTML output
```

### **3. Test Download (5 min)**

```bash
# Test from Windows PC
# Open PowerShell
Invoke-WebRequest -Uri "http://tracker.lppmunud.id/dashboard/installer.php?action=api&do=get-installer-script" `
                 -OutFile "PCMonitor-Install.ps1"

# Check file downloaded
Get-Item "PCMonitor-Install.ps1"
```

### **4. Test Installation (15 min)**

```powershell
# On Windows target PC, run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
.\PCMonitor-Install.ps1

# Wait for completion
# Check dashboard for new agent

# Verify in database
# SELECT * FROM agents WHERE agent_id LIKE 'AGENT-%';
```

### **5. Monitor Registrations (5 min)**

```bash
# Check logs
tail -f /home/lppmunu1/public_html/tracker.lppmunud.id/logs/installer.log

# Monitor new agents
mysql> SELECT * FROM agents ORDER BY created_at DESC LIMIT 5;
```

---

## 📞 SUPPORT

**Installer Issues:**
- Check logs: `C:\Program Files\PCMonitor\logs\`
- Test API: `curl http://tracker.lppmunud.id/api/installer?action=config`
- Verify .NET: `dotnet --version`

**Webhost Issues:**
- Check file permissions
- Verify PHP version >= 7.4
- Check error logs: `/var/log/apache2/error.log`

**Database Issues:**
- Verify agents table exists
- Check database connectivity
- Monitor SQL errors in logs

---

## 📊 STATISTICS

```
Installation Time:        ~5-10 minutes per PC
Downloads Size:           ~50-100MB (agent files)
Service Name:             PCMonitorAgent
Install Path:             C:\Program Files\PCMonitor
.NET Requirement:         6.0 or higher
Windows Requirement:      Windows 10 / 11
Admin Required:           YES
Network Required:         YES (outbound 80/443)
```

---

**Ready to deploy?**

1. ✅ Files created: installer.php + InstallerController.php
2. ✅ API router updated: api/index.php
3. ✅ Documentation complete: WEB_BASED_INSTALLER_GUIDE.md

**Next step:** Upload files to webhost!

