diff --git a/.well-known/host-meta/index.php b/.well-known/host-meta/index.php index 9507b10..b05557c 100644 --- a/.well-known/host-meta/index.php +++ b/.well-known/host-meta/index.php @@ -2,7 +2,9 @@ $serversettings_file = "../../server/serversettings.ini"; $serversettings = parse_ini_file($serversettings_file, true); +require('../../db.php'); require("../../function/function.php"); +blockedIP($_SERVER['REMOTE_ADDR']); if(safetext($serversettings["serverinfo"]["server_activitypub"]) === "true"){ header("Content-Type: application/xml; charset=UTF-8"); diff --git a/.well-known/nodeinfo/index.php b/.well-known/nodeinfo/index.php index 950dc0c..25b6112 100644 --- a/.well-known/nodeinfo/index.php +++ b/.well-known/nodeinfo/index.php @@ -2,7 +2,9 @@ $serversettings_file = "../../server/serversettings.ini"; $serversettings = parse_ini_file($serversettings_file, true); +require('../../db.php'); require("../../function/function.php"); +blockedIP($_SERVER['REMOTE_ADDR']); if(safetext($serversettings["serverinfo"]["server_activitypub"]) === "true"){ header("Content-Type: application/activity+json; charset=utf-8"); diff --git a/.well-known/webfinger/index.php b/.well-known/webfinger/index.php index aac3b42..1267e3b 100644 --- a/.well-known/webfinger/index.php +++ b/.well-known/webfinger/index.php @@ -2,7 +2,9 @@ $serversettings_file = "../../server/serversettings.ini"; $serversettings = parse_ini_file($serversettings_file, true); +require('../../db.php'); require("../../function/function.php"); +blockedIP($_SERVER['REMOTE_ADDR']); if(safetext($serversettings["serverinfo"]["server_activitypub"]) === "true"){ header("Content-Type: application/jrd+json; charset=utf-8"); diff --git a/abi/addabi.php b/abi/addabi.php index dc9502c..4373e81 100644 --- a/abi/addabi.php +++ b/abi/addabi.php @@ -8,6 +8,7 @@ $banurl = array_filter(preg_split("/\r\n|\n|\r/", $banurl_info)); require('../db.php'); require("../function/function.php"); +blockedIP($_SERVER['REMOTE_ADDR']); if (safetext(isset($_POST['uniqid'])) && safetext(isset($_POST['abitext'])) && safetext(isset($_POST['userid'])) && safetext(isset($_POST['account_id']))) { $userid = safetext($_POST['userid']); diff --git a/actor/index.php b/actor/index.php index 1c26c26..0d47419 100644 --- a/actor/index.php +++ b/actor/index.php @@ -2,7 +2,9 @@ $serversettings_file = "../server/serversettings.ini"; $serversettings = parse_ini_file($serversettings_file, true); +require('../db.php'); require("../function/function.php"); +blockedIP($_SERVER['REMOTE_ADDR']); if(safetext($serversettings["serverinfo"]["server_activitypub"]) === "true"){ header("Content-Type: application/activity+json; charset=utf-8"); @@ -10,8 +12,6 @@ if(safetext($serversettings["serverinfo"]["server_activitypub"]) === "true"){ $domain = $_SERVER['HTTP_HOST']; - require('../db.php'); - // データベースに接続 try { $option = array( diff --git a/addauthcode.php b/addauthcode.php index 2cc25de..9d93e5f 100644 --- a/addauthcode.php +++ b/addauthcode.php @@ -50,49 +50,14 @@ try { $error_message[] = $e->getMessage(); } -if(isset($_SESSION['admin_login']) && $_SESSION['admin_login'] === true && isset($_COOKIE['loginid']) && isset($_SESSION['userid'])) { - $options = array( - // SQL実行失敗時に例外をスルー - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - // デフォルトフェッチモードを連想配列形式に設定 - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - // バッファードクエリを使う(一度に結果セットを全て取得し、サーバー負荷を軽減) - // SELECTで得た結果に対してもrowCountメソッドを使えるようにする - PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, - ); - $dbh = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option); - $acck = $dbh->prepare("SELECT userid, loginid FROM account WHERE userid = :userid"); - $acck->bindValue(':userid', $_SESSION['userid']); - $acck->execute(); - $acck_data = $acck->fetch(); - if(!empty($acck_data)){ - if($_COOKIE['loginid'] === $acck_data["loginid"] && $_SESSION['userid'] === $acck_data["userid"] ){ - header("Location: home/index.php"); - exit; - } - } -} elseif (isset($_COOKIE['admin_login']) && $_COOKIE['admin_login'] == true && isset($_COOKIE['loginid']) && isset($_COOKIE['userid'])) { - $options = array( - // SQL実行失敗時に例外をスルー - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - // デフォルトフェッチモードを連想配列形式に設定 - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - // バッファードクエリを使う(一度に結果セットを全て取得し、サーバー負荷を軽減) - // SELECTで得た結果に対してもrowCountメソッドを使えるようにする - PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, - ); - $dbh = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option); - $acck = $dbh->prepare("SELECT userid, loginid FROM account WHERE userid = :userid"); - $acck->bindValue(':userid', $_COOKIE['userid']); - $acck->execute(); - $acck_data = $acck->fetch(); - if(!empty($acck_data)){ - if($_COOKIE['loginid'] === $acck_data["loginid"] && $_COOKIE['userid'] === $acck_data["userid"] ){ - header("Location: home/index.php"); - exit; - } - } +//ログイン認証--------------------------------------------------- +blockedIP($_SERVER['REMOTE_ADDR']); +$is_login = uwuzuUserLogin($_SESSION, $_COOKIE, $_SERVER['REMOTE_ADDR'], "user"); +if(!($is_login === false)){ + header("Location: /home/"); + exit; } +//------------------------------------------------------------- require_once 'authcode/GoogleAuthenticator.php'; diff --git a/admin/addadmin.php b/admin/addadmin.php index 76a649a..7967fca 100644 --- a/admin/addadmin.php +++ b/admin/addadmin.php @@ -3,6 +3,7 @@ require('../db.php'); //関数呼び出し //- EXIF require('../function/function.php'); +blockedIP($_SERVER['REMOTE_ADDR']); $serversettings_file = "../server/serversettings.ini"; $serversettings = parse_ini_file($serversettings_file, true); diff --git a/admin/index.php b/admin/index.php index 4c7e33e..356e2c6 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,6 +1,7 @@ getMessage(); } -if(isset($_SESSION['admin_login']) && $_SESSION['admin_login'] === true && isset($_COOKIE['loginid']) && isset($_SESSION['userid'])) { - $options = array( - // SQL実行失敗時に例外をスルー - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - // デフォルトフェッチモードを連想配列形式に設定 - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - // バッファードクエリを使う(一度に結果セットを全て取得し、サーバー負荷を軽減) - // SELECTで得た結果に対してもrowCountメソッドを使えるようにする - PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, - ); - $dbh = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option); - $acck = $dbh->prepare("SELECT userid, loginid FROM account WHERE userid = :userid"); - $acck->bindValue(':userid', $_SESSION['userid']); - $acck->execute(); - $acck_data = $acck->fetch(); - if(!empty($acck_data)){ - if($_COOKIE['loginid'] === $acck_data["loginid"] && $_SESSION['userid'] === $acck_data["userid"] ){ - header("Location: home/index.php"); - exit; - } - } -} elseif (isset($_COOKIE['admin_login']) && $_COOKIE['admin_login'] == true && isset($_COOKIE['loginid']) && isset($_COOKIE['userid'])) { - $options = array( - // SQL実行失敗時に例外をスルー - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - // デフォルトフェッチモードを連想配列形式に設定 - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - // バッファードクエリを使う(一度に結果セットを全て取得し、サーバー負荷を軽減) - // SELECTで得た結果に対してもrowCountメソッドを使えるようにする - PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, - ); - $dbh = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option); - $acck = $dbh->prepare("SELECT userid, loginid FROM account WHERE userid = :userid"); - $acck->bindValue(':userid', $_COOKIE['userid']); - $acck->execute(); - $acck_data = $acck->fetch(); - if(!empty($acck_data)){ - if($_COOKIE['loginid'] === $acck_data["loginid"] && $_COOKIE['userid'] === $acck_data["userid"] ){ - header("Location: home/index.php"); - exit; - } - } +//ログイン認証--------------------------------------------------- +blockedIP($_SERVER['REMOTE_ADDR']); +$is_login = uwuzuUserLogin($_SESSION, $_COOKIE, $_SERVER['REMOTE_ADDR'], "user"); +if(!($is_login === false)){ + header("Location: /home/"); + exit; } +//------------------------------------------------------------- if( !empty($_POST['btn_submit']) ) { $_SESSION['userid'] = $userid; diff --git a/authlogin.php b/authlogin.php index a0bc939..cc728cf 100644 --- a/authlogin.php +++ b/authlogin.php @@ -46,55 +46,21 @@ try { ); $pdo = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option); + $userData = getUserData($pdo, $userid); } catch(PDOException $e) { // 接続エラーのときエラー内容を取得する $error_message[] = $e->getMessage(); } -if(isset($_SESSION['admin_login']) && $_SESSION['admin_login'] === true && isset($_COOKIE['loginid']) && isset($_SESSION['userid'])) { - $options = array( - // SQL実行失敗時に例外をスルー - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - // デフォルトフェッチモードを連想配列形式に設定 - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - // バッファードクエリを使う(一度に結果セットを全て取得し、サーバー負荷を軽減) - // SELECTで得た結果に対してもrowCountメソッドを使えるようにする - PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, - ); - $dbh = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option); - $acck = $dbh->prepare("SELECT userid, loginid FROM account WHERE userid = :userid"); - $acck->bindValue(':userid', $_SESSION['userid']); - $acck->execute(); - $acck_data = $acck->fetch(); - if(!empty($acck_data)){ - if($_COOKIE['loginid'] === $acck_data["loginid"] && $_SESSION['userid'] === $acck_data["userid"] ){ - header("Location: home/index.php"); - exit; - } - } -} elseif (isset($_COOKIE['admin_login']) && $_COOKIE['admin_login'] == true && isset($_COOKIE['loginid']) && isset($_COOKIE['userid'])) { - $options = array( - // SQL実行失敗時に例外をスルー - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - // デフォルトフェッチモードを連想配列形式に設定 - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - // バッファードクエリを使う(一度に結果セットを全て取得し、サーバー負荷を軽減) - // SELECTで得た結果に対してもrowCountメソッドを使えるようにする - PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, - ); - $dbh = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option); - $acck = $dbh->prepare("SELECT userid, loginid FROM account WHERE userid = :userid"); - $acck->bindValue(':userid', $_COOKIE['userid']); - $acck->execute(); - $acck_data = $acck->fetch(); - if(!empty($acck_data)){ - if($_COOKIE['loginid'] === $acck_data["loginid"] && $_COOKIE['userid'] === $acck_data["userid"] ){ - header("Location: home/index.php"); - exit; - } - } +//ログイン認証--------------------------------------------------- +blockedIP($_SERVER['REMOTE_ADDR']); +$is_login = uwuzuUserLogin($_SESSION, $_COOKIE, $_SERVER['REMOTE_ADDR'], "user"); +if(!($is_login === false)){ + header("Location: /home/"); + exit; } +//------------------------------------------------------------- if( !empty($_POST['btn_submit']) ) { $useragent = safetext($_SERVER['HTTP_USER_AGENT']); @@ -180,41 +146,30 @@ if( !empty($_POST['btn_submit']) ) { } } - setcookie('userid', $userid,[ + setcookie('loginid', $userData["loginid"],[ 'expires' => time() + 60 * 60 * 24 * 28, 'path' => '/', 'samesite' => 'lax', 'secure' => true, 'httponly' => true, ]); - setcookie('loginid', $row["loginid"],[ - 'expires' => time() + 60 * 60 * 24 * 28, - 'path' => '/', - 'samesite' => 'lax', - 'secure' => true, - 'httponly' => true, - ]); - setcookie('username', $row["username"],[ - 'expires' => time() + 60 * 60 * 24 * 28, - 'path' => '/', - 'samesite' => 'lax', - 'secure' => true, - 'httponly' => true, - ]); - setcookie('admin_login', true,[ - 'expires' => time() + 60 * 60 * 24 * 28, - 'path' => '/', - 'samesite' => 'lax', - 'secure' => true, - 'httponly' => true, - ]); - - $_SESSION['admin_login'] = true; - $_SESSION['userid'] = $userid; - $_SESSION['loginid'] = $row["loginid"]; - $_SESSION['username'] = $row["username"]; - $_SESSION['password'] = ""; + $userEncKey = GenUserEnckey($userData["datetime"]); + $userLoginKey = hash_hmac('sha256', $userData["loginid"], $userEncKey); + setcookie('loginkey', $userLoginKey,[ + 'expires' => time() + 60 * 60 * 24 * 28, + 'path' => '/', + 'samesite' => 'lax', + 'secure' => true, + 'httponly' => true, + ]); + + $_SESSION['userid'] = $userid; + $_SESSION['loginid'] = $userData["loginid"]; + $_SESSION['loginkey'] = $userLoginKey; + + $_SESSION['username'] = $username; + $_SESSION['password'] = null; // リダイレクト先のURLへ転送する $url = '/home'; @@ -292,41 +247,29 @@ if( !empty($_POST['btn_submit']) ) { } } - setcookie('userid', $userid,[ + setcookie('loginid', $userData["loginid"],[ 'expires' => time() + 60 * 60 * 24 * 28, 'path' => '/', 'samesite' => 'lax', 'secure' => true, 'httponly' => true, ]); - setcookie('loginid', $row["loginid"],[ - 'expires' => time() + 60 * 60 * 24 * 28, - 'path' => '/', - 'samesite' => 'lax', - 'secure' => true, - 'httponly' => true, - ]); - setcookie('username', $row["username"],[ - 'expires' => time() + 60 * 60 * 24 * 28, - 'path' => '/', - 'samesite' => 'lax', - 'secure' => true, - 'httponly' => true, - ]); - setcookie('admin_login', true,[ - 'expires' => time() + 60 * 60 * 24 * 28, - 'path' => '/', - 'samesite' => 'lax', - 'secure' => true, - 'httponly' => true, - ]); - - $_SESSION['admin_login'] = true; - - $_SESSION['userid'] = $userid; - $_SESSION['loginid'] = $row["loginid"]; - $_SESSION['username'] = $row["username"]; + $userEncKey = GenUserEnckey($userData["datetime"]); + $userLoginKey = hash_hmac('sha256', $userData["loginid"], $userEncKey); + setcookie('loginkey', $userLoginKey,[ + 'expires' => time() + 60 * 60 * 24 * 28, + 'path' => '/', + 'samesite' => 'lax', + 'secure' => true, + 'httponly' => true, + ]); + + $_SESSION['userid'] = $userid; + $_SESSION['loginid'] = $userData["loginid"]; + $_SESSION['loginkey'] = $userLoginKey; + + $_SESSION['username'] = $username; $_SESSION['password'] = null; // リダイレクト先のURLへ転送する diff --git a/check.php b/check.php index 6320414..1b8ec7f 100644 --- a/check.php +++ b/check.php @@ -18,9 +18,6 @@ $res = null; $option = null; $error_message = array(); -$row["userid"] = array(); -$row["password"] = array(); - $ruserid = array(); $rpassword = array(); @@ -47,54 +44,17 @@ try { $userid = $_SESSION['userid']; - - $options = array( - // SQL実行失敗時に例外をスルー - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - // デフォルトフェッチモードを連想配列形式に設定 - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - // バッファードクエリを使う(一度に結果セットを全て取得し、サーバー負荷を軽減) - // SELECTで得た結果に対してもrowCountメソッドを使えるようにする - PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, - ); - - $dbh = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option); - - - $result = $dbh->prepare("SELECT userid, username, profile, role FROM account WHERE userid = :userid"); - - $result->bindValue(':userid', $userid); - // SQL実行 - $result->execute(); - - - $row = $result->fetch(); // ここでデータベースから取得した値を $row に代入する - - $username = $row["username"]; - - $role = $row["role"]; - - - //-------------------------------------- - - $userQuery = $dbh->prepare("SELECT username, userid, loginid, profile, role, iconname FROM account WHERE userid = :userid"); - $userQuery->bindValue(':userid', $userid); - $userQuery->execute(); - $userData = $userQuery->fetch(); - + $userData = getUserData($pdo, $userid); $roles = explode(',', $userData["role"]); // カンマで区切られたロールを配列に分割 $roleDataArray = array(); foreach ($roles as $roleId) { - $rerole = $dbh->prepare("SELECT rolename, roleauth, rolecolor, roleeffect FROM role WHERE roleidname = :role"); + $rerole = $pdo->prepare("SELECT rolename, roleauth, rolecolor, roleeffect FROM role WHERE roleidname = :role"); $rerole->bindValue(':role', $roleId); $rerole->execute(); $roleDataArray[$roleId] = $rerole->fetch(); } - - - } catch(PDOException $e) { // 接続エラーのときエラー内容を取得する @@ -192,13 +152,6 @@ if( !empty($_POST['btn_submit']) ) { } } - setcookie('userid', $userid,[ - 'expires' => time() + 60 * 60 * 24 * 28, - 'path' => '/', - 'samesite' => 'lax', - 'secure' => true, - 'httponly' => true, - ]); setcookie('loginid', $userData["loginid"],[ 'expires' => time() + 60 * 60 * 24 * 28, 'path' => '/', @@ -206,14 +159,10 @@ if( !empty($_POST['btn_submit']) ) { 'secure' => true, 'httponly' => true, ]); - setcookie('username', $username,[ - 'expires' => time() + 60 * 60 * 24 * 28, - 'path' => '/', - 'samesite' => 'lax', - 'secure' => true, - 'httponly' => true, - ]); - setcookie('admin_login', true,[ + + $userEncKey = GenUserEnckey($userData["datetime"]); + $userLoginKey = hash_hmac('sha256', $userData["loginid"], $userEncKey); + setcookie('loginkey', $userLoginKey,[ 'expires' => time() + 60 * 60 * 24 * 28, 'path' => '/', 'samesite' => 'lax', @@ -221,9 +170,9 @@ if( !empty($_POST['btn_submit']) ) { 'httponly' => true, ]); - $_SESSION['admin_login'] = true; $_SESSION['userid'] = $userid; $_SESSION['loginid'] = $userData["loginid"]; + $_SESSION['loginkey'] = $userLoginKey; $_SESSION['username'] = $username; $_SESSION['password'] = null; @@ -285,7 +234,7 @@ $pdo = null;
あなたは ですか?
+あなたは ですか?
ユーザー名
- +プロフィール
- +