UpCloudLtd / upcloud-whmcs-module

A module for integrating UpCloud's services with WHMCS web hosting platform
MIT License
9 stars 11 forks source link

Server title and hostname empty on create #46

Open scop opened 1 week ago

scop commented 1 week ago

When a server (vm) create is attempted using the UpCloud API, the title and hostname are sent over as empty, causing the creation to fail.

Module logs shows request payload starting with

server
{
    "server": {
        "metadata": "yes",
        "zone": "fi-hel2",
        "title": "",
        "hostname": "",

Both title and hostname must be populated.

This quick hack works around the issue, but I'm not sure if it's the appropriate fix.

--- lib/vmManager.php
+++ lib/vmManager.php
@@ -64,3 +64,3 @@
     $user_data = $this->params['customfields']['userData'];
-    $Hostname = $this->params['domain'] ?? 'client' . $this->params['serviceid'] . '.' . $_SERVER['SERVER_NAME'];
+    $Hostname = 'client' . $this->params['serviceid'] . '.' . $_SERVER['SERVER_NAME'];
     $sshkey = empty($sshkey) ? "na" : $sshkey;

I.e. $this->params['domain'] ?? was removed.

adityawbwce commented 6 days ago

Change the line number #65 value from $Hostname = $this->params['domain'] ?? 'client' . $this->params['serviceid'] . '.' . $_SERVER['SERVER_NAME']; to $Hostname = !empty($this->params['domain']) ? $this->params['domain'] : 'client' . $this->params['serviceid'] . '.' . $_SERVER['SERVER_NAME'];