# Panduan Deployment ke Webhost: tracker.lppmunud.id

Dokumen ini berisi langkah-langkah lengkap untuk deploy PC Monitor System ke webhost dengan domain tracker.lppmunud.id.

## ✅ Quick Deployment Checklist

- [ ] Dashboard terinstall di webhost
- [ ] Database setup & migration selesai
- [ ] Config.php sudah updated dengan credential webhost
- [ ] Login dashboard berfungsi
- [ ] Agent C# sudah di-build (Release)
- [ ] install.bat sudah dikopi ke PC target
- [ ] Agent service terinstall dan running
- [ ] Agent muncul di dashboard

---

## BAGIAN 1: Setup Webhost PHP Server

### 1.1 Upload Dashboard & API

**Persyaratan:**
- FTP/SFTP access ke webhost
- cPanel atau hosting control panel
- Domain `tracker.lppmunud.id` sudah pointing ke hosting

**Langkah:**

1. **Koneksikan via FTP** (gunakan FileZilla atau Cyberduck):
   ```
   Host: tracker.lppmunud.id (atau ftp.tracker.lppmunud.id)
   Username: [FTP account]
   Password: [FTP password]
   Port: 21 (atau 22 untuk SFTP)
   ```

2. **Upload folder tracker:**
   ```
   Local folder: C:\xampp\htdocs\tracker\
   Remote folder: public_html/tracker/ (atau root sesuai config)
   ```

3. **Verifikasi akses:**
   ```
   http://tracker.lppmunud.id/tracker/
   ```
   Harus menampilkan file listing atau index page (bukan error 404)

### 1.2 Setup Database

1. **Login ke cPanel:**
   - URL: `https://tracker.lppmunud.id:2083/` atau hosting control panel
   - Username: [cPanel account]
   - Password: [cPanel password]

2. **Buat Database Baru:**
   - Buka: MySQL Databases atau Database Management
   - Database Name: `tracker`
   - Create Database

3. **Buat MySQL User:**
   - Username: `tracker_user`
   - Password: [Generate strong password]
   - Add User to Database: `tracker_user@localhost` → `tracker`
   - Privileges: ALL PRIVILEGES

4. **Import Schema:**
   - Buka: phpMyAdmin
   - Select Database: `tracker`
   - Import tab → Choose file: `/database/tracker_schema.sql`
   - Execute

5. **Verifikasi:**
   ```
   - Database berisi 15+ tables
   - Admin user sudah ada: admin/admin123
   ```

### 1.3 Update Configuration

**Edit file:** `/dashboard/config/Config.php`

```php
<?php
// Database Configuration untuk WEBHOST
define('DB_HOST', 'localhost');  // Biasanya localhost di webhost
define('DB_PORT', 3306);
define('DB_NAME', 'tracker');    // Database name yang dibuat
define('DB_USER', 'tracker_user'); // MySQL user
define('DB_PASS', 'YOUR_PASSWORD');  // MySQL password

// Timezone
define('TIMEZONE', 'Asia/Jakarta');

// Logging
define('LOG_FILE', '/tmp/tracker.log'); // atau sesuai server config
?>
```

**Edit file:** `/api/config/Database.php`

```php
<?php
class Database {
    private $host = 'localhost';
    private $db_name = 'tracker';
    private $db_user = 'tracker_user';
    private $db_pass = 'YOUR_PASSWORD';
    private $charset = 'utf8mb4';
    
    // ... rest of config
}
?>
```

### 1.4 Test Dashboard

1. **Login Test:**
   ```
   URL: http://tracker.lppmunud.id/tracker/dashboard/login.php
   Username: admin
   Password: admin123
   ```

2. **Jika gagal, jalankan diagnostics:**
   ```
   URL: http://tracker.lppmunud.id/tracker/diagnostics.php
   ```
   Tool ini akan auto-fix masalah database

3. **Verifikasi koneksi database pada diagnostics tool:**
   - Check MySQL connection
   - Verify tables
   - Fix hash password jika perlu

---

## BAGIAN 2: Build & Prepare Agent

### 2.1 Download Updated Agent Files

Pastikan sudah punya file-file terbaru:
- ✅ `install.bat` - sudah updated dengan API URL webhost
- ✅ `config.json` - sudah updated dengan API URL
- ✅ Full agent source dari `/agent-csharp/`

### 2.2 Build Agent Service

**Persyaratan:**
- .NET 6.0 SDK installed
- Visual Studio 2022 / VS Code

**Build Steps:**

```cmd
REM 1. Navigate ke project
cd C:\xampp\htdocs\tracker\agent-csharp

REM 2. Restore packages
dotnet restore

REM 3. Build project
dotnet build -c Release

REM 4. Publish untuk Windows Service
dotnet publish -c Release -f net6.0-windows -o "C:\Temp\PCMonitorAgent"
```

**Output folder akan berisi:**
- `PCMonitorAgent.exe`
- `config.json`
- `install.bat`
- Semua required DLLs

### 2.3 Prepare Distribution Package

**Di PC deployment (create distribution cache):**

