function getOurHostID() { $db = gs_db_slave_connect(); $rs = $db->execute('SELECT `id`, `host` FROM `hosts`'); $hosts = array(); while ($r = $rs->fetchRow()) { $hosts[] = $r; } $ips = array(); foreach ($hosts as $h) { $h['host'] = trim(normalizeIPs($h['host'])); if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $h['host'])) { $ips[$h['host']] = $h['id']; } else { $tmp = getHostByNameL($h['host']); if (is_array($tmp)) { foreach ($tmp as $ip) { $ips[normalizeIPs($ip)] = $h['id']; } } } } unset($hosts); $ifconfig = normalizeIPs(trim(@shell_exec('ifconfig 2>>/dev/null'))); foreach ($ips as $ip => $hostid) { if (strPos($ifconfig, $ip) !== false) { return $hostid; } } return false; }
function gs_user_ip_by_ext($ext) { if (!preg_match('/^[\\d]+$/', $ext)) { return new GsError('Extension must be numeric.'); } # connect to db # $db = gs_db_slave_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # get user_id # $user_id = (int) $db->executeGetOne('SELECT `_user_id` FROM `ast_sipfriends` WHERE `name`=\'' . $db->escape($ext) . '\''); if (!$user_id) { return new GsError('Unknown extension.'); } # get IP address # $current_ip = $db->executeGetOne('SELECT `current_ip` FROM `users` WHERE `id`=' . $user_id); if (!$current_ip) { return null; } # check if the user is actually logged in at a phone (or if that # IP address is an outdated entry) # $phone_id = (int) $db->executeGetOne('SELECT `id` FROM `phones` WHERE `user_id`=' . $user_id . ' LIMIT 1'); if ($phone_id < 1) { return null; } return $current_ip; }
function gs_user_missedcalls_get($user, $queue = false) { if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) { return new GsError('User must be alphanumeric.'); } # connect to db # $db = gs_db_slave_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # get user_id # $user_id = (int) $db->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $db->escape($user) . '\''); if ($user_id < 1) { return new GsError('Unknown user.'); } # get count # if (!$queue) { $count = $db->executeGetOne('SELECT Count(*) FROM `dial_log` WHERE `queue_id` IS NULL AND `read`=0 AND `type`=\'missed\' AND `user_id`=' . $user_id); } else { $count = $db->executeGetOne('SELECT Count(*) FROM `dial_log` WHERE `queue_id` IS NOT NULL AND `read`=0 AND `type`=\'missed\' AND `user_id`=' . $user_id); } if (!$count) { return 0; } return $count; }
function _get_user() { $db = gs_db_slave_connect(); $remote_addr = @$_SERVER['REMOTE_ADDR']; //FIXME $user_name = (string) $db->executeGetOne('SELECT `user`, `nobody_index` FROM `users` WHERE `current_ip`=\'' . $db->escape($remote_addr) . '\''); return gs_user_get($user_name); }
function gs_get_listen_to_ids($primary_only = false) { /* if (gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { # return special host ID return array(-1); } */ $GS_INSTALLATION_TYPE_SINGLE = gs_get_conf('GS_INSTALLATION_TYPE_SINGLE'); if (!$GS_INSTALLATION_TYPE_SINGLE) { # get our IPs # $ips = @gs_get_listen_to_ips($primary_only); if (!is_array($ips)) { # kann entweder passieren wenn wir ein Gemeinschaft-Node sind # (dann ist es extrem schlecht wenn die Datei fehlt) oder wenn # wir ein Web-Server ohne Asterisk sind (dann ist es ok) gs_log(GS_LOG_DEBUG, "Failed to get our IP addresses"); return array(); } if (count($ips) < 1) { gs_log(GS_LOG_DEBUG, "We're not configured to listen to any IP addresses"); return array(); } } # connect to db # must be to slave db so we can tell our IDs even if the master is down # $db = gs_db_slave_connect(); if (!$db) { gs_log(GS_LOG_WARNING, "Failed to connect to the database!"); return array(); } if (!$GS_INSTALLATION_TYPE_SINGLE) { # find the corresponding IDs # $ips_escaped = array(); foreach ($ips as $ip) { $ips_escaped[] = '\'' . $db->escape($ip) . '\''; } // count($ips) guaranteed to be > 0 $query = 'SELECT `id` FROM `hosts` WHERE `host` IN (' . implode(',', $ips_escaped) . ')'; } else { $query = 'SELECT `id` FROM `hosts`'; } $rs = $db->execute($query); if (!$rs) { gs_log(GS_LOG_WARNING, "Database error!"); return array(); } $ids = array(); while ($r = $rs->fetchRow()) { $ids[] = (int) $r['id']; } return $ids; }
function _get_user_ext($user_id) { $db = gs_db_slave_connect(); $user_ext = $db->executeGetOne('SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`=\'' . $db->escape($user_id) . '\''); if (!$user_ext) { snom_textscreen(__('Fehler'), __('Unbekannter Benutzer.')); return false; } return $user_ext; }
function _get_user_ext($user_id) { $db = gs_db_slave_connect(); $user_ext = $db->executeGetOne('SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`=\'' . $db->escape($user_id) . '\''); if (!$user_ext) { _err('Unknown user.'); return false; } return $user_ext; }
function gs_sysrec_hash_get($sysrec_id) { if (!preg_match('/^[0-9]+$/', $sysrec_id)) { return new GsError('Sysrecid must be numeric.'); } # connect to db # $db = gs_db_slave_connect(); if (!$db) { return new GsError('Could not connect to database.'); } $filename = $db->executeGetOne('SELECT `md5hashname` FROM `systemrecordings` WHERE id =' . $sysrec_id); if (strlen($filename) > 0) { return $filename; } else { return new GsError('No such sysrec.'); } }
function gs_user_name_by_ext($ext) { if (!preg_match('/^[\\d]+$/', $ext)) { return new GsError('Extension must be numeric.'); } # connect to db # $db = gs_db_slave_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # get user_id # $user_name = $db->executeGetOne('SELECT `user` FROM `users` `u`, `ast_sipfriends` `a` WHERE `a`.`name`=\'' . $db->escape($ext) . '\' AND `a`.`_user_id` = `u`.`id`'); if (!$user_name) { return new GsError('Unknown user for extension ' . $ext . '.'); } return $user_name; }
function _getUser() { $user_entered = strToLower(trim(@$_REQUEST['login_user'])); $pwd_entered = @$_REQUEST['login_pwd']; if ($user_entered == '' || $pwd_entered == '') { return false; } if ($user_entered === 'sysadmin' && in_array(gs_get_conf('GS_INSTALLATION_TYPE'), array('gpbx', 'single'), true)) { //FIXME //Quickhack: sysadmin only valid for /gemeinschaft/setup $pin = false; } else { $db = gs_db_slave_connect(); if (!$db) { return false; } $pin = $db->executeGetOne('SELECT `pin` FROM `users` WHERE `user`=\'' . $db->escape($user_entered) . '\''); } return $pin === $pwd_entered ? $user_entered : false; }
function get_all_room_states() { ## connect to db # $db = gs_db_slave_connect(); if (!$db) { return new GsError('Could not connect to database.'); } $rs = $db->execute('SELECT `extension`, `state` FROM `room_state`'); if (!$rs) { return new GsError('DB-Error.'); } $result = array(); while ($res = $rs->fetchRow()) { $result[] = $res; } return $result; }
function gs_callforward_get($user) { if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) { return new GsError('User must be alphanumeric.'); } # connect to db # $db = gs_db_slave_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # get user_id # $user_id = $db->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $db->escape($user) . '\''); if (!$user_id) { return new GsError('Unknown user.'); } # get states # $sources = array('internal', 'external'); $cases = array('always', 'busy', 'unavail', 'offline'); $forwards = array(); foreach ($sources as $source) { foreach ($cases as $case) { $rs = $db->execute('SELECT `active`, `number_std`, `number_var`, `number_vml`, `timeout`, `vm_rec_id` FROM `callforwards` WHERE `user_id`=' . $user_id . ' AND `source`=\'' . $source . '\' AND `case`=\'' . $case . '\''); if ($r = $rs->fetchRow()) { if (!in_array($r['active'], array('no', 'std', 'var', 'vml', 'ano', 'trl', 'par'), true)) { $r['active'] = 'no'; } $forwards[$source][$case] = $r; } else { $forwards[$source][$case] = array('active' => 'no', 'number_std' => '', 'number_var' => '', 'number_vml' => '', 'timeout' => 20, 'vm_rec_id' => 0); } if ($case != 'unavail') { $forwards[$source][$case]['timeout'] = null; } } } return $forwards; }
function get_alert_tagets_by_time($hour, $minute) { ## test input # if (!preg_match('/^[0-9]{1,2}$/', $hour)) { return new GsError('Hours are not numeric.'); } $hour = (int) $hour; if ($hour < 0 || $hour >= 24) { return new GsError('Hours are out of bounds.'); } if (!preg_match('/^[0-9]{1,2}$/', $minute)) { return new GsError('Minutes are not numeric.'); } $minute = (int) $minute; if ($minute < 0 || $minute >= 60) { return new GsError('Minutes are out of bounds.'); } ## connect to db # $db = gs_db_slave_connect(); if (!$db) { return new GsError('Could not connect to database.'); } $rs = $db->execute('SELECT `wakeup_calls`.`target` FROM `wakeup_calls` WHERE `hour` = ' . $db->escape($hour) . ' AND `minute` =' . $db->escape($minute)); if (!$rs) { return new GsError('Error.'); } $targets = array(); while ($r = $rs->fetchRow()) { $targets[] = $r['target']; } return $targets; }
function _getUser_gemeinschaft() { $user_entered = strToLower(trim(@$_REQUEST['login_user'])); $pwd_entered = @$_REQUEST['login_pwd']; if ($user_entered == '' || $pwd_entered == '') { return false; } if ($user_entered === 'sysadmin' && in_array(gs_get_conf('GS_INSTALLATION_TYPE'), array('gpbx', 'single'), true)) { require_once GS_DIR . 'inc/keyval.php'; $pin = trim(gs_keyval_get('setup_pwd')); if ($pin == '') { $pin = false; } } else { $db = gs_db_slave_connect(); if (!$db) { return false; } $pin = $db->executeGetOne('SELECT `pin` FROM `users` WHERE `user`=\'' . $db->escape($user_entered) . '\''); } return $pin === $pwd_entered ? $user_entered : false; }
if ($user_id < 1) { _err('Unknown user.'); } return $user_id; } $type = trim(@$_REQUEST['t']); if (!in_array($type, array('gs', 'prv', 'imported', 'gss', 'prvs', 'importeds'), true)) { $type = false; } $page = (int) trim(@$_REQUEST['p']); $entry = (int) trim(@$_REQUEST['e']); $search = trim(@$_REQUEST['s']); $name_search = trim(@$_REQUEST['n']); //$per_page = (int)gs_get_conf('GS_AASTRA_PROV_PB_NUM_RESULTS', 10); $per_page = 4; $db = gs_db_slave_connect(); $tmp = array(15 => array('k' => 'gs', 'v' => gs_get_conf('GS_PB_INTERNAL_TITLE', __("Intern"))), 25 => array('k' => 'prv', 'v' => gs_get_conf('GS_PB_PRIVATE_TITLE', __("Persönlich")))); if (gs_get_conf('GS_PB_IMPORTED_ENABLED')) { $pos = (int) gs_get_conf('GS_PB_IMPORTED_ORDER', 9) * 10; $tmp[$pos] = array('k' => 'imported', 'v' => gs_get_conf('GS_PB_IMPORTED_TITLE', __("Extern"))); } kSort($tmp); foreach ($tmp as $arr) { $typeToTitle[$arr['k']] = $arr['v']; } $url_aastra_pb = GS_PROV_SCHEME . '://' . GS_PROV_HOST . (GS_PROV_PORT ? ':' . GS_PROV_PORT : '') . GS_PROV_PATH . 'aastra/pb.php'; #################################### SEARCH SCREEN { if ($search) { $xml = '<AastraIPPhoneInputScreen type = "string">' . "\n"; $xml .= '<Title>' . __('Suchen') . '</Title>' . "\n"; $xml .= '<Prompt>' . __('Name') . ':</Prompt>' . "\n";
function gs_extstate_callable($ext) { include_once GS_DIR . 'inc/db_connect.php'; $db = @gs_db_slave_connect(); if (!$db) { gs_log(GS_LOG_FATAL, 'Could not connect to slave DB!'); return AST_MGR_EXT_UNKNOWN; } //user and parallel call $rs = $db->execute('SELECT `a`.`_user_id`, `a`.`host`, `c`.`active` FROM `ast_sipfriends` `a` LEFT JOIN `callforwards` `c` ON ( `a`.`_user_id`= `c`.`user_id` AND `c`.`source`="internal" AND `c`.`case`="always") WHERE `a`.`name`="' . $ext . '"'); if (!$rs) { return new GsError('DB Error.'); } if (!($user = $rs->FetchRow())) { return new GsError('No extension ' . $ext); } if ($user['active'] == '' || $user['active'] == 'no') { //this is a user, no callforwards $state = gs_extstate($user['host'], $ext); return gs_ast_extstate_try_cc($state); } else { if ($user['active'] == 'par') { //this is a user, parallel call enabled $rs = $db->execute('SELECT `a`.`name`, `a`.`host` FROM `ast_sipfriends` `a`, `cf_parallelcall` `c` WHERE `c`.`_user_id`= ' . $user['_user_id'] . ' AND `c`.`number`=`a`.`name`'); if (!$rs) { return new GsError('DB Error.' . $ext); } $count = 0; $hosts = array(); while ($peer = $rs->FetchRow()) { $count++; $host_id = $peer['host_id']; $hosts[$host_id][] = $peer['name']; } //no callforward users if ($count == 0) { return false; } $allstates = array(); foreach ($hosts as $host => $peers) { $states = gs_extstate($host, $peers); if (is_array($states)) { $allstates = array_merge($allstates, $states); } } foreach ($allstates as $singlestate) { if ($singlestate != AST_MGR_EXT_IDLE) { return false; } } return true; } else { //any other callforward return false; } } return false; }
function gs_queue_status($host, $ext, $getMembers, $getCallers) { static $hosts = array(); if (gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { $host = '127.0.0.1'; } if (!isset($hosts[$host])) { $hosts[$host] = array('sock' => null, 'lasttry' => 0); } if (!is_resource($hosts[$host]['sock'])) { if ($hosts[$host]['lasttry'] > time() - 60) { # we have tried less than a minute ago $hosts[$host]['lasttry'] = time(); return false; } $hosts[$host]['lasttry'] = time(); $sock = @fSockOpen($host, 5038, $err, $errMsg, 2); if (!is_resource($sock)) { gs_log(GS_LOG_WARNING, 'Connection to AMI on ' . $host . ' failed'); return false; } $data = _sock_read($sock, 3, '/[\\r\\n]/'); if (!preg_match('/^Asterisk [^\\/]+\\/(\\d(?:\\.\\d)?)/mis', $data, $m)) { gs_log(GS_LOG_WARNING, 'Incompatible Asterisk manager interface on ' . $host); $m = array(1 => '0.0'); } else { if ($m[1] > '1.1') { # Asterisk 1.4: manager 1.0 # Asterisk 1.6: manager 1.1 gs_log(GS_LOG_NOTICE, 'Asterisk manager interface on ' . $host . ' speaks a new protocol version (' . $m[1] . ')'); # let's try anyway and hope to understand it } } $hosts[$host]['sock'] = $sock; $req = "Action: Login\r\n" . "Username: "******"gscc" . "\r\n" . "Secret: " . "gspass" . "\r\n" . "Events: off\r\n" . "\r\n"; @fWrite($sock, $req, strLen($req)); @fFlush($sock); $data = _sock_read2($sock, 5, '/\\r\\n\\r\\n/S'); if (!preg_match('/Authentication accepted/i', $data)) { gs_log(GS_LOG_WARNING, 'Authentication to AMI on ' . $host . ' failed'); $hosts[$host]['sock'] = null; return false; } } else { $sock = $hosts[$host]['sock']; } $queue_stats = array('maxlen' => null, 'calls' => null, 'holdtime' => null, 'completed' => null, 'abandoned' => null, 'sl' => null, 'slp' => null); if ($getMembers) { $queue_stats['members'] = array(); } if ($getCallers) { $queue_stats['callers'] = array(); } $default_member = array('dynamic' => null, 'calls' => null, 'lastcall' => null, 'devstate' => null, 'paused' => null); $default_caller = array('channel' => null, 'cidnum' => null, 'cidname' => null, 'wait' => null); $req = "Action: QueueStatus\r\n" . "Queue: " . $ext . "\r\n" . "\r\n"; @fWrite($sock, $req, strLen($req)); @fFlush($sock); $resp = trim(_sock_read2($sock, 2, '/Event:\\s*QueueStatusComplete\\r\\n\\r\\n/i')); //echo "\n$resp\n\n"; if (!preg_match('/^Response:\\s*Success/is', $resp)) { return false; } $resp = preg_split('/\\r\\n\\r\\n/S', $resp); /* echo "<pre>"; print_r($resp); echo "</pre>"; */ $manager_ok = false; foreach ($resp as $pkt) { $pkt = lTrim($pkt); if (preg_match('/^Event:\\s*QueueParams/is', $pkt)) { if (!preg_match('/^Queue:\\s*' . $ext . '/mis', $pkt)) { continue; } //echo $pkt, "\n\n"; if (preg_match('/^Max:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['maxlen'] = (int) $m[1] > 0 ? (int) $m[1] : null; } if (preg_match('/^Calls:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['calls'] = (int) $m[1]; } if (preg_match('/^Holdtime:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['holdtime'] = (int) $m[1]; } if (preg_match('/^Completed:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['completed'] = (int) $m[1]; } if (preg_match('/^Abandoned:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['abandoned'] = (int) $m[1]; } if (preg_match('/^ServiceLevel:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['sl'] = (int) $m[1]; } if (preg_match('/^ServiceLevelPerf:\\s*(\\d+?(\\.\\d+)?)/mis', $pkt, $m)) { $queue_stats['slp'] = (double) $m[1]; } $manager_ok = true; } elseif ($getMembers && preg_match('/^Event:\\s*QueueMember/is', $pkt)) { if (!preg_match('/^Queue:\\s*' . $ext . '/mis', $pkt)) { continue; } if (!preg_match('/^Location:\\s*([A-Z\\d\\/]+)/mis', $pkt, $m)) { continue; } $loc = $m[1]; $queue_stats['members'][$loc] = $default_member; //echo $pkt, "\n\n"; if (preg_match('/^Membership:\\s*([a-z]+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['dynamic'] = $m[1] != 'static'; } if (preg_match('/^CallsTaken:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['calls'] = (int) $m[1]; } if (preg_match('/^LastCall:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['lastcall'] = (int) $m[1]; } if (preg_match('/^Status:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['devstate'] = (int) $m[1]; } if (preg_match('/^Paused:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['paused'] = (int) $m[1] > 0; } } elseif ($getCallers && preg_match('/^Event:\\s*QueueEntry/is', $pkt)) { if (!preg_match('/^Queue:\\s*' . $ext . '/mis', $pkt)) { continue; } if (!preg_match('/^Position:\\s*(\\d+)/mis', $pkt, $m)) { continue; } $pos = (int) $m[1]; $queue_stats['callers'][$pos] = $default_caller; //echo $pkt, "\n\n"; if (preg_match('/^Channel:\\s*([^\\n\\r]+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['dynamic'] = trim($m[1]); } if (preg_match('/^CallerID:\\s*([^\\n\\r]+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['cidnum'] = strToLower(trim($m[1])) != 'unknown' ? trim($m[1]) : null; } if (preg_match('/^CallerIDName:\\s*([^\\n\\r]+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['cidname'] = strToLower(trim($m[1])) != 'unknown' ? trim($m[1]) : null; } if (preg_match('/^Wait:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['wait'] = (int) $m[1]; } } } if (!$manager_ok && $getMembers) { # failed to get information about the queue from the manager # interface. this happens after a reload of Asterisk when # no call has entered the queue using Queue() yet $queue_stats['calls'] = 0; $queue_stats['completed'] = 0; $queue_stats['abandoned'] = 0; $queue_stats['holdtime'] = 0; include_once GS_DIR . 'inc/db_connect.php'; $db = @gs_db_slave_connect(); if (!$db) { return $queue_stats; } $maxlen = (int) $db->executeGetOne('SELECT `maxlen` FROM `ast_queues` WHERE `name`=\'' . $db->escape($ext) . '\''); $queue_stats['maxlen'] = $maxlen > 0 ? $maxlen : null; $rs = $db->execute('SELECT `interface` FROM `ast_queue_members` WHERE `queue_name`=\'' . $db->escape($ext) . '\''); $queue_members = array(); while ($r = $rs->fetchRow()) { if (strToUpper(subStr($r['interface'], 0, 4)) == 'SIP/') { $queue_members[] = subStr($r['interface'], 4); } else { $queue_members[] = $r['interface']; } } if (count($queue_members) < 1) { return $queue_stats; } foreach ($queue_members as $queue_member) { $queue_stats['members']['SIP/' . $queue_member] = $default_member; } $ext_states = @gs_extstate($host, $queue_members); if (!is_array($ext_states)) { return $queue_stats; } foreach ($queue_members as $queue_member) { $queue_stats['members']['SIP/' . $queue_member]['devstate'] = extstate_to_devstate(@$ext_states[$queue_member]); } } /* echo "<pre>"; print_r($queue_stats); echo "</pre>"; */ return $queue_stats; }
function _gui_monitor_which_peers_group($sudo_user) { $db_slave = gs_db_slave_connect(); $sudo_user_id = $db_slave->executeGetOne('SELECT `id` FROM `users` WHERE `user` = \'' . $db_slave->escape($sudo_user) . '\''); $group_members = gui_get_grouped_peers($sudo_user_id, 'monitor_peers'); $peers = array(); if (is_array($group_members) && count($group_members) > 0) { $rs = $db_slave->execute('SELECT `user` FROM `users` WHERE `id` IN (' . implode(',', $group_members) . ') '); if ($rs) { while ($r = @$rs->fetchRow()) { $peers[] = $r['user']; } } } return $peers; }
function gs_extstate_single($ext) { if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { include_once GS_DIR . 'inc/db_connect.php'; $db = @gs_db_slave_connect(); if (!$db) { gs_log(GS_LOG_FATAL, 'Could not connect to slave DB!'); return AST_MGR_EXT_UNKNOWN; } $host = $db->executeGetOne('SELECT `h`.`host` FROM `ast_sipfriends` `s` JOIN `users` `u` ON (`u`.`id`=`s`.`_user_id`) JOIN `hosts` `h` ON (`h`.`id`=`u`.`host_id`) WHERE `s`.`name`=\'' . $db->escape($ext) . '\''); if (!$host) { # not a user return AST_MGR_EXT_UNKNOWN; } } else { $host = '127.0.0.1'; } return gs_extstate($host, $ext); }
function _gs_prov_phone_checkcfg_by_ext_do_aastra($ext, $reboot = true) { # We will run into trouble if the IP addr. is not in the database anymore. # see _gs_prov_phone_checkcfg_by_ext_do_siemens() $db = @gs_db_slave_connect(); if (!$db) { gs_log(GS_LOG_WARNING, 'Failed to connect to DB'); return; } $ip = @$db->executeGetOne('SELECT `u`.`current_ip` FROM `ast_sipfriends` `s` JOIN `users` `u` ON (`u`.`id`=`s`.`_user_id`) WHERE `s`.`name`=\'' . $db->escape($ext) . '\''); if (!$ip || !preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $ip)) { gs_log(GS_LOG_WARNING, 'Bad IP'); return; } _gs_prov_phone_checkcfg_by_ip_do_aastra($ip, $reboot, 2); }
function gs_group_connections_get($group_id, $type = false) { $db_slave = gs_db_slave_connect(); if (!$db_slave) { return new GsError('Could not connect to database.'); } $sql_query = 'SELECT * FROM `group_connections` WHERE `group` = ' . $group_id . ' '; if ($type) { $sql_query .= ' AND `type` = \'' . $db_slave->escape($type) . '\''; } $rs = $db_slave->execute($sql_query); $members = array(); if ($rs) { while ($r = $rs->fetchRow()) { $members[] = $r; } } return $members; }
function &gs_db_master_connect($_backtrace_level = 0, $read_fallback_slave = true) { global $gs_db_conn_master, $gs_db_conn_slave; $ret = gs_db_connect($gs_db_conn_master, 'master', GS_DB_MASTER_HOST, GS_DB_MASTER_USER, GS_DB_MASTER_PWD, GS_DB_MASTER_DB, ++$_backtrace_level); if ($ret === 1) { # new connection $gs_db_conn_master->setCustomAttr('w', true); # writeable } elseif (!$ret) { if ($read_fallback_slave) { # if the consumer wants a connection to the master database # but the master is down, give them a connection to the slave # instead and attach the gs_yadb_sql_query_cb_readonly() # callback to make it read-only. if someone tries to write # to the connection that callback deliberately makes the # query fail. gs_log(GS_LOG_NOTICE, 'Failed to connect to master database. Fallback to slave (read-only) ...'); $gs_db_conn_slave = gs_db_slave_connect(); if (!$gs_db_conn_slave) { $null = null; return $null; } $gs_db_conn_slave->setCustomAttr('w', false); # not writeable $gs_db_conn_slave->setQueryCb('gs_yadb_sql_query_cb_readonly'); $gs_db_conn_master = $gs_db_conn_slave; # do not use "=&" here return $gs_db_conn_slave; } $null = null; return $null; } if (gs_db_slave_is_master() && !gs_db_is_connected($gs_db_conn_slave)) { $gs_db_conn_slave =& $gs_db_conn_master; } return $gs_db_conn_master; }
echo '<array>', "\n"; while ($r = $rs->fetchRow()) { echo ' <dict>', "\n"; echo ' <key>firstName</key>', "\n"; echo ' <string>', htmlEnt($r['firstname']), '</string>', "\n"; echo ' <key>lastName</key>', "\n"; echo ' <string>', htmlEnt($r['lastname']), '</string>', "\n"; echo ' <key>telephoneNumber</key>', "\n"; echo ' <string>', $r['number'], '</string>', "\n"; echo ' </dict>', "\n"; } echo '</array>', "\n"; echo '</plist>', "\n"; break; case 'pb_imported': $DB = gs_db_slave_connect(); $rs = $DB->execute('SELECT SQL_CALC_FOUND_ROWS `firstname`, `lastname`, `number` FROM `pb_ldap` ORDER BY `lastname`, `firstname`, `user`, `number` DESC'); echo '<?xml version="1.0" encoding="UTF-8"?>', "\n"; echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">', "\n"; echo '<plist version="1.0">', "\n"; echo '<array>', "\n"; while ($r = $rs->fetchRow()) { echo ' <dict>', "\n"; echo ' <key>firstName</key>', "\n"; echo ' <string>', htmlEnt($r['firstname']), '</string>', "\n"; echo ' <key>lastName</key>', "\n"; echo ' <string>', htmlEnt($r['lastname']), '</string>', "\n";