added claude login for credentials creation if credentials not exist
This commit is contained in:
@@ -425,6 +425,103 @@ async function testProxy(prompt) {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Claude Login im Proxy-Container ─────────────────────
|
||||
|
||||
let loginProcess = null;
|
||||
|
||||
function dockerExecStreaming(containerName, cmd, onData, onEnd) {
|
||||
const createBody = JSON.stringify({
|
||||
AttachStdout: true, AttachStderr: true, AttachStdin: false, Tty: true,
|
||||
Cmd: Array.isArray(cmd) ? cmd : ["sh", "-c", cmd],
|
||||
});
|
||||
|
||||
const createReq = http.request({
|
||||
socketPath: "/var/run/docker.sock",
|
||||
path: `/containers/${containerName}/exec`,
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(createBody) },
|
||||
}, (res) => {
|
||||
let data = "";
|
||||
res.on("data", (c) => data += c);
|
||||
res.on("end", () => {
|
||||
if (res.statusCode !== 201) {
|
||||
onEnd(new Error(`Exec create: HTTP ${res.statusCode}`));
|
||||
return;
|
||||
}
|
||||
const execId = JSON.parse(data).Id;
|
||||
|
||||
const startBody = JSON.stringify({ Detach: false, Tty: true });
|
||||
const startReq = http.request({
|
||||
socketPath: "/var/run/docker.sock",
|
||||
path: `/exec/${execId}/start`,
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(startBody) },
|
||||
}, (sRes) => {
|
||||
// Tty=true: kein Multiplexing, direkt Text
|
||||
sRes.on("data", (chunk) => {
|
||||
const text = chunk.toString("utf-8");
|
||||
if (text.trim()) onData(text);
|
||||
});
|
||||
sRes.on("end", () => onEnd(null));
|
||||
sRes.on("error", (err) => onEnd(err));
|
||||
});
|
||||
startReq.on("error", (err) => onEnd(err));
|
||||
startReq.write(startBody);
|
||||
startReq.end();
|
||||
});
|
||||
});
|
||||
createReq.on("error", (err) => onEnd(err));
|
||||
createReq.write(createBody);
|
||||
createReq.end();
|
||||
}
|
||||
|
||||
function startProxyLogin() {
|
||||
if (loginProcess) {
|
||||
log("warn", "proxy", "Login laeuft bereits");
|
||||
return;
|
||||
}
|
||||
|
||||
loginProcess = true;
|
||||
log("info", "proxy", "Starte Claude Login im Proxy-Container...");
|
||||
broadcast({ type: "login_status", status: "starting" });
|
||||
|
||||
// Volume ist :ro — wir muessen es rw remounten oder direkt im Container schreiben
|
||||
// Da das Volume ro ist, schreiben wir die Credentials in einen temp-Pfad und kopieren sie danach
|
||||
// Einfacher: claude login schreibt nach /root/.config/claude/ — das ist das gemountete Volume
|
||||
// Problem: Volume ist :ro! Login kann nicht schreiben.
|
||||
// Loesung: Login OHNE Volume ausfuehren, dann Credentials rauskopieren
|
||||
// Alternative: Wir machen es anders — Login direkt, Output streamen
|
||||
|
||||
// claude login: --no-open verhindert Browser-Oeffnung (Container hat keinen)
|
||||
// Fallback auf verschiedene CLI-Versionen
|
||||
dockerExecStreaming("aria-proxy", "claude login 2>&1 || echo 'Login-Befehl fehlgeschlagen. claude --version:' && claude --version 2>&1",
|
||||
(chunk) => {
|
||||
// Jeder Chunk wird live an die UI gesendet
|
||||
log("info", "proxy", `[login] ${chunk.trim()}`);
|
||||
|
||||
// URLs erkennen und hervorheben
|
||||
const urlMatch = chunk.match(/https?:\/\/[^\s\]]+/);
|
||||
if (urlMatch) {
|
||||
broadcast({ type: "login_url", url: urlMatch[0], raw: chunk.trim() });
|
||||
} else {
|
||||
broadcast({ type: "login_output", text: chunk.trim() });
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
loginProcess = null;
|
||||
if (err) {
|
||||
log("error", "proxy", `Login fehlgeschlagen: ${err.message}`);
|
||||
broadcast({ type: "login_status", status: "error", error: err.message });
|
||||
} else {
|
||||
log("info", "proxy", "Login-Prozess beendet");
|
||||
broadcast({ type: "login_status", status: "done" });
|
||||
// Auth nochmal pruefen
|
||||
setTimeout(() => checkProxyAuth(), 1000);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function checkProxyAuth() {
|
||||
try {
|
||||
log("info", "proxy", "Pruefe Auth-Dateien im Proxy-Container...");
|
||||
@@ -610,6 +707,8 @@ wss.on("connection", (ws) => {
|
||||
testProxy(msg.text);
|
||||
} else if (msg.action === "check_proxy_auth") {
|
||||
checkProxyAuth();
|
||||
} else if (msg.action === "proxy_login") {
|
||||
startProxyLogin();
|
||||
} else if (msg.action === "docker_logs") {
|
||||
handleDockerLogs(ws, msg.tab, msg.tail);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user