1
0
mirror of https://github.com/Daichimarukana/uwuzu.git synced 2026-06-05 03:24:41 +00:00
Files
uwuzu-mirror/settings_admin/actionlog_admin.php
T
2024-12-27 18:11:13 +09:00

347 lines
10 KiB
PHP

<?php
$serversettings_file = "../server/serversettings.ini";
$serversettings = parse_ini_file($serversettings_file, true);
function random_code($length = 8){
return substr(str_shuffle('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, $length);
}
require('../db.php');
require("../function/function.php");
// 変数の初期化
$datetime = array();
$user_name = null;
$message = array();
$message_data = null;
$error_message = array();
$pdo = null;
$stmt = null;
$res = null;
$option = null;
session_name('uwuzu_s_id');
session_set_cookie_params([
'lifetime' => 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 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 * 28,
'path' => '/',
'samesite' => 'lax',
'secure' => true,
'httponly' => true,
]);
setcookie('username', $username,[
'expires' => time() + 60 * 60 * 24 * 28,
'path' => '/',
'samesite' => 'lax',
'secure' => true,
'httponly' => true,
]);
setcookie('loginid', $res["loginid"],[
'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,
]);
}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 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 * 28,
'path' => '/',
'samesite' => 'lax',
'secure' => true,
'httponly' => true,
]);
setcookie('username', $username,[
'expires' => time() + 60 * 60 * 24 * 28,
'path' => '/',
'samesite' => 'lax',
'secure' => true,
'httponly' => true,
]);
setcookie('loginid', $res["loginid"],[
'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,
]);
}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;
}
if(!($res["admin"] === "yes")){
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'];
require('../logout/logout.php');
if (!empty($pdo)) {
$sql = "SELECT * FROM actionlog ORDER BY datetime DESC LIMIT 100";
$allactionlog = $pdo->query($sql);
while ($row = $allactionlog->fetch(PDO::FETCH_ASSOC)) {
$logs[] = $row;
}
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/home.css">
<script src="../js/jquery-min.js"></script>
<script src="../js/unsupported.js"></script>
<script src="../js/console_notice.js"></script>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="apple-touch-icon" type="image/png" href="../favicon/apple-touch-icon-180x180.png">
<link rel="icon" type="image/png" href="../favicon/icon-192x192.png">
<title>ログ - <?php echo safetext($serversettings["serverinfo"]["server_name"]);?></title>
</head>
<body>
<?php require('../require/leftbox.php');?>
<main>
<?php if( !empty($error_message) ): ?>
<ul class="errmsg">
<?php foreach( $error_message as $value ): ?>
<p>・ <?php echo $value; ?></p>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<div class="admin_settings">
<?php require('settings_left_menu.php');?>
<div class="admin_right">
<div class="formarea">
<h1>ログ</h1>
<p>直近100件のログを表示します。</p>
<div class="p2">この機能はベータ版機能であり、今後変更や削除が行われるおそれがあります。</div>
<?php if(!(empty($logs))){?>
<?php foreach ($logs as $value) {
switch ($value["importance"]){
case 0:
$importance = "INFO";
break;
case 1:
$importance = "NOTICE";
break;
case 2:
$importance = "WARNING";
break;
case 3:
$importance = "ERROR";
break;
case 4:
$importance = "CRITICAL";
break;
default:
$importance = "INFO";
break;
}
?>
<div class="actionlog">
<details>
<summary><span class="<?php echo safetext($importance);?>"><?php echo safetext($importance);?></span><?php echo safetext($value["type"]);?> | <?php echo safetext($value["place"]);?></summary>
<p>種別: <?php echo safetext($value["type"]);?></p>
<p>発生場所: <?php echo safetext($value["place"]);?></p>
<p>発生日時: <?php echo safetext($value["datetime"]);?></p>
<p>実行ユーザー: <?php echo safetext($value["userid"]);?></p>
<p>ターゲット: <?php echo safetext($value["target"]);?></p>
<hr>
<p>内容</p>
<p><?php echo safetext($value["content"]);?></p>
<hr>
</details>
</div>
<?php }?>
<?php }else{?>
<p>ログはありません</p>
<?php }?>
</div>
</div>
</div>
</main>
<?php require('../require/rightbox.php');?>
<?php require('../require/botbox.php');?>
<?php require('../require/noscript_modal.php');?>
</body>
<script type="text/javascript">
function checkForm(inputElement) {
var str = inputElement.value;
while (str.match(/[^A-Za-z\d_]/)) {
str = str.replace(/[^A-Za-z\d_]/, "");
}
inputElement.value = str;
}
var modal = document.getElementById('account_addrole_Modal');
var deleteButton = document.getElementById('deleteButton');
var cancelButton = document.getElementById('cancelButton'); // 追加
var modalMain = $('.modal-content');
document.getElementById("addrole").addEventListener('click', function(){
modal.style.display = 'block';
modalMain.addClass("slideUp");
modalMain.removeClass("slideDown");
deleteButton.addEventListener('click', () => {
modalMain.removeClass("slideUp");
modalMain.addClass("slideDown");
window.setTimeout(function(){
modal.style.display = 'none';
}, 150);
});
cancelButton.addEventListener('click', () => { // 追加
modalMain.removeClass("slideUp");
modalMain.addClass("slideDown");
window.setTimeout(function(){
modal.style.display = 'none';
}, 150);
});
});
var modal2 = document.getElementById('account_delrole_Modal');
var delrole_deleteButton = document.getElementById('delrole_deleteButton');
var delrole_cancelButton = document.getElementById('delrole_cancelButton'); // 追加
var modalMain = $('.modal-content');
document.getElementById("delrole").addEventListener('click', function(){
modal2.style.display = 'block';
modalMain.addClass("slideUp");
modalMain.removeClass("slideDown");
delrole_deleteButton.addEventListener('click', () => {
modalMain.removeClass("slideUp");
modalMain.addClass("slideDown");
window.setTimeout(function(){
modal2.style.display = 'none';
}, 150);
});
delrole_cancelButton.addEventListener('click', () => { // 追加
modalMain.removeClass("slideUp");
modalMain.addClass("slideDown");
window.setTimeout(function(){
modal2.style.display = 'none';
}, 150);
});
});
</script>
</html>