twhiting9275 Posted July 19, 2016 Share Posted July 19, 2016 I don't see why notifying clients that they logged into a billing area would be a bad thing. In fact, it should probably be a default option. 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 1 Quote Link to comment Share on other sites More sharing options...
anas_xrt Posted November 13, 2016 Share Posted November 13, 2016 Loving it, thank you very much 0 Quote Link to comment Share on other sites More sharing options...
Kevin K Posted December 5, 2018 Share Posted December 5, 2018 (edited) I know this topic is a bit old, but I was looking to add an option to this hook that if an admin does a login as a client, it would not send the email notification. This is handy if you need to troubleshoot something on the client side of whmcs. Any feedback would be appreciated. Edited December 5, 2018 by Kevin K 0 Quote Link to comment Share on other sites More sharing options...
HOSKIA INDIA Posted August 22, 2019 Share Posted August 22, 2019 the hook is working 😍 but i need to add $signature also pls any one help me 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 22, 2019 Share Posted August 22, 2019 30 minutes ago, HOSKIA INDIA said: the hook is working 😍 but i need to add $signature also pls any one help me <?php /* Client area login notification for WHMCS modified by brian! */ 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(); $signature = Capsule::table('tblconfiguration')->where('setting', 'Signature')->value('value'); //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 />$signature"; $values["id"] = $userid; $results = localAPI($command, $values, $adminuser); } add_hook('ClientLogin', 1, 'hook_client_login_notify'); 1 Quote Link to comment Share on other sites More sharing options...
HOSKIA INDIA Posted August 22, 2019 Share Posted August 22, 2019 3 35 minutes ago, brian! said: <?php /* Client area login notification for WHMCS modified by brian! */ 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(); $signature = Capsule::table('tblconfiguration')->where('setting', 'Signature')->value('value'); //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 />$signature"; $values["id"] = $userid; $results = localAPI($command, $values, $adminuser); } add_hook('ClientLogin', 1, 'hook_client_login_notify'); i need to give space between signature and hostname like this https://prnt.sc/ow1021 i did like this https://prnt.sc/ow107p is it correct ? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 22, 2019 Share Posted August 22, 2019 Just now, HOSKIA INDIA said: i need to give space between signature and hostname like this https://prnt.sc/ow1021 i did like this https://prnt.sc/ow107p is it correct ? it should just be a case of adding another break return before the signature... $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 /><br />$signature"; 1 Quote Link to comment Share on other sites More sharing options...
mino Posted August 26, 2019 Share Posted August 26, 2019 @brian! how to block message notification if you conected in client area with admin permission 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 27, 2019 Share Posted August 27, 2019 15 hours ago, mino said: how to block message notification if you connected in client area with admin permission I think the following would work - change... function hook_client_login_notify($vars) { $userid = $vars['userid']; send_login_notify($userid); } to... function hook_client_login_notify($vars) { if ($_SESSION['adminid']) {return;} $userid = $vars['userid']; send_login_notify($userid); } if you are logged in to the admin area, and MANUALLY login into the client area in a new tabb/window (e.g you type in their email address and password), then the email notification will still be sent (I can't see any obvious way to prevent that)... however, if you use the "Login As Client" link in the admin client summary page, then the email shouldn't be sent to the client. 2 Quote Link to comment Share on other sites More sharing options...
mino Posted August 27, 2019 Share Posted August 27, 2019 5 hours ago, brian! said: I think the following would work - change... function hook_client_login_notify($vars) { $userid = $vars['userid']; send_login_notify($userid); } to... function hook_client_login_notify($vars) { if ($_SESSION['adminid']) {return;} $userid = $vars['userid']; send_login_notify($userid); } if you are logged in to the admin area, and MANUALLY login into the client area in a new tabb/window (e.g you type in their email address and password), then the email notification will still be sent (I can't see any obvious way to prevent that)... however, if you use the "Login As Client" link in the admin client summary page, then the email shouldn't be sent to the client. Thank You @brian! and its possible add Web browser in this hook 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 28, 2019 Share Posted August 28, 2019 15 hours ago, mino said: its possible add Web browser in this hook three ways I can quickly think of - there will be lots more! the old fashioned way of using $_SERVER['HTTP_USER_AGENT'] - though that can be faked or even omitted, so not 100% reliable. there's a PHP internal function, get_browser, that can identify the browser - but I think it's disabled by default in PHP, so it would have to be enabled on your server before you could use it in a hook. there are numerous GitHub PHP functions that can be used to detect browsers etc. but to keep things simple, let's just use HTTP_USER_AGENT.. { if ($_SESSION['adminid'] || strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) {return;} $userid = $vars['userid']; send_login_notify($userid); } so the above says, if the user is an admin, OR anyone using the Firefox browser, then don't send the email. if you wanted to change that to prevent the emails being sent when Admins using Chrome are logged in, then it would be... if ($_SESSION['adminid'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false) {return;} 0 Quote Link to comment Share on other sites More sharing options...
mino Posted August 28, 2019 Share Posted August 28, 2019 4 hours ago, brian! said: three ways I can quickly think of - there will be lots more! the old fashioned way of using $_SERVER['HTTP_USER_AGENT'] - though that can be faked or even omitted, so not 100% reliable. there's a PHP internal function, get_browser, that can identify the browser - but I think it's disabled by default in PHP, so it would have to be enabled on your server before you could use it in a hook. there are numerous GitHub PHP functions that can be used to detect browsers etc. but to keep things simple, let's just use HTTP_USER_AGENT.. { if ($_SESSION['adminid'] || strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) {return;} $userid = $vars['userid']; send_login_notify($userid); } so the above says, if the user is an admin, OR anyone using the Firefox browser, then don't send the email. if you wanted to change that to prevent the emails being sent when Admins using Chrome are logged in, then it would be... if ($_SESSION['adminid'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false) {return;} Ok after its show Like in a picture or no @brian! 0 Quote Link to comment Share on other sites More sharing options...
Hardik Joshi Posted March 31, 2020 Share Posted March 31, 2020 On 8/22/2019 at 3:28 PM, brian! said: <?php /* Client area login notification for WHMCS modified by brian! */ 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(); $signature = Capsule::table('tblconfiguration')->where('setting', 'Signature')->value('value'); //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 />$signature"; $values["id"] = $userid; $results = localAPI($command, $values, $adminuser); } add_hook('ClientLogin', 1, 'hook_client_login_notify'); bro hook is not working please check it again 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 31, 2020 Share Posted March 31, 2020 21 minutes ago, hardikjoshi said: hook is not working please check it again if you're using any recent version of WHMCS, just remove the references to $adminuser... $command = "sendemail"; $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 />$signature"; $values["id"] = $userid; ... or ensure that the admin is authenticated to use SendEmail. 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted March 31, 2020 Author Share Posted March 31, 2020 changing $results = localAPI($command, $values, $adminuser); to $results = localAPI($command, $values); will do the trick too. I mean, that's the easiest hack to do it. No longer need that adminuser for localAPI 0 Quote Link to comment Share on other sites More sharing options...
Hardik Joshi Posted April 1, 2020 Share Posted April 1, 2020 16 hours ago, brian! said: if you're using any recent version of WHMCS, just remove the references to $adminuser... $command = "sendemail"; $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 />$signature"; $values["id"] = $userid; ... or ensure that the admin is authenticated to use SendEmail. thanks you bro it's working fine 1 Quote Link to comment Share on other sites More sharing options...
Hardik Joshi Posted April 1, 2020 Share Posted April 1, 2020 7 hours ago, twhiting9275 said: changing $results = localAPI($command, $values, $adminuser); to $results = localAPI($command, $values); will do the trick too. I mean, that's the easiest hack to do it. No longer need that adminuser for localAPI yes brother it's also working well 1 Quote Link to comment Share on other sites More sharing options...
Hardik Joshi Posted April 1, 2020 Share Posted April 1, 2020 16 hours ago, brian! said: if you're using any recent version of WHMCS, just remove the references to $adminuser... $command = "sendemail"; $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 />$signature"; $values["id"] = $userid; ... or ensure that the admin is authenticated to use SendEmail. hey bro is it possible to saw internet provider name in hostname https://prnt.sc/rqkolg 1 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 1, 2020 Share Posted April 1, 2020 9 hours ago, hardikjoshi said: is it possible to saw internet provider name in hostname the hook should already be doing that (and does when I test it locally) - though if gethostbyaddr fails, then it returns the IP address (which seems to be what you're seeing). 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted April 1, 2020 Author Share Posted April 1, 2020 18 hours ago, hardikjoshi said: hey bro is it possible to saw internet provider name in hostname https://prnt.sc/rqkolg If you're not seeing a hostname in the email, then there's not likely to be one in there. Put the ip that is given in the email here . This will likely return the IP back, instead of the hostname. That's something the provider needs to setup 0 Quote Link to comment Share on other sites More sharing options...
HostyFly Posted April 2, 2020 Share Posted April 2, 2020 how to setup this hook can you help me please 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 6, 2020 Share Posted April 6, 2020 On 02/04/2020 at 06:20, HostyFly said: how to setup this hook can you help me please you would create an empty .php file in /includes/hooks; give it a memorable filename e,g clientlogin.php; paste the hook code into the file, save it and it should start working immediately. 0 Quote Link to comment Share on other sites More sharing options...
Vittor Posted April 7, 2020 Share Posted April 7, 2020 Hello, does anyone know how to put date and time in the email? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 7, 2020 Share Posted April 7, 2020 12 hours ago, Vittor said: Hello, does anyone know how to put date and time in the email? change... $command = "sendemail"; $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 />$signature"; $values["id"] = $userid; to... $datenow = date('Y-m-d H:i:s'); $date = fromMySQLDate($datenow,true,true); $command = "sendemail"; $values["customtype"] = "general"; $values["customsubject"] = "Account Login from $hostname"; $values["custommessage"] = "<p>Hello $firstname $lastname,<p>Your account was successfully accessed by a remote user at $date. If this was not you, please do contact us immediately<p>IP Address: $ip<br/>Hostname: $hostname<br />$signature"; $values["id"] = $primaryid; 0 Quote Link to comment Share on other sites More sharing options...
Vittor Posted April 7, 2020 Share Posted April 7, 2020 41 minutes ago, brian! said: $values["id"] = $primaryid; in mine it worked by changing $values["id"]=$primaryid; for $values["id"]=$userid; 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.