mirror of
https://github.com/HugoAura/Seewo-HugoAura.git
synced 2026-06-20 23:14:28 +08:00
[🛠️ Fix] Enc config detection issue & Add hosts file clean for Aikari uninst
This commit is contained in:
@@ -4,6 +4,7 @@ const __SCOPE = "main";
|
|||||||
|
|
||||||
const { exec, execSync } = require("child_process");
|
const { exec, execSync } = require("child_process");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const os = require("os");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const nodeHttps = require("https");
|
const nodeHttps = require("https");
|
||||||
const { fsComposables } = require("./fsIpcHandler");
|
const { fsComposables } = require("./fsIpcHandler");
|
||||||
@@ -268,6 +269,46 @@ const functions = {
|
|||||||
fs.unlinkSync(binPath);
|
fs.unlinkSync(binPath);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
clearHostFileItem: async () => {
|
||||||
|
const AIKARI_HOST_STR =
|
||||||
|
"127.11.45.14 iot-broker-mis.seewo.com # This line is generated by HugoAura-Aikari, please do not edit or delete it";
|
||||||
|
const hostPath = path.join(
|
||||||
|
process.env.SystemRoot || "C:\\WINDOWS",
|
||||||
|
"System32",
|
||||||
|
"drivers",
|
||||||
|
"etc",
|
||||||
|
"hosts"
|
||||||
|
);
|
||||||
|
if (fs.existsSync(hostPath)) {
|
||||||
|
try {
|
||||||
|
const content = fs.readFileSync(hostPath, "utf-8");
|
||||||
|
const lines = content.split(/\r?\n/);
|
||||||
|
const newContent = lines.filter((line) => {
|
||||||
|
const shouldKeep = !line.includes(AIKARI_HOST_STR);
|
||||||
|
if (!shouldKeep) {
|
||||||
|
console.log(
|
||||||
|
`[HugoAura / IPC / Aikari] Cleaned hosts file item: ${line}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return shouldKeep;
|
||||||
|
});
|
||||||
|
if (lines.length === newContent.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const newData = newContent.join(os.EOL);
|
||||||
|
fs.writeFileSync(hostPath, newData, "utf-8");
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(
|
||||||
|
"[HugoAura / IPC / Aikari] Error cleaning hosts file: ",
|
||||||
|
err
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -630,6 +671,7 @@ const applyAikariIpcHandler = (ipcMain) => {
|
|||||||
case "inst":
|
case "inst":
|
||||||
// TODO: Impl Aikari INST
|
// TODO: Impl Aikari INST
|
||||||
case "uninst":
|
case "uninst":
|
||||||
|
await functions.clearHostFileItem();
|
||||||
return await functions.execCommand(
|
return await functions.execCommand(
|
||||||
logHeader,
|
logHeader,
|
||||||
AIKARI_UNINSTALLER_PATH,
|
AIKARI_UNINSTALLER_PATH,
|
||||||
|
|||||||
@@ -114,9 +114,16 @@ class ConfigManager {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (fs.existsSync(oldConfigPath)) {
|
if (fs.existsSync(oldConfigPath)) {
|
||||||
|
console.log(
|
||||||
|
`[HugoAura / Config] Old plain config file detected at ${oldConfigPath}, migrating...`
|
||||||
|
);
|
||||||
fs.copyFileSync(oldConfigPath, this.configPath);
|
fs.copyFileSync(oldConfigPath, this.configPath);
|
||||||
fs.unlinkSync(oldConfigPath);
|
fs.unlinkSync(oldConfigPath);
|
||||||
|
this.useEncConfig = false;
|
||||||
} else if (fs.existsSync(oldEncConfigPath)) {
|
} else if (fs.existsSync(oldEncConfigPath)) {
|
||||||
|
console.log(
|
||||||
|
`[HugoAura / Config] Old enc config file detected at ${oldEncConfigPath}, migrating...`
|
||||||
|
);
|
||||||
fs.copyFileSync(oldEncConfigPath, this.encConfigPath);
|
fs.copyFileSync(oldEncConfigPath, this.encConfigPath);
|
||||||
fs.unlinkSync(oldEncConfigPath);
|
fs.unlinkSync(oldEncConfigPath);
|
||||||
this.useEncConfig = true;
|
this.useEncConfig = true;
|
||||||
@@ -176,9 +183,14 @@ class ConfigManager {
|
|||||||
return this.getDefaultConfig(); // should be changed, too
|
return this.getDefaultConfig(); // should be changed, too
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error("[HugoAura / Config / ERROR] Failed to decrypt config");
|
console.error(
|
||||||
|
"[HugoAura / Config / ERROR] Failed to decrypt config, falling back to use plain config"
|
||||||
|
);
|
||||||
|
this.useEncConfig = false;
|
||||||
this.isConfigReadFailed = true;
|
this.isConfigReadFailed = true;
|
||||||
return this.getDefaultConfig(); // This behaviour should be changed later
|
config = JSON.parse(fs.readFileSync(this.configPath, "utf8"));
|
||||||
|
if (this.isConfigReadFailed) this.isConfigReadFailed = false;
|
||||||
|
return config; // This behaviour should be changed later
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
config = JSON.parse(fs.readFileSync(this.configPath, "utf8"));
|
config = JSON.parse(fs.readFileSync(this.configPath, "utf8"));
|
||||||
@@ -208,7 +220,15 @@ class ConfigManager {
|
|||||||
console.error(
|
console.error(
|
||||||
"[HugoAura / Config / Write / ERROR] Failed to write config: Retrieve enc password failed"
|
"[HugoAura / Config / Write / ERROR] Failed to write config: Retrieve enc password failed"
|
||||||
);
|
);
|
||||||
return false;
|
console.warn(
|
||||||
|
"[HugoAura / Config / Write / WARN] Falling back to use plain config."
|
||||||
|
);
|
||||||
|
fs.writeFileSync(
|
||||||
|
this.configPath,
|
||||||
|
JSON.stringify(config, null, 2),
|
||||||
|
"utf8"
|
||||||
|
);
|
||||||
|
this.useEncConfig = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
|
|||||||
@@ -207,10 +207,12 @@ if (!global.__HUGO_AURA_UI_REACTIVES__.subConfig)
|
|||||||
global.__HUGO_AURA_UI_FUNCTIONS__.subConfig.aikariStatus.updateToast(
|
global.__HUGO_AURA_UI_FUNCTIONS__.subConfig.aikariStatus.updateToast(
|
||||||
"success",
|
"success",
|
||||||
"Aikari 已完成卸载",
|
"Aikari 已完成卸载",
|
||||||
null,
|
`<p>
|
||||||
|
您可能需要重启 SeewoCore 以重新建立 IoT 连接
|
||||||
|
</p>`,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
2000
|
5000
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
global.__HUGO_AURA_UI_FUNCTIONS__.subConfig.aikariStatus.updateToast(
|
global.__HUGO_AURA_UI_FUNCTIONS__.subConfig.aikariStatus.updateToast(
|
||||||
|
|||||||
5
src/aura/utils/string.js
Normal file
5
src/aura/utils/string.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const checkIfNonAscii = (str) => {
|
||||||
|
return Buffer.byteLength(str) !== str.length;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = { checkIfNonAscii };
|
||||||
@@ -48,6 +48,7 @@ const ConfigManager = require("../aura/init/shared/configManager");
|
|||||||
const RegistryManager = require("../aura/init/shared/registryManager");
|
const RegistryManager = require("../aura/init/shared/registryManager");
|
||||||
const { buildIpcMain } = require("../aura/init/main/ipcHandler");
|
const { buildIpcMain } = require("../aura/init/main/ipcHandler");
|
||||||
const plsUtils = require("../aura/utils/pls");
|
const plsUtils = require("../aura/utils/pls");
|
||||||
|
const stringUtils = require("../aura/utils/string");
|
||||||
|
|
||||||
const { initLogger } = require("../aura/init/main/logger");
|
const { initLogger } = require("../aura/init/main/logger");
|
||||||
|
|
||||||
@@ -60,18 +61,26 @@ const getUserDocumentsDirPath = () => {
|
|||||||
true,
|
true,
|
||||||
/REG_EXPAND_SZ\s+(.+)/
|
/REG_EXPAND_SZ\s+(.+)/
|
||||||
);
|
);
|
||||||
if (pathInfo.success && pathInfo.data) {
|
try {
|
||||||
const resolvedPath = pathInfo.data.replace(
|
if (pathInfo.success && pathInfo.data) {
|
||||||
/%([^%]+)%/g,
|
const resolvedPath = pathInfo.data.replace(
|
||||||
(match, varName) => {
|
/%([^%]+)%/g,
|
||||||
return process.env[varName] || match;
|
(match, varName) => {
|
||||||
}
|
return process.env[varName] || match;
|
||||||
);
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return resolvedPath;
|
if (stringUtils.checkIfNonAscii(resolvedPath)) {
|
||||||
} else {
|
console.warn("[HugoAura / Init] Detected non-ASCII char in resolved user personal folder: ", resolvedPath);
|
||||||
|
throw new Error("Non-ASCII char detected");
|
||||||
|
}
|
||||||
|
return resolvedPath;
|
||||||
|
} else {
|
||||||
|
throw new Error("Registry data failed to get");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
console.error(
|
console.error(
|
||||||
"[HugoAura / Init / Logger] Failed to get the path of documents dir, using default val."
|
"[HugoAura / Init / Logger] Failed to get the path of documents dir, using default val. | Error: ", err
|
||||||
);
|
);
|
||||||
return path.join(os.homedir(), "Documents");
|
return path.join(os.homedir(), "Documents");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user