function _login_user($new_ext, $password) { $db = gs_db_master_connect(); $remote_addr = @$_SERVER['REMOTE_ADDR']; //FIXME $new_uid = (int) $db->executeGetOne('SELECT `_user_id` FROM `ast_sipfriends` WHERE `name`=\'' . $db->escape($new_ext) . '\''); if ($new_uid < 1) { # unknown user gs_log(GS_LOG_NOTICE, "Mobility: Unknown extension {$new_ext}"); return false; } $pin = $db->executeGetOne('SELECT `pin` FROM `users` WHERE `id`=' . $new_uid); if (trim($pin) == '') { gs_log(GS_LOG_NOTICE, "Mobility:Unknown user or no PIN"); return false; } if ((string) $pin != (string) $password) { # wrong password gs_log(GS_LOG_NOTICE, "Mobility: Login attempt for ext. {$new_ext} - Wrong PIN number"); return false; } # get id of the phone # $remote_addr = @$_SERVER['REMOTE_ADDR']; //FIXME $old_uid = (int) $db->executeGetOne('SELECT `id` FROM `users` WHERE `current_ip`=\'' . $db->escape($remote_addr) . '\''); if ($old_uid < 1) { gs_log(GS_LOG_NOTICE, "Mobility: No user with current IP \"{$remote_addr}\" in database"); return false; } $phone_id = (int) $db->executeGetOne('SELECT `id` FROM `phones` WHERE `user_id`=' . $old_uid . ' LIMIT 1'); if ($phone_id < 1) { gs_log(GS_LOG_WARNING, "Mobility: Login attempt for ext. {$new_ext} - Could not find phone of last user ID {$old_uid}"); # try to find the phone by the corresponding nobody index $nobody_index = (int) $db->executeGetOne('SELECT `nobody_index` FROM `users` WHERE `id`=' . $old_uid); if ($nobody_index > 0) { $phone_id = (int) $db->executeGetOne('SELECT `id` FROM `phones` WHERE `nobody_index`=' . $nobody_index . ' LIMIT 1'); } if ($phone_id < 1) { gs_log(GS_LOG_WARNING, "Mobility: Login attempt for ext. {$new_ext} - Could not find phone of last nobody_index {$nobody_index}"); return false; } } # cache currently used phone types for further use gs_phonetypecache_add_by_uid_to_ip($db, $old_uid); gs_phonetypecache_add_by_ext_to_ip($db, $new_ext); # log out the old user, assign the default nobody # $rs = $db->execute('SELECT `id`, `mac_addr`, `nobody_index`, `user_id` FROM `phones` WHERE `user_id` IN (' . $old_uid . ',' . $new_uid . ') AND `id`<>' . $phone_id); while ($phone = $rs->fetchRow()) { $phone['nobody_index'] = (int) $phone['nobody_index']; $phone['user_id'] = (int) $phone['user_id']; if ($phone['nobody_index'] < 1) { gs_log(GS_LOG_WARNING, "Phone " . $phone['mac_addr'] . " does not have a default nobody user"); $nobody_user_id = null; } else { $nobody_user_id = (int) $db->executeGetOne('SELECT `id` FROM `users` WHERE `nobody_index`=' . $phone['nobody_index']); if ($nobody_user_id < 1) { gs_log(GS_LOG_WARNING, "Could not find user with nobody index " . $phone['nobody_index'] . " for phone " . $phone['mac_addr']); } } gs_log(GS_LOG_DEBUG, "Mobility: Assigning nobody user with ID " . ($nobody_user_id > 0 ? $nobody_user_id : 'NULL') . " to phone " . $phone['mac_addr']); $db->execute('UPDATE `phones` SET ' . '`user_id`=' . ($nobody_user_id > 0 ? $nobody_user_id : 'NULL') . ' ' . 'WHERE ' . '`id`=' . (int) $phone['id'] . ' AND ' . '`user_id` ' . ($phone['user_id'] > 0 ? '=' . $phone['user_id'] : 'IS NULL')); } //$db->execute( 'UPDATE `users` SET `current_ip`=NULL WHERE `id`='. $old_uid ); # log in the new user # $ok = $db->execute('UPDATE `phones` SET `user_id`=' . $new_uid . ' WHERE `id`=' . $phone_id); if (!$ok) { gs_log(GS_LOG_NOTICE, "Mobility: DB error"); echo 'SET VARIABLE ret ' . gs_agi_str_esc('error') . "\n"; //fFlush(STDOUT); // <- do not use. not defined in php-cgi! die; } # get new phone's IP addr. # $new_ip_addr = $db->executeGetOne('SELECT `current_ip` FROM `users` WHERE `id`=' . $new_uid); gs_log(GS_LOG_DEBUG, "Mobility: IP address found for new phone: {$new_ip_addr}"); # reboot old phone # gs_prov_phone_checkcfg_by_ip($remote_addr, true); # reboot new phone # if ($new_ip_addr) { gs_prov_phone_checkcfg_by_ip($new_ip_addr, true); } # generate userevent # if (GS_BUTTONDAEMON_USE == true) { $user_ext = _get_user_ext($new_uid); if ($user_ext) { gs_user_login_ui($user_ext); } } return true; }
$xml .= ' <Label>' . __('OK') . '</Label>' . "\n"; $xml .= ' <URI>SoftKey:Select</URI>' . "\n"; $xml .= '</SoftKey>' . "\n"; $xml .= '<SoftKey index="2">' . "\n"; $xml .= ' <Label>' . __('Anrufen') . '</Label>' . "\n"; $xml .= ' <URI>SoftKey:Dial2</URI>' . "\n"; $xml .= '</SoftKey>' . "\n"; $xml .= '<SoftKey index="4">' . "\n"; $xml .= ' <Label>' . __('Abbrechen') . '</Label>' . "\n"; $xml .= ' <URI>SoftKey:Exit</URI>' . "\n"; $xml .= '</SoftKey>' . "\n"; $xml .= '</AastraIPPhoneTextMenu>' . "\n"; if ($tp === 'missed') { gs_user_watchedmissed($user_id, $is_queue); if (GS_BUTTONDAEMON_USE == true) { $user_ext = _get_user_ext($user_id); if ($user_ext) { gs_user_missedcalls_ui($user_ext, $is_queue); } } } } else { aastra_textscreen($typeToTitle[$type], __('Kein Eintrag')); } } elseif ($type === 'outd' || $type === 'ind' || $type === 'missedd' || $type === 'qmissedd' || $type === 'qind') { $type = substr($type, 0, strlen($type) - 1); $xml = '<AastraIPPhoneFormattedTextScreen destroyOnExit="yes" cancelAction="' . $url_aastra_dl . '?t=' . $type . '">' . "\n"; $queue_null = "IS NOT NULL"; if ($type == 'qin') { $tp = 'in'; } else {