pterodactyl / whmcs

WHMCS Module for Pterodactyl (v0.7.3 and higher)
MIT License
185 stars 77 forks source link

IP Address #102

Closed Talhazzers closed 2 years ago

Talhazzers commented 2 years ago

Can the dedicatedip filled in the WHMCS service properties in the createaccount function npeOLl00PB9tOpIe ?

ConanDoyl commented 2 years ago

Yes it's possible i've added a function to the WHMCS Module that will add the IP and the Port to the Dedicated IP Field in WHMCS. So we can find a Service faster by their IP/Port.

function pterodactyl_CreateAccount(array $params) {
(.....)
        $server = pterodactyl_API($params, 'servers', $serverData, 'POST');

        if($server['status_code'] === 400) throw new Exception('Couldn\'t find any nodes satisfying the request.');
        if($server['status_code'] !== 201) throw new Exception('Failed to create the server, received the error code: ' . $server['status_code'] . '. Enable module debug log for more info.');

        unset($params['password']);

$_nodeID = $server["attributes"]["node"];
        $_allocationID = $server["attributes"]["allocation"];

        $_allocations = pterodactyl_API($params, 'nodes/' . $_nodeID . '/allocations');

        $_pages = $_allocations['meta']['pagination']['total_pages'];
        $_currentPage = $_allocations['meta']['pagination']['current_page'];

        $_IP = "";
        $_Port = "";

            if ($_pages == 1){
                foreach($_allocations['data'] as $alloc){
                    if ($alloc['attributes']['id'] == $_allocationID){

                            $_IP = $alloc['attributes']['ip'];
                            $_Port = $alloc['attributes']['port'];
                        }
                }
            } else {
                for($_currentPage =1; $_currentPage <= $_pages; $_currentPage++){
                    $_allocations_Temp = pterodactyl_API($params, 'nodes/' . $_nodeID . '/allocations?page=' . $_currentPage);
                    foreach($_allocations_Temp['data'] as $alloc2){
                        if ($alloc2['attributes']['id'] == $_allocationID){

                            $_IP = $alloc2['attributes']['ip'];
                            $_Port = $alloc2['attributes']['port'];
                        }
                    }
                }

            }

        try {
            $query = Capsule::table('tblhosting')->where('id', $params['serviceid'])->where('userid', $params['userid'])->update(array('dedicatedip' => $_IP . ":" . $_Port));
        } catch (Exception $e) { return $e->getMessage() . "<br />" . $e->getTraceAsString(); }

I know it's maybe not the best solution but its working.

Talhazzers commented 2 years ago

Yes it's possible i've added a function to the WHMCS Module that will add the IP and the Port to the Dedicated IP Field in WHMCS. So we can find a Service faster by their IP/Port.

function pterodactyl_CreateAccount(array $params) {
(.....)
        $server = pterodactyl_API($params, 'servers', $serverData, 'POST');

        if($server['status_code'] === 400) throw new Exception('Couldn\'t find any nodes satisfying the request.');
        if($server['status_code'] !== 201) throw new Exception('Failed to create the server, received the error code: ' . $server['status_code'] . '. Enable module debug log for more info.');

        unset($params['password']);

$_nodeID = $server["attributes"]["node"];
      $_allocationID = $server["attributes"]["allocation"];

      $_allocations = pterodactyl_API($params, 'nodes/' . $_nodeID . '/allocations');

      $_pages = $_allocations['meta']['pagination']['total_pages'];
      $_currentPage = $_allocations['meta']['pagination']['current_page'];

      $_IP = "";
      $_Port = "";

          if ($_pages == 1){
              foreach($_allocations['data'] as $alloc){
                  if ($alloc['attributes']['id'] == $_allocationID){

                          $_IP = $alloc['attributes']['ip'];
                          $_Port = $alloc['attributes']['port'];
                      }
              }
          } else {
              for($_currentPage =1; $_currentPage <= $_pages; $_currentPage++){
                  $_allocations_Temp = pterodactyl_API($params, 'nodes/' . $_nodeID . '/allocations?page=' . $_currentPage);
                  foreach($_allocations_Temp['data'] as $alloc2){
                      if ($alloc2['attributes']['id'] == $_allocationID){

                          $_IP = $alloc2['attributes']['ip'];
                          $_Port = $alloc2['attributes']['port'];
                      }
                  }
              }

          }

        try {
          $query = Capsule::table('tblhosting')->where('id', $params['serviceid'])->where('userid', $params['userid'])->update(array('dedicatedip' => $_IP . ":" . $_Port));
      } catch (Exception $e) { return $e->getMessage() . "<br />" . $e->getTraceAsString(); }

I know it's maybe not the best solution but its working.

I guess this is not compatible with version 0.7. Do you have a version compatible with 0.7?

ConanDoyl commented 2 years ago

It is i've tested it in 07 first and later i upgraded to 1.x and its still working.

Talhazzers commented 2 years ago

I tested this code in 1.X but it is returning ":", IP and port is empty

ConanDoyl commented 2 years ago

Have you updated your API Permission? because you need the permission for the Allocations the module says it doesn't need it by default but this extension need it.

Talhazzers commented 2 years ago

Thanks, working.