MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
+include_once($path_to_root . "/includes/remote_url.inc");
//---------------------------------------------------------------------------------------------
function get_exchange_rate($rate_id)
{
} while( ($contents == '') && $retry--);
} else {
- $handle = @fopen("http://".$site.$filename, 'rb');
- if ($handle) {
- do
- {
- $data = @fread( $handle, 4096 );
- if ( strlen ( $data ) == 0 )
- break;
- $contents .= $data; // with this syntax only text will be translated, whole text with htmlspecialchars($data)
- }
- while (true);
- @fclose( $handle );
- } // end handle
+ $contents = url_get_contents("http://".$site.$filename);
}
if (!$contents) {
display_warning(_("Cannot retrieve currency rate from $provider page. Please set the rate manually."));
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
include_once($path_to_root. "/includes/archive.inc");
+include_once($path_to_root. "/includes/remote_url.inc");
define('PKG_CACHE_PATH', $path_to_root.'/modules/_cache');
define('PUBKEY_PATH', $path_to_root);
$refresh = true;
do{
if (!file_exists($loclist)) {
- copy(REPO_URL.'/Release.gz', $loclist);
+ url_copy(REPO_URL.'/Release.gz', $loclist);
$refresh = false;
}
- $sig = file_get_contents(REPO_URL.'/Release.sig', 'rb');
+ $sig = url_get_contents(REPO_URL.'/Release.sig');
$data = file_get_contents($loclist);
$cert = file_get_contents(PUBKEY_PATH.'/FA.pem');
if (!openssl_verify($data, $sig, $cert)) {
$refresh = true;
do{
if (!file_exists($locindex)) {
- copy($remoteindex, $locindex);
+ url_copy($remoteindex, $locindex);
$refresh = false;
}
if ($parms['SHA1sum'] != sha1_file($locindex)) { // check subdir index consistency
//download package to temp directory
if ($download) {
$locname = "$path_to_root/tmp/".$pkg['Filename'].'.pkg';
- copy($pkgfullname, $locname);
+ url_copy($pkgfullname, $locname);
// checking sha1 hash is expensive proces, so chekc the package
// consistency just before downloading
if ($pkg['SHA1sum'] != sha1_file($locname)) {
--- /dev/null
+<?php
+/**********************************************************************
+ Copyright (C) FrontAccounting, LLC.
+ Released under the terms of the GNU General Public License, GPL,
+ as published by the Free Software Foundation, either version 3
+ of the License, or (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
+
+/*
+ Read content of remote url via http.
+ Does not require curl php extension nor allow_url_fopen=1.
+*/
+function url_get_contents($url, $timeout=10)
+{
+ // get the host name and url path
+ $parsedUrl = parse_url($url);
+
+ $host = $parsedUrl['host'];
+
+ if (isset($parsedUrl['path'])) {
+ $path = $parsedUrl['path'];
+ } else {
+ // the url is pointing to the host like http://www.mysite.com
+ $path = '/';
+ }
+
+ if (isset($parsedUrl['query'])) {
+ $path .= '?' . $parsedUrl['query'];
+ }
+
+ if (isset($parsedUrl['port'])) {
+ $port = $parsedUrl['port'];
+ } else {
+ // most sites use port 80
+ $port = '80';
+ }
+
+ $response = '';
+
+ // connect to the remote server
+ $fp = @fsockopen($host, $port, $errno, $errstr, $timeout );
+ if( !$fp ) {
+ return null;
+ } else {
+ // send the necessary headers to get the file
+ fputs($fp, "GET $path HTTP/1.0\r\n" .
+ "Host: $host\r\n".
+ (isset($parsedUrl['pass']) ? "Authorization: Basic ".
+ base64_encode($parsedUrl['user'].':'.$parsedUrl['pass'])."\r\n" : '').
+ "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3\r\n" .
+ "Accept: */*\r\n" .
+ "Accept-Language: en-us,en;q=0.5\r\n" .
+ "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" .
+ "Keep-Alive: 300\r\n" .
+ "Connection: keep-alive\r\n" .
+ "Referer: http://$host\r\n\r\n");
+
+ // retrieve the response from the remote server
+ $len =0;
+ while ($line = fread($fp, 4096)) {
+ $response .= $line;
+// if ($host=='localhost')
+// stream_set_blocking($fp, 0); // just after connection switch to nonblocking mode
+ }
+ fclose( $fp );
+
+ if (!strpos($response, "200 OK\r\n"))
+ return null;
+ // strip the headers
+ $pos = strpos($response, "\r\n\r\n");
+
+ $response = substr($response, $pos + 4);
+ }
+
+ // return the file content
+ return $response;
+}
+
+function url_copy($from, $to, $timeout=10)
+{
+ $f = fopen($to, 'wb');
+ fwrite($f, url_get_contents($from, $timeout));
+ fclose($f);
+}