From: charleswrayjr Date: Tue, 9 Sep 2025 15:58:53 +0000 (-0500) Subject: Separating the revoke client functionality from the main vpn lists. X-Git-Url: https://git.phasecustomsoft.com/static/gitweb.js?a=commitdiff_plain;h=aad14e0dc4c9a8f8491cdb6643f7db74ed14da77;p=phs-admin.git Separating the revoke client functionality from the main vpn lists. --- diff --git a/src/app/views/VPN/VPN.jsx b/src/app/views/VPN/VPN.jsx index db17612..dcc8663 100644 --- a/src/app/views/VPN/VPN.jsx +++ b/src/app/views/VPN/VPN.jsx @@ -1,24 +1,52 @@ import React, { useState, useEffect } from 'react'; import { Container, Typography, Button } from '@mui/material'; -import { MaterialReactTable } from 'material-react-table'; -/*import axios from 'axios';*/ -import 'tailwindcss/tailwind.css'; +import { MaterialReactTable, useMaterialReactTable } from 'material-react-table'; import { VPNService } from '../../services'; import { ConfirmRevoke, CreateVPNClientDialog } from '../../components'; const VPN = () => { - /*const [token, setToken] = useState(''); - const [username, setUsername] = useState(''); - const [password, setPassword] = useState('');*/ - /*const [clientName, setClientName] = useState(''); - const [staticIp, setStaticIp] = useState(''); - const [useStaticIp, setUseStaticIp] = useState(false);*/ const [revokeOpen, setRevokeOpen] = useState( false ); const [revokeClientName, setRevokeClientName] = useState(''); const [clients, setClients] = useState([]); const [availableClients, setAvailableClients] = useState( [] ); const [message, setMessage] = useState(''); const [createOpen, setCreateOpen] = useState( false ); + const clientTable = useMaterialReactTable( { + columns: [ + { accessorKey: 'name', header: 'Name' }, + { accessorKey: 'ip', header: 'IP' }, + { accessorFn: row => row.virtual_ip, header: 'Virtual IP' }, + { accessorFn: row => row.connectedSince, header: 'Connected Since' }, + ], + data: clients, + } ); + const availableTable = useMaterialReactTable({ + columns:[ + { accessorKey: 'clientName', header: 'Name' }, + { accessorKey: 'staticIp', header: 'IP' }, + { accessorFn: row => row.hasCertificate ? 'Yes' : 'No', header: 'Active Certificate' }, + { accessorFn: row => clients.find( c => c.name === row.clientName ) ? 'Yes' : 'No', header: 'Connected' }, + { accessorFn: row => row.hasOvpn ? 'Yes' : 'No', header: 'Has Profile' }, + { + header: 'Actions', + Cell: ({ row }) => ( + + ), + }, + ], + data: availableClients, + createDisplayMode: 'modal', + renderCreateRowDialogContent: () => ( setCreateOpen(false)} onCreate={handleCreateClientSubmit} />) + }); const fetchClients = async () => { await VPNService.fetchClients().then( res => setClients( res ) ).catch( err => setMessage( err ) ); @@ -33,17 +61,6 @@ const VPN = () => { fetchAvailableClients().catch( e => setMessage( e ) ); }, [] ); - /*const handleLogin = async (e) => { - e.preventDefault(); - try { - const response = await axios.post('http://localhost:3000/login', { username, password }); - setToken(response.data.token); - setMessage('Logged in successfully'); - } catch (error) { - setMessage(`Error: ${error.response?.data?.error || 'Login failed'}`); - } - };*/ - const handleCreateClientSubmit = async (e, data) => { const { clientName, useStaticIp, staticIp } = data; e.preventDefault(); @@ -58,6 +75,11 @@ const VPN = () => { setRevokeOpen( false ); }; + setTimeout( () => { + fetchClients().catch( e => setMessage( e ) ); + fetchAvailableClients().catch( e => setMessage( e ) ); + }, 10000 * 120 ); + return ( { revokeOpen && @@ -66,118 +88,18 @@ const VPN = () => { onClose={() => setRevokeOpen(false)} onConfirm={handleRevokeClientSubmit} />} - - {createOpen && setCreateOpen(false)} onCreate={handleCreateClientSubmit}/>} - {/*Create OpenVPN Client -
- setClientName(e.target.value)} - fullWidth - /> - - {useStaticIp && ( - setStaticIp(e.target.value)} - fullWidth - placeholder="e.g., 10.8.0.x" - /> - )} - - */} - - {/*Revoke OpenVPN Client -
- setRevokeClientName(e.target.value)} - fullWidth - /> - - */} + {/* + {createOpen && setCreateOpen(false)} onCreate={handleCreateClientSubmit}/>}*/} Available OpenVPN Clients - { - console.log(row.hasCertificate); - return row.hasCertificate ? 'Yes' : 'No'; - }, header: 'Active Certificate' }, - { accessorFn: row => clients.find( c => c.name === row.clientName ) ? 'Yes' : 'No', header: 'Connected' }, - { accessorFn: row => row.hasOvpn ? 'Yes' : 'No', header: 'Has Profile' }, - { - header: 'Actions', - Cell: ({ row }) => ( - - ), - }, - ]} - data={availableClients} - /> + Connected OpenVPN Clients - + {message && {message}}
); - - /*return ( - - PHS Admin Dashboard - {!token ? ( -
- setUsername(e.target.value)} - fullWidth - /> - setPassword(e.target.value)} - fullWidth - /> - - - ) : ( - <> - - )} -
- );*/ }; export default VPN; \ No newline at end of file