From dc458665ffa673bc3672985f6093f44223c9710a Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Thu, 8 Jun 2023 17:35:54 +0900 Subject: [PATCH 01/22] =?UTF-8?q?[change]=20-=20=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=83=B3=E6=83=85=E5=A0=B1=E3=81=AE=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 479c245..4b939bc 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ const e = require("express"); const port = process.env.PORT || 33333; -const SERVER_VERSION = "alpha_20230607"; +const SERVER_VERSION = "alpha_20230608"; const app = express(); const server = http.createServer(app); From 6d6e44964694d857e88b94dfa1fcc08cd2f547cd Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Thu, 8 Jun 2023 17:36:09 +0900 Subject: [PATCH 02/22] =?UTF-8?q?[add]=20-=20=E7=9B=A3=E6=9F=BB=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E7=94=A8=E3=81=AE=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=82=92=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 4b939bc..dfd390a 100644 --- a/index.js +++ b/index.js @@ -47,6 +47,7 @@ try{fs.mkdirSync("./files/");}catch(e){} try{fs.mkdirSync("./usersave/")}catch(e){} try{fs.mkdirSync("./record/");}catch(e){} try{fs.mkdirSync("./img/");}catch(e){} +try{fs.mkdirSync("./modlog/");}catch(e){} //もしバックエンドに直接アクセスされたら用 app.get('/', (req, res) => { From 1277a1e4ba34c3ee9c18d1fa9476156a731d7bc1 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Thu, 8 Jun 2023 17:55:38 +0900 Subject: [PATCH 03/22] =?UTF-8?q?[add]=20-=20=E7=9B=A3=E6=9F=BB=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=82=92=E6=9B=B8=E3=81=8D=E8=BE=BC=E3=82=80=E5=9C=9F?= =?UTF-8?q?=E5=8F=B0=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Message.js | 4 ++-- infoUpdate.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Message.js b/Message.js index 7ae6d45..388a273 100644 --- a/Message.js +++ b/Message.js @@ -125,11 +125,11 @@ let msgMix = function msgMix(m) { } + //返信をしているなら try { - //もし返信なら + //データに返信先の文章を追加 if ( m.replyData.isReplying ) { let msg = getMessage(m.channelid, m.replyData.messageid); - console.log("Message :: msgMix : 返信だね", msg); m.replyData.content = msg.content; m.replyData.userid = msg.userid; diff --git a/infoUpdate.js b/infoUpdate.js index d55a4d1..b48f66c 100644 --- a/infoUpdate.js +++ b/infoUpdate.js @@ -403,6 +403,49 @@ let channelRemove = function channelRemove(dat) { //参加していた人リストにそれぞれクライアントで更新させる return userChanged; +} + +//監査ログへの書き込み +let recordModeration = function recordModeration(actionBy,actionTo,actionInfo,reqSender) { + /* + actionBy => 変更を起こしたユーザーID + 例 : xxxxxx + actionTo => 変更を受けたチャンネルあるいはユーザーID + 例 : { + type: (user|channel|message|config), + targetid: xxxxxxx, + messageid: xxxxxxxx //メッセージの場合メッセージID(それ以外だと基本空) + } + actionInfo => 変更内容 + 例 : { + actionname: DeleteMessage, + actionTargetBefore: 123, //変更前の値 + actionTargetAfter: 321 //消されるようなものの場合空 + } + + } + */ + + //日付別にJSONファイルを書き込むため + let t = new Date(); + //JSONのファイル名 + let nameOfJson = "modlog_" + t.getFullYear() + "_" + (t.getMonth()+1).toString().padStart(2,0) + "_" + t.getDate().toString().padStart(2,0); + + //監査ログを書きこむJSONファイルのディレクトリ + let pathOfJson = "./modlog/" + nameOfJson + ".json"; + + //JSONファイルを開いてみて、いけたらそのまま読み込んで処理、なかったら作る + try { //JSONの存在確認 + //ファイルを読み込んでみる(使いはしない、存在を確認するだけ) + fs.statSync(pathOfJson); + } catch(err) { //存在無しなら(読み込みエラーなら) + //空のJSONを作成 + fs.writeFileSync(pathOfJson, "{}"); //DBをJSONで保存 + } + + + + } exports.config = config; @@ -414,4 +457,5 @@ exports.updateUserSaveConfig = updateUserSaveConfig; //ユーザーの個人デ exports.updateUserSaveMsgReadState = updateUserSaveMsgReadState; //ユーザーの個人データで既読状態を上書き保存 exports.channelAction = channelAction; //チャンネルの参加・退出 exports.channelCreate = channelCreate; //チャンネル作成 -exports.channelRemove = channelRemove; //チャンネル削除 \ No newline at end of file +exports.channelRemove = channelRemove; //チャンネル削除 +exports.recordModeration = recordModeration; //監査ログを書き込む関数 \ No newline at end of file From 1e8df83cee89de3a741a3c41b997bcb9386b8922 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:30:52 +0900 Subject: [PATCH 04/22] =?UTF-8?q?[add]=20-=20=E7=9B=A3=E6=9F=BB=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=82=92=E6=9B=B8=E3=81=8D=E8=BE=BC=E3=82=80=E3=83=97?= =?UTF-8?q?=E3=83=AD=E3=83=88=E3=82=BF=E3=82=A4=E3=83=97=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- infoUpdate.js | 52 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/infoUpdate.js b/infoUpdate.js index b48f66c..0ff04e5 100644 --- a/infoUpdate.js +++ b/infoUpdate.js @@ -418,19 +418,41 @@ let recordModeration = function recordModeration(actionBy,actionTo,actionInfo,re } actionInfo => 変更内容 例 : { - actionname: DeleteMessage, - actionTargetBefore: 123, //変更前の値 - actionTargetAfter: 321 //消されるようなものの場合空 + actionname: "MessageDelete", + actionTargetBefore: "123", //変更前の値 + actionTargetAfter: "" //消されるようなものの場合空 } } + + actionnameの一覧 => + userに対して + UserBan, + UserPardon, + UserDelete, + UserKickFromChannel + channelに対して + channelEditName, + channelEditDesc, + channelChangeScope, + channelCreate, + channelDelete + messageに対して + messageDelete + serverに対して + serverEditName, + serverEditConfig */ //日付別にJSONファイルを書き込むため let t = new Date(); - //JSONのファイル名 - let nameOfJson = "modlog_" + t.getFullYear() + "_" + (t.getMonth()+1).toString().padStart(2,0) + "_" + t.getDate().toString().padStart(2,0); + //日付 + let Date = t.getFullYear() + "_" + (t.getMonth()+1).toString().padStart(2,0) + "_" + t.getDate().toString().padStart(2,0); + //変更ID(actionId)用 + let fullDate = [Date, t.getMilliseconds().toString().padStart(6,0) ].join(""); + //JSONのファイル名 + let nameOfJson = "modlog_" + Date; //監査ログを書きこむJSONファイルのディレクトリ let pathOfJson = "./modlog/" + nameOfJson + ".json"; @@ -443,8 +465,26 @@ let recordModeration = function recordModeration(actionBy,actionTo,actionInfo,re fs.writeFileSync(pathOfJson, "{}"); //DBをJSONで保存 } + //監査ログを読み込み + let dataModlog = JSON.parse(fs.statSync(pathOfJson)); + + //変更の記録処理 + try { + //この変更そのものを判別するためのID + let actionId = [fullDate,Object.keys(dataModlog).length+1].join(""); + //JSONへデータ追加 + dataModlog[ actionId ] = { + actionId: actionId, + actionBy: actionBy, + actionTo: actionTo, + actionInfo: actionInfo + }; + } catch(e) { + return -1; + } - + //JSONファイルを保存 + fs.writeFileSync(pathOfJson, JSON.stringify(dataModlog, null, 4)); } From a94dfe98d84eb19d1088e74c635d28fb5b37e1c2 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:53:11 +0900 Subject: [PATCH 05/22] =?UTF-8?q?[remove]=20-=20=E4=B8=8D=E8=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Message.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Message.js b/Message.js index 388a273..2943e7c 100644 --- a/Message.js +++ b/Message.js @@ -1,4 +1,3 @@ -//msg_server.js //メッセージ関連 const fs = require('fs'); //履歴書き込んだり読み込むために From cc33c8006583451b8127e1b9d27a626cb769f027 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:58:12 +0900 Subject: [PATCH 06/22] =?UTF-8?q?[fix/change]=20-=20=E7=9B=A3=E6=9F=BB?= =?UTF-8?q?=E3=83=AD=E3=82=B0=E3=81=AE=E8=A8=98=E9=8C=B2=E3=81=8C=E5=8B=95?= =?UTF-8?q?=E3=81=8F=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -時間オブジェクトの変数かぶり修正 -情報変更IDのパターン変更 -いらない引数の削除 -そもそもJSONファイルに書き込みができてなかった --- infoUpdate.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/infoUpdate.js b/infoUpdate.js index 0ff04e5..9f31d95 100644 --- a/infoUpdate.js +++ b/infoUpdate.js @@ -406,7 +406,7 @@ let channelRemove = function channelRemove(dat) { } //監査ログへの書き込み -let recordModeration = function recordModeration(actionBy,actionTo,actionInfo,reqSender) { +let recordModeration = function recordModeration(actionBy,actionTo,actionInfo) { /* actionBy => 変更を起こしたユーザーID 例 : xxxxxx @@ -418,41 +418,48 @@ let recordModeration = function recordModeration(actionBy,actionTo,actionInfo,re } actionInfo => 変更内容 例 : { - actionname: "MessageDelete", - actionTargetBefore: "123", //変更前の値 - actionTargetAfter: "" //消されるようなものの場合空 + actionname: "変更対象のパラメータ(下の一覧を参照)", + actionTargetBefore: "asdf", //変更前 + actionTargetAfter: "fdsa" //変更後 } } actionnameの一覧 => userに対して - UserBan, - UserPardon, - UserDelete, - UserKickFromChannel + userBan, + userPardon, + userDelete, + userKickFromChannel + channelに対して channelEditName, channelEditDesc, channelChangeScope, channelCreate, channelDelete + messageに対して - messageDelete - serverに対して + messageDelete //メッセージ削除の場合プライバシーを考慮して変更前と変更後の値は空にする + + serverに対して //serverの場合targetidは空に serverEditName, serverEditConfig */ //日付別にJSONファイルを書き込むため - let t = new Date(); + let t = new Date(); // 正しいコード //日付 - let Date = t.getFullYear() + "_" + (t.getMonth()+1).toString().padStart(2,0) + "_" + t.getDate().toString().padStart(2,0); + let tY = t.getFullYear(); + let tM = (t.getMonth()+1).toString().padStart(2,0); + let tD = t.getDate().toString().padStart(2,0); + let tDateForName = tY + "_" + tM + "_" + tD; + //変更ID(actionId)用 - let fullDate = [Date, t.getMilliseconds().toString().padStart(6,0) ].join(""); + let fullDate = [tY+tM+tD, t.getMilliseconds().toString().padStart(6,0) ].join(""); //JSONのファイル名 - let nameOfJson = "modlog_" + Date; + let nameOfJson = "modlog_" + tDateForName; //監査ログを書きこむJSONファイルのディレクトリ let pathOfJson = "./modlog/" + nameOfJson + ".json"; @@ -466,7 +473,7 @@ let recordModeration = function recordModeration(actionBy,actionTo,actionInfo,re } //監査ログを読み込み - let dataModlog = JSON.parse(fs.statSync(pathOfJson)); + let dataModlog = JSON.parse(fs.readFileSync(pathOfJson, 'utf-8')); //変更の記録処理 try { From af7f47af8d41bbe9eeb03486f7df449b252f591b Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:58:43 +0900 Subject: [PATCH 07/22] =?UTF-8?q?[add]=20-=20=E3=83=A1=E3=83=83=E3=82=BB?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E5=89=8A=E9=99=A4=E6=99=82=E3=81=AB=E7=9B=A3?= =?UTF-8?q?=E6=9F=BB=E3=83=AD=E3=82=B0=E3=81=AB=E6=AE=8B=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Message.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Message.js b/Message.js index 2943e7c..65fe1d7 100644 --- a/Message.js +++ b/Message.js @@ -3,6 +3,7 @@ const fs = require('fs'); //履歴書き込んだり読み込むために const { getLinkPreview } = require("link-preview-js"); const indexjs = require("./index.js"); +const infoUpdate = require("./infoUpdate.js"); //URLプレビュー時のリダイレクト用URLのブロック対象にならないリスト const knownRedirectUrls = [ @@ -421,12 +422,31 @@ let msgDelete = function msgDelete(dat) { return -1; } + //送信者と削除する人が同じじゃなければ監査ログへ書き込む + if ( dat.reqSender.userid !== dataHistory[dat.messageid].userid ) { + //記録処理 + infoUpdate.recordModeration( + dat.reqSender.userid, + { + type: "message", + targetid: dataHistory[dat.messageid].userid, + messageid: dat.messageid + }, + { + actionname: "messageDelete", + actionTargetBefore: "", + actionAfter: "" + } + ); + + } + //削除! delete dataHistory[dat.messageid]; //書き込み fs.writeFileSync(pathOfJson, JSON.stringify(dataHistory, null, 4)); - + //返す結果用に履歴を取得 //let result = msgRecordCall(dat.channelid, 10); let result = { From af206a3b43644b6b8897f54e20035c46cbd1e2d4 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Thu, 8 Jun 2023 19:05:18 +0900 Subject: [PATCH 08/22] =?UTF-8?q?[change]=20-=20actionID=E3=81=AE=E7=94=9F?= =?UTF-8?q?=E6=88=90=E3=83=91=E3=82=BF=E3=83=BC=E3=83=B3=E3=82=92=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- infoUpdate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infoUpdate.js b/infoUpdate.js index 9f31d95..93efcd1 100644 --- a/infoUpdate.js +++ b/infoUpdate.js @@ -454,9 +454,9 @@ let recordModeration = function recordModeration(actionBy,actionTo,actionInfo) { let tM = (t.getMonth()+1).toString().padStart(2,0); let tD = t.getDate().toString().padStart(2,0); let tDateForName = tY + "_" + tM + "_" + tD; - + //変更ID(actionId)用 - let fullDate = [tY+tM+tD, t.getMilliseconds().toString().padStart(6,0) ].join(""); + let fullDate = tY+tM+tD; //JSONのファイル名 let nameOfJson = "modlog_" + tDateForName; From 730c26b81c2ec506ee7d003364e53291a42b3dfe Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Thu, 8 Jun 2023 19:12:38 +0900 Subject: [PATCH 09/22] =?UTF-8?q?[add]=20-=20=E7=9B=A3=E6=9F=BB=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=82=92=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B=E5=9C=9F?= =?UTF-8?q?=E5=8F=B0=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Message.js | 1 + dbControl.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Message.js b/Message.js index 65fe1d7..cc39e72 100644 --- a/Message.js +++ b/Message.js @@ -631,6 +631,7 @@ let msgRecordCallNew = async function msgRecordCall(cid, readLength, startLength let dirOfJson = "./record/" + cid; let readCount = 0; + //startLengthが空なら最初から読むように if ( startLength === undefined ) { startLength = 0; } try { diff --git a/dbControl.js b/dbControl.js index b2c6737..1d854a4 100644 --- a/dbControl.js +++ b/dbControl.js @@ -505,6 +505,37 @@ let getUserSave = function getUserSave(dat) { } +//監査ログの取得 +let getModlog = async function getModlog(dat) { + //JSONファイル一覧を格納する変数 + let ListOfJson = []; + + //JSONファイルの一覧を取得 + try { + ListOfJson = await new Promise((resolve) => { //取得が完了するまで処理を待つ + //読み込み + fs.readdir("./modlog/", (err, files) => { + ListOfJson = files; //ファイルの名前取得 + resolve(); //処理を終了、次の処理へ + + }); + + }).then(() => { + //追加された順だと古い順なので + return ListOfJson.reverse(); + + }); + } catch(e) { + return -1; + } + + for ( let index in ListOfJson) { + console.log("dbControl :: getModlog : ListOfJson->", ListOfJson); + + } + +} + //サーバーの設定情報を取得 let getServerSettings = function getServerSettings(dat) { let sendersInfo = getInfoUser({ From 8eabc4d14826f7ad19daf7e5ee745cf7bb923d9f Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Thu, 8 Jun 2023 19:19:11 +0900 Subject: [PATCH 10/22] =?UTF-8?q?[add]=20-=20=E7=9B=A3=E6=9F=BB=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=82=92=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8Bsocket.on?= =?UTF-8?q?=E3=81=AE=E3=83=97=E3=83=AD=E3=83=88=E3=82=BF=E3=82=A4=E3=83=97?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbControl.js | 3 ++- index.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/dbControl.js b/dbControl.js index 1d854a4..7f43f5b 100644 --- a/dbControl.js +++ b/dbControl.js @@ -509,7 +509,7 @@ let getUserSave = function getUserSave(dat) { let getModlog = async function getModlog(dat) { //JSONファイル一覧を格納する変数 let ListOfJson = []; - + //JSONファイルの一覧を取得 try { ListOfJson = await new Promise((resolve) => { //取得が完了するまで処理を待つ @@ -573,6 +573,7 @@ exports.getInfoChannelJoinedUserList = getInfoChannelJoinedUserList; //チャン exports.getInfoList = getInfoList; //チャンネルリストの取得 exports.searchUserDynamic = searchUserDynamic; //ユーザーを検索する関数 exports.getUserSave = getUserSave; //ユーザーの個人データ(設定や既読状態)を取得 +exports.getModlog = getModlog; //監査ログを取得 exports.getServerSettings = getServerSettings; //サーバーの詳細設定を取得 exports.getInitInfo = getInitInfo; //サーバーの初期情報 diff --git a/index.js b/index.js index dfd390a..3199382 100644 --- a/index.js +++ b/index.js @@ -1206,6 +1206,28 @@ io.on("connection", (socket) => { }); + //監査ログの取得 + socket.on("getModlog", (dat) => { + /* + dat + { + startLength: 0, //メッセージの取得開始位置 + reqSender: { + ... + } + } + */ + + //パケットの整合性確認 + if ( !checkDataIntegrality(dat, ["startLength"], "getModlog") ) return -1; + + //監査ログ取得 + let modLog = dbControl.getModlog(dat); + + //送信 + socket.emit("infoModlog", modLog); + }); + //サーバー設定の取得 socket.on("getServerSettings", (dat) => { /* From 50c65390ab7332c6d9a6b114963a696d61945c05 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 12:35:31 +0900 Subject: [PATCH 11/22] =?UTF-8?q?[fix]=20-=20=E9=96=A2=E6=95=B0=E3=81=AE?= =?UTF-8?q?=E5=8F=82=E7=85=A7=E3=82=B3=E3=83=BC=E3=83=89=E3=81=8C=E9=96=93?= =?UTF-8?q?=E9=81=95=E3=81=A3=E3=81=A6=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3199382..a8c0cfe 100644 --- a/index.js +++ b/index.js @@ -1222,10 +1222,11 @@ io.on("connection", (socket) => { if ( !checkDataIntegrality(dat, ["startLength"], "getModlog") ) return -1; //監査ログ取得 - let modLog = dbControl.getModlog(dat); + let modLog = db.getModlog(dat); //送信 socket.emit("infoModlog", modLog); + }); //サーバー設定の取得 From 2b1ebc2e27f74a524731bf7063078d9eb0a27422 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 13:30:59 +0900 Subject: [PATCH 12/22] =?UTF-8?q?[add]=20-=20=E7=9B=A3=E6=9F=BB=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=82=92=E5=8F=96=E5=BE=97=E3=81=97=E3=81=A6=E8=BF=94?= =?UTF-8?q?=E3=81=9B=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbControl.js | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/dbControl.js b/dbControl.js index 7f43f5b..0afe400 100644 --- a/dbControl.js +++ b/dbControl.js @@ -525,15 +525,54 @@ let getModlog = async function getModlog(dat) { return ListOfJson.reverse(); }); - } catch(e) { + } catch(e) { //一覧がとれなかったら失敗と返す return -1; } - for ( let index in ListOfJson) { + //取り出したデータの個数(デフォルトで10個まで取り出すようにする) + let dataCount = 00; + //送信する監査ログデータ + let dataModlogResult = { + endOfData: false, + data: [] + }; + + //それぞれのJSONファイルからデータを取得して配列に追加 + for ( let jsonIndex in ListOfJson) { + //監査ログを取り出し + let dataModlog = JSON.parse(fs.readFileSync("./modlog/"+ListOfJson[jsonIndex])); console.log("dbControl :: getModlog : ListOfJson->", ListOfJson); + //JSONの長さ + let jsonLength = Object.keys(dataModlog).length; + + //JSONのデータの長さ文ループして送信するデータ配列へ追加 + for ( let itemIndex=0; itemIndex=10 ) break; + + //追加 + dataModlogResult.data.push( + Object.entries(dataModlog)[itemIndex][1] + ); + + //データ個数をカウント + dataCount++; + + } + + if ( dataCount>=10 ) break; + } + //もしデータ個数が最終的に10個未満ならこれでデータ全部ということを設定 + if ( dataCount<10 ) dataModlogResult.endOfData=true; + + console.log("dbControl :: getModlog : データ結果->", dataModlogResult); + + return dataModlogResult; + + } //サーバーの設定情報を取得 From c82dfdcc420773600329d6090f472f82dca3a3fa Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 13:31:12 +0900 Subject: [PATCH 13/22] =?UTF-8?q?[change]=20-=20=E7=9B=A3=E6=9F=BB?= =?UTF-8?q?=E3=83=AD=E3=82=B0=E3=81=AE=E5=8F=96=E5=BE=97=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E3=82=92async=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a8c0cfe..873afbb 100644 --- a/index.js +++ b/index.js @@ -1207,7 +1207,7 @@ io.on("connection", (socket) => { }); //監査ログの取得 - socket.on("getModlog", (dat) => { + socket.on("getModlog", async (dat) => { /* dat { @@ -1221,8 +1221,10 @@ io.on("connection", (socket) => { //パケットの整合性確認 if ( !checkDataIntegrality(dat, ["startLength"], "getModlog") ) return -1; - //監査ログ取得 - let modLog = db.getModlog(dat); + //監査ログ取得(getModlog関数は時間がかかるためasyncにしているのでawait) + let modLog = await db.getModlog(dat); + + console.log("index :: getModlog : modLog->", modLog); //送信 socket.emit("infoModlog", modLog); From 92d8fa16cb30a122b4adfd916418905986cd9f27 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 14:14:36 +0900 Subject: [PATCH 14/22] =?UTF-8?q?[change]=20-=20=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E3=81=AE=E9=A0=85=E7=9B=AE=E5=90=8D=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Message.js | 4 ++-- infoUpdate.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Message.js b/Message.js index cc39e72..ff711ba 100644 --- a/Message.js +++ b/Message.js @@ -434,8 +434,8 @@ let msgDelete = function msgDelete(dat) { }, { actionname: "messageDelete", - actionTargetBefore: "", - actionAfter: "" + valueBefore: "", + valueAfter: "" } ); diff --git a/infoUpdate.js b/infoUpdate.js index 93efcd1..bc103be 100644 --- a/infoUpdate.js +++ b/infoUpdate.js @@ -419,8 +419,8 @@ let recordModeration = function recordModeration(actionBy,actionTo,actionInfo) { actionInfo => 変更内容 例 : { actionname: "変更対象のパラメータ(下の一覧を参照)", - actionTargetBefore: "asdf", //変更前 - actionTargetAfter: "fdsa" //変更後 + valueBefore: "asdf", //変更前 + valueAfter: "fdsa" //変更後 } } From a42736eac48261f490a7c6f1d6fd397a8f93fd02 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 14:45:16 +0900 Subject: [PATCH 15/22] =?UTF-8?q?[add]=20-=20=E3=83=81=E3=83=A3=E3=83=B3?= =?UTF-8?q?=E3=83=8D=E3=83=AB=E4=BD=9C=E6=88=90=E3=81=A8=E3=83=A6=E3=83=BC?= =?UTF-8?q?=E3=82=B6=E3=83=BC=E5=89=8A=E9=99=A4=E3=81=99=E3=82=8B=E3=81=A8?= =?UTF-8?q?=E3=81=8D=E3=81=AB=E7=9B=A3=E6=9F=BB=E3=83=AD=E3=82=B0=E3=81=AB?= =?UTF-8?q?=E6=9B=B8=E3=81=8F=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- infoUpdate.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/infoUpdate.js b/infoUpdate.js index bc103be..2cb286c 100644 --- a/infoUpdate.js +++ b/infoUpdate.js @@ -100,6 +100,21 @@ let mod = function mod(dat) { if ( sendersInfo.role !== "Admin" ) break; //Adminじゃないならここでやめる if ( dat.reqSender.userid === dat.targetid ) break; //送信者自身を消そうとしているならやめる + //監査ログへの記録処理 + recordModeration( + dat.reqSender.userid, + { + type: "user", + targetid: dat.targetid, + messageid: "" + }, + { + actionname: "userDelete", + valueBefore: dat.targetid, + valueAfter: "" + } + ); + delete db.dataUser.user[dat.targetid]; //削除 break; @@ -354,6 +369,21 @@ let channelCreate = async function channelCreate(dat) { //チャンネル作成者をそのまま参加させる db.dataUser.user[dat.reqSender.userid].channel.push(newChannelId); + //監査ログへの記録処理 + recordModeration( + dat.reqSender.userid, + { + type: "channel", + targetid: newChannelId, + messageid: "" + }, + { + actionname: "channelCreate", + valueBefore: "", + valueAfter: dat.channelname + } + ); + //ユーザー情報をファイルへ書き込み fs.writeFileSync("./user.json", JSON.stringify(db.dataUser, null, 4)); From 60f9356bbeb3a45ebfb332cfffc8245ea027c07a Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 15:39:44 +0900 Subject: [PATCH 16/22] =?UTF-8?q?[change]=20-=20=E7=9B=A3=E6=9F=BB?= =?UTF-8?q?=E3=83=AD=E3=82=B0=E3=81=AE=E4=BF=9D=E5=AD=98=E9=A0=85=E7=9B=AE?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Message.js | 3 ++- infoUpdate.js | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Message.js b/Message.js index ff711ba..31e9e54 100644 --- a/Message.js +++ b/Message.js @@ -429,7 +429,8 @@ let msgDelete = function msgDelete(dat) { dat.reqSender.userid, { type: "message", - targetid: dataHistory[dat.messageid].userid, + userid: dataHistory[dat.messageid].userid, + channelid: dataHistory[dat.messageid].channelid, messageid: dat.messageid }, { diff --git a/infoUpdate.js b/infoUpdate.js index 2cb286c..0a4571d 100644 --- a/infoUpdate.js +++ b/infoUpdate.js @@ -105,7 +105,8 @@ let mod = function mod(dat) { dat.reqSender.userid, { type: "user", - targetid: dat.targetid, + userid: dat.targetid, + channelid: "", messageid: "" }, { @@ -308,6 +309,22 @@ let channelAction = function channelAction(dat) { console.log("infoUpdate :: channelAction : 誰かが蹴られるぜ"); + //監査ログへの記録処理 + recordModeration( + dat.reqSender.userid, + { + type: "user", + userid: dat.userid, + channelid: dat.channelid, + messageid: "" + }, + { + actionname: "userKickFromChannel", + valueBefore: "", + valueAfter: "" + } + ); + } //配列からチャンネルIDを削除 @@ -443,7 +460,8 @@ let recordModeration = function recordModeration(actionBy,actionTo,actionInfo) { actionTo => 変更を受けたチャンネルあるいはユーザーID 例 : { type: (user|channel|message|config), - targetid: xxxxxxx, + userid: xxxxxxx, //変更に関係があるユーザーID + channelid: 0000000, //変更に関係があるチャンネルID messageid: xxxxxxxx //メッセージの場合メッセージID(それ以外だと基本空) } actionInfo => 変更内容 From 244f4d2d541585498a71d3220ba943589962183a Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 15:56:15 +0900 Subject: [PATCH 17/22] =?UTF-8?q?[add]=20-=20=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=83=BC=E3=81=AE=E6=A8=A9=E9=99=90=E5=A4=89=E6=9B=B4=E6=99=82?= =?UTF-8?q?=E3=81=AEBAN=E3=81=97=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AB?= =?UTF-8?q?=E7=9B=A3=E6=9F=BB=E3=83=AD=E3=82=B0=E3=81=AB=E8=A8=98=E9=8C=B2?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- infoUpdate.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/infoUpdate.js b/infoUpdate.js index 0a4571d..1b5a3f3 100644 --- a/infoUpdate.js +++ b/infoUpdate.js @@ -84,14 +84,49 @@ let mod = function mod(dat) { switch( dat.action.change ) { //ユーザーのロール変更 case "role": + //監査ログ用 + let roleBefore = db.dataUser.user[dat.targetid].role; //ロール更新 db.dataUser.user[dat.targetid].role = dat.action.value; + + //監査ログへの記録処理 + recordModeration( + dat.reqSender.userid, + { + type: "user", + userid: dat.targetid, + channelid: "", + messageid: "" + }, + { + actionname: "userChangeRole", + valueBefore: roleBefore, + valueAfter: dat.action.value + } + ); + break; //ユーザーのBAN case "ban": console.log("infoUpdate :: mod : BANしました -> " + dat.targetid); db.dataUser.user[dat.targetid].state.banned = dat.action.value; + //監査ログへの記録処理 + recordModeration( + dat.reqSender.userid, + { + type: "user", + userid: dat.targetid, + channelid: "", + messageid: "" + }, + { + actionname: "userBan", + valueBefore: dat.targetid, + valueAfter: "BANNED" + } + ); + break; //ユーザーの削除 @@ -478,6 +513,7 @@ let recordModeration = function recordModeration(actionBy,actionTo,actionInfo) { userBan, userPardon, userDelete, + userChangeRole, userKickFromChannel channelに対して From d3ed113efc848d917887dfeca3146676bfd5cf80 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 16:02:46 +0900 Subject: [PATCH 18/22] =?UTF-8?q?[remove]=20-=20=E4=B8=8D=E8=A6=81?= =?UTF-8?q?=E3=81=AA=E3=83=87=E3=83=90=E3=83=83=E3=82=B0=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbControl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbControl.js b/dbControl.js index 0afe400..61500f7 100644 --- a/dbControl.js +++ b/dbControl.js @@ -568,7 +568,7 @@ let getModlog = async function getModlog(dat) { //もしデータ個数が最終的に10個未満ならこれでデータ全部ということを設定 if ( dataCount<10 ) dataModlogResult.endOfData=true; - console.log("dbControl :: getModlog : データ結果->", dataModlogResult); + //console.log("dbControl :: getModlog : データ結果->", dataModlogResult); return dataModlogResult; From c1ac196bb2468e695273f370f2ae9c8c831c0f61 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 16:11:06 +0900 Subject: [PATCH 19/22] =?UTF-8?q?[add]=20-=20=E7=9B=A3=E6=9F=BB=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=82=92=E9=80=81=E4=BF=A1=E3=81=99=E3=82=8B=E3=81=A8?= =?UTF-8?q?=E3=81=8D=E3=81=AB=E9=80=86=E9=A0=86=E7=95=AA=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbControl.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dbControl.js b/dbControl.js index 61500f7..213fab9 100644 --- a/dbControl.js +++ b/dbControl.js @@ -570,6 +570,8 @@ let getModlog = async function getModlog(dat) { //console.log("dbControl :: getModlog : データ結果->", dataModlogResult); + //上から新しい順に出すために逆順番にして返す + dataModlogResult.data = dataModlogResult.data.reverse(); return dataModlogResult; From 08f4aa019034885750628e85070c7ed7c0d1acd0 Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 17:30:42 +0900 Subject: [PATCH 20/22] =?UTF-8?q?[add]=20-=20=E3=83=90=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E6=83=85=E5=A0=B1=E3=81=AE=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 873afbb..7ad551a 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ const e = require("express"); const port = process.env.PORT || 33333; -const SERVER_VERSION = "alpha_20230608"; +const SERVER_VERSION = "alpha_20230609"; const app = express(); const server = http.createServer(app); From 312523d934bebf654528ecd55bec5a5fbe35cb0f Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 18:25:13 +0900 Subject: [PATCH 21/22] =?UTF-8?q?[add]=20-=20=E8=BF=BD=E5=8A=A0=E3=81=AE?= =?UTF-8?q?=E7=9B=A3=E6=9F=BB=E3=83=AD=E3=82=B0=E3=82=92=E8=AA=AD=E3=81=BF?= =?UTF-8?q?=E8=BE=BC=E3=82=81=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbControl.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/dbControl.js b/dbControl.js index 213fab9..6817447 100644 --- a/dbControl.js +++ b/dbControl.js @@ -80,8 +80,6 @@ try { //読み込んでみる dataServer = JSON.parse(fs.readFileSync('./server.json', 'utf-8')); //サーバー情報のJSON読み込み } -//let dataRole = JSON.parse(fs.readFileSync('./role.json', 'utf-8')); //ロールのJSON読み込み - //起動したときに全員をオフライン状態にする for ( let index in Object.keys(dataUser.user) ) { let userid = Object.keys(dataUser.user)[index]; //ユーザーIDを取得 @@ -528,9 +526,12 @@ let getModlog = async function getModlog(dat) { } catch(e) { //一覧がとれなかったら失敗と返す return -1; } + + //データを確認した回数 + let dataCheckedCount = 0; + //取り出したデータの個数(デフォルトで1回に10個まで取り出すようにする) + let dataSavedCount = 0; - //取り出したデータの個数(デフォルトで10個まで取り出すようにする) - let dataCount = 00; //送信する監査ログデータ let dataModlogResult = { endOfData: false, @@ -541,7 +542,6 @@ let getModlog = async function getModlog(dat) { for ( let jsonIndex in ListOfJson) { //監査ログを取り出し let dataModlog = JSON.parse(fs.readFileSync("./modlog/"+ListOfJson[jsonIndex])); - console.log("dbControl :: getModlog : ListOfJson->", ListOfJson); //JSONの長さ let jsonLength = Object.keys(dataModlog).length; @@ -549,26 +549,33 @@ let getModlog = async function getModlog(dat) { //JSONのデータの長さ文ループして送信するデータ配列へ追加 for ( let itemIndex=0; itemIndex=10 ) break; + if ( dataSavedCount>=10 ) break; - //追加 - dataModlogResult.data.push( - Object.entries(dataModlog)[itemIndex][1] - ); + //もしデータ取得位置がデータ確認回数と同じならデータの追加をする + if ( dataCheckedCount >= dat.startLength ) { - //データ個数をカウント - dataCount++; + //追加 + dataModlogResult.data.push( + Object.entries(dataModlog)[itemIndex][1] + ); + + //データ個数をカウント + dataSavedCount++; + + } + + //データ確認回数をカウント + dataCheckedCount++; } - if ( dataCount>=10 ) break; + //次のJSON読み込む前に念のため確認 + if ( dataSavedCount>=10 ) break; } //もしデータ個数が最終的に10個未満ならこれでデータ全部ということを設定 - if ( dataCount<10 ) dataModlogResult.endOfData=true; - - //console.log("dbControl :: getModlog : データ結果->", dataModlogResult); + if ( dataSavedCount<10 ) dataModlogResult.endOfData=true; //上から新しい順に出すために逆順番にして返す dataModlogResult.data = dataModlogResult.data.reverse(); From ec878a30f219ed308820f9a794b13da2e48e64fa Mon Sep 17 00:00:00 2001 From: NfoAlex <40430040+NfoAlex@users.noreply.github.com> Date: Fri, 9 Jun 2023 18:56:50 +0900 Subject: [PATCH 22/22] =?UTF-8?q?[add]=20-=20=E7=9B=A3=E6=9F=BB=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=81=A7=E3=81=AE"=E5=A4=89=E6=9B=B4"ID=E3=81=AB?= =?UTF-8?q?=E6=99=82=E9=96=93=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- infoUpdate.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/infoUpdate.js b/infoUpdate.js index 1b5a3f3..afcca78 100644 --- a/infoUpdate.js +++ b/infoUpdate.js @@ -537,10 +537,11 @@ let recordModeration = function recordModeration(actionBy,actionTo,actionInfo) { let tY = t.getFullYear(); let tM = (t.getMonth()+1).toString().padStart(2,0); let tD = t.getDate().toString().padStart(2,0); + let tTime = t.getHours().toString().padStart(2,0) + t.getMinutes().toString().padStart(2,0) + t.getSeconds().toString().padStart(2,0); let tDateForName = tY + "_" + tM + "_" + tD; //変更ID(actionId)用 - let fullDate = tY+tM+tD; + let fullDate = tY+tM+tD+tTime; //JSONのファイル名 let nameOfJson = "modlog_" + tDateForName;