Archive for the "PHP" Category

Extracting Credit Card data from Ubersmith

So we recently purchased a number of companies who use Ubersmith as their billing system.

As I’ve mentioned before, we use WHMCS.  Ubersmith weren’t overly helpful with extracting our customers’ credit card data, so I had to spend some time playing about with ubersmith.  As it turned out, it wasn’t hard at all to pull credit card data out.  Most of my required code was in re-encrypting it to store it back into the database with a encryption format so we can pull it out with our standard merge scripts to import into our WHMCS install.

First we want a table to store the data in.

I then placed the below script in the ubersmith web root.  And popped a copy of lib_crypt.php (from https://sourceforge.net/projects/warp-cms/files/smart-framework/ library) into the parent directory – just so it wasn’t polluting the ubersmith install.

After this, it was a simple matter of running “php extractcards.php ubsermith.panel.url.here”, and all cards were saved into the whmcs_merge_carddata table, ready for our merge scripts.

 

Extending the WHMCS API and Fetching Invoice PDF’s

At work, we’re currently doing a FULL rebuild of our customer portal.  Part of the requirements of the system are that our staff must only be logging into one place.  At present they have to be logged into the portal AND WHMCS.  So in v2, we have to basically rebuild 90% of the WHMCS admin interface into our portal, and use the WHMCS API for manipulating data stored in WHMCS.  (We’re also adding a MongoDB caching layer for read access, and then using hooks in WHMCS to update the cache whenever data is modified).

We found a few ‘holes’ (read: missing functionality) in the WHMCS API, so had to see about adding an API to sit alongside WHMCS.  We did ask WHMCS how to go about writing custom API functions to use within the WHMCS API framework, but they came back saying this was not possible.  A fair bit of Googling around, and I managed to find a blog post detailing how to write custom API functions for WHMCS.  With a bit of work, we now have a nice basis for writing WHMCS API modules.  The first one I built for testing was for pulling Invoice PDF’s, which is not currently available in the WHMCS API.

And Voila, a simple WHMCS call such as:

Returned Variables

Then it’s a simple matter to go base64_decode($jsondata->pdf) (assuming you used json format and had done a json_decode() on the returned data…), and you have the binary data for the PDF, ready to save to disk, or pass back out to the user via HTTP.

 

Creating RRD files in PHP

I was looking for a way to store (and graph) data for all of our physical servers.  Now sure, we could install SNMP on every machine and just use MRTG, but as a lot of them are leased by clients, I wanted something out of band which will ‘just work’.  We have a very nice IMPI based system which we use for provisioning every server on the network.  That seemed like a good way to go!  Pulling all the fun info via IPMI is really easy:

That gives us quite a useful amount of info!  Though for our purposes, we’ll ignore everything except the first three columns.

Handling that in PHP, we do something like the following:

Then we need to think about the RRD’s.  We need to check if we HAVE one, if so we put the data in.  Or we generate a new RRD and put the data in.

What we’re doing above is creating the datastore, and creating Round Robin Archives for Min, Max, and Average. Storing a sample every 5 minutes for 24 hours (288 samples), a sample every hour for 7 days, and a sample every day for a year.

Now we need to store our data.  That’s the easy part!

And we’re now storing data.  Note the use of the shell_exec.  At least in PHP5.4 on Ubuntu, rrd_update and rrd_graph do not work.

But that’s not much fun if we can’t display the graphs when we need them!

I could write them out to file and then include them from static HTML etc.  But I’d rather have it all dynamically generated.  I have a php file which generates the HTML table referencing the graphs:

And then the actual graphing script:

And now it’s working very nicely indeed!