Last active
August 26, 2016 17:26
-
-
Save matdave/2250a8007993663f1e5340565697c61f to your computer and use it in GitHub Desktop.
MODX Manager IP Log - Log a managers IP when they login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
switch ($modx->event->name) { | |
case 'OnManagerLogin': | |
$userinfo =& $modx->event->params['user']; | |
if(!empty($userinfo)){ | |
$ip = getenv('HTTP_CLIENT_IP')?: | |
getenv('HTTP_X_FORWARDED_FOR')?: | |
getenv('HTTP_X_FORWARDED')?: | |
getenv('HTTP_FORWARDED_FOR')?: | |
getenv('HTTP_FORWARDED')?: | |
getenv('REMOTE_ADDR'); | |
$profile = $userinfo->getOne('Profile'); | |
$comment = $profile->get('comment'); | |
if (strpos($comment, $ip) === false) { | |
$comment .= $ip."\r\n"; | |
} | |
$profile->set('comment',$comment); | |
if(!$profile->save()){ | |
$modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not save user '.$userinfo->get('username').' with IP '.$ip.'!' ); | |
}else{ | |
$log = $modx->newObject('modManagerLog'); | |
$log->fromArray(array('user'=>$userinfo->get('id'), | |
'occurred' => date('Y-m-d H:i:s'), | |
'action' => 'ip_logged', | |
'classKey' => 'modContext', | |
'item' => $ip | |
)); | |
$log->save(); | |
} | |
}else{ | |
$modx->log(xPDO::LOG_LEVEL_ERROR, 'User not found!' ); | |
} | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment