・
0, 'path' => '/', 'domain' => '', 'secure' => true, 'httponly' => true, 'samesite' => 'Lax' ]); session_start(); session_regenerate_id(true); try { $option = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_MULTI_STATEMENTS => false ); $pdo = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option); } catch(PDOException $e) { // 接続エラーのときエラー内容を取得する $error_message[] = $e->getMessage(); } if(isset($_SESSION['admin_login']) && $_SESSION['admin_login'] == true) { $passQuery = $pdo->prepare("SELECT username,userid,loginid,follow,admin,role,sacinfo,blocklist,mail_settings FROM account WHERE userid = :userid"); $passQuery->bindValue(':userid', safetext($_SESSION['userid'])); $passQuery->execute(); $res = $passQuery->fetch(); if(empty($res["userid"])){ header("Location: ../login.php"); exit; }elseif($_SESSION['loginid'] === $res["loginid"] && $_SESSION['userid'] == $res["userid"]){ // セッションに値をセット $userid = safetext($res['userid']); // セッションに格納されている値をそのままセット $username = safetext($res['username']); // セッションに格納されている値をそのままセット $loginid = safetext($res["loginid"]); $role = safetext($res["role"]); $sacinfo = safetext($res["sacinfo"]); $myblocklist = safetext($res["blocklist"]); $myfollowlist = safetext($res["follow"]); $_SESSION['admin_login'] = true; $_SESSION['userid'] = $userid; $_SESSION['username'] = $username; $_SESSION['loginid'] = $res["loginid"]; setcookie('userid', $userid, [ 'expires' => time() + 60 * 60 * 24 * 14, 'path' => '/', 'samesite' => 'lax', 'secure' => true, 'httponly' => true, ]); setcookie('username', $username,[ 'expires' => time() + 60 * 60 * 24 * 14, 'path' => '/', 'samesite' => 'lax', 'secure' => true, 'httponly' => true, ]); setcookie('loginid', $res["loginid"],[ 'expires' => time() + 60 * 60 * 24 * 14, 'path' => '/', 'samesite' => 'lax', 'secure' => true, 'httponly' => true, ]); setcookie('admin_login', true,[ 'expires' => time() + 60 * 60 * 24 * 14, 'path' => '/', 'samesite' => 'lax', 'secure' => true, 'httponly' => true, ]); }else{ header("Location: ../login.php"); exit; } } elseif (isset($_COOKIE['admin_login']) && $_COOKIE['admin_login'] == true) { $passQuery = $pdo->prepare("SELECT username,userid,loginid,follow,admin,role,sacinfo,blocklist,mail_settings FROM account WHERE userid = :userid"); $passQuery->bindValue(':userid', safetext($_COOKIE['userid'])); $passQuery->execute(); $res = $passQuery->fetch(); if(empty($res["userid"])){ header("Location: ../login.php"); exit; }elseif($_COOKIE['loginid'] === $res["loginid"] && $_COOKIE['userid'] == $res["userid"]){ // セッションに値をセット $userid = safetext($res['userid']); // クッキーから取得した値をセット $username = safetext($res['username']); // クッキーから取得した値をセット $loginid = safetext($res["loginid"]); $role = safetext($res["role"]); $sacinfo = safetext($res["sacinfo"]); $myblocklist = safetext($res["blocklist"]); $myfollowlist = safetext($res["follow"]); $_SESSION['admin_login'] = true; $_SESSION['userid'] = $userid; $_SESSION['username'] = $username; $_SESSION['loginid'] = $res["loginid"]; setcookie('userid', $userid,[ 'expires' => time() + 60 * 60 * 24 * 14, 'path' => '/', 'samesite' => 'lax', 'secure' => true, 'httponly' => true, ]); setcookie('username', $username,[ 'expires' => time() + 60 * 60 * 24 * 14, 'path' => '/', 'samesite' => 'lax', 'secure' => true, 'httponly' => true, ]); setcookie('loginid', $res["loginid"],[ 'expires' => time() + 60 * 60 * 24 * 14, 'path' => '/', 'samesite' => 'lax', 'secure' => true, 'httponly' => true, ]); setcookie('admin_login', true,[ 'expires' => time() + 60 * 60 * 24 * 14, 'path' => '/', 'samesite' => 'lax', 'secure' => true, 'httponly' => true, ]); }else{ header("Location: ../login.php"); exit; } } else { // ログインが許可されていない場合、ログインページにリダイレクト header("Location: ../login.php"); exit; } if(empty($userid)){ header("Location: ../login.php"); exit; } if(empty($username)){ header("Location: ../login.php"); exit; } $notiQuery = $pdo->prepare("SELECT COUNT(*) as notification_count FROM notification WHERE touserid = :userid AND userchk = 'none'"); $notiQuery->bindValue(':userid', $userid); $notiQuery->execute(); $notiData = $notiQuery->fetch(PDO::FETCH_ASSOC); $notificationcount = $notiData['notification_count']; //ページ内のみ使用変数------------------------- $mail_settings = safetext($res["mail_settings"]); //------------------------------------------ //phpmailer-------------------------------------------- require('../settings_admin/plugin_settings/phpmailer_settings.php'); //------------------------------------------------------ if( !empty($pdo) ) { // データベース接続の設定 $userQuery = $pdo->prepare("SELECT * FROM account WHERE userid = :userid"); $userQuery->bindValue(':userid', $userid); $userQuery->execute(); $userData = $userQuery->fetch(); $role = $userData["role"]; if(!(empty($userData["encryption_ivkey"]))){ $view_mailadds = DecryptionUseEncrKey($userData["mailadds"], GenUserEnckey($userData["datetime"]), $userData["encryption_ivkey"]); }else{ $view_mailadds = $userData["mailadds"]; } if(empty($userData["notification_settings"])){ $notification_settings_list = ["system","favorite","reply","reuse","ueuse","follow","mention","other"]; }else{ $notification_settings_list = explode(',', $userData["notification_settings"]); } } if( !empty($_POST['btn_submit']) ) { if(!(empty($_POST['im_bot']))){ if($_POST['im_bot'] == "on"){ $saveim_bot = "bot"; }else{ $saveim_bot = "none"; } }else{ $saveim_bot = "none"; } $username = safetext($_POST['username']); $mailadds = safetext($_POST['mailadds']); if( !empty($_POST['mail_important']) ) { $mail_important = safetext($_POST['mail_important']); }else{ $mail_important = "false"; } if(!(empty($mailadds))){ if(filter_var($mailadds, FILTER_VALIDATE_EMAIL)){ if($mail_important === "true"){ $savemail_important = "important"; }else{ $savemail_important = "none"; } if(!(empty($userData["encryption_ivkey"]))){ $userEnckey = GenUserEnckey($userData["datetime"]); $enc_mailadds = EncryptionUseEncrKey($mailadds, $userEnckey, $userData["encryption_ivkey"]); }else{ $ivLength = openssl_cipher_iv_length('aes-256-cbc'); $randomBytes = random_bytes($ivLength); $randomhash = hash('sha3-512', $randomBytes); $iv = substr($randomhash, 0, $ivLength); // トランザクション開始 $pdo->beginTransaction(); try { // SQL作成 $stmt = $pdo->prepare("UPDATE account SET encryption_ivkey = :encryption_ivkey WHERE userid = :userid;"); $stmt->bindParam(':encryption_ivkey', $iv, PDO::PARAM_STR); $stmt->bindValue(':userid', $userid, PDO::PARAM_STR); $res = $stmt->execute(); $res = $pdo->commit(); } catch (Exception $e) { $pdo->rollBack(); } if (!($res)) { $error_message[] = "アカウント操作に失敗しました(ERROR)"; } $stmt = null; $userEnckey = GenUserEnckey($userData["datetime"]); $enc_mailadds = EncryptionUseEncrKey($mailadds, $userEnckey, $iv); } }else{ $savemail_important = "none"; $error_message[] = 'メールアドレスが正しい形式ではありません。(MAILADDS_CHECK_DAME)'; } }else{ $enc_mailadds = ""; } $profile = safetext($_POST['profile']); if( 1024 < mb_strlen($profile, 'UTF-8') ) { $error_message[] = 'プロフィールは1024文字以内で入力してください。(INPUT_OVER_MAX_COUNT)'; } // ユーザーネームの入力チェック if( empty($username) ) { $error_message[] = '表示名を入力してください。(USERNAME_INPUT_PLEASE)'; } else { // 文字数を確認 if( 50 < mb_strlen($username, 'UTF-8') ) { $error_message[] = 'ユーザーネームは50文字以内で入力してください。(USERNAME_OVER_MAX_COUNT)'; } } if( empty($error_message) ) { // トランザクション開始 $pdo->beginTransaction(); $hashpassword = password_hash($password, PASSWORD_DEFAULT); try { // SQL作成 $stmt = $pdo->prepare("UPDATE account SET username = :username, mailadds = :mailadds, profile = :profile, sacinfo = :saveimbot, mail_settings = :mail_settings WHERE userid = :userid;"); // 他の値をセット $stmt->bindParam(':username', $username, PDO::PARAM_STR); $stmt->bindParam(':mailadds', $enc_mailadds, PDO::PARAM_STR); $stmt->bindParam(':profile', $profile, PDO::PARAM_STR); $stmt->bindParam(':saveimbot', $saveim_bot, PDO::PARAM_STR); $stmt->bindParam(':mail_settings', $savemail_important, PDO::PARAM_STR); // 条件を指定 // 以下の部分を適切な条件に置き換えてください $stmt->bindValue(':userid', $userid, PDO::PARAM_STR); // SQLクエリの実行 $res = $stmt->execute(); // コミット $res = $pdo->commit(); } catch (Exception $e) { // エラーが発生した時はロールバック $pdo->rollBack(); } if ($res) { $url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header("Location:".$url.""); exit; } else { $error_message[] = '更新に失敗しました。(REGISTERED_DAME)'; } // プリペアドステートメントを削除 $stmt = null; } } if( !empty($_POST['pass_submit']) ) { $pass_chk = safetext($_POST['passchk_userid']); $password = $_POST['password']; $hashpassword = password_hash($password, PASSWORD_DEFAULT); if(empty($pass_chk)){ $error_message[] = 'ユーザーidを入力してください。(USERID_INPUT_PLEASE)'; }else{ if(!(preg_match("/^[a-zA-Z0-9_]+$/", $pass_chk))){ $error_message[] = "IDは半角英数字で作成してください。(「_」は使用可能です。)(USERID_DONT_USE_WORD)"; }else{ if(!($pass_chk === $userData["userid"])){ $error_message[] = 'ユーザーidが不正です。(USERID_CHIGAUYANKE)'; } } } // パスワードの入力チェック if( empty($password) ) { $error_message[] = 'パスワードを入力してください。(PASSWORD_INPUT_PLEASE)'; } else { if(in_array($password, $badpass) === true ){ $error_message[] = "パスワードが弱いです。セキュリティ上変更してください。(PASSWORD_ZEIJAKU)"; } if( 4 > mb_strlen($password, 'UTF-8') ) { $error_message[] = 'パスワードは4文字以上である必要があります。(PASSWORD_TODOITENAI_MIN_COUNT)'; } // 文字数を確認 if( 256 < mb_strlen($password, 'UTF-8') ) { $error_message[] = 'パスワードは256文字以内で入力してください。(PASSWORD_OVER_MAX_COUNT)'; } } if( empty($error_message) ) { // トランザクション開始 $pdo->beginTransaction(); $hashpassword = password_hash($password, PASSWORD_DEFAULT); try { // SQL作成 $stmt = $pdo->prepare("UPDATE account SET password = :password WHERE userid = :userid"); // 他の値をセット $stmt->bindParam(':password', $hashpassword, PDO::PARAM_STR); // 条件を指定 // 以下の部分を適切な条件に置き換えてください $stmt->bindValue(':userid', $userid, PDO::PARAM_STR); // SQLクエリの実行 $res = $stmt->execute(); // コミット $res = $pdo->commit(); } catch (Exception $e) { // エラーが発生した時はロールバック $pdo->rollBack(); } if ($res) { $url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header("Location:".$url.""); exit; } else { $error_message[] = '更新に失敗しました。(REGISTERED_DAME)'; } // プリペアドステートメントを削除 $stmt = null; } } if( !empty($_POST['logout']) ) { if (isset($_SERVER['HTTP_COOKIE'])) { $cookies = explode(';', $_SERVER['HTTP_COOKIE']); foreach($cookies as $cookie) { $parts = explode('=', $cookie); $name = trim($parts[0]); setcookie($name, '', time()-1000); setcookie($name, '', time()-1000, '/'); } } // リダイレクト先のURLへ転送する $url = '../index.php'; header('Location: ' . $url, true, 303); // すべての出力を終了 exit; } if( !empty($_POST['img1btn_submit']) ) { if (!empty($_FILES['image2s']['name'])) { // アップロードされたファイル情報 $uploadedFile = $_FILES['image2s']; if(check_mime($uploadedFile['tmp_name'])){ // アップロードされたファイルの拡張子を取得 $extension = pathinfo($uploadedFile['name'], PATHINFO_EXTENSION); // EXIF削除 delete_exif($extension, $uploadedFile['tmp_name']); // リサイズ resizeImage($uploadedFile['tmp_name'], 2048, 1024); if(check_mime($uploadedFile['tmp_name']) == "image/webp"){ // 新しいファイル名を生成(uniqid + 拡張子) $newFilename = uniqid() . '-'.$userid.'.webp'; }else{ // 新しいファイル名を生成(uniqid + 拡張子) $newFilename = uniqid() . '-'.$userid.'.' . $extension; } // 保存先のパスを生成 $uploadedPath = 'userheads/' . $newFilename; // ファイルを移動 $result = move_uploaded_file($uploadedFile['tmp_name'], '../'.$uploadedPath); if ($result) { $headName = $uploadedPath; // 保存されたファイルのパスを使用 } else { $errnum = $uploadedFile['error']; if($errnum === 1){$errcode = "FILE_DEKASUGUI_PHP_INI_KAKUNIN";} if($errnum === 2){$errcode = "FILE_DEKASUGUI_HTML_KAKUNIN";} if($errnum === 3){$errcode = "FILE_SUKOSHIDAKE_UPLOAD";} if($errnum === 4){$errcode = "FILE_UPLOAD_DEKINAKATTA";} if($errnum === 6){$errcode = "TMP_FOLDER_NAI";} if($errnum === 7){$errcode = "FILE_KAKIKOMI_SIPPAI";} if($errnum === 8){$errcode = "PHPINFO()_KAKUNIN";} $error_message[] = 'アップロード失敗!(2)エラーコード:' .$errcode.''; } }else{ $error_message[] = "使用できない画像形式です。(FILE_UPLOAD_DEKINAKATTA)"; } }else{ $error_message[] = 'ヘッダー画像を選択してください(PHOTO_SELECT_PLEASE)'; } if( empty($error_message) ) { // トランザクション開始 $pdo->beginTransaction(); try { // SQL作成 $stmt = $pdo->prepare("UPDATE account SET headname = :headname WHERE userid = :userid"); // ヘッダー画像のバインド $stmt->bindValue(':headname', $headName, PDO::PARAM_STR); // ユーザーIDのバインド(WHERE句に必要) $stmt->bindValue(':userid', $userid, PDO::PARAM_STR); // SQLクエリの実行 $res = $stmt->execute(); // コミット $res = $pdo->commit(); } catch (Exception $e) { // エラーが発生した時はロールバック $pdo->rollBack(); } if ($res) { $url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header("Location:".$url.""); exit; } else { $error_message[] = '更新に失敗しました。(REGISTERED_DAME)'; } // プリペアドステートメントを削除 $stmt = null; } } if( !empty($_POST['img2btn_submit']) ) { if (!empty($_FILES['image']['name'])) { // アップロードされたファイル情報 $uploadedFile = $_FILES['image']; if(check_mime($uploadedFile['tmp_name'])){ // アップロードされたファイルの拡張子を取得 $extension = pathinfo($uploadedFile['name'], PATHINFO_EXTENSION); // EXIF削除 delete_exif($extension, $uploadedFile['tmp_name']); // リサイズ resizeImage($uploadedFile['tmp_name'], 512, 512); if(check_mime($uploadedFile['tmp_name']) == "image/webp"){ // 新しいファイル名を生成(uniqid + 拡張子) $newFilename = uniqid() . '-'.$userid.'.webp'; }else{ // 新しいファイル名を生成(uniqid + 拡張子) $newFilename = uniqid() . '-'.$userid.'.' . $extension; } // 保存先のパスを生成 $uploadedPath = 'usericons/' . $newFilename; // ファイルを移動 $result = move_uploaded_file($uploadedFile['tmp_name'], '../'.$uploadedPath); if ($result) { $iconName = $uploadedPath; // 保存されたファイルのパスを使用 } else { $errnum = $uploadedFile['error']; if($errnum === 1){$errcode = "FILE_DEKASUGUI_PHP_INI_KAKUNIN";} if($errnum === 2){$errcode = "FILE_DEKASUGUI_HTML_KAKUNIN";} if($errnum === 3){$errcode = "FILE_SUKOSHIDAKE_UPLOAD";} if($errnum === 4){$errcode = "FILE_UPLOAD_DEKINAKATTA";} if($errnum === 6){$errcode = "TMP_FOLDER_NAI";} if($errnum === 7){$errcode = "FILE_KAKIKOMI_SIPPAI";} if($errnum === 8){$errcode = "PHPINFO()_KAKUNIN";} $error_message[] = 'アップロード失敗!(2)エラーコード:' .$errcode.''; } }else{ $error_message[] = "使用できない画像形式です。(FILE_UPLOAD_DEKINAKATTA)"; } }else{ $error_message[] = 'アイコン画像を選択してください(PHOTO_SELECT_PLEASE)'; } if( empty($error_message) ) { // トランザクション開始 $pdo->beginTransaction(); try { // SQL作成 $stmt = $pdo->prepare("UPDATE account SET iconname = :iconname WHERE userid = :userid"); // アイコン画像のバインド $stmt->bindValue(':iconname', $iconName, PDO::PARAM_STR); // ユーザーIDのバインド(WHERE句に必要) $stmt->bindValue(':userid', $userid, PDO::PARAM_STR); // SQLクエリの実行 $res = $stmt->execute(); // コミット $res = $pdo->commit(); } catch (Exception $e) { // エラーが発生した時はロールバック $pdo->rollBack(); } if ($res) { $url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header("Location:".$url.""); exit; } else { $error_message[] = '更新に失敗しました。(REGISTERED_DAME)'; } // プリペアドステートメントを削除 $stmt = null; } } require('../logout/logout.php'); if( !empty($_POST['auth_on_submit']) ) { $_SESSION['userid'] = $userid; // リダイレクト先のURLへ転送する $url = 'addauthcode.php'; header('Location: ' . $url, true, 303); // すべての出力を終了 exit; } if( !empty($_POST['auth_off_submit']) ) { if( empty($error_message) ) { $secret = ""; $backupcode = ""; // トランザクション開始 $pdo->beginTransaction(); try { // SQL作成 $stmt = $pdo->prepare("UPDATE account SET authcode = :authcode,backupcode = :backupcode WHERE userid = :userid"); $stmt->bindValue(':authcode', $secret, PDO::PARAM_STR); $stmt->bindValue(':backupcode', $backupcode, PDO::PARAM_STR); // ユーザーIDのバインド(WHERE句に必要) $stmt->bindValue(':userid', $userid, PDO::PARAM_STR); // SQLクエリの実行 $res = $stmt->execute(); // コミット $res = $pdo->commit(); } catch (Exception $e) { // エラーが発生した時はロールバック $pdo->rollBack(); } if ($res) { $url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header("Location:".$url.""); exit; } else { $error_message[] = '更新に失敗しました。(REGISTERED_DAME)'; } // プリペアドステートメントを削除 $stmt = null; } } if( !empty($_POST['notification_submit']) ) { $New_notification_list = ["system", "other"]; if(!(empty($_POST['notification_favorite']))){ if($_POST['notification_favorite'] == "on"){ $New_notification_list[] = "favorite"; } } if(!(empty($_POST['notification_reuse']))){ if($_POST['notification_reuse'] == "on"){ $New_notification_list[] = "reuse"; } } if(!(empty($_POST['notification_reply']))){ if($_POST['notification_reply'] == "on"){ $New_notification_list[] = "reply"; } } if(!(empty($_POST['notification_mention']))){ if($_POST['notification_mention'] == "on"){ $New_notification_list[] = "mention"; } } if(!(empty($_POST['notification_follow']))){ if($_POST['notification_follow'] == "on"){ $New_notification_list[] = "follow"; } } if( empty($error_message) ) { $Save_notification_list = implode(',', array_unique($New_notification_list)); // トランザクション開始 $pdo->beginTransaction(); try { $stmt = $pdo->prepare("UPDATE account SET notification_settings = :notification_settings WHERE userid = :userid"); $stmt->bindValue(':notification_settings', $Save_notification_list, PDO::PARAM_STR); $stmt->bindValue(':userid', $userid, PDO::PARAM_STR); $res = $stmt->execute(); // コミット $res = $pdo->commit(); } catch (Exception $e) { $pdo->rollBack(); } if ($res) { $url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header("Location:".$url.""); exit; } else { $error_message[] = '更新に失敗しました。(REGISTERED_DAME)'; } // プリペアドステートメントを削除 $stmt = null; } } // データベースの接続を閉じる $pdo = null; ?>
・