ウエブサイトの追加機能性

このコミットが含まれているのは:
守矢諏訪子 2022-06-03 04:24:26 +09:00
コミット 9fe62b6af5
6個のファイルの変更256行の追加13行の削除

ファイルの表示

@ -0,0 +1,67 @@
# 検索オンライン (β)
日本産検索エンジン。
## 必要なサーバーサイドソフト
* nginx
* crontab
* PHP 8.0以上
* MariaDB
* curl
* whois
* tor
* torsocks
* grep
* pandoc
### Debian、Devuan、Ubuntuでインストール
```sh
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2
echo "deb https://packages.sury.org/php/ bullseye main" | sudo tee /etc/apt/sources.list.d/sury-php.list
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
sudo apt update
sudo apt install nginx php8.1 php8.1-{gd,fpm,common,cli,mbstring,intl,mysql,bcmath,curl} mariadb-{client,server} curl whois tor torsocks pandoc
```
### Arch、Artix、Manjaroでインストール
```sh
sudo pacman -S nginx php php-fpm mariadb curl whois tor torsocks pandoc
```
## やることリスト
# 1.0
- [x] ホームページ
- [x] 検索機能性
- [x] 検索結果
- [x] スタイリング
- [x] 更新BOT
- [x] ウエブサイトの追加
- [ ] ウエブサイトの追加は複数レベル化
- [ ] 検索オンラインについて
- [ ] 複数キーワード
### 1.1
- [ ] "my ip"
- [ ] "my useragent"
- [ ] "is tor"
- [ ] "site:"
- [ ] 「""」で検索
- [ ] 通貨交換(例:!crnc 100 jpy to xmr)
- [ ] 電卓(例:!calc 2+2)
- [ ] 天気予報(例:!wttr tokyo)
- [ ] 翻訳(例:"!tran en ja frog")
### 1.2
- [ ] アーカイバー(hozon.site)で保存
- [ ] 短縮URL(urlo.li)で共有
### 1.3
- [ ] 画像検索
- [ ] 動画検索
### 1.4
- [ ] ドメイン検索

ファイルの表示

@ -5,4 +5,100 @@
echo '</pre>';
die();
}
function uuid () {
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 32bitlow
mt_rand(0, 0xffff), // 16bitmid
mt_rand(0, 0x0fff) | 0x4000, // 16bithigh
mt_rand(0, 0x3fff) | 0x8000, // 16bit|8bithigh|low
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) // 48bitnode
);
}
function isdomainexist (string $url): bool {
return inet_pton(gethostbyname(get_domain($url))) !== false;
}
function domainsecuritycheck (string $url): array {
$err = [];
// ホスト名のみかどうかチェック
if ($url !== parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST)) {
$err[] = 'URLは「http」又は「https」からTLDまでのみではありません。ご変更下さい。<br />Error: URL is not limited to "http" or "https" to TLD. Please change.';
}
// ドメインは存在するかどうかチェック
if (!isdomainexist($url)) {
$err[] = 'このドメイン名は未登録みたいです。<br />Error: This domain name seems to be unregistered.';
}
// ブラフレを使っているかどうかチェック
if (!is_null(shell_exec('whois '.get_domain($url).' | grep -i "cloudflare" 2>&1'))) {
$err[] = 'ウェブサイトはCloudFlareを使っているみたいです。追加依頼拒否。<br />Error: The website seems to be using CloudFlare. Rejection of additional request.';
}
// Torブロックのチェック
if (!is_null(shell_exec('torsocks curl -s -L '.$url.' | grep "Please stand by, while we are checking your browser...\|We are checking your browser...\|Ray ID" 2>&1'))) {
$err[] = 'ウェブサイトはTorで接続出来ないみたいです。追加依頼拒否。<br />Error: The website doesn\'t seem to be able to connect with Tor. Rejection of additional request.';
}
// DOCTYPE htmlタグがあるかどうかチェック
if (is_null(shell_exec('curl -s -L '.$url.' | grep -i "<\!DOCTYPE html" 2>&1'))) {
$err[] = 'ウェブサイトは「!DOCTYPE html」タグを含めていません。<br />Error: The website does not include the "! DOCTYPE html" tag.';
}
// titleタグがあるかどうかチェック
if (is_null(shell_exec('curl -s -L '.$url.' | grep -i "<title>" 2>&1'))) {
$err[] = 'ウェブサイトは「title」タグを含めていません。<br />Error: The website does not include the "title" tag.';
}
return $err;
}
// 下記の機能性は https://newbedev.com/get-domain-name-not-subdomain-in-php より
function tld_list ($cache_dir=null) {
$cache_dir = isset($cache_dir) ? $cache_dir : sys_get_temp_dir();
$lock_dir = $cache_dir . '/public_suffix_list_lock/';
$list_dir = $cache_dir . '/public_suffix_list/';
if (file_exists($list_dir) && @filemtime($list_dir) + 2592000 > time()) return $list_dir;
if (!file_exists($lock_dir) && @mkdir($lock_dir)) {
$list = @fopen('https://publicsuffix.org/list/public_suffix_list.dat', 'r');
if ($list) {
if (file_exists($list_dir)) {
foreach (glob($list_dir . '*') as $filename) unlink($filename);
rmdir($list_dir);
}
mkdir($list_dir);
while ($line = fgets($list)) {
if ($line[0] == '/' || !$line) continue;
if ($line[0] . $line[1] == '*.') $line = substr($line, 2);
if ($line[0] == '!') $line = substr($line, 1);
$line = implode('.', array_reverse(explode('.', (trim($line)))));
touch($list_dir . $line);
}
fclose($list);
}
@rmdir($lock_dir);
}
if (file_exists($lock_dir) && mt_rand(0, 100) == 0 && @filemtime($lock_dir) + 86400 < time()) @rmdir($lock_dir);
return $list_dir;
}
function get_domain ($url=null) {
$tld_dir = tld_list();
$url = isset($url) ? $url : $_SERVER['SERVER_NAME'];
$url = !isset($url[5]) || ($url[3] != ':' && $url[4] != ':' && $url[5] != ':') ? 'http://' . $url : $url;
$url = parse_url($url, PHP_URL_HOST);
$url = trim($url, '.');
$url = explode('.', $url);
$parts = array_reverse($url);
foreach ($parts as $key => $part) {
$tld = implode('.', $parts);
if (file_exists($tld_dir.$tld)) return !$key ? '' : implode('.', array_slice($url, $key - 1));
array_pop($parts);
}
return '';
}
?>

ファイルの表示

@ -9,12 +9,12 @@
<?php } else { ?>
<a href="/"><img src="/static/logo.png" alt="ロゴ" style="width: 24px;" /></a> |
<?php } ?>
<a href="/image">画像</a> |
<a href="/video">動画</a> |
<a href="/domain">ドメイン</a>
<a href="/image.php">画像</a> |
<a href="/video.php">動画</a> |
<a href="/domain.php">ドメイン</a>
</p>
<p>
<a href="/about">検索オンラインについて</a> |
<a href="/submit">ウエブサイトの追加</a>
<a href="/about.php">検索オンラインについて</a> |
<a href="/submit.php">ウエブサイトの追加</a>
</p>
</div>

ファイルの表示

