debug server

This commit is contained in:
fyears 2024-01-07 01:09:47 +08:00
parent 4d6e660f90
commit a6146f98cd
7 changed files with 159 additions and 0 deletions

25
debugServer.js Normal file
View File

@ -0,0 +1,25 @@
// Importing the http module
const http = require("http");
const requestHandler = (req, res) => {
let body = [];
req
.on("data", (chunk) => {
body.push(chunk);
})
.on("end", () => {
const parsed = JSON.parse(Buffer.concat(body).toString());
const prettyParsed = JSON.stringify(parsed, null, 2);
console.log(prettyParsed);
res.setHeader("Content-Type", "application/json");
res.end(prettyParsed);
});
};
const server = http.createServer(requestHandler);
const addr = "0.0.0.0";
const port = 3000;
server.listen(port, addr, undefined, () => {
console.log(`Server is Running on ${addr}:${port}`);
});

View File

@ -104,6 +104,10 @@
"modal_sizesconflict_desc": "You've set skipping files larger than {{thresholdMB}} MB ({{thresholdBytes}} bytes).\nBut the following files have sizes larger than the threshold on one side, and sizes smaller than the threshold on the other side.\nTo avoid unexpected overwriting or deleting, the plugin stops, and you have to manually deal with at least one side of the files.",
"modal_sizesconflict_copybutton": "Click to copy all the below sizes conflicts info",
"modal_sizesconflict_copynotice": "All the sizes conflicts info have been copied to the clipboard!",
"modal_logtohttpserver_title": "Log To HTTP(S) Server Is DANGEROUS!",
"modal_logtohttpserver_desc": "All your sensitive logging information will be posted to the HTTP(S) server without any authentications!!!!!\nPlease make sure you trust the HTTP(S) server, and it's better to setup a HTTPS one instead of HTTP one.\nIt's for debugging purposes only, especially on mobile.",
"modal_logtohttpserver_secondconfirm": "I know it's dangerous, and insist, and am willing to bear all possible losses.",
"modal_logtohttpserver_notice": "OK.",
"settings_basic": "Basic Settings",
"settings_password": "Encryption Password",
"settings_password_desc": "Password for E2E encryption. Empty for no password. You need to click \"Confirm\". Attention: the password and other info are saved locally.",
@ -274,6 +278,9 @@
"settings_logtodbclear_desc": "Delete all the console logs saved inside DB. This setting applies to all saved logs for all vaults in this device.",
"settings_logtodbclear_button": "Delete",
"settings_logtodbclear_notice": "All console logs saved in DB are deleted!",
"settings_logtohttpserver": "Log To HTTP Server Temporarily",
"settings_logtohttpserver_desc": "It's very dangerous and please use the function with greate cautions!!!!! It will temporarily allow sending console loggins to HTTP server.",
"settings_logtohttpserver_reset_notice": "Already removed the setting of logging to HTTP server.",
"settings_delsyncmap": "Delete Sync Mappings History In DB",
"settings_delsyncmap_desc": "Sync mappings history stores the actual LOCAL last modified time of the REMOTE objects. Clearing it may cause unnecessary data exchanges in next-time sync. Click the button to delete sync mappings history in DB.",
"settings_delsyncmap_button": "Delete Sync Mappings",

View File

@ -104,6 +104,10 @@
"modal_sizesconflict_desc": "您设置了跳过同步大于 {{thresholdMB}} MB{{thresholdBytes}} bytes的文件。\n但是以下文件的大小在一端大于阈值在另一端则小于阈值。\n为了避免意外的覆盖或删除插件停止了运作您需要手动处理至少一端的文件。",
"modal_sizesconflict_copybutton": "点击以复制以下所有文件大小冲突信息",
"modal_sizesconflict_copynotice": "所有的文件大小冲突信息,已被复制到剪贴板!",
"modal_logtohttpserver_title": "转发终端日志到 HTTP 服务器,此操作很危险!",
"modal_logtohttpserver_desc": "所有您的带敏感信息的终端日志,都会被转发到 HTTP(S) 服务器,没有任何鉴权!!!!!\n请确保您信任对应的服务器最好设置为 HTTPS 而不是 HTTP。\n仅仅用于 debug 用途,例如手机上的 debug。",
"modal_logtohttpserver_secondconfirm": "我知道很危险,坚持要设置,愿意承担所有可能损失。",
"modal_logtohttpserver_notice": "已设置。",
"settings_basic": "基本设置",
"settings_password": "密码",
"settings_password_desc": "端到端加密的密码。不填写则代表没密码。您需要点击“确认”来修改。注意:密码和其它信息都会在本地保存。",
@ -274,6 +278,9 @@
"settings_logtodbclear_desc": "删除数据库内的所有已保存的终端日志。本设置会影响本设备下所有资料库的所有已保存日志。",
"settings_logtodbclear_button": "删除",
"settings_logtodbclear_notice": "数据库内的所有终端日志已删除!",
"settings_logtohttpserver": "临时设定终端日志实时转发到 HTTP 服务器。",
"settings_logtohttpserver_desc": "非常危险,谨慎行动!!!!!临时设定终端日志实时转发到 HTTP 服务器。",
"settings_logtohttpserver_reset_notice": "移除了终端日志转发到 HTTP 服务器的设定。",
"settings_delsyncmap": "删除数据库里的同步映射历史",
"settings_delsyncmap_desc": "同步映射历史存储了本地真正的最后修改时间和远程文件时间的映射。删除之可能会导致下一次同步时发生不必要的数据交换。点击按钮删除数据库里的同步映射历史。",
"settings_delsyncmap_button": "删除同步映射历史",

View File

@ -104,6 +104,10 @@
"modal_sizesconflict_desc": "您設定了跳過同步大於 {{thresholdMB}} MB{{thresholdBytes}} bytes的檔案。\n但是以下檔案的大小在一端大於閾值在另一端則小於閾值。\n為了避免意外的覆蓋或刪除外掛停止了運作您需要手動處理至少一端的檔案。",
"modal_sizesconflict_copybutton": "點選以複製以下所有檔案大小衝突資訊",
"modal_sizesconflict_copynotice": "所有的檔案大小衝突資訊,已被複制到剪貼簿!",
"modal_logtohttpserver_title": "轉發終端日誌到 HTTP 伺服器,此操作很危險!",
"modal_logtohttpserver_desc": "所有您的帶敏感資訊的終端日誌,都會被轉發到 HTTP(S) 伺服器,沒有任何鑑權!!!!!\n請確保您信任對應的伺服器最好設定為 HTTPS 而不是 HTTP。\n僅僅用於 debug 用途,例如手機上的 debug。",
"modal_logtohttpserver_secondconfirm": "我知道很危險,堅持要設定,願意承擔所有可能損失。",
"modal_logtohttpserver_notice": "已設定。",
"settings_basic": "基本設定",
"settings_password": "密碼",
"settings_password_desc": "端到端加密的密碼。不填寫則代表沒密碼。您需要點選“確認”來修改。注意:密碼和其它資訊都會在本地儲存。",
@ -274,6 +278,9 @@
"settings_logtodbclear_desc": "刪除資料庫內的所有已儲存的終端日誌。本設定會影響本裝置下所有資料庫的所有已儲存日誌。",
"settings_logtodbclear_button": "刪除",
"settings_logtodbclear_notice": "資料庫內的所有終端日誌已刪除!",
"settings_logtohttpserver": "臨時設定終端日誌實時轉發到 HTTP 伺服器。",
"settings_logtohttpserver_desc": "非常危險,謹慎行動!!!!!臨時設定終端日誌實時轉發到 HTTP 伺服器。",
"settings_logtohttpserver_reset_notice": "移除了終端日誌轉發到 HTTP 伺服器的設定。",
"settings_delsyncmap": "刪除資料庫裡的同步對映歷史",
"settings_delsyncmap_desc": "同步對映歷史儲存了本地真正的最後修改時間和遠端檔案時間的對映。刪除之可能會導致下一次同步時發生不必要的資料交換。點選按鈕刪除資料庫裡的同步對映歷史。",
"settings_delsyncmap_button": "刪除同步對映歷史",

