示例#1
0
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;
}
示例#2
0
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;
}
示例#3
0
 $queues = explode(',', $user['queues']);
 # this damn function returns array(0=>'') for an empty string
 if (@$queues[0] == '') {
     $queues = array();
 }
 echo '<tr class="', ++$i % 2 === 0 ? 'even' : 'odd', '">';
 echo '<td>', htmlEnt($user['ext']), '</td>';
 echo '<td>', htmlEnt($user['ln']);
 if ($user['fn'] != '') {
     echo ', ', htmlEnt($user['fn']);
 }
 echo '</td>';
 if ($GS_INSTALLATION_TYPE_SINGLE) {
     $user['host'] = '127.0.0.1';
 }
 $extstate = gs_extstate($user['host'], $user['ext']);
 $extinfos[$user['ext']]['info'] = $user;
 $extinfos[$user['ext']]['state'] = $extstate;
 $extstatev = _extstate2v($extstate);
 if (gs_get_conf('GS_GUI_MON_NOQUEUEBLUE')) {
     if ($extstate === AST_MGR_EXT_IDLE && count($queues) < 1) {
         # blue LED for available users who are not member of a queue
         $extstatev['s'] = 'blue';
     }
 }
 if (@$extstatev['s']) {
     $img = '<img alt=" " src="' . GS_URL_PATH;
     switch ($extstatev['s']) {
         case 'green':
             $img .= 'crystal-svg/16/act/greenled.png';
             break;
示例#4
0
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);
}
示例#5
0
     echo '<tr><td colspan="3"><i>- ', htmlEnt(__('keine')), ' -</i></td></tr>';
 } else {
     $i = 0;
     while ($r = $rs_members->fetchRow()) {
         echo '<tr class="', ++$i % 2 == 0 ? 'even' : 'odd', '">';
         echo '<td>', htmlEnt($r['ext']), '</td>';
         $sudo_url = @$_SESSION['sudo_user']['name'] == @$_SESSION['real_user']['name'] ? '' : '&amp;sudo=' . @$_SESSION['sudo_user']['name'];
         echo '<td>', htmlEnt($r['ln']);
         if ($r['fn'] != '') {
             echo ', ', htmlEnt($r['fn']);
         }
         echo '</td>';
         if ($GS_INSTALLATION_TYPE_SINGLE) {
             $r['host'] = '127.0.0.1';
         }
         $extstate = gs_extstate($r['host'], $r['ext']);
         $extinfos[$r['ext']]['info'] = $r;
         $extinfos[$r['ext']]['state'] = $extstate;
         $extstatev = _extstate2v($extstate);
         if (@$extstatev['s']) {
             $img = '<img alt=" " src="' . GS_URL_PATH;
             switch ($extstatev['s']) {
                 case 'green':
                     $img .= 'crystal-svg/16/act/greenled.png';
                     break;
                 case 'yellow':
                     $img .= 'crystal-svg/16/act/yellowled.png';
                     break;
                 case 'red':
                     $img .= 'crystal-svg/16/act/redled.png';
                     break;