@ -44,7 +44,7 @@
$out = array_unique($out); // 複写URLの消し
foreach ($out as $i => $o) { // HTMLだけを保存したいですので、なければarrayから消します
$cres = shell_exec('curl -s -L '.$o.' | grep "<\!DOCTYPE html" 2>&1');
$cres = shell_exec('curl -s -L '.$o.' | grep -i "<\!DOCTYPE html" 2>&1');
if (is_null($cres)) unset($out[$i]);
unset($cres);
}
@ -55,7 +55,7 @@
foreach ($out as $i => $o) { // ページタイトル及び内容を受け取って
// タイトル
$ptitle = shell_exec('curl -s -L '.$o.' | grep "<title>" 2>&1');
$ptitle = shell_exec('curl -s -L '.$o.' | grep -i "<title>" 2>&1');
$ptitle = trim($ptitle);
$ptitle = str_replace('<title>', '', $ptitle);
$ptitle = str_replace('</title>', '', $ptitle);

ファイルの表示

@ -18,10 +18,6 @@ h1, .footer {
text-align: center;
}
h1 {
padding-bottom: 60px;
}
.kappa {
background-color: #16a085;
border: 2px #10f3c6 solid;

ファイルの表示

@ -1,16 +1,100 @@
<?php
session_start();
require_once('../helper.php');
require_once('../config.php');
$err = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!isset($_SESSION['csrf'])) die('不正なリクエスト。');
if (!isset($_POST['csrf']) || $_POST['csrf'] !== $_SESSION['csrf']) die('不正なリクエスト。');
$h = htmlspecialchars($_POST['hostname']);
if (str_ends_with($h, '/')) $h = substr($h, 0, -1); // 「/」で終わったら、消して
//// セキュリティチェック
$err = domainsecuritycheck($h);
// OKですDBに入りましょう
if (empty($err)) {
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($site = mysqli_prepare($mysqli, "SELECT id FROM website WHERE url = ?")) {
mysqli_stmt_bind_param($site, "s", $h);
mysqli_stmt_execute($site);
mysqli_stmt_bind_result($site, $wid);
mysqli_execute($site);
mysqli_stmt_fetch($site);
$rid = $wid;
$wid = null;
mysqli_stmt_close($site);
if (is_null($rid)) mysqli_query($mysqli, "INSERT INTO `website` (url) VALUES ('".$h."');");
else $err[] = 'このウェブサイトは既に索引中です。<br />Error: This website is already being indexed.';
}
mysqli_close($mysqli);
}
}
else {
$csrf = uuid().'-'.bin2hex(openssl_random_pseudo_bytes(16));
$_SESSION['csrf'] = $csrf;
}
$title = 'ウエブサイトの追加';
$linktype = 'top';
$linktype = 'side';
require_once('../include/header.php');
require_once('../include/menu.php');
?>
<hr />
開発中…
<?php if ($_SERVER['REQUEST_METHOD'] === 'POST') { ?>
<p>
<h1><?php echo $h; ?>の追加</h1>
<?php if (empty($err)) { ?>
URLを追加しました。<br />
24時間以内から索引作業開始しますので、お待ち下さいませ。<br /><br />
Added URL.<br />
Indexing work will start within 24 hours, so please be patient.
<?php } else { ?>
下記のエラーが出ました (I got the following error)<br />
<ul>
<?php foreach ($err as $e) { ?>
<li><?php echo $e; ?></li>
<?php } ?>
</ul>
<?php } ?>
</p>
<?php } else {?>
<h1>ルール</h1>
<p>送信したウエブサイトは審査キューに入りますので、すぐ見つけられる様になりません。</p>
<ul>
<li>ウェブページは自動的にウィルスをダウンロードされるのは禁止です。</li>
<li>ウェブページはTor又はVPNユーザーをブロックされる(特にCloudFlareをご利用場合)のは禁止です。</li>
<li>送信URLは「http(s)://」からTLD(.moe, .jp, .com, .net, .org等)までです。クローラーは自動で全部のページを追加されます。</li>
<li>うまく追加するには、「DOCTYPE html」及び「title」タグは必須となります。</li>
</ul>
<p>The website you sent will be in the cron queue, so you won't be able to find it right away.</p>
<ul>
<li>Web pages are prohibited from automatically downloading viruses.</li>
<li>Web pages are prohibited from blocking Tor or VPN users (especially if you are using CloudFlare).</li>
<li>The sending URL is from "http (s): //" to TLD (.moe, .jp, .com, .net, .org, etc.). The crawler will automatically add all pages.</li>
<li>The "DOCTYPE html" and "title" tags are required for successful addition.</li>
</ul>
<hr />
<form action="/submit.php" method="POST">
<input type="hidden" name="csrf" value="<?php echo $csrf; ?>" />
URL<input type="text" name="hostname" placeholder="例)https://suwakochan.moe" value="" />
<input type="submit" value="送信" />
</form>
<?php } ?>
<?php
require_once('../include/footer.php');