You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

App.js 9.1 kB

2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // Copyright 2023 The casbin Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import React, {Component} from 'react';
  15. import {Switch, Redirect, Route, withRouter, Link} from 'react-router-dom';
  16. import {Avatar, BackTop, Dropdown, Layout, Menu} from 'antd';
  17. import {DownOutlined, LogoutOutlined, SettingOutlined} from '@ant-design/icons';
  18. import './App.less';
  19. import * as Setting from "./Setting";
  20. import * as AccountBackend from "./backend/AccountBackend";
  21. import AuthCallback from "./AuthCallback";
  22. import * as Conf from "./Conf";
  23. import HomePage from "./HomePage";
  24. import DatasetListPage from "./DatasetListPage";
  25. import DatasetEditPage from "./DatasetEditPage";
  26. import SigninPage from "./SigninPage";
  27. import i18next from "i18next";
  28. import SelectLanguageBox from "./SelectLanguageBox";
  29. const {Header, Footer} = Layout;
  30. class App extends Component {
  31. constructor(props) {
  32. super(props);
  33. this.state = {
  34. classes: props,
  35. selectedMenuKey: 0,
  36. account: undefined,
  37. uri: null,
  38. };
  39. Setting.initServerUrl();
  40. Setting.initCasdoorSdk(Conf.AuthConfig);
  41. }
  42. componentWillMount() {
  43. this.updateMenuKey();
  44. this.getAccount();
  45. }
  46. componentDidUpdate() {
  47. // eslint-disable-next-line no-restricted-globals
  48. const uri = location.pathname;
  49. if (this.state.uri !== uri) {
  50. this.updateMenuKey();
  51. }
  52. }
  53. updateMenuKey() {
  54. // eslint-disable-next-line no-restricted-globals
  55. const uri = location.pathname;
  56. this.setState({
  57. uri: uri,
  58. });
  59. if (uri === '/') {
  60. this.setState({selectedMenuKey: '/'});
  61. } else if (uri.includes('/datasets')) {
  62. this.setState({ selectedMenuKey: '/datasets' });
  63. } else {
  64. this.setState({selectedMenuKey: 'null'});
  65. }
  66. }
  67. onUpdateAccount(account) {
  68. this.setState({
  69. account: account
  70. });
  71. }
  72. setLanguage(account) {
  73. // let language = account?.language;
  74. let language = localStorage.getItem("language");
  75. if (language !== "" && language !== i18next.language) {
  76. Setting.setLanguage(language);
  77. }
  78. }
  79. getAccount() {
  80. AccountBackend.getAccount()
  81. .then((res) => {
  82. let account = res.data;
  83. if (account !== null) {
  84. this.setLanguage(account);
  85. }
  86. this.setState({
  87. account: account,
  88. });
  89. });
  90. }
  91. signout() {
  92. AccountBackend.signout()
  93. .then((res) => {
  94. if (res.status === 'ok') {
  95. this.setState({
  96. account: null
  97. });
  98. Setting.showMessage("success", `Successfully signed out, redirected to homepage`);
  99. Setting.goToLink("/");
  100. // this.props.history.push("/");
  101. } else {
  102. Setting.showMessage("error", `Signout failed: ${res.msg}`);
  103. }
  104. });
  105. }
  106. handleRightDropdownClick(e) {
  107. if (e.key === '/account') {
  108. Setting.openLink(Setting.getMyProfileUrl(this.state.account));
  109. } else if (e.key === '/logout') {
  110. this.signout();
  111. }
  112. }
  113. renderAvatar() {
  114. if (this.state.account.avatar === "") {
  115. return (
  116. <Avatar style={{ backgroundColor: Setting.getAvatarColor(this.state.account.name), verticalAlign: 'middle' }} size="large">
  117. {Setting.getShortName(this.state.account.name)}
  118. </Avatar>
  119. )
  120. } else {
  121. return (
  122. <Avatar src={this.state.account.avatar} style={{verticalAlign: 'middle' }} size="large">
  123. {Setting.getShortName(this.state.account.name)}
  124. </Avatar>
  125. )
  126. }
  127. }
  128. renderRightDropdown() {
  129. const menu = (
  130. <Menu onClick={this.handleRightDropdownClick.bind(this)}>
  131. <Menu.Item key="/account">
  132. <SettingOutlined />
  133. {i18next.t("account:My Account")}
  134. </Menu.Item>
  135. <Menu.Item key="/logout">
  136. <LogoutOutlined />
  137. {i18next.t("account:Sign Out")}
  138. </Menu.Item>
  139. </Menu>
  140. );
  141. return (
  142. <Dropdown key="/rightDropDown" overlay={menu} className="rightDropDown">
  143. <div className="ant-dropdown-link" style={{float: 'right', cursor: 'pointer'}}>
  144. &nbsp;
  145. &nbsp;
  146. {
  147. this.renderAvatar()
  148. }
  149. &nbsp;
  150. &nbsp;
  151. {Setting.isMobile() ? null : Setting.getShortName(this.state.account.displayName)} &nbsp; <DownOutlined />
  152. &nbsp;
  153. &nbsp;
  154. &nbsp;
  155. </div>
  156. </Dropdown>
  157. )
  158. }
  159. renderAccount() {
  160. let res = [];
  161. if (this.state.account === undefined) {
  162. return null;
  163. } else if (this.state.account === null) {
  164. res.push(
  165. <Menu.Item key="/signup" style={{float: 'right', marginRight: '20px'}}>
  166. <a href={Setting.getSignupUrl()}>
  167. {i18next.t("account:Sign Up")}
  168. </a>
  169. </Menu.Item>
  170. );
  171. res.push(
  172. <Menu.Item key="/signin" style={{float: 'right'}}>
  173. <a href={Setting.getSigninUrl()}>
  174. {i18next.t("account:Sign In")}
  175. </a>
  176. </Menu.Item>
  177. );
  178. res.push(
  179. <Menu.Item key="/" style={{float: 'right'}}>
  180. <a href="/">
  181. {i18next.t("general:Home")}
  182. </a>
  183. </Menu.Item>
  184. );
  185. } else {
  186. res.push(this.renderRightDropdown());
  187. return (
  188. <div style={{float: 'right', margin: '0px', padding: '0px'}}>
  189. {
  190. res
  191. }
  192. </div>
  193. )
  194. }
  195. return res;
  196. }
  197. renderMenu() {
  198. let res = [];
  199. if (this.state.account === null || this.state.account === undefined) {
  200. return [];
  201. }
  202. res.push(
  203. <Menu.Item key="/">
  204. <a href="/">
  205. {i18next.t("general:Home")}
  206. </a>
  207. {/*<Link to="/">*/}
  208. {/* Home*/}
  209. {/*</Link>*/}
  210. </Menu.Item>
  211. );
  212. res.push(
  213. <Menu.Item key="/datasets">
  214. <Link to="/datasets">
  215. {i18next.t("general:Datasets")}
  216. </Link>
  217. </Menu.Item>
  218. );
  219. return res;
  220. }
  221. renderHomeIfSignedIn(component) {
  222. if (this.state.account !== null && this.state.account !== undefined) {
  223. return <Redirect to='/' />
  224. } else {
  225. return component;
  226. }
  227. }
  228. renderSigninIfNotSignedIn(component) {
  229. if (this.state.account === null) {
  230. sessionStorage.setItem("from", window.location.pathname);
  231. return <Redirect to='/signin' />
  232. } else if (this.state.account === undefined) {
  233. return null;
  234. }
  235. else {
  236. return component;
  237. }
  238. }
  239. renderContent() {
  240. return (
  241. <div>
  242. <Header style={{padding: '0', marginBottom: '3px'}}>
  243. {
  244. Setting.isMobile() ? null : <a className="logo" href={"/"}/>
  245. }
  246. <Menu
  247. // theme="dark"
  248. mode={"horizontal"}
  249. selectedKeys={[`${this.state.selectedMenuKey}`]}
  250. style={{lineHeight: '64px'}}
  251. >
  252. {
  253. this.renderMenu()
  254. }
  255. {
  256. this.renderAccount()
  257. }
  258. <SelectLanguageBox />
  259. </Menu>
  260. </Header>
  261. <Switch>
  262. <Route exact path="/callback" component={AuthCallback}/>
  263. <Route exact path="/" render={(props) => <HomePage account={this.state.account} {...props} />}/>
  264. <Route exact path="/signin" render={(props) => this.renderHomeIfSignedIn(<SigninPage {...props} />)}/>
  265. <Route exact path="/datasets" render={(props) => this.renderSigninIfNotSignedIn(<DatasetListPage account={this.state.account} {...props} />)}/>
  266. <Route exact path="/datasets/:datasetName" render={(props) => this.renderSigninIfNotSignedIn(<DatasetEditPage account={this.state.account} {...props} />)}/>
  267. </Switch>
  268. </div>
  269. )
  270. }
  271. renderFooter() {
  272. // How to keep your footer where it belongs ?
  273. // https://www.freecodecamp.org/news/how-to-keep-your-footer-where-it-belongs-59c6aa05c59c/
  274. return (
  275. <Footer id="footer" style={
  276. {
  277. borderTop: '1px solid #e8e8e8',
  278. backgroundColor: 'white',
  279. textAlign: 'center',
  280. }
  281. }>
  282. Made with <span style={{color: 'rgb(255, 255, 255)'}}>❤️</span> by <a style={{fontWeight: "bold", color: "black"}} target="_blank" href="https://github.com/casbin/casvisor">Casvisor</a>, { Setting.isMobile() ? "Mobile" : "Desktop" } View
  283. </Footer>
  284. )
  285. }
  286. render() {
  287. return (
  288. <div id="parent-area">
  289. <BackTop/>
  290. <div id="content-wrap">
  291. {
  292. this.renderContent()
  293. }
  294. </div>
  295. {
  296. this.renderFooter()
  297. }
  298. </div>
  299. );
  300. }
  301. }
  302. export default withRouter(App);

Caswire是一款基于人工智能技术的开源反病毒和入侵检测系统。该系统通过深度学习和模式识别技术,能够实时识别和防御各种网络威胁,包括病毒、恶意软件以及其他安全威胁。Caswire支持动态学习和适应网络环境的变化,确保持续的安全防护。我们期望在Caswire上:1)增强其机器学习模型,以提高恶意行为的检测准确率;2)优化系统的实时响应能力,提升在高威胁环境下的表现。