Aldryic C'boas
The Pony
WARNING: _NEVER_ under any circumstance run untested code on your production deployments. WHMCS will issue you a development license if requested: _ALWAYS_ test unknown code in a development environment before use on production servers.
Those of you running WHMCS know that you can view the last login of any given client - but I found it more helpful to have a login history for individual clients. Tracking duplicate accounts, compromises; there are plenty of reasons why you would want more than simply the last IP someone has logged in with.
For those interested, extending login tracking is quite simple. To start, login to your SQLd, and run the following query:
CREATE TABLE tbllogins (clientid INT(10), ip VARCHAR(15), date TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE INDEX idx1 ON tbllogins(clientid); CREATE INDEX idx2 ON tbllogins(ip); CREATE INDEX idx3 ON tbllogins(date);
You can use DESCRIBE tbllogins; after to confirm successful creation, and should see the following:
With this done, you need merely add the following script to your /WHMCS/includes/hooks/ directory; I've used the filename logins.php:
<?php
function track_logins($vars) {
mysql_query("INSERT INTO tbllogins (clientid, ip) VALUES ('". $vars['userid'] ."', '". $_SERVER['REMOTE_ADDR'] ."')") or die(mysql_error());
// Trim logins to 30 latest
mysql_query("DELETE FROM tbllogins WHERE clientid = '". $vars['userid'] ."' AND date NOT IN (SELECT * FROM (SELECT date FROM tbllogins WHERE clientid = '". $vars['userid'] ."' ORDER BY date DESC LIMIT 30) alias)");
}
add_hook("ClientLogin",1,"track_logins");
?>
(EDIT: Yikes, looks like IPB didn't want to add the linebreaks. I've posted this same script at http://pastebin.com/YVm2bPmz for easier reading)
With this added, the last 30 logins of each client will be stored. You can change the number of logins you wish to keep per client simply by changing the LIMIT 30 to the numeric of your choice.
Give some time for the table to populate, and you will be able to see what IPs a client has logged in from:
SELECT ip, date FROM tbllogins WHERE clientid = '123';
as well as which clients are logging in from a particular IP:
SELECT clientid, date FROM tbllogins WHERE ip = '1.2.3.4';
Those of you that are comfortable with editing .tpl files can even make this a nice pop-up report in the Admin area.
Disclaimer: Due to how WHMCS hooks operate, using the `Login as Client` function WILL add that administrator's IP to the client login history.
Those of you running WHMCS know that you can view the last login of any given client - but I found it more helpful to have a login history for individual clients. Tracking duplicate accounts, compromises; there are plenty of reasons why you would want more than simply the last IP someone has logged in with.
For those interested, extending login tracking is quite simple. To start, login to your SQLd, and run the following query:
CREATE TABLE tbllogins (clientid INT(10), ip VARCHAR(15), date TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CREATE INDEX idx1 ON tbllogins(clientid); CREATE INDEX idx2 ON tbllogins(ip); CREATE INDEX idx3 ON tbllogins(date);
You can use DESCRIBE tbllogins; after to confirm successful creation, and should see the following:

With this done, you need merely add the following script to your /WHMCS/includes/hooks/ directory; I've used the filename logins.php:
<?php
function track_logins($vars) {
mysql_query("INSERT INTO tbllogins (clientid, ip) VALUES ('". $vars['userid'] ."', '". $_SERVER['REMOTE_ADDR'] ."')") or die(mysql_error());
// Trim logins to 30 latest
mysql_query("DELETE FROM tbllogins WHERE clientid = '". $vars['userid'] ."' AND date NOT IN (SELECT * FROM (SELECT date FROM tbllogins WHERE clientid = '". $vars['userid'] ."' ORDER BY date DESC LIMIT 30) alias)");
}
add_hook("ClientLogin",1,"track_logins");
?>
(EDIT: Yikes, looks like IPB didn't want to add the linebreaks. I've posted this same script at http://pastebin.com/YVm2bPmz for easier reading)
With this added, the last 30 logins of each client will be stored. You can change the number of logins you wish to keep per client simply by changing the LIMIT 30 to the numeric of your choice.
Give some time for the table to populate, and you will be able to see what IPs a client has logged in from:
SELECT ip, date FROM tbllogins WHERE clientid = '123';
as well as which clients are logging in from a particular IP:
SELECT clientid, date FROM tbllogins WHERE ip = '1.2.3.4';
Those of you that are comfortable with editing .tpl files can even make this a nice pop-up report in the Admin area.
Disclaimer: Due to how WHMCS hooks operate, using the `Login as Client` function WILL add that administrator's IP to the client login history.
Last edited by a moderator: