パラメートルを持っているURLの修正+保存に失敗した場合のエラー

このコミットが含まれているのは:
守矢諏訪子 2022-08-11 22:48:08 +09:00
コミット 45dc3cee80
1個のファイルの変更19行の追加7行の削除

ファイルの表示

@ -9,10 +9,13 @@
$ex = explode('/', parse_url($_POST['hozonsite'])['path']);
$ex = $ex[array_key_last($ex)];
if (null !== parse_url($_POST['hozonsite'])['query']) $ex .= '@'.parse_url($_POST['hozonsite'])['query'];
if ($ex == '') $ex = 'index.html';
$basename = isset(parse_url($_POST['hozonsite'])['path']) ? $ex : 'index.html';
unset($ex);
$ex = explode('/', $p);
$ex[array_key_last($ex)] = str_replace('?', '@', $ex[array_key_last($ex)]);
$ex[array_key_last($ex)] = parse_url($ex[array_key_last($ex)])['path'];
if ($ex[array_key_last($ex)] == $basename) {
unset($ex[array_key_last($ex)]);
@ -25,10 +28,13 @@
return $p.'/'.$basename;
}
function archiving (string $url): string {
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']);
function archiving (string $url): array {
system("cd ".$url." && wget -LpExk --no-check-certificate --restrict-file-names=windows --max-redirect=3 --default-page=index.html --reject js,json,mp4,mov,mkv,mp3,ogg,ogv ".$_POST['hozonsite']);
if (count(array_diff(scandir($url), array('..', '.'))) == 0) {
return ['code' => 0, 'err' => '保存に失敗しました。'];
}
return $url.'/'.geturl();
return ['code' => 1, 'url' => $url.'/'.geturl()];
}
function striptags (string $text): string {
@ -69,7 +75,7 @@
$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; font-size: 14px; width: 100%;\">保存サイトでアーカイブしました。Archived with Hozon Site.<br /><a style=\"color: #ffeb3b;\" href=\"/\">トップページへ</a></div><div style=\"padding-top: 74px;\">".$file.'</div></body></html>';
$file = "<!DOCTYPE html><html><head><meta charset=\"utf-8\" /><head><body><div style=\"background-color: #320202 !important; display: block !important; border: 4px #ff3b3b groove !important; color: #ea8181 !important; padding: 10px !important; z-index: 999999 !important; position: fixed !important; left: 0 !important; top: 0 !important; font-size: 14px !important; font-family: unset !important; width: 100% !important;\">保存サイトでアーカイブしました。Archived with Hozon Site.<br /><a style=\"color: #ffeb3b !important;\" href=\"/\">トップページへ</a></div><div style=\"padding-top: 74px !important;\">".$file.'</div></body></html>';
// 保存
file_put_contents(urldecode($path), $file);
@ -97,10 +103,16 @@
if (count($exists) == 0 || (count($exists) > 0 && isset($_POST['agree']))) {
if (!mkdir('./'.$fullurl, 0755, true)) die('エラー'); // ダイレクトリーを作成出来なければ、死ね
$url = archiving('./'.$fullurl); // ウエブページのダウンロード
sanitize_archive($url); // 危険なタグの削除
if ($url['code'] == 0) {
$err = $url['err'];
}
else {
$url = $url['url'];
sanitize_archive($url); // 危険なタグの削除
header('Location: '.$url); // 移転
die();
header('Location: '.$url); // 移転
die();
}
}
}
}