めっちゃ修正したこれ!!

このコミットが含まれているのは:
守矢諏訪子 2022-08-08 21:56:33 +09:00
コミット 6b6b66bab4
1個のファイルの変更33行の追加15行の削除

ファイルの表示

@ -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('/\<script[\s\S]+?\<\/script\>/', '', $text);
$text = preg_replace('/visibility: hidden/', '', $text);
$text = preg_replace('/\<div class\=\"blocker-error\"\>[\s\S]+?\<\/div\>/', '', $text);
$text = preg_replace('/\<div class\=\"blocker\"\>[\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 = "<!DOCTYPE html><html><head><meta charset=\"utf-8\" /><head><body><div style=\"background-color: #320202; display: block; border: 4px #ff3b3b groove; color: #ea8181; padding: 10px; z-index: 999999; position: fixed; left: 0; top: 0; width: 100%;\">保存サイトでアーカイブしました。Archived with Hozon Site.<br /><a style=\"color: #ffeb3b;\" href=\"/\">トップページへ</a></div><div style=\"padding-top: 74px;\">".$file.'</div></body></html>';
// 保存
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();
}
}