Jump to content

Alert login client


hebergeni

Recommended Posts

Here you go. Save this as a php file in whmcs/includes/hooks. Change the 'adminuser' to be your username (or another full admin)

<?php
/* 
Client area login notification for WHMCS
Developed by http://www.whmcsguru.com
*/

use Illuminate\Database\Capsule\Manager as Capsule;
function hook_client_login_notify($vars)
{
$userid = $vars['userid'];

send_login_notify($userid);
}

function send_login_notify($userid)
{
$ip = $_SERVER['REMOTE_ADDR'] ;
$hostname = gethostbyaddr($ip);
$userinfo = Capsule::table('tblclients')->select('firstname', 'lastname')->WHERE('id', $userid)->get();
//greet them
foreach ($userinfo as $userrow)
{
	$firstname = $userrow->firstname;
	$lastname = $userrow->lastname;
}
$command = "sendemail";
$adminuser = "YOUR ADMIN USERNAME HERE";
$values["customtype"] = "general";
$values["customsubject"] = "Account Login from $hostname";
$values["custommessage"] = "<p>Hello $firstname $lastname,<p>Your account was recently successfully accessed by a remote user. If this was not you, please do contact us immediately<p>IP Address: $ip<br/>Hostname: $hostname<br />";
$values["id"] = $userid;

$results = localAPI($command, $values, $adminuser);
}

add_hook('ClientLogin', 1, 'hook_client_login_notify');

 

This uses Hooks:ClientLogin and API:SendEmail

 

Nothing else needed, this will detect the ip (and hostname) and let the user know via mail.

Edited by twhiting9275
sanitized. Looks like the php flag is broken
Link to comment
Share on other sites

  • 4 months later...

Here you go

<?php
/*
Client area login notification for WHMCS
Developed by http://www.whmcsguru.com
v1.0.1
*/

use Illuminate\Database\Capsule\Manager as Capsule;
function hook_client_login_notify($vars)
{
$userid = $vars['userid'];
$adminid = $_SESSION['adminid'];
if (empty($adminid))
{
	send_login_notify($userid);
}
}

function send_login_notify($userid)
{
$ip = $_SERVER['REMOTE_ADDR'] ;
$hostname = gethostbyaddr($ip);
$userinfo = Capsule::table('tblclients')->select('firstname', 'lastname')->WHERE('id', $userid)->get();
//greet them
foreach ($userinfo as $userrow)
{
	$firstname = $userrow->firstname;
	$lastname = $userrow->lastname;
}
$command = "sendemail";
$adminuser = "twhiting9275";
$values["customtype"] = "general";
$values["customsubject"] = "Account Login from $hostname";
$values["custommessage"] = "<p>Hello $firstname $lastname,<p>Your account was recently successfully accessed by a remote user. If this was not you, please do contact us immediately<p>IP Address: $ip<br/>Hostname: $hostname<br />";
$values["id"] = $userid;

$results = localAPI($command, $values, $adminuser);
}

add_hook('ClientLogin', 1, 'hook_client_login_notify');

 

This will check for an admin session variable, and if exists, won't mail the client upon login

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated