203f2bf189
- Removed hardcoded corporate proxy URL from all scripts. - Updated bridge.js to load configuration from /opt/proxy-bridge/config.json. - Updated setup.js to interactively configure upstream proxy and credentials. - Enhanced install_proxy.sh to automatically configure APT, Bash, and system services. - Purged sensitive URL from git history and verified zero leakage.
82 lines
2.4 KiB
JavaScript
82 lines
2.4 KiB
JavaScript
const readline = require('readline');
|
|
const { execFileSync } = require('child_process');
|
|
const fs = require('fs');
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
});
|
|
|
|
const CONFIG_DIR = '/opt/proxy-bridge';
|
|
const CONFIG_FILE = `${CONFIG_DIR}/config.json`;
|
|
const USER_FILE = `${CONFIG_DIR}/user.json`;
|
|
|
|
console.log("=== Proxy Bridge Configuration Setup ===");
|
|
|
|
function ask(question, defaultValue = "") {
|
|
return new Promise((resolve) => {
|
|
const prompt = defaultValue ? `${question} [${defaultValue}]: ` : `${question}: `;
|
|
rl.question(prompt, (answer) => {
|
|
resolve(answer || defaultValue);
|
|
});
|
|
});
|
|
}
|
|
|
|
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");
|
|
|
|
if (!host) {
|
|
console.error("❌ Hostname is required.");
|
|
process.exit(1);
|
|
}
|
|
|
|
// 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
|
|
if (!fs.existsSync(CONFIG_DIR)) {
|
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
}
|
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify({ host, port }, null, 2));
|
|
|
|
// 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
|
|
});
|
|
|
|
console.log("\n✅ Configuration and credentials successfully stored.");
|
|
} catch (error) {
|
|
console.error("\n❌ Setup failed:", error.message);
|
|
process.exit(1);
|
|
} finally {
|
|
rl.close();
|
|
}
|
|
}
|
|
|
|
run();
|