|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html> |
3 | | - <head> |
| 3 | +<head> |
4 | 4 | <title>Proxy</title> |
5 | | - </head> |
6 | | - <body> |
7 | | - <?php |
| 5 | +</head> |
| 6 | +<body> |
| 7 | +<?php |
8 | 8 | /* |
9 | 9 | * html2canvas-php-proxy 1.1.4 |
10 | 10 | * |
|
13 | 13 | * Released under the MIT license |
14 | 14 | */ |
15 | 15 |
|
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 |
17 | 19 | ini_set('display_errors', 'Off'); |
| 20 | +error_reporting(E_ALL); |
18 | 21 |
|
19 | 22 | // Setup |
20 | 23 | 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 |
22 | 25 | define('H2CP_CACHE', 60 * 5 * 1000); // Limit access-control and cache, define 0/false/null/-1 to prevent cache |
23 | 26 | define('H2CP_TIMEOUT', 20); // Timeout from load Socket |
24 | 27 | define('H2CP_MAX_LOOP', 10); // Configure loop limit for redirects (location header) |
25 | 28 | 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 |
27 | 30 | define('H2CP_SECPREFIX', 'h2cp_'); // Prefix temp filename |
28 | 31 | 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' ) |
29 | 32 | define('H2CP_ALLOWED_PORTS', '80,443'); // Allowed ports |
|
494 | 497 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
495 | 498 | curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); |
496 | 499 |
|
| 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 | + |
497 | 515 | if (isset($uri['user'])) { |
498 | 516 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
499 | 517 | curl_setopt($ch, CURLOPT_USERPWD, $uri['user'] . ':' . (isset($uri['pass']) ? $uri['pass'] : '')); |
500 | 518 | } |
501 | 519 |
|
502 | 520 | $headers = array(); |
503 | 521 |
|
504 | | - if (false === empty($_SERVER['HTTP_ACCEPT'])) { |
| 522 | + if (!empty($_SERVER['HTTP_ACCEPT'])) { |
505 | 523 | $headers[] = 'Accept: ' . $_SERVER['HTTP_ACCEPT']; |
506 | 524 | } |
507 | 525 |
|
508 | | - if (false === empty($_SERVER['HTTP_USER_AGENT'])) { |
| 526 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
509 | 527 | $headers[] = 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT']; |
510 | 528 | } |
511 | 529 |
|
512 | | - if (false === empty($_SERVER['HTTP_REFERER'])) { |
| 530 | + if (!empty($_SERVER['HTTP_REFERER'])) { |
513 | 531 | $headers[] = 'Referer: ' . $_SERVER['HTTP_REFERER']; |
514 | 532 | } |
515 | 533 |
|
|
595 | 613 | fwrite($fp, 'Authorization: Basic ' . $auth . H2CP_EOL); |
596 | 614 | } |
597 | 615 |
|
598 | | - if (false === empty($_SERVER['HTTP_ACCEPT'])) { |
| 616 | + if (!empty($_SERVER['HTTP_ACCEPT'])) { |
599 | 617 | fwrite($fp, 'Accept: ' . $_SERVER['HTTP_ACCEPT'] . H2CP_EOL); |
600 | 618 | } |
601 | 619 |
|
602 | | - if (false === empty($_SERVER['HTTP_USER_AGENT'])) { |
| 620 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
603 | 621 | fwrite($fp, 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'] . H2CP_EOL); |
604 | 622 | } |
605 | 623 |
|
606 | | - if (false === empty($_SERVER['HTTP_REFERER'])) { |
| 624 | + if (!empty($_SERVER['HTTP_REFERER'])) { |
607 | 625 | fwrite($fp, 'Referer: ' . $_SERVER['HTTP_REFERER'] . H2CP_EOL); |
608 | 626 | } |
609 | 627 |
|
|
617 | 635 | $mime = null; |
618 | 636 | $data = ''; |
619 | 637 |
|
620 | | - while (false === feof($fp)) { |
| 638 | + while (!feof($fp)) { |
621 | 639 | if (H2CP_MAX_EXEC !== 0 && (time() - H2CP_INIT_EXEC) >= H2CP_MAX_EXEC) { |
622 | 640 | 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)'); |
623 | 641 | } |
|
701 | 719 | } elseif ($isRedirect) { |
702 | 720 | fclose($fp); |
703 | 721 | $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:"'); |
705 | 723 | } elseif ($mime === null) { |
706 | 724 | fclose($fp); |
707 | 725 | $data = ''; |
|
871 | 889 | echo $callback, '(', |
872 | 890 | JsonEncodeString('error: html2canvas-proxy-php: ' . $response['error']), |
873 | 891 | ');'; |
874 | | - </body> |
| 892 | +?> |
| 893 | +</body> |
875 | 894 | </html> |
0 commit comments