コード例 #1
0
function gs_prov_get_wan_outbound_proxy($db, $phone_ip, $user_id)
{
    $ret = array('sip_proxy_from_wan' => '', 'sip_server_from_wan' => '');
    if (ip_addr_in_network_list($phone_ip, gs_get_conf('GS_PROV_LAN_NETS'))) {
        gs_log(GS_LOG_DEBUG, "Phone {$phone_ip} is in LAN => no SIP proxy");
        return $ret;
    }
    $rs = $db->execute('SELECT `h`.`id`, `h`.`host` ' . 'FROM ' . '`users` `u` JOIN ' . '`hosts` `h` ON (`h`.`id`=`u`.`host_id`) ' . 'WHERE `u`.`id`=' . $user_id);
    if (!$rs || !($host = $rs->getRow())) {
        gs_log(GS_LOG_WARNING, "Failed to find host for user id {$user_id}");
        return $ret;
    }
    if (!ip_addr_in_network_list($host['host'], gs_get_conf('GS_PROV_LAN_NETS'))) {
        gs_log(GS_LOG_DEBUG, "Host " . $host['host'] . " is in WAN => no SIP proxy");
        return $ret;
    }
    # phone in WAN, host in LAN => get outbound proxy for the phone
    $ret['sip_proxy_from_wan'] = $db->executeGetOne('SELECT `value` ' . 'FROM `host_params` ' . 'WHERE ' . '`host_id`=' . (int) $host['id'] . ' AND ' . '`param`=\'sip_proxy_from_wan\'');
    if (!$ret['sip_proxy_from_wan']) {
        $ret['sip_proxy_from_wan'] = '';
    } else {
        if (!preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $ret['sip_proxy_from_wan'])) {
            gs_log(GS_LOG_WARNING, 'Invalid proxy IP addr. "' . $ret['sip_proxy_from_wan'] . '"');
            $ret['sip_proxy_from_wan'] = '';
        }
    }
    # phone in WAN, host in LAN => get server for the phone
    $ret['sip_server_from_wan'] = $db->executeGetOne('SELECT `value` ' . 'FROM `host_params` ' . 'WHERE ' . '`host_id`=' . (int) $host['id'] . ' AND ' . '`param`=\'sip_server_from_wan\'');
    if (!$ret['sip_server_from_wan']) {
        $ret['sip_server_from_wan'] = '';
    } else {
        if (!preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $ret['sip_server_from_wan'])) {
            gs_log(GS_LOG_WARNING, 'Invalid SBC IP addr. "' . $ret['sip_server_from_wan'] . '"');
            $ret['sip_server_from_wan'] = '';
        }
    }
    gs_log(GS_LOG_DEBUG, "Phone {$phone_ip} in WAN, host " . $host['host'] . " in LAN => sip_proxy_from_wan: " . $ret['sip_proxy_from_wan'] . ", sip_server_from_wan: " . $ret['sip_server_from_wan']);
    return $ret;
}
コード例 #2
0
function _deploy_file($type, $ftp_path, $filename, $wan = null)
{
    global $nonce;
    global $requester;
    $type = strToUpper($type);
    $deploy_via_http = gs_get_conf('GS_SIEMENS_PROV_PREFER_HTTP') && $type === 'RINGTONE';
    if (!$deploy_via_http) {
        # FTP
        if ($wan === null) {
            include_once GS_DIR . 'inc/netmask.php';
            $wan = ip_addr_in_network_list($requester['phone_ip'], gs_get_conf('GS_PROV_LAN_NETS'));
        }
        gs_log(GS_LOG_DEBUG, 'Phone ' . $requester['phone_ip'] . ' is in ' . ($wan ? 'WAN' : 'LAN'));
        $file_server = gs_get_conf($wan ? 'GS_PROV_SIEMENS_FTP_SERVER_WAN' : 'GS_PROV_SIEMENS_FTP_SERVER_LAN', gs_get_conf('GS_PROV_HOST'));
        if ($ftp_path == '' || $ftp_path === '/') {
            $ftp_path = './';
        }
        $external_ftp_path = gs_get_conf('GS_PROV_SIEMENS_FTP_PATH');
        if ($external_ftp_path !== null) {
            if (subStr($external_ftp_path, -1) !== '/') {
                $external_ftp_path .= '/';
            }
            $ftp_path = $external_ftp_path . $ftp_path;
        }
        unset($external_ftp_path);
    } else {
        # HTTPS
        switch ($type) {
            case 'RINGTONE':
                $ftp_path = '/ringtones/';
        }
        $http_url = 'https://' . gs_get_conf('GS_PROV_HOST') . ':18443' . $ftp_path . $filename;
    }
    if (!$deploy_via_http) {
        # FTP
        include_once GS_DIR . 'inc/ftp-filesize.php';
        $ftp = new GS_FTP_FileSize();
        if (!$ftp->connect($file_server, null, gs_get_conf('GS_PROV_SIEMENS_FTP_USER'), gs_get_conf('GS_PROV_SIEMENS_FTP_PWD'))) {
            gs_log(GS_LOG_DEBUG, 'Siemens prov.: Can\'t deploy ' . $type . ' file (FTP server failed)');
            return false;
        } else {
            $filesize = $ftp->file_size($ftp_path . $filename);
            $ftp->disconnect();
            if ($filesize < 0) {
                gs_log(GS_LOG_DEBUG, 'Siemens prov.: Can\'t deploy ' . $type . ' file (' . $ftp_path . $filename . ' does not exist)');
                return false;
            } elseif ($filesize < 1) {
                gs_log(GS_LOG_DEBUG, 'Siemens prov.: Can\'t deploy ' . $type . ' file (' . $ftp_path . $filename . ' empty)');
                return false;
            }
        }
    } else {
        # HTTPS
        // check if file is reachable via HTTPS ...
    }
    @ob_end_clean();
    ob_start();
    _dls_message_open($nonce);
    echo "\t", '<Action>', $type === 'APP' ? 'Software' : 'File', 'Deployment</Action>', "\n";
    echo "\t", '<ItemList>', "\n";
    //echo '<Item name="file-action">'  , 'deploy' ,'</Item>',"\n";
    echo '<Item name="file-type">', _siemens_xml_esc($type), '</Item>', "\n";
    # 0=normal, 1=immediate:
    echo '<Item name="file-priority">', $type === 'APP' ? '0' : '1', '</Item>', "\n";
    if (!$deploy_via_http) {
        # FTP
        echo '<Item name="file-server">', _siemens_xml_esc($file_server), '</Item>', "\n";
        echo '<Item name="file-port">', '21', '</Item>', "\n";
        echo '<Item name="file-username">', _siemens_xml_esc(gs_get_conf('GS_PROV_SIEMENS_FTP_USER')), '</Item>', "\n";
        echo '<Item name="file-pwd">', _siemens_xml_esc(gs_get_conf('GS_PROV_SIEMENS_FTP_PWD')), '</Item>', "\n";
        echo '<Item name="file-path">', _siemens_xml_esc($ftp_path), '</Item>', "\n";
        echo '<Item name="file-name">', _siemens_xml_esc($filename), '</Item>', "\n";
    } else {
        # HTTPS
        echo '<Item name="file-https-base-url">', _siemens_xml_esc($http_url), '</Item>', "\n";
    }
    echo "\t", '</ItemList>', "\n";
    _dls_message_close();
    $ob = ob_get_clean();
    if (!headers_sent()) {
        header('X-Powered-By: Gemeinschaft');
        header('Content-Type: text/xml');
        header('Content-Length: ' . strLen($ob));
    }
    echo $ob;
    @_write_raw_log("OUR RESPONSE:\n\n" . _get_response_headers_as_string() . $ob);
    die;
}