Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


SolusVM/WHMCS IP Auditor
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

SolusVM/WHMCS IP Auditor

DamianDamian Member
edited February 2013 in Providers

I've noticed that, at times, when WHMCS will terminate a client, either auto-term or when we do it manually, the VPS container won't actually be removed from the node, and Solus still thinks it's an active product. Manually auditing WHMCS/Solus inventory accuracy is hellish, and there's not really any other automatic methods to determine if there are containers in Solus that are 'untracked' by WHMCS.

Obviously, giving out free product is Bad, so I've written this script to:

-retrieve a list of nodes from Solus
-retrieve a list of IPs by node from Solus
-on a per-IP basis, interface with the WHMCS DB to determine if WHMCS knows about the IP address
-generates a list of IPs that are not in WHMCS

Here's a screenshot of the output:
image

You can get it from:
https://github.com/damianharouff/solus-ip-audit

Be sure to read the README for basic setup and usage information.

«1

Comments

  • KuJoeKuJoe Member, Host Rep

    You rock again!

  • I'll have no use for this, but that script looks pretty clean and sexy, great job Damian.

  • KuJoeKuJoe Member, Host Rep

    Got an error in the middle of my list of IPs. :(

    PHP Notice: Undefined variable: badcount in /root/checkips.php on line 101

  • @KuJoe said: Got an error in the middle of my list of IPs. :(

    Looking at the code, he doesn't actually define the variable before using it..

    Could probably just add

    $badcount = 0; after he defines tempiplist to fix that.

  • Seems nifty, will check it out!

  • YAY! Node audits are boring anyway.

  • laaevlaaev Member
    edited February 2013

    Nice script, but I don't think it'll work well for hosts with VPS resellers because it won't detect VPS reseller's clients (end users) IP simply because those end-users of theirs will not be in WHMCS.

  • @CVPS_Kevin said: Nice script, but I don't think it'll work well for hosts with VPS resellers because it won't detect VPS reseller's clients (end users) IP simply because those end-users of theirs will not be in WHMCS.

    and that's what I just added in :)

    Only checks the username prefix so if resellers have the same prefix it'll be a no go. Stupid SolusVM Admin API has nothing to check the who's the reseller.

  • Line 96, missing ' to parse $ip.

    assignedips LIKE "%.$ip.%\n")');

    to

    assignedips LIKE "%'.$ip.'%\n")');

  • +1 for using PDO instead of mysql_*, -1 for not actually using PDO properly.

  • Thanks for the feedback, everyone!

    @KuJoe said: Got an error in the middle of my list of IPs. :(

    I updated it to define $badcount as a variable. I've put the update on git (or "pushed it to github" or whatever the correct terminology is); try now.

    @CVPS_Kevin said: Nice script, but I don't think it'll work well for hosts with VPS resellers because it won't detect VPS reseller's clients (end users) IP simply because those end-users of theirs will not be in WHMCS.

    Thanks for the info, did not know!

    @NickO said: Stupid SolusVM Admin API has nothing to check the who's the reseller.

    Might be able to use http://docs.solusvm.com/admin_api#list_reseller_usernames to get a list of usernames that are resellers.. not sure if that only returns the reseller's usernames, or if it also returns the reseller's client's usernames too. We don't have resellers to be able to test :(

    @Kenshin said: assignedips LIKE "%'.$ip.'%\n")');

    Thanks, I had actually fixed this last night and was trying to put it on git, but then the cable modem crapped out, and I then got tired of messing with it, so I went to bed.

    @NickM said: -1 for not actually using PDO properly.

    I will freely admit that I learned PDO through trial and error. What have I done wrong? Feel free to slap me around a bit.

  • @Damian said: "pushed it to github" or whatever the correct terminology is

    Made a commit and pushed it to master ;-)

  • @Damian
    You should have used prepare http://php.net/manual/en/pdo.prepare.php instead of inserting the variables directly.

  • @BronzeByte said: Made a commit and pushed it to master ;-)

    Thanks. I've used github quite a bit for using other people's software, but it's only recently that I have started to put my own things on it.

    @dnom said: You should have used prepare http://php.net/manual/en/pdo.prepare.php instead of inserting the variables directly.

    Thanks, additionally @Wintereise slapped me around a bit about it too, so I have a good idea of what I need to do. I will implement this this evening.

  • You should have used prepare http://php.net/manual/en/pdo.prepare.php instead of inserting the variables directly.

    It's on github so I think you can send him some changes as well.

  • @Corey said: It's on github so I think you can send him some changes as well.

    Indeed, however, I do need to learn the proper way, so i'd rather have people tell me "hey stupid, you did it wrong, here's the basic idea of what you need to do" than have it fixed for me.

  • An ignore list would be nice, I kinda have my own VMs that aren't in WHMCS. I think most other providers would have a couple too?

    Just wondering, does the check include secondary IPs or just the primary IP for the VM?

  • It will only lists IP's that are active/live/assigned via solusvm and not present on whmcs right? Or will it also list unassigned ips?

  • JacobJacob Member
    edited February 2013

    @Kenshin, 8 so far. :geek:

  • @Kenshin said: An ignore list would be nice, I kinda have my own VMs that aren't in WHMCS. I think most other providers would have a couple too?

    I thought about this too, since we also have VMs in Solus that aren't tracked in WHMCS. Haven't thought of a brainy way to make this happen, though.

    @Kenshin said: Just wondering, does the check include secondary IPs or just the primary IP for the VM?

    The Solus API call returns a list of all IPs in use by the nodeid.. this seems to get all of them, as it claims we have 1004 IPs in use, and that seems correct.

    @NHNahian said: It will only lists IP's that are active/live/assigned via solusvm and not present on whmcs right?

    Yes, it gets a list of all IPs that Solus thinks are in use, then compares them to the "dedicatedip" and "assignedips" fields on WHMCS, which are these fields that you see in WHMCS:

    image

  • You ROCK!

  • Yeah, I'll check this out now and let you know how goes.

  • Great work Damian! Works flawlessly :)

    @Kenshin said: An ignore list would be nice, I kinda have my own VMs that aren't in WHMCS. I think most other providers would have a couple too?

    +1

  • KenshinKenshin Member
    edited February 2013

    Quick hack, not the most efficient but it works.

    # Add to top of file
    $ignorelist = array('X.X.X.X', 'Y.Y.Y.Y');
    
    ......
            $iplist = array_merge($tempiplist[1], $iplist);
    }
    
    // Sort & Match Ignore IPs
    $tempiplist = array();
    sort($iplist);
    foreach ($iplist as $ip) {
      $ignore = 0;
      foreach ($ignorelist as $ignoreip) {
        if ($ip == $ignoreip) { $ignore = 1; }
      }
      if ($ignore == 0) { array_push($tempiplist, $ip); }
    }
    $iplist = $tempiplist;
    
    print "Found " . count($iplist) . " IP addresses." . PHP_EOL;
    ......
    

    Also, minor hack on the assignedip matching, I had one WHMCS assigned IP record without a newline, didn't match, so I added a match for last line.

    assignedips LIKE "%'.$ip.'%\n" OR assignedips LIKE "%'.$ip.'$")');

    Though in all honesty, the SQL query is pretty inefficient since it's being run repeatedly per IP. Probably would have been better to do a single grab of all the records and do 2 way matching between the two lists.

  • Awesome thanks for making this!

  • HassanHassan Member, Patron Provider
    edited February 2013

    Any idea why I get this:

    php audit.php

    Parse error: syntax error, unexpected '$postfields' (T_VARIABLE) in /home/audit.php on line 34

  • Unexpected? Maybe declaring the array first would help, weird. ( $postfields = array(); )

    Try updating it first though.

  • Kinda got the PDO prepare thing worked on... had a bunch of other fires to put out.

    @Kenshin said: Also, minor hack on the assignedip matching, I had one WHMCS assigned IP record without a newline, didn't match, so I added a match for last line.

    Was this for a single IP?

    @Kenshin said: Though in all honesty, the SQL query is pretty inefficient since it's being run repeatedly per IP. Probably would have been better to do a single grab of all the records and do 2 way matching between the two lists.

    Indeed, I considered this, however, I chose to query for every IP instead of using PHP for sorting. Reason was that, logically, MySQL should be better at answering queries with data, since that's what it's built for, than PHP would be at sorting data. I don't know if it's truly slower.

    On the other hand, I don't expect to run this more than every few weeks, or monthly or so, and:

    Found 11 nodes.
    Found 983 IP addresses.
    
    The following IP addresses are not in WHMCS: 
    
    27 addresses found.
    
    
    real    0m6.815s
    user    0m0.278s
    sys 0m0.132s
    

    Is fast enough for me :)

    @Hassan said: Any idea why I get this:

    Did you download this from github via git, or copy/pasted out of browser? What version of PHP are you using? You can get this information by running: php -v

  • HassanHassan Member, Patron Provider
    edited February 2013

    @Wintereise said: Unexpected? Maybe declaring the array first would help, weird. ( $postfields = array(); )

    Try updating it first though.

    Didn't work :/

    @Damian
    Copied+pasted from the browser

    php -v

    PHP 5.4.12 (cli) (built: Feb 27 2013 14:30:00)
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd.

  • Now add a feature so it can check the vserverID and IP match, cause I know mine has a lot that do not match correctly.

Sign In or Register to comment.