Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenefvdm committed Oct 26, 2022
1 parent ef5118f commit 3623ac8
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 100 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Update Changelog"

on:
release:
types: [released]

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: main

- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
5 changes: 5 additions & 0 deletions HOWTO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Module logging

`logModuleCall($module, $action, $requestString, $responseData, $processedData, $replaceVars);`

See https://developers.whmcs.com/provisioning-modules/module-logging/
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,32 @@ A new package is applied to the service. If the package is linked to an API, the

# Testing

Run the following command to test:
`./vendor/bin/pest`

./vendor/bin/pest
If you want to run individual tests, append `->only();` to each test.

If you want to test individual tests, append this to the end of a test `->only();`.
To test custom API actions, use a script such as the following:

`sh .scp updateclientaddon.php;./vendor/bin/pest`

The `.scp` file should have a copy command, e.g.:

```bash
#!/bin/bash
echo "Present Working Directory:"
pwd
echo "Copying $1 to WHMCS install directory"

cp includes/api/$1 ../whmcs/includes/api
echo "Done."
ls -la ../whmcs/includes/api/$1
```

## No errors on API actions but not working

API actions are difficult to troubleshoot if you don't observe the server log file. Only some exceptions e.g. model problems will be caught by the Try Catch block. So help tail your server log file. For example, if you're using Laravel's Valet's NGinx server do this:

`tail -f ~/.valet/Log/nginx-error.log`

## Invalid IP 127.0.0.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
if ($client) {

$apiresults = [
"result" => "success",
"message" => "ok",
"result" => "success",
'clientid' => $client->id,
];

Expand All @@ -35,8 +34,7 @@

if ($client) {
$apiresults = [
"result" => "success",
"message" => "ok",
"result" => "success",
'clientid' => $client->id,
];

Expand Down
32 changes: 32 additions & 0 deletions includes/api/setregistrarvalue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php // WARNING! Ensure <?php is the very first line of this file

use WHMCS\Database\Capsule;
use \WHMCS\Module\RegistrarSetting;

if (!defined("WHMCS"))
die("This file cannot be accessed directly");

try {
logModuleCall("Custom action: SetRegistrarValue", "Init", $_REQUEST, "", "", "");

$registrar = $_REQUEST['registrar'];
$value = $_REQUEST['value'];

$setting = RegistrarSetting::where('registrar', '=', $registrar)->first();
$setting->value = $value;
$setting->save();

$apiresults = [
"result" => "success",
"id" => $setting->id,
"registrar" => $setting->registrar,
"setting" => $setting->setting,
"value" => $setting->value,
];
} catch (Exception $e) {
$apiresults = [
"result" => "error",
"message" => $e->getMessage(),
"log" => $log,
];
}
49 changes: 49 additions & 0 deletions includes/api/updateclientaddon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php // WARNING! Ensure <?php is the very first line of this file

use WHMCS\Database\Capsule;

if (!defined("WHMCS"))
die("This file cannot be accessed directly");

try {
logModuleCall("Add custom API actions", "Start", $_REQUEST, "", "", "");

$apiActions = $_REQUEST['apis'];

$log .= "Requested new API actions: " . implode('|', $apiActions) . "\n";

$apiRoles = Capsule::table('tblapi_roles')
->first();

$currentPermissions = $apiRoles->permissions;

// Remove the last brace...
$updatedPermissions = str_replace("}", "", $currentPermissions);

// ...then check and remove the custom API action
foreach ($apiActions as $apiAction) {
$updatedPermissions = str_replace(",\"$apiAction\":1", "", $updatedPermissions);
// now add it again...
$updatedPermissions .= ",\"$apiAction\":1";
}
$updatedPermissions .= "}";

$apiRoles = Capsule::table('tblapi_roles');
$apiRoles->update(
[
'permissions' => $updatedPermissions
]
);

$apiresults = [
"result" => "success",
"log" => $log,
"permissions" => $updatedPermissions,
];
} catch (Exception $e) {
$apiresults = [
"result" => "error",
"message" => $e->getMessage(),
"log" => $log,
];
}
Loading

0 comments on commit 3623ac8

Please sign in to comment.