当前位置: 首页>>代码示例>>PHP>>正文


PHP fWrite函数代码示例

本文整理汇总了PHP中fWrite函数的典型用法代码示例。如果您正苦于以下问题:PHP fWrite函数的具体用法?PHP fWrite怎么用?PHP fWrite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fWrite函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: siemens_push_str

function siemens_push_str($phone_ip, $postdata)
{
    $prov_host = gs_get_conf('GS_PROV_HOST');
    $data = "POST /server_push.html/ServerPush HTTP/1.1\r\n";
    $data .= "User-Agent: Gemeinschaft\r\n";
    $data .= "Host: {$phone_ip}:8085\r\n";
    $data .= "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n";
    $data .= "Connection: keep-alive\r\n";
    $data .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $data .= "Content-Length: " . strLen($postdata) . "\r\n\r\n";
    $data .= $postdata;
    $socket = @fSockOpen($phone_ip, 8085, $error_no, $error_str, 4);
    if (!$socket) {
        gs_log(GS_LOG_NOTICE, "Siemens: Failed to open socket - IP: {$phone_ip}");
        return 0;
    }
    stream_set_timeout($socket, 4);
    $bytes_written = (int) @fWrite($socket, $data, strLen($data));
    @fFlush($socket);
    $response = @fGetS($socket);
    @fClose($socket);
    if (strPos($response, '200') === false) {
        gs_log(GS_LOG_WARNING, "Siemens: Failed to push to phone {$phone_ip}");
        return 0;
    }
    gs_log(GS_LOG_DEBUG, "Siemens: Pushed {$bytes_written} bytes to phone {$phone_ip}");
    return $bytes_written;
}
开发者ID:hehol,项目名称:GemeinschaftPBX,代码行数:28,代码来源:siemens-fns.php

示例2: accept

 public function accept($extractionResult)
 {
     foreach (new ArrayObject($extractionResult->getTriples()) as $triple) {
         // TODO: make sure that https://sourceforge.net/tracker/?func=detail&aid=2901137&group_id=190976&atid=935520 is fixed
         $tripleString = explode(">", $triple->toStringNoEscape());
         $s = trim(str_replace("<", "", $tripleString[0]));
         $s = preg_replace('~^' . DB_RESOURCE_NS . '~', "", $s);
         $p = trim(str_replace("<", "", $tripleString[1]));
         $p = preg_replace('~^' . DB_PROPERTY_NS . '~', "", $p);
         if (preg_match('/^<http:/', $tripleString[2])) {
             $object_is = 'r';
         } else {
             $object_is = 'l';
         }
         $o = trim(str_replace("<", "", $tripleString[2]));
         $dtypePos = strpos($o, "^^");
         $langPos = strpos($o, "@");
         if ($dtypePos) {
             $o = substr($o, 0, $dtypePos);
         }
         if ($langPos) {
             $o = substr($o, 0, $langPos);
         }
         $o = preg_replace('/(^")|("$)/', "", $o);
         $o = preg_replace('~^' . DB_RESOURCE_NS . '~', "", $o);
         #if ( !preg_match('/^[0-9\.,]+$/', $o) ) $o = "\"" . $o . "\"";
         #print("\"" . $s . "\"" . $this->delimiter . "\"" . $p . "\"" .  $this->delimiter . $o . "\n");
         //triple in Datei schreiben
         fWrite($this->DumpFile, $s . $this->delimiter . $p . $this->delimiter . $o . $this->delimiter . $object_is . "\n");
     }
     $this->counter++;
     echo $this->counter . "\n";
 }
开发者ID:ljarray,项目名称:dbpedia,代码行数:33,代码来源:csvDestination.php

示例3: send_sip_packet

function send_sip_packet($ip, $port, $packet, $source_ip = false)
{
    $spoof = $source_ip ? '-s \'' . $source_ip . '\'' : '';
    $p = pOpen('netcat -u -n -p 5060 -w 1 -q 0 ' . $spoof . ' ' . $ip . ' ' . $port . ' >>/dev/null', 'wb');
    fWrite($p, $packet, strLen($packet));
    fClose($p);
}
开发者ID:rkania,项目名称:GS3,代码行数:7,代码来源:sip-desktop-message.php

示例4: InitRecordCall

