Skip to content

Commit 1de4a7f

Browse files
index.html
1 parent 4b111b5 commit 1de4a7f

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

index.html

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
3+
<head>
44
<title>Proxy</title>
5-
</head>
6-
<body>
7-
<?php
5+
</head>
6+
<body>
7+
<?php
88
/*
99
* html2canvas-php-proxy 1.1.4
1010
*
@@ -13,17 +13,20 @@
1313
* Released under the MIT license
1414
*/
1515

16-
// Turn off errors because the script already own uses "error_get_last"
16+
// Enable error logging
17+
ini_set('log_errors', 'On');
18+
ini_set('error_log', 'path/to/error.log'); // Set your error log path
1719
ini_set('display_errors', 'Off');
20+
error_reporting(E_ALL);
1821

1922
// Setup
2023
define('H2CP_PATH', 'cache'); // Relative folder where the images are saved
21-
define('H2CP_PERMISSION', 0666); // use 644 or 666 for remove execution for prevent sploits
24+
define('H2CP_PERMISSION', 0777); // Ensure directory is writable
2225
define('H2CP_CACHE', 60 * 5 * 1000); // Limit access-control and cache, define 0/false/null/-1 to prevent cache
2326
define('H2CP_TIMEOUT', 20); // Timeout from load Socket
2427
define('H2CP_MAX_LOOP', 10); // Configure loop limit for redirects (location header)
2528
define('H2CP_DATAURI', false); // Enable use of "data URI scheme"
26-
define('H2CP_PREFER_CURL', true); // Enable curl if avaliable or disable
29+
define('H2CP_PREFER_CURL', true); // Enable curl if available or disable
2730
define('H2CP_SECPREFIX', 'h2cp_'); // Prefix temp filename
2831
define('H2CP_ALLOWED_DOMAINS', '*'); // * allow all domains, *.site.com for sub-domains, or fixed domains use `define('H2CP_ALLOWED_DOMAINS', 'site.com,www.site.com' )
2932
define('H2CP_ALLOWED_PORTS', '80,443'); // Allowed ports
@@ -494,22 +497,37 @@
494497
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
495498
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
496499

500+
if (isset($uri['user'])) {
501+
curl_setopt($curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
502+
curl_setopt($ch, CURLOPT_CAINFO, H2CP_SSL_VERIFY_PEER);
503+
} else {
504+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
505+
}
506+
507+
curl_setopt($ch, CURLOPT_TIMEOUT, H2CP_TIMEOUT);
508+
curl_setopt($ch, CURLOPT_URL, $currentUrl);
509+
curl_setopt($ch, CURLOPT_HEADER, false);
510+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
511+
curl_setopt($ch, CURLOPT_MAXREDIRS, H2CP_MAX_LOOP);
512+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
513+
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
514+
497515
if (isset($uri['user'])) {
498516
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
499517
curl_setopt($ch, CURLOPT_USERPWD, $uri['user'] . ':' . (isset($uri['pass']) ? $uri['pass'] : ''));
500518
}
501519

502520
$headers = array();
503521

504-
if (false === empty($_SERVER['HTTP_ACCEPT'])) {
522+
if (!empty($_SERVER['HTTP_ACCEPT'])) {
505523
$headers[] = 'Accept: ' . $_SERVER['HTTP_ACCEPT'];
506524
}
507525

508-
if (false === empty($_SERVER['HTTP_USER_AGENT'])) {
526+
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
509527
$headers[] = 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'];
510528
}
511529

512-
if (false === empty($_SERVER['HTTP_REFERER'])) {
530+
if (!empty($_SERVER['HTTP_REFERER'])) {
513531
$headers[] = 'Referer: ' . $_SERVER['HTTP_REFERER'];
514532
}
515533

@@ -595,15 +613,15 @@
595613
fwrite($fp, 'Authorization: Basic ' . $auth . H2CP_EOL);
596614
}
597615

598-
if (false === empty($_SERVER['HTTP_ACCEPT'])) {
616+
if (!empty($_SERVER['HTTP_ACCEPT'])) {
599617
fwrite($fp, 'Accept: ' . $_SERVER['HTTP_ACCEPT'] . H2CP_EOL);
600618
}
601619

602-
if (false === empty($_SERVER['HTTP_USER_AGENT'])) {
620+
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
603621
fwrite($fp, 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'] . H2CP_EOL);
604622
}
605623

606-
if (false === empty($_SERVER['HTTP_REFERER'])) {
624+
if (!empty($_SERVER['HTTP_REFERER'])) {
607625
fwrite($fp, 'Referer: ' . $_SERVER['HTTP_REFERER'] . H2CP_EOL);
608626
}
609627

@@ -617,7 +635,7 @@
617635
$mime = null;
618636
$data = '';
619637

620-
while (false === feof($fp)) {
638+
while (!feof($fp)) {
621639
if (H2CP_MAX_EXEC !== 0 && (time() - H2CP_INIT_EXEC) >= H2CP_MAX_EXEC) {
622640
return array('error' => 'Maximum execution time of ' . (H2CP_MAX_EXEC + 5) . ' seconds exceeded, configure this with ini_set/set_time_limit or "php.ini" (if safe_mode is enabled)');
623641
}
@@ -701,7 +719,7 @@
701719
} elseif ($isRedirect) {
702720
fclose($fp);
703721
$data = '';
704-
return array('error' => 'The response should be a redirect "' . $url . '", but did not inform which header "Localtion:"');
722+
return array('error' => 'The response should be a redirect "' . $url . '", but did not inform which header "Location:"');
705723
} elseif ($mime === null) {
706724
fclose($fp);
707725
$data = '';
@@ -871,5 +889,6 @@
871889
echo $callback, '(',
872890
JsonEncodeString('error: html2canvas-proxy-php: ' . $response['error']),
873891
');';
874-
</body>
892+
?>
893+
</body>
875894
</html>

0 commit comments

Comments
 (0)