Switched to UTF-8 fixing non-english character bugs, revamped console logging system, fixed misc console errors, and fixed copy/paste. Warning: the terminal sizing in this version is very buggy so be warned.

This commit is contained in:
LukeGus
2025-03-09 01:44:53 -06:00
committed by Karmaa
parent 6e71cc8070
commit 0a81bea075
4 changed files with 56 additions and 47 deletions

View File

@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import { CssVarsProvider } from '@mui/joy/styles';
import { Modal, Button, FormControl, FormLabel, Input, Stack, DialogTitle, DialogContent, ModalDialog, Select, Option } from '@mui/joy';
import { Modal, Button, FormControl, FormLabel, Input, Stack, DialogTitle, DialogContent, ModalDialog, Select, Option, FormHelperText } from '@mui/joy';
import theme from './theme';
const AddHostModal = ({ isHidden, form, setForm, handleAddHost, setIsAddHostHidden }) => {
@@ -54,47 +54,42 @@ const AddHostModal = ({ isHidden, form, setForm, handleAddHost, setIsAddHostHidd
<Input
value={form.name}
onChange={(e) => setForm({ ...form, name: e.target.value })}
required={false}
sx={{
backgroundColor: theme.palette.general.primary,
color: theme.palette.text.primary,
}}
/>
</FormControl>
<FormControl>
<FormControl error={!form.ip}>
<FormLabel>Host IP</FormLabel>
<Input
value={form.ip}
onChange={(e) => setForm({ ...form, ip: e.target.value })}
required
error={!form.ip ? "Please provide an IP address" : ""}
sx={{
backgroundColor: theme.palette.general.primary,
color: theme.palette.text.primary,
}}
/>
</FormControl>
<FormControl>
<FormControl error={!form.user}>
<FormLabel>Host User</FormLabel>
<Input
value={form.user}
onChange={(e) => setForm({ ...form, user: e.target.value })}
required
error={form.user ? "" : "Please provide a username"}
sx={{
backgroundColor: theme.palette.general.primary,
color: theme.palette.text.primary,
}}
/>
</FormControl>
<FormControl>
<FormControl error={!form.authMethod || form.authMethod === 'Select Auth'}>
<FormLabel>Authentication Method</FormLabel>
<Select
value={form.authMethod}
value={form.authMethod || 'Select Auth'}
onChange={(e, newValue) => setForm({ ...form, authMethod: newValue })}
required
displayEmpty
error={!form.authMethod || form.authMethod === 'Select Auth'}
sx={{
backgroundColor: !form.authMethod || form.authMethod === 'Select Auth' ? theme.palette.general.tertiary : theme.palette.general.primary,
color: theme.palette.text.primary,
@@ -103,7 +98,7 @@ const AddHostModal = ({ isHidden, form, setForm, handleAddHost, setIsAddHostHidd
},
}}
>
<Option value="" disabled>
<Option value="Select Auth" disabled>
Select Auth
</Option>
<Option value="password">Password</Option>
@@ -111,14 +106,13 @@ const AddHostModal = ({ isHidden, form, setForm, handleAddHost, setIsAddHostHidd
</Select>
</FormControl>
{form.authMethod === 'password' && (
<FormControl>
<FormControl error={!form.password}>
<FormLabel>Host Password</FormLabel>
<Input
type="password"
value={form.password}
onChange={(e) => setForm({ ...form, password: e.target.value })}
required
error={form.password ? "" : "Please provide a password"}
sx={{
backgroundColor: theme.palette.general.primary,
color: theme.palette.text.primary,
@@ -127,13 +121,12 @@ const AddHostModal = ({ isHidden, form, setForm, handleAddHost, setIsAddHostHidd
</FormControl>
)}
{form.authMethod === 'rsaKey' && (
<FormControl>
<FormControl error={!form.rsaKey}>
<FormLabel>RSA Key</FormLabel>
<Input
type="file"
onChange={handleFileChange}
required
error={!form.rsaKey ? "Please upload a valid RSA private key file" : ""}
sx={{
backgroundColor: theme.palette.general.primary,
color: theme.palette.text.primary,
@@ -146,7 +139,7 @@ const AddHostModal = ({ isHidden, form, setForm, handleAddHost, setIsAddHostHidd
/>
</FormControl>
)}
<FormControl>
<FormControl error={form.port < 1 || form.port > 65535}>
<FormLabel>Host Port</FormLabel>
<Input
value={form.port}
@@ -154,7 +147,6 @@ const AddHostModal = ({ isHidden, form, setForm, handleAddHost, setIsAddHostHidd
min={1}
max={65535}
required
error={form.port < 1 || form.port > 65535 ? "Port must be between 1 and 65535" : ""}
sx={{
backgroundColor: theme.palette.general.primary,
color: theme.palette.text.primary,

View File

@@ -21,6 +21,7 @@ function App() {
user: "",
password: "",
port: 22,
authMethod: "Select Auth",
});
const [isLaunchpadOpen, setIsLaunchpadOpen] = useState(false);
const [splitTabIds, setSplitTabIds] = useState([]);
@@ -90,7 +91,7 @@ function App() {
user: form.user,
password: form.authMethod === 'password' ? form.password : undefined,
rsaKey: form.authMethod === 'rsaKey' ? form.rsaKey : undefined,
port: Number(form.port),
port: String(form.port),
},
terminalRef: null,
};

View File

@@ -50,8 +50,8 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible }, ref) => {
},
fontSize: 14,
scrollback: 1000,
rendererType: "canvas",
allowTransparency: true,
fontFamily: 'monospace',
ignoreBracketedPasteMode: true,
});
terminalInstance.current.loadAddon(fitAddon.current);
@@ -63,8 +63,6 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible }, ref) => {
terminalInstance.current.focus();
}, 50);
terminalInstance.current.write("\r\n*** Connecting to backend ***\r\n");
const socket = io(
window.location.hostname === "localhost"
? "http://localhost:8081"
@@ -81,23 +79,47 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible }, ref) => {
resizeTerminal();
const { cols, rows } = terminalInstance.current;
socket.emit("connectToHost", cols, rows, hostConfig);
terminalInstance.current.write("\r\n*** Connected to backend ***\r\n");
});
socket.on("data", (data) => {
terminalInstance.current.write(data);
const decoder = new TextDecoder("utf-8");
terminalInstance.current.write(decoder.decode(new Uint8Array(data)));
});
socket.on("disconnect", () => {
terminalInstance.current.write("\r\n*** Disconnected from backend ***\r\n");
terminalInstance.current.onData((data) => {
socketRef.current.emit("data", data);
});
terminalInstance.current.onKey(({ key }) => {
socket.emit("data", key);
terminalInstance.current.attachCustomKeyEventHandler((event) => {
if (
(event.ctrlKey && event.key === "v") ||
(event.metaKey && event.key === "v") ||
(event.shiftKey && event.key === "Insert")
) {
navigator.clipboard
.readText()
.then((text) => {
socketRef.current.emit("data", text);
})
.catch((err) => {
console.error("Failed to read clipboard contents:", err);
});
return false;
}
return true;
});
socket.on("connect_error", (err) => {
terminalInstance.current.write(`\r\n*** Error: ${err.message} ***\r\n`);
terminalInstance.current.onKey(({ domEvent }) => {
if (domEvent.key === "c" && (domEvent.ctrlKey || domEvent.metaKey)) {
const selection = terminalInstance.current.getSelection();
if (selection) {
navigator.clipboard.writeText(selection);
}
}
});
socket.on("error", (err) => {
terminalInstance.current.write(`\r\n*** Error: ${err} ***\r\n`);
});
return () => {

View File

@@ -22,7 +22,7 @@ io.on("connection", (socket) => {
console.error("Invalid hostConfig received:", hostConfig);
return;
}
// Redact only sensitive info for logging
const safeHostConfig = {
ip: hostConfig.ip,
@@ -31,7 +31,7 @@ io.on("connection", (socket) => {
password: hostConfig.password ? '***REDACTED***' : undefined,
rsaKey: hostConfig.rsaKey ? '***REDACTED***' : undefined,
};
console.log("Received hostConfig:", safeHostConfig);
const { ip, port, user, password, rsaKey } = hostConfig;
@@ -39,25 +39,22 @@ io.on("connection", (socket) => {
conn
.on("ready", function () {
console.log("SSH connection established");
socket.emit("data", "\r\n*** SSH CONNECTION ESTABLISHED ***\r\n");
conn.shell({ term: "xterm-256color" }, function (err, newStream) {
if (err) {
console.error("Error opening SSH shell:", err);
return socket.emit(
"data",
"\r\n*** SSH SHELL ERROR: " + err.message + " ***\r\n"
);
console.error("Error:", err.message);
socket.emit("error", err.message);
return;
}
stream = newStream;
stream = newStream;
// Set initial terminal size
stream.setWindow(rows, cols, rows * 100, cols * 100);
console.log(`Initial terminal size: cols=${cols}, rows=${rows}`);
// Pipe SSH output to client
stream.on("data", function (data) {
socket.emit("data", data.toString("binary"));
socket.emit("data", data);
});
stream.on("close", function () {
@@ -84,14 +81,11 @@ io.on("connection", (socket) => {
})
.on("close", function () {
console.log("SSH connection closed");
socket.emit("data", "\r\n*** SSH CONNECTION CLOSED ***\r\n");
socket.emit("error", "SSH connection closed");
})
.on("error", function (err) {
console.error("SSH connection error:", err);
socket.emit(
"data",
"\r\n*** SSH CONNECTION ERROR: " + err.message + " ***\r\n"
);
console.error("Error:", err.message);
socket.emit("error", err.message);
})
.connect({
host: ip,
@@ -109,4 +103,4 @@ io.on("connection", (socket) => {
server.listen(8081, '0.0.0.0', () => {
console.log("Server is running on port 8081");
});
});