Update proxy bridge setup
This commit is contained in:
+60
-36
@@ -17,7 +17,7 @@ function ask(question, defaultValue = "") {
|
||||
return new Promise((resolve) => {
|
||||
const prompt = defaultValue ? `${question} [${defaultValue}]: ` : `${question}: `;
|
||||
rl.question(prompt, (answer) => {
|
||||
resolve(answer || defaultValue);
|
||||
resolve(answer.trim() || defaultValue);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -26,50 +26,74 @@ async function run() {
|
||||
try {
|
||||
// 1. Upstream Proxy Configuration
|
||||
console.log("\n--- Upstream Proxy (Corporate) ---");
|
||||
const host = await ask("Corporate Proxy Hostname (e.g. proxy.company.com)");
|
||||
const port = await ask("Corporate Proxy Port", "8080");
|
||||
const enableUpstream = (await ask("Enable Corporate Upstream Proxy? (y/n)", "y")).toLowerCase() === 'y';
|
||||
|
||||
let host = "";
|
||||
let port = "8080";
|
||||
let user = "";
|
||||
let pass = "";
|
||||
|
||||
if (!host) {
|
||||
console.error("❌ Hostname is required.");
|
||||
process.exit(1);
|
||||
if (enableUpstream) {
|
||||
host = await ask("Corporate Proxy Hostname (e.g. proxy.company.com)");
|
||||
port = await ask("Corporate Proxy Port", "8080");
|
||||
|
||||
if (!host) {
|
||||
console.error("❌ Hostname is required if upstream is enabled.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// 2. Credentials
|
||||
console.log("\n--- Credentials ---");
|
||||
user = await ask("Corporate Username");
|
||||
|
||||
// Setup password mask (temporary swap)
|
||||
const oldWrite = rl._writeToOutput;
|
||||
rl._writeToOutput = function _writeToOutput(stringToWrite) {
|
||||
// If it's a newline or specific strings, let it through
|
||||
if (stringToWrite === "\n" || stringToWrite === "\r" || stringToWrite === "\r\n") {
|
||||
rl.output.write(stringToWrite);
|
||||
} else {
|
||||
rl.output.write("*");
|
||||
}
|
||||
};
|
||||
pass = await ask("Corporate Password");
|
||||
rl._writeToOutput = oldWrite;
|
||||
}
|
||||
|
||||
// 2. Credentials
|
||||
console.log("\n--- Credentials ---");
|
||||
const user = await ask("Corporate Username");
|
||||
|
||||
// Setup password mask
|
||||
const oldWrite = rl._writeToOutput;
|
||||
rl._writeToOutput = function _writeToOutput(stringToWrite) {
|
||||
if (rl.line.length > 0) rl.output.write("*");
|
||||
else rl.output.write(stringToWrite);
|
||||
};
|
||||
const pass = await ask("Corporate Password");
|
||||
rl._writeToOutput = oldWrite;
|
||||
|
||||
// Save Proxy Config
|
||||
// Save Config
|
||||
if (!fs.existsSync(CONFIG_DIR)) {
|
||||
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(CONFIG_FILE, JSON.stringify({ host, port }, null, 2));
|
||||
|
||||
fs.writeFileSync(CONFIG_FILE, JSON.stringify({
|
||||
enabled: enableUpstream,
|
||||
host: host,
|
||||
port: port
|
||||
}, null, 2));
|
||||
|
||||
// Save Username
|
||||
fs.writeFileSync(USER_FILE, JSON.stringify({ username: user }));
|
||||
if (enableUpstream) {
|
||||
// Save Username
|
||||
fs.writeFileSync(USER_FILE, JSON.stringify({ username: user }));
|
||||
|
||||
// Store Password in Keyring
|
||||
console.log("\n--> Storing password in system keyring...");
|
||||
execFileSync('secret-tool', [
|
||||
'store',
|
||||
'--label=Proxy Bridge Credentials',
|
||||
'service',
|
||||
'proxy-bridge',
|
||||
'account',
|
||||
user,
|
||||
], {
|
||||
input: pass
|
||||
});
|
||||
// Store Password in Keyring
|
||||
console.log("\n--> Storing password in system keyring...");
|
||||
try {
|
||||
execFileSync('secret-tool', [
|
||||
'store',
|
||||
'--label=Proxy Bridge Credentials',
|
||||
'service',
|
||||
'proxy-bridge',
|
||||
'account',
|
||||
user,
|
||||
], {
|
||||
input: pass
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn("⚠️ Warning: Failed to store password in keyring. Ensure libsecret-tools is installed.");
|
||||
}
|
||||
}
|
||||
|
||||
console.log("\n✅ Configuration and credentials successfully stored.");
|
||||
console.log("\n✅ Configuration successfully updated.");
|
||||
} catch (error) {
|
||||
console.error("\n❌ Setup failed:", error.message);
|
||||
process.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user