diff --git a/helper.php b/helper.php
index 01a5fa2..d197698 100644
--- a/helper.php
+++ b/helper.php
@@ -21,24 +21,28 @@
return inet_pton(gethostbyname(get_domain($url))) !== false;
}
+ function isurl (string $url): bool {
+ return $url && is_string($url) && preg_match('/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i', $url) && $url === parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST);
+ }
+
function domainsecuritycheck (string $url): array {
$err = [];
// ホスト名のみかどうかチェック
- if ($url !== parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST)) {
+ if (isurl($url)) {
$err[] = 'URLは「http」又は「https」からTLDまでのみではありません。ご変更下さい。
URL is not limited to "http" or "https" to TLD. Please change.';
+ return $err;
}
// ドメインは存在するかどうかチェック
if (!isdomainexist($url)) {
$err[] = 'このドメイン名は未登録みたいです。
This domain name seems to be unregistered.';
+ return $err;
}
// ウエブページが移転されているかどうか
- if (
- (int)trim(shell_exec('curl -o /dev/null -s -w "%{http_code}\n" '.$url.' 2>&1') >= 301) &&
- (int)trim(shell_exec('curl -o /dev/null -s -w "%{http_code}\n" '.$url.' 2>&1') <= 399)
- ) {
+ $out = execcurl($url);
+ if ($httpcode >= 301 && $httpcode <= 399) {
$err[] = 'ウェブサイトは移転されているみたいです。直接URLをご入力下さい。
The website seems to have been relocated. Please enter the URL directly.';
}
@@ -48,23 +52,44 @@
}
// Torブロックのチェック
- if ((int)trim(shell_exec('torsocks curl -o /dev/null -s -w "%{http_code}\n" '.$url.' 2>&1') >= 400)) {
+ if (execcurl($url, 'code', true) >= 400) {
$err[] = 'ウェブサイトはTorで接続出来ないみたいです。追加依頼拒否。
The website doesn\'t seem to be able to connect with Tor. Rejection of additional request.';
}
// DOCTYPE htmlタグがあるかどうかチェック
- if (is_null(shell_exec('curl -s -L '.$url.' | grep -i "<\!DOCTYPE html" 2>&1'))) {
+ $out = execcurl($url, 'cout');
+ if (strpos($out, 'The website does not include the "! DOCTYPE html" tag.';
}
// titleタグがあるかどうかチェック
- if (is_null(shell_exec('curl -s -L '.$url.' | grep -i "