React Interface v2

This commit is contained in:
DomySh
2022-06-12 14:40:48 +02:00
parent 25d0705432
commit 18379dd8d7
7 changed files with 99 additions and 20 deletions

View File

@@ -1,2 +1,4 @@
$primary_color: #242a33; $primary_color: #242a33;
$second_color: #1A1B1E;
$third_color:#25262b;

View File

@@ -1,6 +1,13 @@
@use "../../vars" as *;
.box{ .box{
padding:30px; padding:30px;
margin:5px; margin:5px;
} }
.regex_text{
padding: 10px;
background-color: $third_color;
border-radius: 15px;
}

View File

@@ -1,17 +1,85 @@
import { TextInput } from '@mantine/core'; import { Center, Grid, SegmentedControl, Text, Title, Box, Badge, Space, ActionIcon } from '@mantine/core';
import React from 'react'; import React from 'react';
import { RegexFilter } from '../../js/models'; import { RegexFilter } from '../../js/models';
import { getHumanReadableRegex } from '../../js/utils'; import { getHumanReadableRegex } from '../../js/utils';
import style from "./RegexView.module.scss"; import style from "./RegexView.module.scss";
import { FaListAlt } from "react-icons/fa"
import { TiCancel } from "react-icons/ti"
import { BsTrashFill } from "react-icons/bs"
function RegexView({ regexInfo }:{ regexInfo:RegexFilter }) { function RegexView({ regexInfo }:{ regexInfo:RegexFilter }) {
const mode_string = regexInfo.mode == "C"? "C -> S":
regexInfo.mode == "S"? "S -> C":
regexInfo.mode == "B"? "S <-> C": "🤔"
let regex_expr = getHumanReadableRegex(regexInfo.regex);
let exact_regex = true;
if (regex_expr.length>=4 && regex_expr.startsWith(".*") && regex_expr.endsWith(".*")){
regex_expr = regex_expr.substring(2,regex_expr.length-2)
exact_regex = false;
}
return <div className={style.box}> return <div className={style.box}>
<TextInput <Grid>
<Grid.Col span={2}>
<Title order={2} style={{color:"#FFF"}}>Regex:</Title>
</Grid.Col>
<Grid.Col span={8}>
<Text className={style.regex_text}> {regex_expr}</Text>
</Grid.Col>
<Grid.Col span={2}>
<ActionIcon color="red" onClick={()=>{}} size="xl" radius="md" variant="filled"><BsTrashFill size={22} /></ActionIcon>
</Grid.Col>
<Grid.Col span={2} />
<Grid.Col className='center-flex-row' span={4}>
<Space h="xs" />
<SegmentedControl
data={[
{
value: 'blacklist',
label: (
<Center style={{color:"#FFF"}}>
<TiCancel size={23} color="red"/>
<Box ml={10}>Blacklist</Box>
</Center>
),
},
{
value: 'whitelist',
label: (
<Center style={{color:"#FFF"}}>
<FaListAlt size={16} color="gray"/>
<Box ml={10}>Whitelist</Box>
</Center>
),
},
]}
size="md"
color="gray"
disabled disabled
value={getHumanReadableRegex(regexInfo.regex)}
/> />
<Space h="md" />
<div className='center-flex'>
<Badge size="md" color="green" variant="filled">Service: {regexInfo.service_id}</Badge>
<Space w="xs" />
<Badge size="md" color="gray" variant="filled">ID: {regexInfo.id}</Badge>
</div>
</Grid.Col>
<Grid.Col style={{width:"100%"}} span={6}>
<Space h="xs" />
<div className='center-flex-row'>
<Badge size="md" color={exact_regex?"grape":"pink"} variant="filled">Match: {exact_regex?"EXACT":"FIND"}</Badge>
<Space h="xs" />
<Badge size="md" color="yellow" variant="filled">Packets filtered: {regexInfo.n_packets}</Badge>
<Space h="xs" />
<Badge size="md" color="blue" variant="filled">Mode: {mode_string}</Badge>
</div>
</Grid.Col>
</Grid>
</div> </div>
} }

View File

