示例#1
0
 function _upload_ringtone($ringtonefile)
 {
     $file = '/opt/gemeinschaft-siemens/conf.php';
     if (file_exists($file) && is_readable($file)) {
         include_once $file;
     } else {
         gs_log(GS_LOG_NOTICE, "Siemens provisioning not available");
         return false;
     }
     $fileserver['wan'] = gs_get_conf('GS_PROV_SIEMENS_FTP_SERVER_WAN');
     $fileserver['lan'] = gs_get_conf('GS_PROV_SIEMENS_FTP_SERVER_LAN');
     //$fileserver['local'] = gs_get_conf('GS_PROV_HOST');
     $ftp_path = '';
     $external_ftp_path = gs_get_conf('GS_PROV_SIEMENS_FTP_RINGTONE_PATH');
     if ($external_ftp_path === null) {
         $external_ftp_path = '/';
     }
     include_once GS_DIR . 'inc/ftp-filesize.php';
     $ftp = new GS_FTP_FileSize();
     foreach ($fileserver as $file_server) {
         if ($file_server == '') {
             continue;
         }
         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_WARNING, 'Siemens prov.: Can\'t upload ' . $ringtonefile . ' file to ' . $file_server . ' (FTP server failed)');
         } else {
             $ok = $ftp->upload_file($ringtonefile, $external_ftp_path);
             $ftp->disconnect();
             if (!$ok) {
                 gs_log(GS_LOG_WARNING, 'Failed to copy ringtone to FTP server');
             }
         }
     }
     return true;
 }
示例#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;
}