コミット
59bbf8a9a7
41
helper.php
41
helper.php
|
@ -21,24 +21,28 @@
|
||||||
return inet_pton(gethostbyname(get_domain($url))) !== false;
|
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 {
|
function domainsecuritycheck (string $url): array {
|
||||||
$err = [];
|
$err = [];
|
||||||
|
|
||||||
// ホスト名のみかどうかチェック
|
// ホスト名のみかどうかチェック
|
||||||
if ($url !== parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST)) {
|
if (isurl($url)) {
|
||||||
$err[] = 'URLは「http」又は「https」からTLDまでのみではありません。ご変更下さい。<br />URL is not limited to "http" or "https" to TLD. Please change.';
|
$err[] = 'URLは「http」又は「https」からTLDまでのみではありません。ご変更下さい。<br />URL is not limited to "http" or "https" to TLD. Please change.';
|
||||||
|
return $err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ドメインは存在するかどうかチェック
|
// ドメインは存在するかどうかチェック
|
||||||
if (!isdomainexist($url)) {
|
if (!isdomainexist($url)) {
|
||||||
$err[] = 'このドメイン名は未登録みたいです。<br />This domain name seems to be unregistered.';
|
$err[] = 'このドメイン名は未登録みたいです。<br />This domain name seems to be unregistered.';
|
||||||
|
return $err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ウエブページが移転されているかどうか
|
// ウエブページが移転されているかどうか
|
||||||
if (
|
$out = execcurl($url);
|
||||||
(int)trim(shell_exec('curl -o /dev/null -s -w "%{http_code}\n" '.$url.' 2>&1') >= 301) &&
|
if ($httpcode >= 301 && $httpcode <= 399) {
|
||||||
(int)trim(shell_exec('curl -o /dev/null -s -w "%{http_code}\n" '.$url.' 2>&1') <= 399)
|
|
||||||
) {
|
|
||||||
$err[] = 'ウェブサイトは移転されているみたいです。直接URLをご入力下さい。<br />The website seems to have been relocated. Please enter the URL directly.';
|
$err[] = 'ウェブサイトは移転されているみたいです。直接URLをご入力下さい。<br />The website seems to have been relocated. Please enter the URL directly.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,23 +52,44 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Torブロックのチェック
|
// 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で接続出来ないみたいです。追加依頼拒否。<br />The website doesn\'t seem to be able to connect with Tor. Rejection of additional request.';
|
$err[] = 'ウェブサイトはTorで接続出来ないみたいです。追加依頼拒否。<br />The website doesn\'t seem to be able to connect with Tor. Rejection of additional request.';
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOCTYPE htmlタグがあるかどうかチェック
|
// DOCTYPE htmlタグがあるかどうかチェック
|
||||||
if (is_null(shell_exec('curl -s -L '.$url.' | grep -i "<\!DOCTYPE html" 2>&1'))) {
|
$out = execcurl($url, 'cout');
|
||||||
|
if (strpos($out, '<!DOCTYPE html') === false) {
|
||||||
$err[] = 'ウェブサイトは「!DOCTYPE html」タグを含めていません。<br />The website does not include the "! DOCTYPE html" tag.';
|
$err[] = 'ウェブサイトは「!DOCTYPE html」タグを含めていません。<br />The website does not include the "! DOCTYPE html" tag.';
|
||||||
}
|
}
|
||||||
|
|
||||||
// titleタグがあるかどうかチェック
|
// titleタグがあるかどうかチェック
|
||||||
if (is_null(shell_exec('curl -s -L '.$url.' | grep -i "<title>" 2>&1'))) {
|
if (strpos($out, '<title>') === false) {
|
||||||
$err[] = 'ウェブサイトは「title」タグを含めていません。<br />The website does not include the "title" tag.';
|
$err[] = 'ウェブサイトは「title」タグを含めていません。<br />The website does not include the "title" tag.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $err;
|
return $err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function execcurl (string $url, string $return='code', bool $proxy=false, bool $header=true, bool $nobody=true): string|int|bool {
|
||||||
|
// return = code → HTTPステータスコード
|
||||||
|
// return = cout → curl_exec
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, $header);
|
||||||
|
curl_setopt($ch, CURLOPT_NOBODY, $nobody);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, $proxy);
|
||||||
|
if ($proxy) {
|
||||||
|
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:9050');
|
||||||
|
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
|
||||||
|
}
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||||
|
$output = curl_exec($ch);
|
||||||
|
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
return $return == 'code' ? $httpcode : $output;
|
||||||
|
}
|
||||||
|
|
||||||
// 下記の機能性は https://newbedev.com/get-domain-name-not-subdomain-in-php より
|
// 下記の機能性は https://newbedev.com/get-domain-name-not-subdomain-in-php より
|
||||||
function tld_list ($cache_dir=null) {
|
function tld_list ($cache_dir=null) {
|
||||||
$cache_dir = isset($cache_dir) ? $cache_dir : sys_get_temp_dir();
|
$cache_dir = isset($cache_dir) ? $cache_dir : sys_get_temp_dir();
|
||||||
|
|
|
@ -44,9 +44,7 @@
|
||||||
$out = array_unique($out); // 複写URLの消し
|
$out = array_unique($out); // 複写URLの消し
|
||||||
|
|
||||||
foreach ($out as $i => $o) { // HTMLだけを保存したいですので、なければarrayから消します
|
foreach ($out as $i => $o) { // HTMLだけを保存したいですので、なければarrayから消します
|
||||||
$cres = shell_exec('curl -s -L '.$o.' | grep -i "<\!DOCTYPE html" 2>&1');
|
if (strpos(execcurl($o, 'cout', false, false, false), '<!DOCTYPE html') === false) unset($out[$i]);
|
||||||
if (is_null($cres)) unset($out[$i]);
|
|
||||||
unset($cres);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$out = array_values($out); // メモリに優しくなりましょう
|
$out = array_values($out); // メモリに優しくなりましょう
|
||||||
|
@ -55,7 +53,9 @@
|
||||||
|
|
||||||
foreach ($out as $i => $o) { // ページタイトル及び内容を受け取って
|
foreach ($out as $i => $o) { // ページタイトル及び内容を受け取って
|
||||||
// タイトル
|
// タイトル
|
||||||
$ptitle = shell_exec('curl -s -L '.$o.' | grep -i "<title>" 2>&1');
|
$curl = execcurl($o, 'cout', false, false, false);
|
||||||
|
$ptitle = mb_stristr($ptitle, '<title>');
|
||||||
|
$ptitle = mb_stristr($ptitle, '</title>', true);
|
||||||
$ptitle = trim($ptitle);
|
$ptitle = trim($ptitle);
|
||||||
$ptitle = str_replace('<title>', '', $ptitle);
|
$ptitle = str_replace('<title>', '', $ptitle);
|
||||||
$ptitle = str_replace('</title>', '', $ptitle);
|
$ptitle = str_replace('</title>', '', $ptitle);
|
||||||
|
|
新しいイシューから参照