@@ -14,4 +14,5 @@
font-weight: bolder; font-weight: bolder;
margin-right: 10px; margin-right: 10px;
margin-bottom: 13px; margin-bottom: 13px;
color:#FFF;
} }

View File

@@ -6,7 +6,7 @@ import { MdOutlineArrowForwardIos } from "react-icons/md"
import style from "./ServiceRow.module.scss"; import style from "./ServiceRow.module.scss";
//"status":"stop"/"wait"/"active"/"pause", //"status":"stop"/"wait"/"active"/"pause",
function ServiceRow({ service, onClick }:{ service:Service, onClick?:()=>void }) { function ServiceRow({ service, onClick, additional_buttons }:{ service:Service, onClick?:()=>void, additional_buttons?:any }) {
let status_color = "gray"; let status_color = "gray";
switch(service.status){ switch(service.status){
@@ -32,6 +32,7 @@ function ServiceRow({ service, onClick }:{ service:Service, onClick?:()=>void })
</div> </div>
<Space w="xl" /><Space w="xl" /> <Space w="xl" /><Space w="xl" />
<div className="center-flex"> <div className="center-flex">
{additional_buttons}
<ActionIcon color={service.status === "pause"?"yellow":"red"} size="xl" radius="md" variant="filled" disabled={!["wait","active","pause"].includes(service.status)?true:false}> <ActionIcon color={service.status === "pause"?"yellow":"red"} size="xl" radius="md" variant="filled" disabled={!["wait","active","pause"].includes(service.status)?true:false}>
{service.status === "pause"?<FaStop size="20px" />:<FaPause size="20px" />} {service.status === "pause"?<FaStop size="20px" />:<FaPause size="20px" />}
</ActionIcon> </ActionIcon>

View File

@@ -34,5 +34,6 @@ export type RegexFilter = {
service_id:string, service_id:string,
regex:string regex:string
is_blacklist:boolean, is_blacklist:boolean,
mode:string // C->S S->C BOTH mode:string //C S B => C->S S->C BOTH
n_packets:number
} }

View File

@@ -1,6 +1,7 @@
import { Grid, Space, Title } from '@mantine/core'; import { ActionIcon, Grid, Space, Title } from '@mantine/core';
import { showNotification } from '@mantine/notifications'; import { showNotification } from '@mantine/notifications';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { BsTrashFill } from 'react-icons/bs';
import { ImCross } from 'react-icons/im'; import { ImCross } from 'react-icons/im';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import RegexView from '../components/RegexView'; import RegexView from '../components/RegexView';
@@ -26,22 +27,17 @@ function ServiceDetails() {
id:3546, id:3546,
is_blacklist:true, is_blacklist:true,
mode:"B", mode:"B",
regex:"d2VkcmZoaXdlZGZoYnVp", regex:"LipmbGFnX2NoZWNrLio=",
service_id:"ctfe" service_id:"ctfe",
n_packets:5,
}, },
{ {
id:3546, id:3546,
is_blacklist:true, is_blacklist:true,
mode:"B", mode:"B",
regex:"d2VkcmZoaXdlZGZoYnVp", regex:"d2VkcmZoaXdlZGZoYnVp",
service_id:"ctfe" service_id:"ctfe",
}, n_packets: 54
{
id:3546,
is_blacklist:true,
mode:"B",
regex:"d2VkcmZoaXdlZGZoYnVp",
service_id:"ctfe"
} }
]) ])
@@ -84,7 +80,10 @@ function ServiceDetails() {
}, []); }, []);
return <> return <>
<ServiceRow service={serviceInfo}></ServiceRow> <ServiceRow service={serviceInfo} additional_buttons={<>
<ActionIcon color="red" onClick={()=>{}} size="xl" radius="md" variant="filled"><BsTrashFill size={22} /></ActionIcon>
<Space w="md"/>
</>}></ServiceRow>
{regexesList.length === 0? {regexesList.length === 0?
<><Space h="xl" /> <Title className='center-flex' order={1}>No regex found for this service! Add one clicking the add button above</Title></>: <><Space h="xl" /> <Title className='center-flex' order={1}>No regex found for this service! Add one clicking the add button above</Title></>:
<Grid> <Grid>