From 6b6b66bab41026c76913fe34eb0f4c6e3281f494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=82=AF=E3=83=8B=E3=82=AB=E3=83=AB=E8=AB=8F?= =?UTF-8?q?=E8=A8=AA=E5=AD=90?= Date: Mon, 8 Aug 2022 21:56:33 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=81=E3=81=A3=E3=81=A1=E3=82=83=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=81=97=E3=81=9F=E3=81=93=E3=82=8C=EF=BC=81=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/index.php | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/www/index.php b/www/index.php index be1bbe9..413cde2 100644 --- a/www/index.php +++ b/www/index.php @@ -4,10 +4,35 @@ $url = ''; function archiving ($url) { - system("cd ".$url." && wget -LpExk --default-page=index.html --reject js,json,mp4,mov,mkv,mp3,ogg,ogv ".$_POST['hozonsite']); + $p = str_replace('https://', '', $_POST['hozonsite']); + $p = str_replace('http://', '', $p); + + system("cd ".$url." && wget -LpExk --no-check-certificate --max-redirect=3 --default-page=index.html --reject js,json,mp4,mov,mkv,mp3,ogg,ogv ".$_POST['hozonsite']); + + $ex = explode('/', parse_url($_POST['hozonsite'])['path']); + $ex = $ex[array_key_last($ex)]; + if ($ex == '') $ex = 'index.html'; + $basename = isset(parse_url($_POST['hozonsite'])['path']) ? $ex : 'index.html'; + unset($ex); + $ex = explode('/', $p); + + if ($ex[array_key_last($ex)] == $basename) { + unset($ex[array_key_last($ex)]); + $p = implode('/', $ex); + } + + unset($ex); + $basename .= (!str_ends_with($basename, '.html') && !str_ends_with($basename, '.htm') && !str_ends_with($basename, '.xhtml') ? '.html' : ''); + + return $url.'/'.$p.'/'.$basename; } function striptags (string $text): string { + $text = preg_replace('/\/', '', $text); + $text = preg_replace('/visibility: hidden/', '', $text); + $text = preg_replace('/\
[\s\S]+?\<\/div\>/', '', $text); + $text = preg_replace('/\
[\s\S]+?\<\/div\>/', '', $text); + $allowed = [ '!doctype', 'a', 'abbr', 'acronym', 'address', 'applet', 'area', 'article', 'aside', /*'audio',*/ @@ -36,14 +61,14 @@ } function sanitize_archive ($path) { - $file = file_get_contents($path); // ファイルの開く + $file = file_get_contents(urldecode($path)); // ファイルの開く $file = striptags($file); // 危険なタグの削除 // ヘッダーの追加 $file = "
保存サイトでアーカイブしました。Archived with Hozon Site.
トップページへ
".$file.'
'; // 保存 - file_put_contents($path, $file); + file_put_contents(urldecode($path), $file); } if (count($_POST) > 0) { @@ -56,13 +81,13 @@ $url = str_replace('http://', '', $url); if ( !str_ends_with($url, '.html') && - !str_ends_with($url, '/') && + !str_ends_with($url, '\/') && !str_ends_with($url, '.htm') && !str_ends_with($url, '.xhtml') && !str_ends_with($url, '.php') && !str_ends_with($url, '.asp') && !str_ends_with($url, '.aspx') - ) $url = $url.'/'; + ) $url = $url.'*'; $fullurl = 'archive/'.time(); $exists = glob('archive/*/'.$url); @@ -77,17 +102,10 @@ if (count($exists) == 0 || (count($exists) > 0 && isset($_POST['agree']))) { if (!mkdir('./'.$fullurl, 0755, true)) die('エラー'); // ダイレクトリーを作成出来なければ、死ね - archiving('./'.$fullurl); // ウエブページのダウンロード + $url = archiving('./'.$fullurl); // ウエブページのダウンロード + sanitize_archive($url); // 危険なタグの削除 - // URL - if (!str_ends_with($url, '.html') && !str_ends_with($url, '.htm') && !str_ends_with($url, '.php')) { - if (str_ends_with($url, '/')) $url .= 'index.html'; - else $url .= '.html'; - } - - sanitize_archive($fullurl.'/'.$url); // 危険なタグの削除 - - header('Location: '.$fullurl.'/'.$url); // 移転 + header('Location: '.$url); // 移転 die(); } }