import PropTypes from 'prop-types'; import { CssVarsProvider } from '@mui/joy/styles'; import { Modal, Button, FormControl, FormLabel, Input, Stack, DialogTitle, DialogContent, ModalDialog, IconButton, Select, Option, } from '@mui/joy'; import theme from '/src/theme'; import { useState, useEffect } from 'react'; import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; const NoAuthenticationModal = ({ isHidden, setIsHidden, onAuthenticate }) => { const [form, setForm] = useState({ authMethod: 'Select Auth', password: '', privateKey: '', keyType: '', passphrase: '' }); const [showPassword, setShowPassword] = useState(false); const [showPassphrase, setShowPassphrase] = useState(false); const handleSubmit = (e) => { e.preventDefault(); onAuthenticate({ authMethod: form.authMethod, password: form.password, privateKey: form.privateKey, keyType: form.keyType, passphrase: form.passphrase }); setIsHidden(true); }; const handleFileChange = (e) => { const file = e.target.files[0]; const supportedKeyTypes = { 'id_rsa': 'RSA', 'id_ed25519': 'ED25519', 'id_ecdsa': 'ECDSA', 'id_dsa': 'DSA', '.pem': 'PEM', '.key': 'KEY', '.ppk': 'PPK' }; const isValidKeyFile = Object.keys(supportedKeyTypes).some(ext => file.name.toLowerCase().includes(ext) || file.name.endsWith('.pub') ); if (isValidKeyFile) { const reader = new FileReader(); reader.onload = (event) => { const keyContent = event.target.result; let keyType = 'UNKNOWN'; // Detect key type from content if (keyContent.includes('BEGIN RSA PRIVATE KEY') || keyContent.includes('BEGIN RSA PUBLIC KEY')) { keyType = 'RSA'; } else if (keyContent.includes('BEGIN OPENSSH PRIVATE KEY') && keyContent.includes('ssh-ed25519')) { keyType = 'ED25519'; } else if (keyContent.includes('BEGIN EC PRIVATE KEY') || keyContent.includes('BEGIN EC PUBLIC KEY')) { keyType = 'ECDSA'; } else if (keyContent.includes('BEGIN DSA PRIVATE KEY')) { keyType = 'DSA'; } setForm({ ...form, privateKey: keyContent, keyType: keyType, authMethod: 'key' }); }; reader.readAsText(file); } else { alert('Please upload a valid SSH key file (RSA, ED25519, ECDSA, DSA, PEM, or PPK format).'); } }; return ( setIsHidden(true)} > Authentication Required
Authentication Method {form.authMethod === 'password' && ( Password setForm({ ...form, password: e.target.value })} endDecorator={ setShowPassword(!showPassword)}> {showPassword ? : } } /> )} {form.authMethod === 'key' && ( SSH Key {form.privateKey && ( Key Passphrase (optional) setForm(prev => ({ ...prev, passphrase: e.target.value }))} endDecorator={ setShowPassphrase(!showPassphrase)}> {showPassphrase ? : } } /> )} )}
); }; NoAuthenticationModal.propTypes = { isHidden: PropTypes.bool.isRequired, setIsHidden: PropTypes.func.isRequired, onAuthenticate: PropTypes.func.isRequired, }; export default NoAuthenticationModal;