• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP fWrite函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: gs_callforward_activate

function gs_callforward_activate($user, $source, $case, $active)
{
    if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) {
        return new GsError('User must be alphanumeric.');
    }
    if (!in_array($source, array('internal', 'external'), true)) {
        return new GsError('Source must be internal|external.');
    }
    if (!in_array($case, array('always', 'busy', 'unavail', 'offline'), true)) {
        return new GsError('Case must be always|busy|unavail|offline.');
    }
    if (!in_array($active, array('no', 'std', 'var', 'vml', 'ano', 'trl', 'par'), true)) {
        return new GsError('Active must be no|std|var|vml|ano|trl|par.');
    }
    # 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 `name` FROM `ast_sipfriends` WHERE `_user_id`=\'' . $db->escape($user_id) . '\'');
    if (!$user_ext) {
        return new GsError('Unknown user extension.');
    }
    # check if user has an entry
    #
    $num = $db->executeGetOne('SELECT COUNT(*) FROM `callforwards` WHERE `user_id`=' . $user_id . ' AND `source`=\'' . $db->escape($source) . '\' AND `case`=\'' . $db->escape($case) . '\'');
    if ($num < 1) {
        $ok = $db->execute('INSERT INTO `callforwards` (`user_id`, `source`, `case`, `number_std`, `number_var`, `number_vml`, `active`) VALUES (' . $user_id . ', \'' . $db->escape($source) . '\', \'' . $db->escape($case) . '\', \'\', \'\', \'\', \'no\')');
    } else {
        $ok = true;
    }
    # do not allow time rules if no time rules  are defined
    #
    if ($active == 'trl') {
        $id = (int) $db->executeGetOne('SELECT `_user_id` from `cf_timerules` WHERE `_user_id`=' . $user_id);
        if (!$id) {
            return new GsError('No time rules defined. Cannot activate call forward.');
        }
    } else {
        if ($active == 'par') {
            $id = (int) $db->executeGetOne('SELECT `_user_id` from `cf_parallelcall` WHERE `_user_id`=' . $user_id);
            if (!$id) {
                return new GsError('No parsllel call tragets. Cannot activate call forward.');
            }
        }
    }
    # set state
    #
    $ok = $ok && $db->execute('UPDATE `callforwards` SET
	`active`=\'' . $db->escape($active) . '\'
WHERE
	`user_id`=' . $user_id . ' AND
	`source`=\'' . $db->escape($source) . '\' AND
	`case`=\'' . $db->escape($case) . '\'
LIMIT 1');
    if (!$ok) {
        return new GsError('Failed to set call forwarding status.');
    }
    # do not allow an empty number to be active
    #
    if ($active == 'std' || $active == 'var') {
        $field = 'number_' . $active;
        $number = $db->executeGetOne('SELECT `' . $field . '` FROM `callforwards` WHERE `user_id`=' . $user_id . ' AND `source`=\'' . $db->escape($source) . '\' AND `case`=\'' . $db->escape($case) . '\'');
        if (trim($number) == '') {
            $db->execute('UPDATE `callforwards` SET `active`=\'no\' WHERE `user_id`=' . $user_id . ' AND `source`=\'' . $db->escape($source) . '\' AND `case`=\'' . $db->escape($case) . '\'');
            return new GsError('Number is empty. Cannot activate call forward.');
        }
    }
    if ($case === 'always') {
        $filename = '/tmp/gs-' . $user_id . '-' . time() . '-' . rand(10000, 99999) . '.call';
        $call = "Channel: local/toggle@toggle-cfwd-hint\n" . "MaxRetries: 0\n" . "WaitTime: 15\n" . "Context: toggle-cfwd-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";
        $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
//.........这里部分代码省略.........
开发者ID:hehol,项目名称:GemeinschaftPBX,代码行数:101,代码来源:gs_callforward_activate.php


示例17: buildlanguage

 /**
  * build language files from database
  *
  * @param	boolean	$force
  */
 public static function buildlanguage($force = false)
 {
     $availableLanguages = array("de", "en");
     foreach ($availableLanguages as $languageID => $languageCode) {
         $file = DNS_DIR . "/lang/" . $languageCode . ".lang.php";
         if (!file_exists($file) || filemtime($file) + 86400 < time() || $force === true) {
             if (file_exists($file)) {
                 @unlink($file);
             }
             @touch($file);
             $items = self::getDB()->query("select * from dns_language where languageID = ?", array($languageID));
             $content = "<?php\n/**\n* language: " . $languageCode . "\n* encoding: UTF-8\n* generated at " . gmdate("r") . "\n* \n* DO NOT EDIT THIS FILE\n*/\n";
             $content .= "\$lang = array();\n";
             while ($row = self::getDB()->fetch_array($items)) {
                 print_r($row);
                 $content .= "\$lang['" . $row['languageItem'] . "'] = '" . str_replace("\$", '$', $row['languageValue']) . "';\n";
             }
             $handler = fOpen($file, "a+");
             fWrite($handler, $content);
             fClose($handler);
         }
     }
 }
开发者ID:cengjing,项目名称:Domain-Control-Panel,代码行数:28,代码来源:DNS.class.php


示例18: writeDataFile

function writeDataFile($data_file)
{
    global $node;
    $save_struct = serialize($node);
    $datafilep = @fOpen($data_file, 'wb');
    if (!$datafilep) {
        write_log("Cannot open {$data_file} for writing! Bad things will happen!");
        return 1;
    }
    @fWrite($datafilep, $save_struct, strLen($save_struct));
    fClose($datafilep);
    write_log("Data file {$data_file} written.");
}
开发者ID:rkania,项目名称:GS3,代码行数:13,代码来源:gs-cluster-watchdog.php


示例19: fWrite

        fWrite($handler, $out);
        fClose($handler);
        $signed = false;
        if ($sign === true) {
            shell_exec("cd /srv/bind/ && /usr/sbin/dnssec-signzone -r /dev/urandom -A -N INCREMENT -K /srv/bind/dnssec/" . $zone['soa']['origin'] . "/ -o " . $zone['soa']['origin'] . " -t " . $zone['soa']['origin'] . "db");
            if (file_exists("/srv/bind/" . $zone['soa']['origin'] . "db.signed")) {
                $signed = true;
            }
        }
        $cout = "zone \"" . $zone['soa']['origin'] . "\" {\n";
        $cout .= "\ttype master;\n";
        $cout .= "\tnotify no;\n";
        $cout .= "\tfile \"/srv/bind/" . $zone['soa']['origin'] . "db" . ($signed === true ? ".signed" : "") . "\";\n";
        $cout .= "};\n\n";
        $handler = fOpen("/srv/bind/domains.cfg", "a+");
        fWrite($handler, $cout);
        fClose($handler);
    }
    shell_exec("/etc/init.d/bind9 reload");
}
function getFileName($zone, $algo, $id, $type)
{
    $len = strlen($id);
    if ($len == "1") {
        $id = "0000" . $id;
    } else {
        if ($len == "2") {
            $id = "000" . $id;
        } else {
            if ($len == "3") {
                $id = "00" . $id;
开发者ID:cengjing,项目名称:Domain-Control-Panel,代码行数:31,代码来源:bind9.php


示例20: gs_extstate

function gs_extstate($host, $exts)
{
    static $hosts = array();
    if (!is_array($exts)) {
        $exts = array($exts);
        $return_single = true;
    } else {
        $return_single = false;
    }
    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 $return_single ? AST_MGR_EXT_UNKNOWN : array();
        }
        $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 $return_single ? AST_MGR_EXT_UNKNOWN : array();
        }
        $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_read($sock, 3, '/\\r\\n\\r\\n/S');
        if ($data === false) {
            gs_log(GS_LOG_WARNING, 'Authentication to AMI on ' . $host . ' failed (timeout)');
            $hosts[$host]['sock'] = null;
            return $return_single ? AST_MGR_EXT_UNKNOWN : array();
        } elseif (!preg_match('/Authentication accepted/i', $data)) {
            gs_log(GS_LOG_WARNING, 'Authentication to AMI on ' . $host . ' failed');
            $hosts[$host]['sock'] = null;
            return $return_single ? AST_MGR_EXT_UNKNOWN : array();
        }
    } else {
        $sock = $hosts[$host]['sock'];
    }
    $states = array();
    foreach ($exts as $ext) {
        $req = "Action: ExtensionState\r\n" . "Context: to-internal-users\r\n" . "Exten: " . $ext . "\r\n" . "\r\n";
        @fWrite($sock, $req, strLen($req));
        @fFlush($sock);
        $resp = trim(_sock_read($sock, 3, '/\\r\\n\\r\\n/S'));
        //echo "\n$resp\n\n";
        $states[$ext] = AST_MGR_EXT_UNKNOWN;
        if (!preg_match('/^Response:\\s*Success/is', $resp)) {
            continue;
        }
        if (!preg_match('/^Exten:\\s*([\\da-z]+)/mis', $resp, $m)) {
            continue;
        }
        $resp_ext = $m[1];
        if (!preg_match('/^Status:\\s*(-?\\d+)/mis', $resp, $m)) {
            continue;
        }
        $resp_state = (int) $m[1];
        $states[$resp_ext] = $resp_state;
    }
    if ($return_single) {
        return array_key_exists($exts[0], $states) ? $states[$exts[0]] : AST_MGR_EXT_UNKNOWN;
    } else {
        return $states;
    }
}
开发者ID:hehol,项目名称:GemeinschaftPBX,代码行数:83,代码来源:extension-state.php



注:本文中的fWrite函数示例整理自Github/MS


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP f_hsc函数代码示例发布时间:2022-05-15
下一篇:
PHP fToDate函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap