import { Button, Card, Group, Image, Loader, LoadingOverlay, Notification, Space, Stack, PasswordInput, Title, Text, Code, ThemeIcon, Box } from '@mantine/core'; import { useForm } from '@mantine/form'; import { useEffect, useState } from 'react'; import { ImCross } from 'react-icons/im'; import { MdCloudOff } from 'react-icons/md'; import { Outlet, Route, Routes } from 'react-router'; import MainLayout from './components/MainLayout'; import { PasswordSend, ServerStatusResponse } from './js/models'; import { errorNotify, getstatus, HomeRedirector, IS_DEV, login, setpassword, socketio } from './js/utils'; import NFRegex from './pages/NFRegex'; import ServiceDetailsNFRegex from './pages/NFRegex/ServiceDetails'; import PortHijack from './pages/PortHijack'; import { Firewall } from './pages/Firewall'; import { useQueryClient } from '@tanstack/react-query'; import NFProxy from './pages/NFProxy'; import ServiceDetailsNFProxy from './pages/NFProxy/ServiceDetails'; import { useAuthStore, useSystemStore } from './js/store'; const AuthShell = ({ children }: { children: React.ReactNode }) => ( Firegex logo [Fi]*regex {children} ) const StatusCard = ({ title, description, color, children }: { title: string, description: string, color: string, children?: React.ReactNode }) => ( {title} {description} {children} ) function App() { const [loading, setLoading] = useState(true); const [systemStatus, setSystemStatus] = useState({ status: "", loggined: false }) const [reqError, setReqError] = useState() const [error, setError] = useState() const [loadinBtn, setLoadingBtn] = useState(false); const queryClient = useQueryClient() const { access_token } = useAuthStore() const { setVersion, setAuthDisabled } = useSystemStore() useEffect(() => { socketio.auth = { token: access_token || "" } socketio.connect() getStatus() socketio.on("update", (data) => { queryClient.invalidateQueries({ queryKey: data }) }) socketio.on("connect_error", (err) => { if (access_token) { errorNotify("Socket.Io connection failed! ", `Error message: [${err.message}]`) } getStatus() }); return () => { socketio.off("update") socketio.off("connect_error") socketio.disconnect() } }, [access_token]) const getStatus = () => { getstatus().then(res => { setSystemStatus(res) setVersion(res.version || "unknown") setAuthDisabled(res.auth_disabled === true) if (!res.loggined && useAuthStore.getState().getAccessToken()) { useAuthStore.getState().clearAccessToken() } setReqError(undefined) }).catch(err => { setReqError(err.toString()) setTimeout(getStatus, 500) }).finally(() => setLoading(false)) } useEffect(() => { getStatus() }, []) const form = useForm({ initialValues: { password: "", }, validate: { password: (value) => value !== "" ? null : "Password is required", } }) if (loading) { return } else if (reqError) { return {reqError} } else if (systemStatus.status === "init") { const submitRequest = async (values: PasswordSend) => { setLoadingBtn(true) await setpassword(values).then(res => { if (!res) { setSystemStatus({ loggined: true, status: "run" }) } else { setError(res) } }).catch(err => setError(err.toString())) setLoadingBtn(false) form.reset() } return Choose the password for access to the firewall 🔒
{error && <> } color="red" onClose={() => { setError(null) }}> Error: {error} }
} else if (systemStatus.status === "run" && !systemStatus.loggined) { const submitRequest = async (values: PasswordSend) => { setLoadingBtn(true) await login(values).then(res => { if (!res) { queryClient.invalidateQueries() setSystemStatus({ ...systemStatus, loggined: true }) } else { setError("Login failed") } }).catch(err => setError(err.toString())) setLoadingBtn(false) form.reset() } return Insert the password to unlock the firewall 🔒
{error && <> } color="red" onClose={() => { setError(null) }}> Error: {error} }
} else if (systemStatus.status === "run" && systemStatus.loggined) { return } else { return } } import TLSDecrypt from './pages/TLSDecrypt'; const PageRouting = ({ getStatus }: { getStatus: () => void }) => { return }> } /> } > } /> } > } /> } /> } /> } /> } export default App;