# SMS App - Deployment Guide

## Automated FTPS Deployment

Your SMS app is now set up for automatic deployment to your FTPS server.

### 📋 Deployment Methods

#### Option 1: Manual Deployment (One-Time)
```bash
cd D:\SMS
php deploy.php
```

**Output:**
```
[*] Connecting to FTPS server...
[✓] Connected successfully
[*] Starting deployment...
[↑] Uploading: index.php
[↑] Uploading: api.php
...
[✓] Deployment complete!
    Uploaded: 7 files
```

#### Option 2: Automatic Deployment (Git Hook)

After making changes, commit and push:
```bash
cd D:\SMS
git add .
git commit -m "Update SMS app"
```

The post-commit hook automatically runs `deploy.php` and uploads changes to your FTPS server.

### 🔧 Configuration

**File:** `deploy.php` (lines 7-10)
```php
$ftpHost = 'ftp.shanesmith.com.au';
$ftpPort = 21;
$ftpUser = 'sms@sms.praetorianx.au';
$ftpPass = '1Fuck3dP@ssw0rd';
$ftpPath = '/public_html/sms'; // Change to your remote path
```

### 🚫 Files Excluded from Deployment

The `.deployignore` file prevents these from uploading:
- `messages.json` — Local conversations (don't sync production data)
- `token_cache.json` — OAuth2 tokens
- `webhook_log.json` — Webhook debug logs
- `.env` — Environment variables
- `.git` — Git repository
- `deploy.php` — Deployment script itself

### ⚠️ Security Notes

1. **Credentials at risk** — Your FTP credentials are stored in `deploy.php`
   - Move to environment variables:
   ```php
   $ftpPass = getenv('FTP_PASSWORD');
   ```

2. **Git history** — If credentials are in commits, they're recoverable
   - Regenerate FTPS credentials immediately
   - Use `git filter-branch` to remove from history if needed

3. **Production safety** — Never include:
   - `messages.json` (user data)
   - `token_cache.json` (OAuth tokens)
   - Actual `.env` files with secrets

### 🔄 Workflow Example

```bash
# Make changes to your app
echo "// Updated code" >> api.php

# Stage changes
git add api.php

# Commit (triggers auto-deploy)
git commit -m "Improve error handling in API"

# Automatic deployment happens!
# Output shows upload progress
```

### ✅ Verify Deployment

Check your remote server:
```bash
# On remote server or via file manager
ls -la /public_html/sms/
```

Should show:
```
-rw-r--r-- index.php
-rw-r--r-- api.php
-rw-r--r-- TelstraAPI.php
-rw-r--r-- webhook.php
-rw-r--r-- app.js
-rw-r--r-- style.css
```

### 🐛 Troubleshooting

**"Failed to connect to FTPS server"**
- Check FTP host, port, and credentials
- Ensure FTPS port 21 is accessible
- Try telnet: `telnet ftp.shanesmith.com.au 21`

**"Login failed"**
- Verify username and password
- Check if account is active in cPanel/hosting panel

**"Permission denied uploading file"**
- Remote directory may need permissions: `chmod 755 /public_html/sms/`
- FTP user may not have write permissions

**Git hook not running**
- Make sure hook is executable: `chmod +x .git/hooks/post-commit`
- Windows: Use Git Bash, not Command Prompt

### 📊 Deploy Status Codes

- ✓ = File uploaded successfully
- ✗ = Upload failed (permission or connection issue)
- ⊘ = File skipped (in .deployignore)
- * = Directory created

### 🔐 Recommended Security Setup

1. **Change FTP password:**
   ```
   Use your hosting control panel (cPanel, Plesk, etc.)
   ```

2. **Use environment variables:**
   ```bash
   # In D:\SMS\.env (add to .gitignore)
   FTP_HOST=ftp.shanesmith.com.au
   FTP_USER=sms@sms.praetorianx.au
   FTP_PASS=YourNewPassword
   ```

3. **Load from .env:**
   ```php
   // In deploy.php
   require 'vendor/autoload.php'; // or use parse_ini_file()
   $ftpPass = getenv('FTP_PASS');
   ```

---

**Ready to deploy?** Run: `php deploy.php`