function InitRecordCall($filename, $index, $comment)
{
    //FIXME
    $user = gs_user_get($_SESSION['sudo_user']['name']);
    $call = "Channel: SIP/" . $_SESSION['sudo_user']['info']['ext'] . "\n" . "MaxRetries: 0\n" . "WaitTime: 15\n" . "Context: vm-rec-multiple\n" . "Extension: webdialrecord\n" . "Callerid: {$comment} <Aufnahme>\n" . "Setvar: __user_id=" . $_SESSION['sudo_user']['info']['id'] . "\n" . "Setvar: __user_name=" . $_SESSION['sudo_user']['info']['ext'] . "\n" . "Setvar: CHANNEL(language)=" . gs_get_conf('GS_INTL_ASTERISK_LANG', 'de') . "\n" . "Setvar: __is_callfile_origin=1\n" . "Setvar: __callfile_from_user=" . $_SESSION['sudo_user']['info']['ext'] . "\n" . "Setvar: __record_file=" . $filename . "\n";
    $filename = '/tmp/gs-' . $_SESSION['sudo_user']['info']['id'] . '-' . _pack_int(time()) . rand(100, 999) . '.call';
    $cf = @fOpen($filename, 'wb');
    if (!$cf) {
        gs_log(GS_LOG_WARNING, 'Failed to write call file "' . $filename . '"');
        echo 'Failed to write call file.';
        die;
    }
    @fWrite($cf, $call, strLen($call));
    @fClose($cf);
    @chmod($filename, 0666);
    $spoolfile = '/var/spool/asterisk/outgoing/' . baseName($filename);
    if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) {
        $our_host_ids = @gs_get_listen_to_ids();
        if (!is_array($our_host_ids)) {
            $our_host_ids = array();
        }
        $user_is_on_this_host = in_array($_SESSION['sudo_user']['info']['host_id'], $our_host_ids);
    } else {
        $user_is_on_this_host = true;
    }
    if ($user_is_on_this_host) {
        # the Asterisk of this user and the web server both run on this host
        $err = 0;
        $out = array();
        @exec('sudo mv ' . qsa($filename) . ' ' . qsa($spoolfile) . ' 1>>/dev/null 2>>/dev/null', $out, $err);
        if ($err != 0) {
            @unlink($filename);
            gs_log(GS_LOG_WARNING, 'Failed to move call file "' . $filename . '" to "' . '/var/spool/asterisk/outgoing/' . baseName($filename) . '"');
            echo 'Failed to move call file.';
            die;
        }
    } else {
        $cmd = 'sudo scp -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa($filename) . ' ' . qsa('root@' . $user['host'] . ':' . $filename);
        //echo $cmd, "\n";
        @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err);
        @unlink($filename);
        if ($err != 0) {
            gs_log(GS_LOG_WARNING, 'Failed to scp call file "' . $filename . '" to ' . $user['host']);
            echo 'Failed to scp call file.';
            die;
        }
        //remote_exec( $user['host'], $cmd, 10, $out, $err ); // <-- does not use sudo!
        $cmd = 'sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ' . qsa($user['host']) . ' ' . qsa('mv ' . qsa($filename) . ' ' . qsa($spoolfile));
        //echo $cmd, "\n";
        @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err);
        if ($err != 0) {
            gs_log(GS_LOG_WARNING, 'Failed to mv call file "' . $filename . '" on ' . $user['host'] . ' to "' . $spoolfile . '"');
            echo 'Failed to mv call file on remote host.';
            die;
        }
    }
}
开发者ID:rkania,项目名称:GS3,代码行数:57,代码来源:forwards_queues.php

示例5: accept

 public function accept($extractionResult)
 {
     foreach (new ArrayObject($extractionResult->getTriples()) as $triple) {
         //triple in Datei schreiben
         fWrite($this->DumpFile, $triple->toString());
         //print($triple->toString());
     }
     $this->counter++;
     echo $this->counter . "\n";
 }
开发者ID:ljarray,项目名称:dbpedia,代码行数:10,代码来源:NTripleDumpDestination.php

示例6: set

 /**
  * @see	\dns\system\cache\source\ICacheSource::set()
  */
 public function set($cacheName, $value, $maxLifetime)
 {
     $filename = $this->getFilename($cacheName);
     $content = "<?php exit; /* cache: " . $cacheName . " (generated at " . gmdate('r') . ") DO NOT EDIT THIS FILE */ ?>\n";
     $content .= serialize($value);
     if (!file_exists($filename)) {
         @touch($filename);
     }
     $handler = fOpen($filename, "a+");
     fWrite($handler, $content);
     fClose($handler);
 }
开发者ID:cengjing,项目名称:Domain-Control-Panel,代码行数:15,代码来源:DiskCacheSource.class.php

示例7: gs_hylafax_authfile_create

