import '@/beautiful-scrollbar.css'; import '@/App.css'; import React, {lazy, useEffect} from "react"; import {createBrowserRouter, RouterProvider} from "react-router-dom"; import '@/react-i18next/i18n' import ManagerLayout from '@/layout/ManagerLayout'; import AccessPage from "@/pages/access/AccessPage"; import eventEmitter from "@/api/core/event-emitter"; import {baseUrl} from "@/api/core/requests"; import {useTranslation} from "react-i18next"; import {message} from "antd"; import TerminalPage from "@/pages/access/TerminalPage"; import GuacamolePage from "@/pages/access/GuacamolePage"; const AuthorisedAssetPage = lazy(() => import("@/pages/authorised/AuthorisedAssetPage")); const AuthorisedWebsitePage = lazy(() => import("@/pages/authorised/AuthorisedWebsitePage")); const AuthorisedAssetPost = lazy(() => import("@/pages/authorised/AuthorisedAssetPost")); const AuthorisedWebsitePost = lazy(() => import("@/pages/authorised/AuthorisedWebsitePost")); const LoginPage = lazy(() => import("@/pages/account/LoginPage")); const WechatWorkCallback = lazy(() => import("@/pages/account/WechatWorkCallback")); const OidcCallback = lazy(() => import("@/pages/account/OidcCallback")); const OidcServerConsent = lazy(() => import("@/pages/account/OidcServerConsent")); const MobileAccessTerminal = lazy(() => import("@/pages/access/MobileAccessTerminal")); const UserPage = lazy(() => import("@/pages/identity/UserPage")); const UserDetailPage = lazy(() => import("@/pages/identity/UserDetailPage")); const SettingPage = lazy(() => import("@/pages/sysconf/SettingPage")); const InfoPage = lazy(() => import("@/pages/account/InfoPage")); const DepartmentPage = lazy(() => import("@/pages/identity/DepartmentPage")); const DepartmentDetail = lazy(() => import("@/pages/identity/DepartmentDetail")); const RolePage = lazy(() => import("@/pages/identity/RolePage")); const RoleDetail = lazy(() => import("@/pages/identity/RoleDetail")); const LoginLockedPage = lazy(() => import("@/pages/identity/LoginLockedPage")); const LoginPolicyPage = lazy(() => import("@/pages/identity/LoginPolicyPage")); const LoginPolicyPostPage = lazy(() => import("@/pages/identity/LoginPolicyPostPage")); const LoginPolicyDetailPage = lazy(() => import("@/pages/identity/LoginPolicyDetailPage")); const OidcClientPage = lazy(() => import("@/pages/identity/OidcClientPage")); const AssetsPage = lazy(() => import("@/pages/assets/AssetPage")); const DatabaseAssetPage = lazy(() => import("@/pages/assets/DatabaseAssetPage")); const CredentialPage = lazy(() => import("@/pages/assets/CredentialPage")); const CertificatePage = lazy(() => import("@/pages/assets/CertificatePage")); const SnippetPage = lazy(() => import("@/pages/assets/SnippetPage")); const StrategyPage = lazy(() => import("@/pages/authorised/StrategyPage")); const CommandFilterPage = lazy(() => import("@/pages/authorised/CommandFilterPage")); const CommandFilterDetail = lazy(() => import("@/pages/authorised/CommandFilterDetail")); const AuthorisedDatabaseAssetPage = lazy(() => import("@/pages/authorised/AuthorisedDatabaseAssetPage")); const AuthorisedDatabaseAssetPost = lazy(() => import("@/pages/authorised/AuthorisedDatabaseAssetPost")); const ScheduledTaskPage = lazy(() => import("@/pages/sysops/ScheduledTaskPage")); const ToolsPage = lazy(() => import("@/pages/sysops/ToolsPage")); const LoginLogPage = lazy(() => import("@/pages/audit/LoginLogPage")); const OperationLogPage = lazy(() => import("@/pages/audit/OperationLogPage")); const OfflineSessionPage = lazy(() => import("@/pages/audit/OfflineSessionPage")); const OnlineSessionPage = lazy(() => import("@/pages/audit/OnlineSessionPage")); const TerminalPlayback = lazy(() => import("@/pages/access/TerminalPlayback")); const TerminalMonitor = lazy(() => import("@/pages/access/TerminalMonitor")); const GuacdPlayback = lazy(() => import("@/pages/access/GuacdPlayback")); const GuacdMonitor = lazy(() => import("@/pages/access/GuacdMonitor")); const FileSystemLogPage = lazy(() => import("@/pages/audit/FileSystemLogPage")); const AccessLogPage = lazy(() => import("@/pages/audit/AccessLogPage")); const AccessLogStatsPage = lazy(() => import("@/pages/audit/AccessLogStatsPage")); const DatabaseSQLLogPage = lazy(() => import("@/pages/dbproxy/DatabaseSQLLogPage")); const SshGatewayPage = lazy(() => import("@/pages/gateway/SshGatewayPage")); const AgentGatewayPage = lazy(() => import("@/pages/gateway/AgentGatewayPage")); const GatewayGroupPage = lazy(() => import("@/pages/gateway/GatewayGroupPage")); const ErrorPage = lazy(() => import("@/components/ErrorPage")); const StoragePage = lazy(() => import("@/pages/assets/StoragePage")); const WebsitePage = lazy(() => import("@/pages/assets/WebsitePage")); const BrowserPage = lazy(() => import("@/pages/access/BrowserPage")); const FacadePage = lazy(() => import("@/pages/facade/AssetFacadePage.tsx")); const WebsiteFacadePage = lazy(() => import("@/pages/facade/WebsiteFacadePage")); const RedirectPage = lazy(() => import("@/layout/RedirectPage")); const UserLayout = lazy(() => import("@/layout/UserLayout")); const DashboardPage = lazy(() => import("@/pages/dashboard/DashboardPage")); const UserInfoPage = lazy(() => import("@/pages/facade/UserInfoPage")); const SnippetUserPage = lazy(() => import("@/pages/facade/SnippetUserPage")); const DatabaseAssetFacadePage = lazy(() => import("@/pages/facade/DatabaseAssetFacadePage")); const SystemMonitorPage = lazy(() => import("@/pages/sysops/SystemMonitorPage")); const SetupPage = lazy(() => import("@/pages/identity/SetupPage")); const DatabaseWorkOrderPage = lazy(() => import("@/pages/dbproxy/DatabaseWorkOrderPage")); const DatabaseWorkOrderUserPage = lazy(() => import("@/pages/facade/DatabaseWorkOrderUserPage")); const router = createBrowserRouter([ {path: "/setup", element: }, {path: "/access", element: }, {path: "/login", element: }, {path: "/wechat-work/callback", element: }, {path: "/oidc/callback", element: }, {path: "/oidc/server/consent", element: }, {path: "/terminal-playback", element: }, {path: "/terminal-monitor", element: }, {path: "/graphics-playback", element: }, {path: "/graphics-monitor", element: }, {path: "/terminal", element: ,}, {path: "/mobile-terminal", element: ,}, {path: "/graphics", element: ,}, {path: "/browser", element: ,}, {path: "/", element: , errorElement: ,}, { element: , children: [ {path: "/x-asset", element: ,}, {path: "/x-database-asset", element: ,}, {path: "/x-website", element: ,}, {path: "/x-snippet", element: ,}, {path: "/x-info", element: ,}, {path: "/x-db-work-order", element: }, ] }, { element: , children: [ {path: "/dashboard", element: }, {path: "/user", element: }, {path: "/user/:userId", element: }, {path: "/department", element: }, {path: "/department/:departmentId", element: }, {path: "/login-locked", element: }, {path: "/login-policy", element: }, {path: "/login-policy/new", element: }, {path: "/login-policy/:loginPolicyId", element: }, {path: "/role", element: }, {path: "/role/:roleId", element: }, {path: "/oidc-client", element: }, {path: "/login-log", element: }, {path: "/operation-log", element: }, {path: "/asset", element: }, {path: "/database-asset", element: }, {path: "/credential", element: }, {path: "/snippet", element: }, {path: "/storage", element: }, {path: "/website", element: }, {path: "/certificate", element: }, {path: "/db-work-order", element: }, {path: "/strategy", element: }, {path: "/command-filter", element: }, {path: "/command-filter/:commandFilterId", element: }, {path: "/authorised-asset", element: }, {path: "/authorised-asset/post", element: }, {path: "/authorised-website", element: }, {path: "/authorised-website/post", element: }, {path: "/authorised-database-asset", element: }, {path: "/authorised-database-asset/post", element: }, {path: "/scheduled-task", element: }, {path: "/tools", element: }, {path: "/monitoring", element: }, {path: "/offline-session", element: }, {path: "/online-session", element: }, {path: "/filesystem-log", element: }, {path: "/access-log", element: }, {path: "/access-log-stats", element: }, {path: "/database-sql-log", element: }, {path: "/ssh-gateway", element: }, {path: "/agent-gateway", element: }, {path: "/gateway-group", element: }, {path: "/setting", element: }, {path: "/info", element: }, ], } ]); function App() { let {t} = useTranslation(); useEffect(() => { let link = document.querySelector("link[rel~='icon']") as HTMLLinkElement; if (!link) { link = document.createElement('link'); link.rel = 'icon'; document.getElementsByTagName('head')[0].appendChild(link); } link.href = `${baseUrl()}/logo`; }, []); const un_auth = () => { window.location.href = '/login'; } const redirect = (url: string) => { window.location.href = url; } let _lastErrorMsg = ''; let _lastErrorTime = 0; const validate_error = (errorCode: number, error: string) => { let msg = t(`errors.${errorCode}`); if (!msg || msg === `errors.${errorCode}`) { msg = error; } const now = Date.now(); if (_lastErrorMsg === msg && now - _lastErrorTime < 2000) { return; } _lastErrorMsg = msg; _lastErrorTime = now; message.error(msg); } useEffect(() => { eventEmitter.on("API:UN_AUTH", un_auth) eventEmitter.on("API:REDIRECT", redirect) eventEmitter.on("API:VALIDATE_ERROR", validate_error) return () => { eventEmitter.off("API:UN_AUTH", un_auth) eventEmitter.off("API:REDIRECT", redirect) eventEmitter.off("API:VALIDATE_ERROR", validate_error) } }, []); return } export default App