1. **Create folder:**
   ```
   C:\Deployment\PCMonitorAgent\
   ```

2. **Copy dari publish output:**
   ```
   C:\Temp\PCMonitorAgent\ → C:\Deployment\PCMonitorAgent\
   ```

3. **Verifikasi file:**
   ```
   ✓ PCMonitorAgent.exe
   ✓ install.bat
   ✓ config.json
   ✓ All .dll files
   ✓ *.json config files
   ```

---

## BAGIAN 3: Deploy Agent ke PC Target

### 3.1 Pre-Deployment Requirements

Pada setiap PC target yang akan di-monitor:
- ✓ Windows 10+ (Pro/Enterprise/Home)
- ✓ Internet connection (koneksi ke `tracker.lppmunud.id`)
- ✓ Administrator access
- ✓ Windows Defender/Antivirus whitelist agent folder (optional)

### 3.2 Installation Steps

**Langkah praktis di PC Target:**

1. **Copy Agent Folder:**
   ```
   Dari: C:\Deployment\PCMonitorAgent\ 
   Ke: C:\Program Files\PCMonitorAgent\
   
   OR
   
   Share folder: \\deployment-server\PCMonitorAgent
   Copy ke local: C:\Program Files\PCMonitorAgent\
   ```

2. **Run Installer (Admin):**
   ```
   - Right-click: install.bat
   - Select: "Run as administrator"
   - Wait for UAC prompt
   ```

3. **Follow Wizard:**
   ```
   ✓ Admin check: SUCCESS
   ✓ Check existing service: None found
   ✓ API Server URL prompt: Enter http://tracker.lppmunud.id/tracker/api
   ✓ Config created: SUCCESS
   ✓ Service registered: SUCCESS
   ✓ Service started: SUCCESS
   ```

4. **Verify Installation:**

   **Method 1: Services Console**
   ```
   Win + R → services.msc
   Find: "PC Monitor Agent"
   Status: Running
   Startup Type: Automatic
   ```

   **Method 2: Command Line**
   ```cmd
   sc query PCMonitorAgent
   
   Expected output:
   STATE              : 4  RUNNING
   ```

   **Method 3: Check Logs**
   ```
   C:\Windows\Logs\PCMonitorAgent\agent.log
   
   Harus ada entries seperti:
   [INFO] Agent started
   [INFO] Connected to API
   [INFO] Sending activity data
   ```

### 3.3 Batch Deployment (Multiple PCs)

Jika perlu install di multiple PCs, buat script deployment:

**deploy-agent.ps1:**
```powershell
# PowerShell Script for batch agent deployment

param(
    [string]$SourcePath = "C:\Deployment\PCMonitorAgent",
    [string]$TargetPC = "192.168.1.100",
    [string]$AdminUser = "Administrator",
    [string]$AdminPass = "password"
)

# Copy ke remote PC
$RemoteShare = "\\$TargetPC\c$\Program Files"
Copy-Item -Path $SourcePath -Destination $RemoteShare -Recurse -Force

# Remote execute install.bat
$PSSession = New-PSSession -ComputerName $TargetPC -Credential $(
    New-Object System.Management.Automation.PSCredential($AdminUser, $(
        ConvertTo-SecureString $AdminPass -AsPlainText -Force))
)

Invoke-Command -Session $PSSession -ScriptBlock {
    & "C:\Program Files\PCMonitorAgent\install.bat"
}

Remove-PSSession $PSSession
```

**Run:**
```powershell
.\deploy-agent.ps1 -TargetPC "192.168.1.100"
```

---

## BAGIAN 4: Verification & Monitoring

### 4.1 Dashboard Check

1. **Login ke Dashboard:**
   - URL: `http://tracker.lppmunud.id/tracker/dashboard/login.php`
   - Username: `admin`
   - Password: `admin123`

2. **Verify Agent Registered:**
   - Menu: Agents
   - Harus muncul agent yang baru diinstall dalam 30-60 detik
   - Status: ONLINE (jika connection ok), atau OFFLINE

3. **Check Activity:**
   - Menu: Activities
   - Harus ada logs dari PC target
   - Timestamps harus current time

### 4.2 API Health Check

```bash
# Test API connectivity
curl -X GET http://tracker.lppmunud.id/tracker/api/agents

# Expected response (JSON):
{
  "status": "success",
  "data": [
    {
      "id": 1,
      "agent_id": "1234567890",
      "hostname": "PC-TARGET",
      "status": "online",
      "last_seen": "2026-03-27 14:30:15"
    }
  ]
}
```

### 4.3 Troubleshooting

**Problem: Agent tidak muncul di dashboard**

1. **Check service status di PC target:**
   ```cmd
   sc query PCMonitorAgent
   REM Pastikan STATE = 4 (RUNNING)
   ```

2. **Check config.json:**
   ```cmd
   type "C:\Program Files\PCMonitorAgent\config.json"
   REM Pastikan "api_url" benar: http://tracker.lppmunud.id/tracker/api
   ```

3. **Check firewall:**
   ```cmd
   # Dari PC target, coba ping server domain
   ping tracker.lppmunud.id
   
   # Test port 80
   telnet tracker.lppmunud.id 80
   ```

4. **Check logs:**
   ```
   File: C:\Windows\Logs\PCMonitorAgent\agent.log
   
   Cari error messages, pastikan tidak ada:
   - Connection refused
   - DNS resolution failed
   - Timeout
   ```

5. **Manual restart service:**
   ```cmd
   net stop PCMonitorAgent
   timeout /t 5
   net start PCMonitorAgent
   ```

**Problem: Dashboard login gagal**

1. **Run diagnostics:**
   ```
   http://tracker.lppmunud.id/tracker/diagnostics.php
   ```

2. **Check database connection:**
   - Host: `localhost`
   - Database: `tracker`
   - User: `tracker_user`
   - Password: [sesuai konfigurasi]

3. **Fix password hash (jika perlu):**
   ```sql
   UPDATE users 
   SET password = '$2y$10$rJI/5W5Z1QvLLlQ3U5RqpO5P7Uo0GZVz4Ep9BZEqYc8x5JZVRh5Hy'
   WHERE username = 'admin';
   ```

---

## BAGIAN 5: Maintenance & Operations

### 5.1 Monitoring Dashboard

**Akses harian:**
```
URL: http://tracker.lppmunud.id/tracker/dashboard/
```

**Monitor:**
- Agent status (online/offline)
- CPU/Memory usage
- Running applications
- Network bandwidth
- Recent activities

### 5.2 Common Operations

**Send Command to Agent:**
```
Dashboard → Commands → Select PC → Execute
```

Available commands:
- `screenshot` - Capture screen
- `get_processes` - List running processes
- `get_system_info` - System information
- `shutdown` - Shutdown PC
- `restart` - Restart PC
- `disconnect_internet` - Block internet

**Update Agent Config:**
1. Edit `config.json` di PC target
2. Restart service:
   ```cmd
   net stop PCMonitorAgent
   net start PCMonitorAgent
   ```

### 5.3 Backup & Recovery

**Backup Database:**
```
cPanel → phpMyAdmin → Database: tracker → Export
```
Schedule weekly backup via:
- cPanel backup tool
- Manual export
- Database replication (jika available)

**Restore Database:**
```
cPanel → phpMyAdmin → Import → Select backup file
```

---

## BAGIAN 6: Security Configuration

### 6.1 Firewall Rules

**Inbound (Webhost):**
- Port 80 (HTTP) - dari Agent IP ranges
- Port 443 (HTTPS) - dari Agent IP ranges (optional)

**Outbound (PC Target):**
- Port 80/443 - ke tracker.lppmunud.id

### 6.2 Credential Security

1. **Change default admin password:**
   ```
   URL: http://tracker.lppmunud.id/tracker/dashboard/
   profile settings → Change password
   ```

2. **Update API keys di agent:**
   ```
   config.json: "api_key": "[generate-strong-key]"
   ```

3. **Update MySQL password:**
   ```sql
   ALTER USER 'tracker_user'@'localhost' IDENTIFIED BY '[new-strong-password]';
   FLUSH PRIVILEGES;
   ```

### 6.3 HTTPS Configuration (Recommended)

1. **Enable SSL di webhost:**
   - cPanel → AutoSSL (Let's Encrypt)
   - Atau purchase SSL certificate

2. **Update config di agent:**
   ```json
   "api_url": "https://tracker.lppmunud.id/tracker/api"
   ```

3. **Update dashboard config:**
   ```php
   define('API_URL', 'https://tracker.lppmunud.id/tracker/api');
   ```

---

## BAGIAN 7: Quick Reference

### URL Setup

| Component | URL |
|-----------|-----|
| Dashboard | http://tracker.lppmunud.id/tracker/dashboard/ |
| Login | http://tracker.lppmunud.id/tracker/dashboard/login.php |
| API | http://tracker.lppmunud.id/tracker/api/ |
| Diagnostics | http://tracker.lppmunud.id/tracker/diagnostics.php |

### Credentials

```
Dashboard:
- Username: admin
- Password: admin123 (change after first login)

MySQL (webhost):
- Host: localhost
- Database: tracker
- User: tracker_user
- Password: [sesuai setup]
```

### File Locations

| File | Location |
|------|----------|
| Dashboard Config | /dashboard/config/Config.php |
| API Config | /api/config/Database.php |
| Database Schema | /database/tracker_schema.sql |
| Agent Config | C:\Program Files\PCMonitorAgent\config.json |
| Agent Logs | C:\Windows\Logs\PCMonitorAgent\agent.log |
| Service | services.msc (search: PCMonitorAgent) |

### Support Contact

- **Issue**: Database tidak connect
  - Check Config.php credentials
  - Verify MySQL user permissions
  - Run diagnostics.php

- **Issue**: Agent tidak register
  - Check API URL di config.json
  - Verify internet connectivity
  - Check firewall rules

- **Issue**: Dashboard slow
  - Check MySQL query performance
  - Optimize database indices
  - Check webhost resource usage

---

**Last Updated:** March 27, 2026  
**System Version:** 1.0.0  
**Domain:** tracker.lppmunud.id
