Skip to content

Commit

Permalink
Merge pull request #48 from gnmyt/fixes/ssh-key
Browse files Browse the repository at this point in the history
🐛 Allow ssh keys without passphrase
  • Loading branch information
gnmyt authored Sep 3, 2024
2 parents ca73c84 + 52ca270 commit 30091e5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/src/common/components/IconInput/IconInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const IconInput = ({ type, id, name, required, icon, placeholder, customC
<Icon path={icon} className="input-icon" />
<input type={type} id={id} name={name} required={required} className={"input" + (customClass ? " " + customClass : "")}
placeholder={placeholder} autoComplete={autoComplete} onInput={onChange}
onBlur={onBlur} value={value} onChange={(event) => setValue(event.target.value)} />
onBlur={onBlur} value={value} onChange={(event) => setValue ? setValue(event.target.value) : null} />
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const ProxmoxDialog = ({ open, onClose, currentFolderId, editServerId })
}

useEffect(() => {
if (editServerId) {
if (editServerId && open) {
getRequest(`pve-servers/${editServerId.split("-")[1]}`).then(server => {
setName(server.name);
setIp(server.ip);
Expand Down
31 changes: 26 additions & 5 deletions client/src/pages/Servers/components/ServerDialog/ServerDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import Button from "@/common/components/Button";
import { getRequest, patchRequest, putRequest } from "@/common/utils/RequestUtil.js";
import { ServerContext } from "@/common/contexts/ServerContext.jsx";
import IdentityPage from "@/pages/Servers/components/ServerDialog/pages/IdentityPage.jsx";
import { IdentityContext } from "@/common/contexts/IdentityContext.jsx";

const tabs = ["Details", "Identities", "Settings"];

export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) => {

const { loadServers } = useContext(ServerContext);
const { loadIdentities } = useContext(IdentityContext);

const [name, setName] = useState("");
const [icon, setIcon] = useState(null);
Expand All @@ -26,14 +28,20 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =

const postIdentity = async (identity) => {
try {
console.log(identity);
if (identity.username === "") identity.username = undefined;
if (identity.passphrase === "") identity.passphrase = undefined;
if (identity.password === "") identity.password = undefined;
if (identity.sshKey === null) identity.sshKey = undefined;

const result = await putRequest("identities", {
name: identity.name, username: identity.username, type: identity.authType,
password: identity.password, sshKey: identity.sshKey, passphrase: identity.passphrase,
});

if (result.id) setIdentityUpdates({});

refreshIdentities();

return result;
} catch (error) {
console.error(error);
Expand All @@ -42,6 +50,11 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =

const patchIdentity = async (identity) => {
try {
if (identity.username === "") identity.username = undefined;
if (identity.passphrase === "") identity.passphrase = undefined;
if (identity.password === "") identity.password = undefined;
if (identity.sshKey === null) identity.sshKey = undefined;

await patchRequest("identities/" + identity.id, {
name: identity.name, username: identity.username, type: identity.authType,
password: identity.password, sshKey: identity.sshKey, passphrase: identity.passphrase,
Expand All @@ -66,11 +79,18 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =

const createServer = async () => {
try {
const { id } = await updateIdentities();
let identity = null;
if (Object.keys(identityUpdates).length > 0) {
identity = await updateIdentities();

if (!identity) return;

loadIdentities();
}

const result = await putRequest("servers", {
name, icon: icon, ip, port, protocol: protocol,
folderId: currentFolderId, identities: id ? [id] : [],
folderId: currentFolderId, identities: identity?.id ? [identity?.id] : [],
});

loadServers();
Expand All @@ -82,9 +102,10 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =

const patchServer = async () => {
try {
await updateIdentities();
const identity = await updateIdentities();

await patchRequest("servers/" + editServerId, { name, icon: icon, ip, port, protocol: protocol });
await patchRequest("servers/" + editServerId, { name, icon: icon, ip, port, protocol: protocol,
identities: identity?.id ? [identity?.id] : undefined });

loadServers();
onClose();
Expand Down
2 changes: 1 addition & 1 deletion server/models/Identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = db.define("identities", {
},
username: {
type: Sequelize.STRING,
allowNull: false,
allowNull: true,
},
type: {
type: Sequelize.STRING,
Expand Down
2 changes: 1 addition & 1 deletion server/validations/identity.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Joi = require("joi");
module.exports.createIdentityValidation = Joi.object({
name: Joi.string().min(3).max(255).required(),
username: Joi.string().max(255).required(),
username: Joi.string().max(255).optional(),
type: Joi.string().valid("password", "ssh").required(),
password: Joi.string().optional(),
sshKey: Joi.string().optional(),
Expand Down

0 comments on commit 30091e5

Please sign in to comment.