Month: January 2017

27 Jan

How to know WHMCS Admin Username for local API call?

For calling WHMCS API’s internally from the WHMCS, we have a function named
localAPI. To call this function we have to pass
1)command; What api you would like to call.
2)data
3)admin user name of the WHMCS.

A sample API command UpdateClientProduct can be called as shown below.

        $command = 'UpdateClientProduct';
        $postData = array(
            'serviceid' => 11, // your service id
            'recurringamount' => 17,// recurring amount
        );
        //if WHMCS admin name is admin
        $adminUsername = "admin"; 
        $results = localAPI(
                       $command,
                       $postData, 
                       $adminUsername
        );

We hard coded the admin user name in the above code.
But hard coding the admin user name is a bad way of coding.
The code won’t work if admin username is changed or the code is uploaded
to another WHMCS where admin username is different.

So we can use below function to get the admin name.

use Illuminate\Database\Capsule\Manager as Capsule;
function getAdminUserName() {
    $adminData = Capsule::table('tbladmins')
            ->where('disabled', '=', 0)
            ->first();
    if (!empty($adminData))
        return $adminData->username;
    else
        die('No admin exist. Why So?');
}

So the API can be called as below.

  $command = 'UpdateClientProduct';
  $postData = array(
            'serviceid' => $product['service_id'],
            'recurringamount' => $deducted_amount,
  );
  $adminUsername = getAdminUserName();
  $results = localAPI(
                 $command, 
                 $postData, 
                $adminUsername
  );
16 Jan

Calling worldsteram.nl APIs from WHMCS

Calling worldsteram.nl APIs from WHMCS.

worldsteram.nl Provides API ID, and that must be used with API Calls.
So first of all create a file named worldstream.php and it must be
uploaded to the folder /modules/servers/worldstream.

<?php
function worldstream_ConfigOptions() {
    return array(
        'API ID' => array(
            'Type' => 'text',
            'Size' => '30',
            'Default' => '_API-ID_',
            'Description' => 'REplace _API-ID_ with your API ID',
        )
    );
}

/**
 The content that we will display on the page
[server.com]/clientarea.php?action=productdetails&id=[SERVICE_ID]
**/
function worldstream_ClientArea($vars) {
    //store your api id in config option and fetch it.
    $api_id = $vars['configoption2'];
    //create a custom field to store your server id 
    //and fetch it
    if(!empty($vars['customfields']['Server ID'])){
       $server_id = $vars['customfields']['Server ID'];
    } 
    
    
      if (empty($server_id)) {
        $return_array['status'] = 0;
        return array(
            'templatefile' => 'no_serverid',
            'vars' => array(
                'response' => $return_array
            )
        );
      }

      /*
          Call the function getMyServer to get
          server details.
      */
      $result_array = getMyServer($api_id, $server_id);
      return array(
                'templatefile' => 'clientarea',
                'vars' => array(
                    'response' => $result_array
                ),
      );
}

/**
 Let's call the API get_dedicated_list 
**/
function getMyServer($api_id, $server_id) {
    $url = 'https://www.customerpanel.nl/api.php';
    $data = array(
        "api_id" => $api_id,
        "method" => "get_dedicated_list"
    );

    $options = array(
        'CURLOPT_TIMEOUT' => '300',
    );
    $response = curlCall($url, $data, $options);
    $return = array();
    $result_array = json_decode($response);
    if ($result_array->StatusCode == 1) {
        unset($result_array->StatusCode);
        unset($result_array->StatusMessage);
        foreach ($result_array as $k => $value) {
            if ($value->Server_Id == $server_id) {
                $return['Status'] = 1;
                $return['Default_Password'] =
                    $value->Default_Password;
                $return['Main_IP'] = $value->Main_IP;
                $return['IPv6'] = isset($value->IPv6)
                    ? $value->IPv6 : "None";
                $return['Max_Datatraffic'] = 
                    $value->Max_Datatraffic;
                $return['Status'] = $value->Status;
                return $return;
            } else {
                continue;
            }
        }
    }
    $return['Status'] = 0;
    return $return;
}

Create a folder named templates in the path /modules/servers/worldstream.
Within that folder create a file named clientarea.tpl.
Then store the below contents to that file.

<div class="row">
    
    <div class="col-sm-12">
        <strong class="text-center">
               Server Details:
        </strong>
    </div>
</div>

<div class="row">
    
    <div class="col-sm-5 text-right">
        IPv4 Addresses:
    </div>
    <div class="col-sm-7 text-left">
       {$response['Main_IP']}
    </div>

</div>
<div class="row">
    
    <div class="col-sm-5 text-right">
       IPv6 Addresses:
    </div>
    <div class="col-sm-7 text-left">
      {$response['IPv6']}
    </div>
</div>

<div class="row">
    
    <div class="col-sm-5 text-right">
           Max. Datatraffic:
    </div>
    <div class="col-sm-7 text-left">
       {$response['Max_Datatraffic']}GB
    </div>
</div>

<div class="row">
    
    <div class="col-sm-5 text-right">
          Default Password:
    </div>
    <div class="col-sm-7 text-left">
          {$response['Default_Password']}
    </div>
</div>

<div class="row">
    
    <div class="col-sm-5 text-right">
          Status:
    </div>
    <div class="col-sm-7 text-left">
       {$response['Status']}
    </div>
</div>
10 Jan

How to do FTP auto login from Linux?

How to create a FTP auto login set up in Linux?

1)Go to your home folder.

cd /home/my-name

2)Crate a file named .netrc in your home folder.

And add a line as below.
machine [ftp.myserver.com] login [my-username] password [my-password]

Then save the file

3)Set permissions so that only owner can read the file.

chmod 0600 ~/.netrc

4)From shell just type
ftp [ftp.myserver.com] [port]

You are logged in!
It won’t ask any user name or password now.