|
| 1 | +--- |
| 2 | +name: license-cli-script |
| 3 | +description: Creates a new CLI script in bin/ for Softaculous/Webuzo/Virtualizor/SiteMush license operations. Use when user says 'add CLI script', 'new bin command', 'create license tool', or 'add a script to bin/'. Do NOT use for src/ classes, test files, or Plugin hooks. |
| 4 | +--- |
| 5 | +# License CLI Script |
| 6 | + |
| 7 | +## Critical |
| 8 | + |
| 9 | +- All CLI scripts go in `bin/` — never in `src/` or `tests/`. |
| 10 | +- Every script MUST start with `#!/usr/bin/env php` shebang line. |
| 11 | +- Require the parent MyAdmin bootstrap: `require_once __DIR__.'/../../../../include/functions.inc.php';` |
| 12 | +- Use credential constants `SOFTACULOUS_USERNAME` / `SOFTACULOUS_PASSWORD` (or `WEBUZO_USERNAME` / `WEBUZO_PASSWORD` for Webuzo-specific scripts). Never hardcode credentials. |
| 13 | +- CLI arguments come from `$_SERVER['argv']`, not `$argc`/`$argv`. |
| 14 | +- Never add argument parsing libraries or option parsers — keep scripts minimal. |
| 15 | + |
| 16 | +## Instructions |
| 17 | + |
| 18 | +1. **Determine the API method to call.** Check `src/SoftaculousNOC.php` for available methods. Common ones: |
| 19 | + - `licenses($key, $ip)` — list/search licenses |
| 20 | + - `cancel($key, $ip)` — cancel a license |
| 21 | + - `refund($actid)` — refund a license |
| 22 | + - `licenselogs($key)` — get license logs |
| 23 | + - `invoicedetails($invoid)` — get invoice details |
| 24 | + - `editips($lid, $ips)` — change license IP |
| 25 | + - `autorenewals()` / `addautorenewal($key)` / `removeautorenewal($key)` |
| 26 | + - Prefixed variants: `webuzo_*`, `virt_*`, `sitemush_*` |
| 27 | + |
| 28 | + Verify the method exists and note its parameters before proceeding. |
| 29 | + |
| 30 | +2. **Create the script file.** Name it `bin/<name>.php` using snake_case. Match the naming pattern of existing scripts: |
| 31 | + - `bin/cancel_by_ip.php`, `bin/cancel_by_key.php`, `bin/license_by_ip.php` |
| 32 | + - `bin/license_logs.php`, `bin/license_refund.php`, `bin/invoice_details.php` |
| 33 | + - `bin/licenses.php`, `bin/update_data.php` |
| 34 | + |
| 35 | + Verify the filename does not already exist in `bin/`. |
| 36 | + |
| 37 | +3. **Write the script** following this exact template: |
| 38 | + |
| 39 | +```php |
| 40 | +#!/usr/bin/env php |
| 41 | +<?php |
| 42 | + |
| 43 | +require_once __DIR__.'/../../../../include/functions.inc.php'; |
| 44 | + |
| 45 | +$noc = new \Detain\MyAdminSoftaculous\SoftaculousNOC(SOFTACULOUS_USERNAME, SOFTACULOUS_PASSWORD); |
| 46 | + |
| 47 | +print_r($noc->methodName($_SERVER['argv'][1])); |
| 48 | +print_r($noc->response); |
| 49 | + |
| 50 | +//$GLOBALS['tf']->session->destroy(); |
| 51 | +``` |
| 52 | + |
| 53 | + Key rules: |
| 54 | + - Use fully-qualified class name `\Detain\MyAdminSoftaculous\SoftaculousNOC` (no `use` statement). |
| 55 | + - If the method returns the result directly (like `licenses()`), just `print_r()` the return value — skip `print_r($noc->response)`. See `bin/licenses.php` for this pattern. |
| 56 | + - If the method requires side-effect inspection, print both the return value AND `$noc->response` (see `bin/cancel_by_key.php`, `bin/license_refund.php`). |
| 57 | + - CLI arguments map positionally: `$_SERVER['argv'][1]` is the first arg, `$_SERVER['argv'][2]` is the second, etc. |
| 58 | + - Keep the commented-out `$GLOBALS['tf']->session->destroy();` line at the bottom — this is the project convention. |
| 59 | + |
| 60 | +4. **Verify the script.** Run `php -l bin/<name>.php` to check for syntax errors. |
| 61 | + |
| 62 | +## Examples |
| 63 | + |
| 64 | +### User says: "Add a CLI script to check auto-renewals for a license key" |
| 65 | + |
| 66 | +**Actions:** |
| 67 | +1. Confirm `autorenewals($key)` exists in `src/SoftaculousNOC.php`. |
| 68 | +2. Create a new file in `bin/` (e.g., `bin/auto_renewals.php`): |
| 69 | + |
| 70 | +```php |
| 71 | +#!/usr/bin/env php |
| 72 | +<?php |
| 73 | + |
| 74 | +require_once __DIR__.'/../../../../include/functions.inc.php'; |
| 75 | + |
| 76 | +$noc = new \Detain\MyAdminSoftaculous\SoftaculousNOC(SOFTACULOUS_USERNAME, SOFTACULOUS_PASSWORD); |
| 77 | + |
| 78 | +print_r($noc->autorenewals($_SERVER['argv'][1])); |
| 79 | +print_r($noc->response); |
| 80 | + |
| 81 | +//$GLOBALS['tf']->session->destroy(); |
| 82 | +``` |
| 83 | + |
| 84 | +3. Run `php -l` on the new file — no errors. |
| 85 | + |
| 86 | +**Result:** New script in `bin/` — usage: `php bin/auto_renewals.php <license_key>` |
| 87 | + |
| 88 | +### User says: "Create a script to edit IPs on a Virtualizor license" |
| 89 | + |
| 90 | +**Actions:** |
| 91 | +1. Confirm `virt_editips($lid, $ips)` exists in `src/SoftaculousNOC.php`. |
| 92 | +2. Create a new file in `bin/` (e.g., `bin/virt_edit_ips.php`): |
| 93 | + |
| 94 | +```php |
| 95 | +#!/usr/bin/env php |
| 96 | +<?php |
| 97 | + |
| 98 | +require_once __DIR__.'/../../../../include/functions.inc.php'; |
| 99 | + |
| 100 | +$noc = new \Detain\MyAdminSoftaculous\SoftaculousNOC(SOFTACULOUS_USERNAME, SOFTACULOUS_PASSWORD); |
| 101 | + |
| 102 | +print_r($noc->virt_editips($_SERVER['argv'][1], $_SERVER['argv'][2])); |
| 103 | +print_r($noc->response); |
| 104 | + |
| 105 | +//$GLOBALS['tf']->session->destroy(); |
| 106 | +``` |
| 107 | + |
| 108 | +3. Run `php -l` on the new file — no errors. |
| 109 | + |
| 110 | +**Result:** New script in `bin/` — usage: `php bin/virt_edit_ips.php <license_id> <new_ip>` |
| 111 | + |
| 112 | +## Common Issues |
| 113 | + |
| 114 | +- **`PHP Fatal error: Uncaught Error: Undefined constant "SOFTACULOUS_USERNAME"`**: The `functions.inc.php` path is wrong. The `bin/` scripts use `__DIR__.'/../../../../include/functions.inc.php'` because the package is installed at `vendor/detain/myadmin-softaculous-licensing/`. Count the directory levels: `bin/` → package root → `detain/` → `vendor/` → project root → `include/`. Verify with `ls $(dirname bin/new_script.php)/../../../../include/functions.inc.php`. |
| 115 | + |
| 116 | +- **`Undefined offset: 1` when running the script**: The user forgot to pass a CLI argument. The existing scripts do not validate arguments — this is intentional to keep them minimal. Do not add argument validation unless the user specifically asks for it. |
| 117 | + |
| 118 | +- **Script runs but prints empty output**: Check `$noc->response` — the API may have returned an error. Also verify the credential constants are defined and non-empty in the MyAdmin configuration. |
| 119 | + |
| 120 | +- **Using Webuzo credentials for Webuzo methods**: If calling `webuzo_*` methods, use `WEBUZO_USERNAME` and `WEBUZO_PASSWORD` instead of the Softaculous constants. Check `tests/.env.example` for the full list of expected credential constants. |
0 commit comments