Archive for the "Uncategorized" 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 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”, and all cards were saved into the whmcs_merge_carddata table, ready for our merge scripts.


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!



WHMCS Password Encryption and Decryption

So at my work, we just bought out a couple of other hosting companies, and needed to bring all their customer data from WHMCS into our WHMCS install.

We figured ‘no problems, WHMCS has a merge tool’.   Yeah, that didn’t work at all!

So.  We sat down and wrote one!

Where things almost came unstuck, was transferring passwords.  WHMCS stores all manner of passwords – customer passwords, hosting account passwords, even server passwords.  For that matter, they also store credit card details.  And they’re all stored Encrypted!

After discovering this helpful class, and mucking about for a few hours working out how they use the hash, I was ready to go! Using it is a breeze.  You just need your cc_encryption_hash from your WHMCS configuration.php, and off you go.

If you were to run this code, it would display ‘MyPassword’.

So in my case, transferring between two WHMCS installations, I use a code block like the following:

Assuming you had the encrypted password from the old system in $oldpass, you will now have the password for the new system in $newpass.

Hopefully this helps someone! Google was no help at all for re-encrypting the password!