function gs_hylafax_authfile_create($authfile)
{
    # connect to db
    #
    $db = gs_db_master_connect();
    if (!$db) {
        return new GsError('Could not connect to database.');
    }
    # get user list
    #
    $rs = $db->execute('SELECT `id`, `user`, `pin`
FROM `users`
WHERE `nobody_index` IS NULL
ORDER BY `id`');
    if (!$rs) {
        return new GsError('Error.');
    }
    # create temporary hylafax host/user authentication file
    #
    if (file_exists($authfile) && !is_writable($authfile)) {
        @exec('sudo rm -f ' . qsa($authfile) . ' 2>>/dev/null');
    }
    $fh = @fOpen($authfile, 'w');
    if (!$fh) {
        return new GsError('Failed to open HylaFax authfile.');
    }
    # create localhost access without authentication first, if enabled
    #
    if (gs_get_conf('GS_FAX_NOAUTH_LOCALHOST') === true) {
        fWrite($fh, "127.0.0.1\n", strLen("127.0.0.1\n"));
    }
    # create admin entry first
    #
    if (gs_get_conf('GS_FAX_HYLAFAX_ADMIN') != '') {
        $crypted = crypt(gs_get_conf('GS_FAX_HYLAFAX_PASS'), 'pF');
        $user_entry = '^' . preg_quote(gs_get_conf('GS_FAX_HYLAFAX_ADMIN')) . '@:' . '0' . ':' . $crypted . ':' . $crypted . "\n";
        fWrite($fh, $user_entry, strLen($user_entry));
    }
    # create user entries
    #
    while ($user = $rs->fetchRow()) {
        $crypted = crypt($user['pin'], 'ml');
        $user_entry = '^' . preg_quote($user['user']) . '@:' . $user['id'] . ':' . $crypted . "\n";
        fWrite($fh, $user_entry, strLen($user_entry));
    }
    # close file
    #
    if (@fclose($fh)) {
        return true;
    } else {
        return new GsError('Error.');
    }
}
开发者ID:hehol,项目名称:GemeinschaftPBX,代码行数:53,代码来源:gs_hylafax_authfile.php

示例8: gs_write_error

function gs_write_error($data)
{
    if (!defined('STDERR')) {
        define('STDERR', @fOpen('php://stderr', 'wb'));
    }
    if (php_sapi_name() === 'cli' && STDERR) {
        @fWrite(STDERR, $data, strLen($data));
        @fFlush(STDERR);
    } else {
        echo $data;
    }
}
开发者ID:rkania,项目名称:GS3,代码行数:12,代码来源:util.php

示例9: gif_outputAsPng

function gif_outputAsPng($gif, $lpszFileName, $bgColor = -1)
{
    if (!isset($gif) || @get_class($gif) != "cgif" || !$gif->loaded() || $lpszFileName == "") {
        return false;
    }
    $fd = $gif->getPng($bgColor);
    if (strlen($fd) <= 0) {
        return false;
    }
    if (!($fh = @fOpen($lpszFileName, "wb"))) {
        return false;
    }
    @fWrite($fh, $fd, strlen($fd));
    @fFlush($fh);
    @fClose($fh);
    return true;
}
开发者ID:BackupTheBerlios,项目名称:soopa,代码行数:17,代码来源:gif.php

示例10: ami_send_command

 public function ami_send_command($command)
 {
     @fWrite($this->_socket, $command, strLen($command));
     @fFlush($this->_socket);
     $data = array();
     while (!fEof($this->_socket)) {
         $tmp = @fgets($this->_socket, 8192);
         if (strlen(trim($tmp)) <= 0) {
             break;
         }
         list($first, $last) = explode(':', $tmp);
         $data[trim($first)] = trim($last);
         usleep(1000);
         # sleep 0.001 secs
     }
     return $data;
 }
开发者ID:hehol,项目名称:GemeinschaftPBX,代码行数:17,代码来源:ami-fns.php

示例11: ami_send_command

 public function ami_send_command($command)
 {
     @fWrite($this->_socket, $command, strLen($command));
     @fFlush($this->_socket);
     $data = array();
     while (!fEof($this->_socket)) {
         $tmp = @fRead($this->_socket, 8192);
         list($first, $last) = explode(':', $tmp);
         $data[trim($first)] = trim($last);
         if (@preg_match('/\\r\\n\\r\\n/S', $tmp)) {
             break;
         }
         usleep(1000);
         # sleep 0.001 secs
     }
     return $data;
 }
开发者ID:rkania,项目名称:GS3,代码行数:17,代码来源:ami-fns.php

示例12: gs_send_phone_desktop_msg

function gs_send_phone_desktop_msg($ip, $port, $ext, $registrar, $text, $extra = array())
{
    static $sock = null;
    static $lAddr = '0.0.0.0';
    static $lPort = 0;
    static $have_sockets = null;
    if ($have_sockets === null) {
        $have_sockets = function_exists('socket_create');
        // about 15 to 45 % faster
    }
    if (is_array($extra) && array_key_exists('fake_callid', $extra)) {
        $fake_callid = $extra['fake_callid'];
    } else {
        $fake_callid = rand(1000000000, 2000000000);
    }
    if ($have_sockets) {
        if (!$sock) {
            $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
            if (!$sock) {
                return false;
            }
            //socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1);
            //socket_bind($sock, '0.0.0.0', 12345);
            @socket_getSockName($sock, $lAddr, $lPort);
            //echo "Local socket is at $lAddr:$lPort\n";
            @socket_set_nonblock($sock);
        }
    } else {
        $sock = @fSockOpen('udp://' . $ip, $port, $err, $errmsg, 1);
        if (!$sock) {
            return false;
        }
        @stream_set_blocking($sock, 0);
        @stream_set_timeout($sock, 1);
    }
    $sipmsg = 'MESSAGE sip:' . $ext . '@' . $ip . ' SIP/2.0' . "\r\n" . 'Via: SIP/2.0/UDP ' . $registrar . ':' . $lPort . "\r\n" . 'To: sip:' . $ext . '@' . $ip . '' . "\r\n" . 'Call-ID: ' . $fake_callid . '@' . $registrar . "\r\n" . 'CSeq: 1 MESSAGE' . "\r\n" . 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'Max-Forwards: 9' . "\r\n" . 'From: sip:fake@' . $registrar . ':' . $lPort . ';tag=fake' . "\r\n" . 'Content-Length: ' . strLen($text) . "\r\n" . 'Content-Disposition: desktop' . "\r\n" . "\r\n" . $text;
    if ($have_sockets) {
        return @socket_sendto($sock, $sipmsg, strLen($sipmsg), 0, $ip, $port);
    } else {
        $written = @fWrite($sock, $sipmsg, strlen($sipmsg));
        @fClose($sock);
        return $written;
    }
}
开发者ID:rkania,项目名称:GS3,代码行数:44,代码来源:send-phone-msg.php

示例13: aastra_push_str

function aastra_push_str($phone_ip, $xml)
{
    $prov_host = gs_get_conf('GS_PROV_HOST');
    //FIXME - call wget or something. this function should not block
    // for so long!
    // see _gs_prov_phone_checkcfg_by_ip_do_aastra() in
    // opt/gemeinschaft/inc/gs-fns/gs_prov_phone_checkcfg.php
    //$xml = utf8_decode($xml);
    if (subStr($xml, 0, 5) !== '<' . '?xml') {
        $xmlpi = '<' . '?xml version="1.0" encoding="UTF-8"?' . '>' . "\n";
    } else {
        $xmlpi = '';
    }
    $data = "POST / HTTP/1.1\r\n";
    $data .= "Host: {$phone_ip}\r\n";
    $data .= "Referer: {$prov_host}\r\n";
    $data .= "Connection: Close\r\n";
    $data .= "Content-Type: text/xml; charset=utf-8\r\n";
    $data .= "Content-Length: " . (strLen('xml=') + strLen($xmlpi) + strLen($xml)) . "\r\n";
    $data .= "\r\n";
    $data .= 'xml=' . $xmlpi . $xml;
    $socket = @fSockOpen($phone_ip, 80, $error_no, $error_str, 4);
    if (!$socket) {
        gs_log(GS_LOG_NOTICE, "Aastra: Failed to open socket - IP: {$phone_ip}");
        return 0;
    }
    stream_set_timeout($socket, 4);
    $bytes_written = (int) @fWrite($socket, $data, strLen($data));
    @fFlush($socket);
    $response = @fGetS($socket);
    @fClose($socket);
    if (strPos($response, '200') === false) {
        gs_log(GS_LOG_WARNING, "Aastra: Failed to push XML to phone {$phone_ip}");
        return 0;
    }
    gs_log(GS_LOG_DEBUG, "Aastra: Pushed {$bytes_written} bytes to phone {$phone_ip}");
    return $bytes_written;
}
开发者ID:rkania,项目名称:GS3,代码行数:38,代码来源:aastra-fns.php

示例14: gs_queue_status

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)) {
//.........这里部分代码省略.........
开发者ID:rkania,项目名称:GS3,代码行数:101,代码来源:queue-status.php

示例15: gs_callwaiting_activate

function gs_callwaiting_activate($user, $active)
{
    if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) {
        return new GsError('User must be alphanumeric.');
    }
    $active = !!$active;
    # connect to db
    #
    $db = gs_db_master_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 user_ext
    $user_ext = $db->executeGetOne('SELECT `s`.`name` `ext`
FROM
	`users` `u` JOIN
	`ast_sipfriends` `s` ON (`s`.`_user_id`=`u`.`id`)
WHERE `u`.`user`=\'' . $db->escape($user) . '\'');
    if (!$user_ext) {
        return new GsError('Unknown user.');
    }
    # (de)activate
    #
    $num = $db->executeGetOne('SELECT COUNT(*) FROM `callwaiting` WHERE `user_id`=' . $user_id);
    if ($num < 1) {
        $ok = $db->execute('INSERT INTO `callwaiting` (`user_id`, `active`) VALUES (' . $user_id . ', 0)');
    } else {
        $ok = true;
    }
    $ok = $ok && $db->execute('UPDATE `callwaiting` SET `active`=' . (int) $active . ' WHERE `user_id`=' . $user_id);
    if (!$ok) {
        return new GsError('Failed to set call waiting.');
    }
    $call = "Channel: local/toggle@toggle-cwait-hint\n" . "MaxRetries: 0\n" . "WaitTime: 15\n" . "Context: toggle-cwait-hint\n" . "Extension: toggle\n" . "Callerid: {$user} <Toggle>\n" . "Setvar: __user_id=" . $user_id . "\n" . "Setvar: __user_name=" . $user_ext . "\n" . "Setvar: CHANNEL(language)=" . gs_get_conf('GS_INTL_ASTERISK_LANG', 'de') . "\n" . "Setvar: __is_callfile_origin=1\n" . "Setvar: __callfile_from_user=" . $user_ext . "\n" . "Setvar: __record_file=" . $filename . "\n";
    $filename = '/tmp/gs-' . $user_id . '-' . time() . '-' . rand(10000, 99999) . '.call';
    $cf = @fOpen($filename, 'wb');
    if (!$cf) {
        gs_log(GS_LOG_WARNING, 'Failed to write call file "' . $filename . '"');
        return new GsError('Failed to write call file.');
    }
    @fWrite($cf, $call, strLen($call));
    @fClose($cf);
    @chmod($filename, 0666);
    $spoolfile = '/var/spool/asterisk/outgoing/' . baseName($filename);
    if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) {
        $our_host_ids = @gs_get_listen_to_ids();
        if (!is_array($our_host_ids)) {
            $our_host_ids = array();
        }
        $user_is_on_this_host = in_array($_SESSION['sudo_user']['info']['host_id'], $our_host_ids);
    } else {
        $user_is_on_this_host = true;
    }
    if ($user_is_on_this_host) {
        # the Asterisk of this user and the web server both run on this host
        $err = 0;
        $out = array();
        @exec('sudo mv ' . qsa($filename) . ' ' . qsa($spoolfile) . ' 1>>/dev/null 2>>/dev/null', $out, $err);
        if ($err != 0) {
            @unlink($filename);
            gs_log(GS_LOG_WARNING, 'Failed to move call file "' . $filename . '" to "' . $spoolfile . '"');
            return new GsError('Failed to move call file.');
        }
    } else {
        $cmd = 'sudo scp -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa($filename) . ' ' . qsa('root@' . $user['host'] . ':' . $filename);
        //echo $cmd, "\n";
        @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err);
        @unlink($filename);
        if ($err != 0) {
            gs_log(GS_LOG_WARNING, 'Failed to scp call file "' . $filename . '" to ' . $user['host']);
            return new GsError('Failed to scp call file.');
        }
        //remote_exec( $user['host'], $cmd, 10, $out, $err ); // <-- does not use sudo!
        $cmd = 'sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ' . qsa($user['host']) . ' ' . qsa('mv ' . qsa($filename) . ' ' . qsa($spoolfile));
        //echo $cmd, "\n";
        @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err);
        if ($err != 0) {
            gs_log(GS_LOG_WARNING, 'Failed to mv call file "' . $filename . '" on ' . $user['host'] . ' to "' . $spoolfile . '"');
            return new GsError('Failed to mv call file on remote host.');
        }
    }
    # reload phone config
    #
    //$user_name = $db->executeGetOne( 'SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`='. $user_id );
    //@ exec( 'asterisk -rx \'sip notify snom-reboot '. $user_name .'\'' );
    //@ gs_prov_phone_checkcfg_by_user( $user, false ); //FIXME
    return true;
}
开发者ID:rkania,项目名称:GS3,代码行数:94,代码来源:gs_callwaiting_activate.php


注:本文中的fWrite函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。