Skip to content

Commit 9352722

Browse files
committed
Version 1.1.0
Fixed bug in constants
1 parent 9ad9527 commit 9352722

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Definition | Description
7070
`define('H2CP_DATAURI', false);` | Enable use of "data URI scheme"
7171
`define('H2CP_PREFER_CURL', true);` | Prefer curl if avaliable or disable
7272
`define('H2CP_SSL_VERIFY_PEER', false);` | Set false for disable SSL checking or true for enable (require config PHP.INI with `curl.cainfo=/path/to/cacert.pem`). You can set path manualy like this: `define('H2CP_SSL_VERIFY_PEER', '/path/to/cacert.pem');`
73-
`define('H2CP_ALLOWED_DOMAINS', array( '*' ));` | `*` allow all domains, for subdomains use like this `*.site.com`, for fixed domains use `array( 'site.com', 'www.site.com' )`
74-
`define('H2CP_ALLOWED_PORTS', array( 80, 443 ));` | Config allowed ports
73+
`define('H2CP_ALLOWED_DOMAINS', '*');` | `*` allow all domains, for subdomains use like this `*.site.com`, for fixed domains use `, 'site.com,www.site.com'` (`string` separed by commas)
74+
`define('H2CP_ALLOWED_PORTS', '80,443');` | Config allowed ports (`string` separed by commas)
7575

7676
## Usage
7777

html2canvasproxy.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* html2canvas-php-proxy 1.0.0
3+
* html2canvas-php-proxy 1.1.0
44
*
55
* Copyright (c) 2018 Guilherme Nascimento ([email protected])
66
*
@@ -19,8 +19,8 @@
1919
define('H2CP_DATAURI', false); // Enable use of "data URI scheme"
2020
define('H2CP_PREFER_CURL', true); // Enable curl if avaliable or disable
2121
define('H2CP_SECPREFIX', 'h2cp_'); // Prefix temp filename
22-
define('H2CP_ALLOWED_DOMAINS', array( '*' )); // * allow all domains, *.site.com for sub-domains, or fixed domains use array( 'site.com', 'www.site.com' )
23-
define('H2CP_ALLOWED_PORTS', array( 80, 443 )); // Allowed ports
22+
define('H2CP_ALLOWED_DOMAINS', '*'); // * allow all domains, *.site.com for sub-domains, or fixed domains use array( 'site.com', 'www.site.com' )
23+
define('H2CP_ALLOWED_PORTS', '80,443'); // Allowed ports
2424

2525
/*
2626
* Set false for disable SSL check
@@ -347,7 +347,9 @@ function isHttpUrl($url)
347347
function isAllowedUrl($url, &$message) {
348348
$uri = parse_url($url);
349349

350-
if (in_array('*', H2CP_ALLOWED_DOMAINS) === false) {
350+
$domains = array_map('trim', explode(',', H2CP_ALLOWED_DOMAINS));
351+
352+
if (in_array('*', $domains) === false) {
351353
$ok = false;
352354

353355
foreach (H2CP_ALLOWED_DOMAINS as $domain) {
@@ -379,25 +381,12 @@ function isAllowedUrl($url, &$message) {
379381
$port = $uri['port'];
380382
}
381383

382-
$ok = false;
384+
$ports = array_map('trim', explode(',', H2CP_ALLOWED_PORTS));
383385

384-
foreach (H2CP_ALLOWED_PORTS as $allowed_port) {
385-
if ($port == $allowed_port) {
386-
$ok = true;
387-
break;
388-
}
389-
}
390-
391-
if ($ok) {
386+
if (in_array($port, $ports)) {
392387
return true;
393388
}
394389

395-
if (empty($uri['port'])) {
396-
$port = strcasecmp('https', $uri['scheme']) === 0 ? 443 : 80;
397-
} else {
398-
$port = $uri['port'];
399-
}
400-
401390
$message = '"' . $port . '" port is not allowed';
402391

403392
return false;

0 commit comments

Comments
 (0)