Esempio n. 1
0
function receiveAjax()
{
    setHeaders();
    if (!isset($_GET['username'])) {
        echo json_encode(array("error" => "No username specified."));
        return;
    }
    $xmlh = @simplexml_load_file("http://projecteuler.net/profile/" . $_GET['username'] . ".xml");
    if (!$xmlh) {
        echo json_encode(array("error" => "Username does not exist."));
        return;
    }
    echo json_encode($xmlh);
}
                    }
                    $tmp = $response = null;
                    if (strpos($mime, 'image/svg') !== 0 && strpos($mime, 'image/') === 0) {
                        echo $param_callback, '("data:', $mime, ';base64,', base64_encode(file_get_contents($locationFile)), '");';
                    } else {
                        echo $param_callback, '("data:', $mime, ',', asciiToInline(file_get_contents($locationFile)), '");';
                    }
                } else {
                    $tmp = $response = null;
                    $dir_name = dirname($_SERVER['SCRIPT_NAME']);
                    if ($dir_name === '\\/' || $dir_name === '\\') {
                        $dir_name = '';
                    }
                    echo $param_callback, '(', JsonEncodeString(($http_port === 443 ? 'https://' : 'http://') . preg_replace('#:[0-9]+$#', '', $_SERVER['HTTP_HOST']) . ($http_port === 80 || $http_port === 443 ? '' : ':' . $_SERVER['SERVER_PORT']) . $dir_name . '/' . $locationFile), ');';
                }
                exit;
            } else {
                $response = array('error' => 'Failed to rename the temporary file');
            }
        }
    }
}
if (is_array($tmp) && isset($tmp['location']) && file_exists($tmp['location'])) {
    //remove temporary file if an error occurred
    unlink($tmp['location']);
}
//errors
setHeaders(true);
//no-cache
remove_old_files();
echo $param_callback, '(', JsonEncodeString('error: html2canvas-proxy-php: ' . $response['error']), ');';
Esempio n. 3
0
    header("Cache-Control: \"max-age={$cache_age}, public, must-revalidate, proxy-revalidate\"");
    if ($if_modified_since && $if_modified_since == $tsstring) {
        header("HTTP/1.1 304 Not Modified");
        exit;
    }
}
require_once "config.inc.php";
if (!isset($_GET["file"]) || !isset($_GET["type"])) {
    call_404();
}
$file = $_SERVER["DOCUMENT_ROOT"] . $_GET["file"];
$cache = $_SERVER["DOCUMENT_ROOT"] . "/cache/" . $_GET["type"] . "/" . $_GET["file"] . ".php";
if (!file_exists($file)) {
    call_404();
}
setHeaders();
if (!$compressorEnabled || $_GET["file"] == "/scripts/jQuery.js") {
    readfile($file);
    exit;
}
if (file_exists($cache)) {
    require_once $cache;
} else {
    $hash = "";
    if (!file_exists(dirname($cache))) {
        mkdir(dirname($cache), 0775, true);
    }
}
if ($hash != ($file_hash = sha1_file("{$file}"))) {
    // Compress the css or js file with the API of http://cssminifier.com or http://javascript-minifier.com
    if ($_GET["type"] == "css") {
Esempio n. 4
0
                    preg_replace('#:[0-9]+$#', '', $_SERVER['HTTP_HOST']) .
                    ($http_port === 80 || $http_port === 443 ? '' : (
                        ':' . $_SERVER['SERVER_PORT']
                    )) .
                    dirname($_SERVER['SCRIPT_NAME']). '/' .
                    $locationFile
                ),
            ');';
            exit;
        } else {
            $response = array('error' => 'Failed to rename the temporary file');
        }
    }
}

if(is_array($tmp) && isset($tmp['location']) && file_exists($tmp['location'])) {
    //remove temporary file if an error occurred
    unlink($tmp['location']);
}

//errors
setHeaders(true);//no-cache

remove_old_files();

echo $param_callback, '(',
    json_encode_string(
        'error: html2canvas-proxy-php: ' . $response['error']
    ),
');';
Esempio n. 5
0
/**
 * Callback to for proxy page
 */
