161 行
6.1 KiB
PHP
161 行
6.1 KiB
PHP
<?php
|
||
$err = '';
|
||
$exists = [];
|
||
$url = '';
|
||
|
||
function archiving ($url) {
|
||
system("cd ".$url." && wget -LpExk --default-page=index.html --reject js,json,mp4,mov,mkv,mp3,ogg,ogv ".$_POST['hozonsite']);
|
||
}
|
||
|
||
function striptags (string $text): string {
|
||
$allowed = [
|
||
'!doctype',
|
||
'a', 'abbr', 'acronym', 'address', 'applet', 'area', 'article', 'aside', /*'audio',*/
|
||
'b', 'base', 'basefont', 'bb', 'bdo', 'big', 'blockquote', 'body', 'br', 'button',
|
||
'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'command',
|
||
'datagrid', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt',
|
||
'em', 'embed', 'eventsource',
|
||
'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'frame', 'frameset',
|
||
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', /*'html',*/
|
||
'i', /*'iframe',*/ 'img', 'input', 'ins', 'isindex', 'kbd', 'keygen',
|
||
'label', 'legend', 'li', 'link',
|
||
'map', 'mark', 'menu', 'meta', 'meter',
|
||
'nav', 'noframes', 'noscript',
|
||
'object', 'ol', 'optgroup', 'option', 'output',
|
||
'p', 'param', 'pre', 'progress',
|
||
'q',
|
||
'rp', 'rt', 'ruby',
|
||
's', 'samp', /*'script',*/ 'section', 'select', 'small', 'source', 'span', 'strike', 'strong', 'style', 'sub', 'sup',
|
||
'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'tt',
|
||
'u', 'ul',
|
||
'var', /*'video',*/
|
||
'wbr'
|
||
];
|
||
|
||
return strip_tags($text, $allowed);
|
||
}
|
||
|
||
function sanitize_archive ($path) {
|
||
$file = file_get_contents($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);
|
||
}
|
||
|
||
if (count($_POST) > 0) {
|
||
// HTTPかHTTPSじゃない場合
|
||
if (!str_starts_with($_POST['hozonsite'], 'https://') && !str_starts_with($_POST['hozonsite'], 'http://')) {
|
||
$err = 'URLは「http://」又は「https://」で始めます。';
|
||
}
|
||
else {
|
||
$url = str_replace('https://', '', $_POST['hozonsite']);
|
||
$url = str_replace('http://', '', $url);
|
||
if (
|
||
!str_ends_with($url, '.html') &&
|
||
!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.'/';
|
||
$fullurl = 'archive/'.time();
|
||
$exists = glob('archive/*/'.$url);
|
||
|
||
if ($exists) {
|
||
$tmp = [];
|
||
foreach ($exists as $k => $v) {
|
||
$tmp[$k] = explode('/', $v)[1];
|
||
}
|
||
$exists = $tmp;
|
||
unset($tmp);
|
||
}
|
||
|
||
if (count($exists) == 0 || (count($exists) > 0 && isset($_POST['agree']))) {
|
||
if (!mkdir('./'.$fullurl, 0755, true)) die('エラー'); // ダイレクトリーを作成出来なければ、死ね
|
||
archiving('./'.$fullurl); // ウエブページのダウンロード
|
||
|
||
// 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); // 移転
|
||
die();
|
||
}
|
||
}
|
||
}
|
||
?>
|
||
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
|
||
<head>
|
||
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
|
||
<title>保存サイト</title>
|
||
<link rel="stylesheet" type="text/css" href="/style.css" />
|
||
</head>
|
||
<body>
|
||
<div class="jswarning" id="jswarning">注意:JavsScriptはONです。安全・安心の為、JavaScriptをOFFにしてお願い致します。</div>
|
||
<?php if ($err != '') { ?><div class="error"><?php echo $err; ?></div> <?php } ?>
|
||
<script type="text/javascript">
|
||
document.getElementById('jswarning').style.display = 'block';
|
||
</script>
|
||
<h1>保存サイト</h1>
|
||
<div class="body">
|
||
<p>
|
||
<a href="/">トップ</a> |
|
||
β版です。<a href="https://gitler.moe/TechnicalSuwako/hozon.site/issues">バグの報告はこちらです。</a>
|
||
</p>
|
||
<hr />
|
||
<div class="central">
|
||
<?php
|
||
if (count($_POST) > 0 && count($exists) > 0) {
|
||
?>
|
||
<h3><?php echo $url; ?></h3>
|
||
既に保存されたページ:<br />
|
||
<?php
|
||
foreach ($exists as $e) {
|
||
echo '<a href="/archive/'.$e.'/'.$url.'/index.html">'.date('Y年m月d日 H:i:s', $e).'</a>';
|
||
echo "<br />";
|
||
}
|
||
?>
|
||
<p>
|
||
このページが既に保存されているみたいです。<br />
|
||
本当に手続きましょうか?
|
||
</p>
|
||
<form action="/" method="post">
|
||
<input type="hidden" name="hozonsite" value="<?php echo $_POST['hozonsite']; ?>" />
|
||
<input type="hidden" name="agree" value="1" />
|
||
<div class="submit">
|
||
<input type="submit" name="submit" value="はい、保存して下さい!!" />
|
||
</div>
|
||
</form>
|
||
<?php
|
||
}
|
||
else {
|
||
?>
|
||
どのページを保存しますか?
|
||
<form action="/" method="post">
|
||
<input type="text" name="hozonsite" value="" />
|
||
<div class="submit">
|
||
<input type="submit" name="submit" value="保存" />
|
||
</div>
|
||
</form>
|
||
<?php
|
||
}
|
||
?>
|
||
</div>
|
||
</div>
|
||
<div class="submit">
|
||
<a href="https://gitler.moe/TechnicalSuwako/hozon.site"><img src="/git.png" alt="ソースコード" /></a> | <a href="https://076.moe">匿名自営業076</a>
|
||
</div>
|
||
</body>
|
||
</html>
|