Examples of cPanel License API in BASH & curl

I have a need to maintain my list of cPanel licenses. This is a dull thing to do as these are in the hundreds. If you have to do it by hand it is a real pain in the 4R53 – so I have automated it. I had to write a license killer. It works, but it is clunky. I have not shared it here as I am no developer. It serves my needs, however, and it uses the snippets below for the key interactions.

The key parts to the logic involved are as follows:

  1. For each License we need an IP to check;
  2. See if it is listening on port 2087 for the WHM login;
  3. If it is not – make sure it’s not got another license via cPanel (for example CloudLinux).

The logic is very language specific – however, nmap -p 2087 $FOO, and some BASH work for me. But the key parts are the API calls – so below are some little nuggets to help you on your way. Bon voyage.

FIND IP ADDRESSES OF EACH CPANEL LICENSE

curl -u $CPANELUSER:$CPANELPASSWORD “https://manage2.cpanel.net/XMLlicenseInfo.cgi?expired=0″ |sed ‘s/.*ip=\”//’ |sed ‘s/\” lice.*//’ |sed ‘s/.*>//’|sed ‘s/<.*//’

Which will a return of all of the IP addresses you have licenses for, used or otherwise.

CHECK AN IP AGAINST A SPECIFIC LICENSE TYPE

curl -u $CPANELUSER:$CPANELPASSWORD “https://manage2.cpanel.net/XMLlicenseInfo.cgi?package=$” |grep $FOO

Where $PACKAGE is the name given to that specific package group (say for example CLOUD-LINUX-LICENSES)

FIGURE OUT A CPANEL LICENSE FROM AN IP ADDRESS

curl -u $CPANELUSER:$CPANELPASSWORD “https://manage2.cpanel.net/XMLlookup.cgi?ip=$FOO” | sed ‘s/.*id=\”//’ | sed ‘s/\”.*//’

Where $foo is the address you are looking to find out the license number for.

TERMINATE A SPECIFIC CPANEL LICENSE

curl -u $CPANELUSER:$CPANELPASSWORD “https://manage2.cpanel.net/XMLlicenseExpire.cgi?liscid=$LICENSE&reason=Automated%20cancellation&expcode=normal”

Where you can change the message to be as you wish – just be sure to keep it all %20 for space, and where $LICENSE is the number you are looking to hit over the head.

Happy days.

I hope you find that a useful starting place – or – “hello future me – I a bet you are glad you wrote those down!” … which is what most of these are.

As always – if you have more – please do share.

2 Responses to “Examples of cPanel License API in BASH & curl

  • how about adding license detection according to ip to bash script? :)

  • Thank you for your suggestion eth.

    These are understandably fragments of usefulness.

    When culling licenses when VM’s are retired from the pool we do indeed involve a bunch of logic.

    The logic does a bunch of things including forming a pool of IP’s, nmap scanning, checking to see if they are cPanel, checking to see if we have a license for CloudLinux through cPanel – and building a list for further action of all of those IP’s with a license on an IP and not running cPanel.

    So yeah, that kind of thing and more is alive and well… and if I can implement it I am damned sure anyone can.

    The above, as with so many of my posts, are intended as an aide memoir – and to assist others if they face similar.

    Please feel free to share back your offerings too : )

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this:
Skip to toolbar