chore: update package version to 0.2.71 and enhance MITM tools

This commit is contained in:
decolua 2026-02-09 00:15:31 +07:00
parent bd0cebcfff
commit 635d327dbc
5 changed files with 41 additions and 17 deletions

View file

@ -1,5 +1,6 @@
// Claude helper functions for translator
import { DEFAULT_THINKING_CLAUDE_SIGNATURE } from "../../config/defaultThinkingSignature.js";
import { adjustMaxTokens } from "./maxTokensHelper.js";
// Check if message has valid non-empty content
export function hasValidContent(msg) {

View file

@ -9,13 +9,17 @@ export function adjustMaxTokens(body) {
let maxTokens = body.max_tokens || DEFAULT_MAX_TOKENS;
// Auto-increase for tool calling to prevent truncated arguments
// Tool calls with large content (like writing files) need more tokens
if (body.tools && Array.isArray(body.tools) && body.tools.length > 0) {
if (maxTokens < DEFAULT_MIN_TOKENS) {
maxTokens = DEFAULT_MIN_TOKENS;
}
}
// Ensure max_tokens > thinking.budget_tokens (Claude API requirement)
if (body.thinking?.budget_tokens && maxTokens <= body.thinking.budget_tokens) {
maxTokens = DEFAULT_MAX_TOKENS;
}
return maxTokens;
}

View file

@ -1,6 +1,6 @@
{
"name": "9router-app",
"version": "0.2.70",
"version": "0.2.72",
"description": "9Router web dashboard",
"private": true,
"scripts": {

View file

@ -66,7 +66,7 @@ async function installCert(sudoPassword, certPath) {
}
async function installCertMac(sudoPassword, certPath) {
const command = `sudo -S security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "${certPath}"`;
const command = `security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "${certPath}"`;
try {
await execWithPassword(command, sudoPassword);
console.log(`✅ Installed certificate to system keychain: ${certPath}`);
@ -110,7 +110,7 @@ async function uninstallCert(sudoPassword, certPath) {
async function uninstallCertMac(sudoPassword, certPath) {
const fingerprint = getCertFingerprint(certPath).replace(/:/g, "");
const command = `sudo -S security delete-certificate -Z "${fingerprint}" /Library/Keychains/System.keychain`;
const command = `security delete-certificate -Z "${fingerprint}" /Library/Keychains/System.keychain`;
try {
await execWithPassword(command, sudoPassword);
console.log("✅ Uninstalled certificate from system keychain");

View file

@ -1,4 +1,4 @@
const { exec } = require("child_process");
const { exec, spawn } = require("child_process");
const fs = require("fs");
const path = require("path");
@ -13,13 +13,20 @@ const HOSTS_FILE = IS_WIN
*/
function execWithPassword(command, password) {
return new Promise((resolve, reject) => {
const child = exec(command, (error, stdout, stderr) => {
if (error) {
reject(new Error(`Command failed: ${error.message}\n${stderr}`));
} else {
resolve(stdout);
}
const child = spawn("sudo", ["-S", "sh", "-c", command], {
stdio: ["pipe", "pipe", "pipe"]
});
let stdout = "";
let stderr = "";
child.stdout.on("data", (d) => { stdout += d; });
child.stderr.on("data", (d) => { stderr += d; });
child.on("close", (code) => {
if (code === 0) resolve(stdout);
else reject(new Error(stderr || `Exit code ${code}`));
});
child.stdin.write(`${password}\n`);
child.stdin.end();
});
@ -69,12 +76,18 @@ async function addDNSEntry(sudoPassword) {
// Windows: use elevated echo >> hosts
await execElevatedWindows(`echo ${entry} >> "${HOSTS_FILE}"`);
} else {
const command = `echo "${entry}" | sudo -S tee -a ${HOSTS_FILE} > /dev/null`;
await execWithPassword(command, sudoPassword);
await execWithPassword(`echo "${entry}" >> ${HOSTS_FILE}`, sudoPassword);
}
// Flush DNS cache
if (IS_WIN) {
await execElevatedWindows("ipconfig /flushdns");
} else {
await execWithPassword("dscacheutil -flushcache && killall -HUP mDNSResponder", sudoPassword);
}
console.log(`✅ Added DNS entry: ${entry}`);
} catch (error) {
throw new Error(`Failed to add DNS entry: ${error.message}`);
const msg = error.message?.includes("incorrect password") ? "Wrong sudo password" : "Failed to add DNS entry";
throw new Error(msg);
}
}
@ -99,12 +112,18 @@ async function removeDNSEntry(sudoPassword) {
});
});
} else {
const command = `sudo -S sed -i '' '/${TARGET_HOST}/d' ${HOSTS_FILE}`;
await execWithPassword(command, sudoPassword);
await execWithPassword(`sed -i '' '/${TARGET_HOST}/d' ${HOSTS_FILE}`, sudoPassword);
}
// Flush DNS cache
if (IS_WIN) {
await execElevatedWindows("ipconfig /flushdns");
} else {
await execWithPassword("dscacheutil -flushcache && killall -HUP mDNSResponder", sudoPassword);
}
console.log(`✅ Removed DNS entry for ${TARGET_HOST}`);
} catch (error) {
throw new Error(`Failed to remove DNS entry: ${error.message}`);
const msg = error.message?.includes("incorrect password") ? "Wrong sudo password" : "Failed to remove DNS entry";
throw new Error(msg);
}
}