# Onoxsoft WHMCS Plugin — Installation Guide

## Prerequisites

- WHMCS 8.x or 9.x installed
- Onoxsoft Panel 1.0+ with a valid API token
- PHP `curl` extension enabled on your WHMCS server

---

## Step 1 — Copy Module Files

Copy the `modules/servers/onox` directory into your WHMCS installation:

```bash
cp -r modules/servers/onox  /path/to/whmcs/modules/servers/
```

Set correct ownership:

```bash
chown -R www-data:www-data /path/to/whmcs/modules/servers/onox
chmod -R 755 /path/to/whmcs/modules/servers/onox
```

---

## Step 2 — Generate an Onoxsoft API Token

1. Log in to your Onoxsoft Panel as Administrator.
2. Navigate to **Admin → API Tokens → Create Token**.
3. Select abilities: `accounts:*` (or at minimum `accounts:create`, `accounts:suspend`, etc.)
4. Copy the generated token — you will only see it once.

---

## Step 3 — Add Onoxsoft as a WHMCS Server

1. WHMCS Admin → **Setup → Products/Services → Servers → Add New Server**
2. Fill in:
   - **Name**: Onoxsoft Production (any label)
   - **Hostname**: `panel.yourdomain.com` (no `https://`, no trailing slash)
   - **IP Address**: Your Onoxsoft server IP
   - **Username**: *(leave blank)*
   - **Password**: Paste your Onoxsoft API token here
   - **Module**: Select **Onoxsoft Panel**
   - **Secure** (HTTPS): ✓ Checked (recommended)
   - **Active**: ✓ Checked
3. Click **Test Connection** — you should see "Connection Successful".
4. Save.

---

## Step 4 — Create a Product Linked to Onoxsoft Panel

1. WHMCS Admin → **Setup → Products/Services → Products/Services → Create a New Product**
2. Under the **Module Settings** tab:
   - **Module Name**: Onoxsoft Panel
   - **Server Group**: select the server group containing your Onoxsoft server
   - **Onoxsoft Package Slug**: enter the exact slug from your Onoxsoft panel (e.g. `starter`)
   - Toggle DNS / SSL / welcome email options as desired
3. Save.

---

## Step 5 — Test

1. Place a test order for the product.
2. Manually accept the order in **Admin → Orders**.
3. Check **Admin → Utilities → Logs → Module Log** — you should see a successful `CreateAccount` entry.
4. Verify the account appeared in the Onoxsoft panel under **Admin → Accounts**.

---

## Step 6 — UsageUpdate Cron (Optional)

WHMCS runs a `UsageUpdate` cron nightly to sync disk/bandwidth.
Ensure the WHMCS cron is set up:

```bash
# Typical WHMCS cron (already configured if WHMCS is running normally)
*/5 * * * * php /path/to/whmcs/crons/cron.php
```

No additional configuration needed for `UsageUpdate` — it is triggered automatically.

---

## Upgrading

To upgrade the plugin:

1. Download the new version.
2. Back up the existing `modules/servers/onox` directory.
3. Overwrite with the new files (your configuration is stored in WHMCS database, not in plugin files).
4. Clear WHMCS template cache: **Admin → Utilities → System → Cleanup & Repair**.

---

## Troubleshooting

| Symptom                              | Fix                                                                  |
|--------------------------------------|----------------------------------------------------------------------|
| Test Connection fails                | Verify hostname (no `http://`), check API token, check firewall      |
| "Onoxsoft account ID not found"          | Account not yet provisioned — check Module Log for CreateAccount     |
| SSO button shows error               | API token may lack `accounts:read` ability; regenerate token         |
| Disk usage not updating              | Check WHMCS cron is running; verify `accounts:read` token ability    |
| Module not appearing in Module list  | Ensure files are in `whmcs/modules/servers/onox/` (not `onox/onox/`)|

---

## Packaging a Release ZIP

```bash
cd packages/whmcs-onox-plugin
zip -r onox-whmcs-plugin-$(cat version.txt).zip modules/ README.md INSTALL.md CHANGELOG.md version.txt
```

This produces e.g. `onox-whmcs-plugin-1.0.0.zip` for distribution.
