I have made a modification to include AMI UserEvents? on user log in/out events. The target file is /var/lib/asterisk/agi-bin/user_login_out.agi. The modifications are noted by the //ADDED LINE comments.
// Insert a specificed user into a specified device and then
// update the hint for that user to reflect the new device(s)
// and update the voicemial link
//
function insert_user($user, $device) {
debug("insert_user: user: $user, device: $device",8);
global $agi;
global $astspooldir;
global $fm_devstate;
global $dnd_devstate;
set_device_user($device, $user);
$previous_devices = get_devices($user);
$new_devices = insert_device($previous_devices,$device);
debug("insert_user: Setting user $user to devices $new_devices",5);
set_user_devices($user, $new_devices);
set_hint($user, $new_devices);
$agi->exec("UserEvent", "UserDeviceAdded|Data:{$user},{$device}");//ADDED LINE
if ($fm_devstate) {
debug("insert_user: Setting FollowMe DEVSTATES for device $device",5);
$agi->set_variable('DEVSTATE(Custom:FOLLOWME'.$device.')',get_followme_state($user));
}
if ($dnd_devstate) {
debug("insert_user: Setting DND DEVSTATES for device $device",5);
$agi->set_variable('DEVSTATE(Custom:DEVDND'.$device.')',get_dnd_state($user));
}
$vmcontext = get_voicemail_context($user);
if ($vmcontext != 'novm') {
exec("/bin/ln -s {$astspooldir}/voicemail/{$vmcontext}/{$user}/ {$astspooldir}/voicemail/device/$device", $output, $ret);
if ($ret) {
debug("Got Return code: $ret trying to: /bin/ln -s {$astspooldir}/voicemail/{$vmcontext}/{$user}/ {$astspooldir}/voicemail/device/$device",5);
}
}
}
// Remove the current user from a device and then update
// the hint of that current user to reflect their current devices
//
function remove_user($device) {
debug("remove_user: device: $device",8);
global $agi;
global $astspooldir;
global $fm_devstate;
global $dnd_devstate;
$current_user = get_user($device);
if ($current_user != '') {
$current_devices = get_devices($current_user);
$new_devices = remove_device($current_devices,$device);
debug("remove_user: Setting user $current_user to devices $new_devices",5);
set_user_devices($current_user, $new_devices);
set_hint($current_user, $new_devices);
$agi->exec("UserEvent", "UserDeviceRemoved|Data:{$current_user},{$device}");//ADDED LINE
exec("/bin/rm -f {$astspooldir}/voicemail/device/$device",$output, $ret);
debug("Setting device $device states to INVALID before deleting them",5);
if ($fm_devstate) {
debug("Setting device $device FollowMe state to INVALID before deleting",5);
$agi->set_variable('DEVSTATE(Custom:FOLLOWME'.$device.')','INVALID');
}
if ($dnd_devstate) {
debug("Setting device $device DND state to INVALID before deleting",5);
$agi->set_variable('DEVSTATE(Custom:DEVDND'.$device.')','INVALID');
}
// I thought they should then be deleted, but they still end up there probably because setting them to invalid re-creates them
//
//$agi->database_deltree('CustomDevstate','FOLLOWME'.$device);
//$agi->database_deltree('CustomDevstate','DEVDND'.$device);
if ($ret) {
debug("Got Return code: $ret trying to remove: {$astspooldir}/voicemail/device/$device",5);
}
set_device_user($device, 'none');
}
}