View File

@ -143,6 +143,7 @@ export default class RemotelySavePlugin extends Plugin {
syncOnSaveIntervalID?: number;
i18n: I18n;
vaultRandomID: string;
debugServerTemp?: string;
async syncRun(triggerSource: SyncTriggerSourceType = "manual") {
const t = (x: TransItemType, vars?: any) => {

View File

@ -6,6 +6,7 @@ import {
Setting,
Platform,
requireApiVersion,
requestUrl,
} from "obsidian";
import type { TextComponent } from "obsidian";
import { createElement, Eye, EyeOff } from "lucide";
@ -713,6 +714,65 @@ class ExportSettingsQrCodeModal extends Modal {
}
}
class SetLogToHttpServerModal extends Modal {
plugin: RemotelySavePlugin;
serverAddr: string;
callBack: any;
constructor(
app: App,
plugin: RemotelySavePlugin,
serverAddr: string,
callBack: any
) {
super(app);
this.plugin = plugin;
this.serverAddr = serverAddr;
this.callBack = callBack;
}
onOpen() {
let { contentEl } = this;
const t = (x: TransItemType, vars?: any) => {
return this.plugin.i18n.t(x, vars);
};
contentEl.createEl("h2", { text: t("modal_logtohttpserver_title") });
const div1 = contentEl.createDiv();
div1.addClass("logtohttpserver-warning");
t("modal_logtohttpserver_desc")
.split("\n")
.forEach((val) => {
div1.createEl("p", {
text: val,
});
});
new Setting(contentEl)
.addButton((button) => {
button.setButtonText(t("modal_logtohttpserver_secondconfirm"));
button.setClass("logtohttpserver-warning");
button.onClick(async () => {
this.callBack();
new Notice(t("modal_logtohttpserver_notice"));
this.close();
});
})
.addButton((button) => {
button.setButtonText(t("goback"));
button.onClick(() => {
this.close();
});
});
}
onClose() {
let { contentEl } = this;
contentEl.empty();
}
}
const getEyesElements = () => {
const eyeEl = createElement(Eye);
const eyeOffEl = createElement(EyeOff);
@ -2078,6 +2138,53 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
});
});
let logToHttpServer = this.plugin.debugServerTemp || "";
new Setting(debugDiv)
.setName(t("settings_logtohttpserver"))
.setDesc(t("settings_logtohttpserver_desc"))
.addText(async (text) => {
text.setValue(logToHttpServer).onChange(async (value) => {
logToHttpServer = value.trim();
});
})
.addButton(async (button) => {
button.setButtonText(t("confirm"));
button.onClick(async () => {
if (logToHttpServer === "" || !logToHttpServer.startsWith("http")) {
this.plugin.debugServerTemp = "";
logToHttpServer = "";
restoreLogWritterInplace();
new Notice(t("settings_logtohttpserver_reset_notice"));
} else {
new SetLogToHttpServerModal(
this.app,
this.plugin,
logToHttpServer,
() => {
this.plugin.debugServerTemp = logToHttpServer;
applyLogWriterInplace((...msg: any[]) => {
try {
requestUrl({
url: logToHttpServer,
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
send_time: Date.now(),
log_text: msg,
}),
});
} catch (e) {
// pass
}
});
}
).open();
}
});
});
new Setting(debugDiv)
.setName(t("settings_delsyncmap"))
.setDesc(t("settings_delsyncmap_desc"))

View File

@ -65,3 +65,8 @@
.ignorepaths-textarea {
font-family: monospace;
}
.logtohttpserver-warning {
color: red;
font-weight: bolder;
}