From 446ca02e6f9a60d8cca4f8e648d14e628c06b373 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: Thu, 11 Aug 2022 06:44:02 +0900 Subject: [PATCH] ... --- www/index.php | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 www/index.php diff --git a/www/index.php b/www/index.php new file mode 100644 index 0000000..d84b4b3 --- /dev/null +++ b/www/index.php @@ -0,0 +1,111 @@ + $v) { + if ($newstring == $k) return mkstring(); + } + + return $newstring; + } + + // パラメートルがなければ、スキップ。 + if (isset($_POST['sosin'])) { + $newadd = $_POST['newadd']; + if (!str_starts_with($newadd, 'http://') && !str_starts_with($newadd, 'https://')) { + $title = '076エラー - 不正なURL'; + $h1 = '【エラー】不正なURL'; + $bg = 'daityan'; + $bgpos = 'top right 100px'; + $err = 'URLは「http://」又は「https://」で始まります。'; + include_once('../views/404.php'); + exit; + } + + if (strlen($newadd) > 500) { + $title = '076エラー - 不正なURL'; + $h1 = '【エラー】URLは長すぎ'; + $bg = 'daityan'; + $bgpos = 'top right 100px'; + $err = 'URLは500文字以内です。'; + include_once('../views/404.php'); + exit; + } + + $data = file_get_contents('links.json'); + + $arr = json_decode($data, true); + foreach ($arr as $k => $v) { + if ($newadd == $v) { + if (isset($_POST['api']) && $_POST['api'] == 1) { + header('Content-Type: application/json'); + echo json_encode(['res' => $k]); + } + else header('Location: /?newurl='.$k); + exit; + } + } + + $newstring = mkstring(); + + $arr[$newstring] = $newadd; + $newdata = json_encode($arr); + file_put_contents('links.json', $newdata); + + if (isset($_POST['api']) && $_POST['api'] == 1) { + header('Content-Type: application/json'); + echo json_encode(['res' => $newstring]); + } + else header('Location: /?newurl='.$newstring); + exit; + } + else if (!isset($_GET['url']) && isset($_GET['newurl'])) { + $newurl = $_GET['newurl']; + $bg = 'kasen'; + $bgpos = 'top 10px left 120px'; + include_once('../views/submitted.php'); + } + else if (isset($_GET['url']) && $_GET['url'] != '') { + $data = file_get_contents('links.json'); + + foreach (json_decode($data) as $k => $v) { + // jsonファイルでキーを見つければ、転送されます。なければ、404エラーが出ます。 + if ($_GET['url'] == $k) { + if (isset($_GET['api']) && $_GET['api'] == 1) { + header('Content-Type: application/json'); + echo json_encode(['res' => $v]); + } + else header('Location: '.$v); + exit; + } + else { + $title = '076エラー - 未検出'; + $h1 = '【404】未検出'; + $bg = 'daityan'; + $bgpos = 'top right 100px'; + $err = 'このURLを見つけられませんでした。'; + include_once('../views/404.php'); + } + } + } + else if (!isset($_GET['url']) && $_SERVER['REQUEST_URI'] == '/') { + $bg = 'rumia'; + $bgpos = 'top -30px right 90px'; + include_once('../views/index.php'); + } + else { + $title = '076エラー - 未検出'; + $h1 = '【404】未検出'; + $bg = 'daityan'; + $bgpos = 'top right 100px'; + $err = 'このURLを見つけられませんでした。'; + include_once('../views/404.php'); + } +?>