function ac_templates_proxy()
{
    drupal_add_http_header('Content-Type', 'application/javascript');
    if (isset($_GET['callback']) && strlen($_GET['callback']) > 0) {
        $param_callback = $_GET['callback'];
    }
    if (isset($_SERVER['HTTP_HOST']) === FALSE || strlen($_SERVER['HTTP_HOST']) === 0) {
        $response = array('error' => 'The client did not send the Host header');
    } else {
        if (isset($_SERVER['SERVER_PORT']) === FALSE) {
            $response = array('error' => 'The Server-proxy did not send the PORT (configure PHP)');
        } else {
            if (MAX_EXEC < 10) {
                $response = array('error' => 'Execution time is less 15 seconds, configure this with ini_set/set_time_limit or "php.ini" (if safe_mode is enabled), recommended time is 30 seconds or more');
            } else {
                if (MAX_EXEC <= TIMEOUT) {
                    $response = array('error' => 'The execution time is not configured enough to TIMEOUT in SOCKET, configure this with ini_set/set_time_limit or "php.ini" (if safe_mode is enabled), recommended that the "max_execution_time =;" be a minimum of 5 seconds longer or reduce the TIMEOUT in "define(\'TIMEOUT\', ' . TIMEOUT . ');"');
                } else {
                    if (isset($_GET['url']) === FALSE || strlen($_GET['url']) === 0) {
                        $response = array('error' => 'No such parameter "url"');
                    } else {
                        if (isHttpUrl($_GET['url']) === FALSE) {
                            $response = array('error' => 'Only http scheme and https scheme are allowed');
                        } else {
                            if (preg_match('#[^A-Za-z0-9_[.]\\[\\]]#', $param_callback) !== 0) {
                                $response = array('error' => 'Parameter "callback" contains invalid characters');
                                $param_callback = JSLOG;
                            } else {
                                if (createFolder() === FALSE) {
                                    $err = get_error();
                                    $response = array('error' => 'Can not create directory' . ($err !== NULL && isset($err['message']) && strlen($err['message']) > 0 ? ': ' . $err['message'] : ''));
                                    $err = NULL;
                                } else {
                                    $http_port = (int) $_SERVER['SERVER_PORT'];
                                    $tmp = createTmpFile($_GET['url'], FALSE);
                                    if ($tmp === FALSE) {
                                        $err = get_error();
                                        $response = array('error' => 'Can not create file' . ($err !== NULL && isset($err['message']) && strlen($err['message']) > 0 ? ': ' . $err['message'] : ''));
                                        $err = NULL;
                                    } else {
                                        $response = downloadSource($_GET['url'], $tmp['source'], 0);
                                        fclose($tmp['source']);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (is_array($response) && isset($response['mime']) && strlen($response['mime']) > 0) {
        clearstatcache();
        if (FALSE === file_exists($tmp['location'])) {
            $response = array('error' => 'Request was downloaded, but file can not be found, try again');
        } else {
            if (filesize($tmp['location']) < 1) {
                $response = array('error' => 'Request was downloaded, but there was some problem and now the file is empty, try again');
            } else {
                $extension = str_replace(array('image/', 'text/', 'application/'), '', $response['mime']);
                $extension = str_replace(array('windows-bmp', 'ms-bmp'), 'bmp', $extension);
                $extension = str_replace(array('svg+xml', 'svg-xml'), 'svg', $extension);
                $extension = str_replace('xhtml+xml', 'xhtml', $extension);
                $extension = str_replace('jpeg', 'jpg', $extension);
                $locationFile = preg_replace('#[.][0-9_]+$#', '.' . $extension, $tmp['location']);
                if (file_exists($locationFile)) {
                    unlink($locationFile);
                }
                if (rename($tmp['location'], $locationFile)) {
                    //set cache
                    setHeaders(FALSE);
                    remove_old_files();
                    if (CROSS_DOMAIN === 1) {
                        $mime = JsonEncodeString($response['mime'], TRUE);
                        $mime = $response['mime'];
                        if ($response['encode'] !== NULL) {
                            $mime .= ';charset=' . JsonEncodeString($response['encode'], TRUE);
                        }
                        $tmp = $response = NULL;
                        if (strpos($mime, 'image/svg') !== 0 && strpos($mime, 'image/') === 0) {
                            echo $param_callback, '("data:', $mime, ';base64,', base64_encode(file_get_contents($locationFile)), '");';
                        } else {
                            echo $param_callback, '("data:', $mime, ',', asciiToInline(file_get_contents($locationFile)), '");';
                        }
                    } else {
                        $tmp = $response = NULL;
                        $dir_name = dirname($_SERVER['SCRIPT_NAME']);
                        if ($dir_name === '\\/' || $dir_name === '\\') {
                            $dir_name = '';
                        }
                        if (strpos($locationFile, 'public://') === FALSE) {
                            $parse_file_location = explode('/', $locationFile);
                            $locationFile = sprintf('%s/%s', PATH, end($parse_file_location));
                        }
                        echo $param_callback, '(', JsonEncodeString(file_create_url($locationFile)), ');';
                    }
                    exit;
                } else {
                    $response = array('error' => 'Failed to rename the temporary file');
                }
            }
        }
    }
    if (is_array($tmp) && isset($tmp['location']) && file_exists($tmp['location'])) {
        //remove temporary file if an error occurred
        unlink($tmp['location']);
    }
    //errors
    setHeaders(TRUE);
    //no-cache
    remove_old_files();
    echo $param_callback, '(', JsonEncodeString('error: html2canvas-proxy-php: ' . $response['error']), ');';
}
Esempio n. 6
0
<?php

/**
 * PHP Proxy Script for AJAX requests to Travelgrove from the Travel-Search plugin
 *
 * @package Travel-Search
 * @subpackage AJAX Requests
 * @author Travelgrove Labs (http://labs.travelgrove.com/)
 * @since 1.0
 */
/*	handling invalid input	*/
if (empty($_POST['citytype']) || !in_array($_POST['citytype'], array('airports', 'cities'))) {
    exit;
}
/*	PHP proxy functions	*/
require_once 'functions.php';
$baseUrl = TG_SERVER_BASEPATH . TG_ASAJAX_PATH;
$currentUrl = $_POST['citytype'] == 'airports' ? 'airport_new.php' : 'hotel_suggest.php';
$_POST['ref'] = 'TG_HTTP_PROXY';
$response = http_post($baseUrl . $currentUrl, $_POST);
setHeaders($response['headers']);
exit($response['content']);
Esempio n. 7
0
        setHeaders($encoding, $contentType, filesize($cachefullpath), $expires);
        fpassthru($fp);
        fclose($fp);
        exit;
    }
}
// request not yet cached
$output = '';
$pathToPkgAssets = '../lib/1.1.0/';
foreach ($validFiles as $validFile) {
    $output .= file_get_contents($pathToPkgAssets . $validFile);
}
if ('none' != $encoding) {
    $output = gzencode($output, 9, $encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE);
}
setHeaders($encoding, $contentType, strlen($output), $expires);
echo $output;
// store the file in disk cache
if ($fp = fopen($cachefullpath, 'wb')) {
    fwrite($fp, $output);
    fclose($fp);
}
/* functions */
function setHeaders($encoding, $contentType, $contentLength, $expires)
{
    if ('none' != $encoding) {
        header('Content-Encoding: ' . $encoding);
    }
    header('Content-Type: ' . $contentType);
    header('Content-Length: ' . $contentLength);
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
Esempio n. 8
0
        return null;
    }
    // store output in a internal buffer
    ob_start();
    // create file stream
    $df = fopen("php://output", 'w');
    // write csv headers (firstName, lastName etc) to filestream
    fputcsv($df, array_keys(reset($array)));
    // iterate subsequent rows and write data
    foreach ($array as $row) {
        fputcsv($df, $row);
    }
    fclose($df);
    // gets the current buffer contents and delete current output buffer.
    return ob_get_clean();
}
function setHeaders($filename)
{
    // force download
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    // disposition / encoding on response body
    header("Content-Disposition: attachment;filename={$filename}");
    header("Content-Transfer-Encoding: binary");
}
// get the data from the query parameters
$query_parameters = array($_GET);
setHeaders("linkedin-csv-export.csv");
echo createCSV($query_parameters);
die;