PCRE2 standard applied

This commit is contained in:
DomySh
2022-07-01 02:29:28 +02:00
parent 8d41b94c36
commit 509fdbc8ca
14 changed files with 66 additions and 155 deletions

View File

@@ -1,13 +1,13 @@
{
"files": {
"main.css": "/static/css/main.c375ae17.css",
"main.js": "/static/js/main.bf062beb.js",
"main.js": "/static/js/main.b694f5e6.js",
"index.html": "/index.html",
"main.c375ae17.css.map": "/static/css/main.c375ae17.css.map",
"main.bf062beb.js.map": "/static/js/main.bf062beb.js.map"
"main.b694f5e6.js.map": "/static/js/main.b694f5e6.js.map"
},
"entrypoints": [
"static/css/main.c375ae17.css",
"static/js/main.bf062beb.js"
"static/js/main.b694f5e6.js"
]
}

View File

@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="manifest" href="/site.webmanifest"><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#FFFFFFFF"/><meta name="description" content="Firegex by Pwnzer0tt1"/><title>Firegex</title><script defer="defer" src="/static/js/main.bf062beb.js"></script><link href="/static/css/main.c375ae17.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="manifest" href="/site.webmanifest"><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#FFFFFFFF"/><meta name="description" content="Firegex by Pwnzer0tt1"/><title>Firegex</title><script defer="defer" src="/static/js/main.b694f5e6.js"></script><link href="/static/css/main.c375ae17.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

File diff suppressed because one or more lines are too long

View File

@@ -1,8 +1,8 @@
import { Button, Group, Space, TextInput, Notification, Switch, NativeSelect, Tooltip, Modal } from '@mantine/core';
import { Button, Group, Space, TextInput, Notification, Switch, NativeSelect, Modal } from '@mantine/core';
import { useForm } from '@mantine/hooks';
import React, { useState } from 'react';
import { RegexAddForm } from '../js/models';
import { addregex, b64encode, fireUpdateRequest, getBinaryRegex, getHumanReadableRegex, okNotify } from '../js/utils';
import { addregex, b64decode, b64encode, fireUpdateRequest, okNotify } from '../js/utils';
import { ImCross } from "react-icons/im"
import FilterTypeSelector from './FilterTypeSelector';
@@ -12,7 +12,7 @@ type RegexAddInfo = {
type:string,
mode:string,
is_case_insensitive:boolean,
percentage_encoding:boolean
deactive:boolean
}
function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>void, service:string }) {
@@ -23,7 +23,7 @@ function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>
type:"blacklist",
mode:"C -> S",
is_case_insensitive:false,
percentage_encoding:false
deactive:false
},
validationRules:{
regex: (value) => value !== "",
@@ -45,17 +45,13 @@ function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>
setSubmitLoading(true)
const filter_mode = ({'C -> S':'C', 'S -> C':'S', 'C <-> S':'B'}[values.mode])
let final_regex:string|number[] = values.regex
if (values.percentage_encoding){
final_regex = getBinaryRegex(final_regex)
}
const request:RegexAddForm = {
is_blacklist:values.type !== "whitelist",
is_case_sensitive: !values.is_case_insensitive,
service_id: service,
mode: filter_mode?filter_mode:"B",
regex: b64encode(final_regex)
regex: b64encode(values.regex),
active: !values.deactive
}
setSubmitLoading(false)
addregex(request).then( res => {
@@ -63,7 +59,7 @@ function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>
setSubmitLoading(false)
close();
fireUpdateRequest();
okNotify(`Regex ${getHumanReadableRegex(request.regex)} has been added`, `Successfully added ${request.is_case_sensitive?"case sensitive":"case insensitive"} ${request.is_blacklist?"blacklist":"whitelist"} regex to ${request.service_id} service`)
okNotify(`Regex ${b64decode(request.regex)} has been added`, `Successfully added ${request.is_case_sensitive?"case sensitive":"case insensitive"} ${request.is_blacklist?"blacklist":"whitelist"} regex to ${request.service_id} service`)
}else if (res.toLowerCase() === "invalid regex"){
setSubmitLoading(false)
form.setFieldError("regex", "Invalid Regex")
@@ -87,19 +83,16 @@ function AddNewRegex({ opened, onClose, service }:{ opened:boolean, onClose:()=>
{...form.getInputProps('regex')}
/>
<Space h="md" />
<Tooltip label="To represent binary data use URL encoding. Example: %01" transition="slide-right" openDelay={500} transitionDuration={500} transitionTimingFunction="ease"
color="gray" wrapLines width={220} withArrow position='right' gutter={20}>
<Switch
label="Use percentage encoding for binary values"
{...form.getInputProps('percentage_encoding', { type: 'checkbox' })}
/>
</Tooltip>
<Space h="md" />
<Switch
label="Case insensitive"
{...form.getInputProps('is_case_insensitive', { type: 'checkbox' })}
/>
<Space h="md" />
<Switch
label="Deactivate"
{...form.getInputProps('deactive', { type: 'checkbox' })}
/>
<Space h="md" />
<NativeSelect
data={['C -> S', 'S -> C', 'C <-> S']}
label="Choose the source of the packets to filter"

View File

@@ -1,7 +1,7 @@
import { Grid, Text, Title, Badge, Space, ActionIcon, Tooltip } from '@mantine/core';
import React, { useState } from 'react';
import { RegexFilter } from '../../js/models';
import { activateregex, deactivateregex, deleteregex, errorNotify, fireUpdateRequest, getHumanReadableRegex, okNotify } from '../../js/utils';
import { activateregex, b64decode, deactivateregex, deleteregex, errorNotify, fireUpdateRequest, okNotify } from '../../js/utils';
import style from "./RegexView.module.scss";
import { BsTrashFill } from "react-icons/bs"
import YesNoModal from '../YesNoModal';
@@ -15,7 +15,7 @@ function RegexView({ regexInfo }:{ regexInfo:RegexFilter }) {
regexInfo.mode === "S"? "S -> C":
regexInfo.mode === "B"? "S <-> C": "🤔"
let regex_expr = getHumanReadableRegex(regexInfo.regex);
let regex_expr = b64decode(regexInfo.regex);
const [deleteModal, setDeleteModal] = useState(false);
const [deleteTooltipOpened, setDeleteTooltipOpened] = useState(false);

View File

@@ -4,7 +4,7 @@ import React, { useEffect, useState } from 'react';
import { changeports, fireUpdateRequest, okNotify } from '../../js/utils';
import { ImCross } from "react-icons/im"
import { Service } from '../../js/models';
import { BsArrowDownSquareFill } from 'react-icons/bs';
import { FaLongArrowAltDown } from 'react-icons/fa';
type InputForm = {
internalPort:number,
@@ -70,7 +70,7 @@ function ChangePortModal({ service, opened, onClose }:{ service:Service, opened:
/>
<Space h="xl" />
<Center><BsArrowDownSquareFill size={50}/></Center>
<Center><FaLongArrowAltDown size={50}/></Center>
<NumberInput
placeholder="8080"

View File

@@ -74,5 +74,6 @@ export type RegexAddForm = {
regex:string,
is_case_sensitive:boolean,
is_blacklist:boolean,
mode:string // C->S S->C BOTH
mode:string, // C->S S->C BOTH,
active: boolean
}

View File

@@ -152,50 +152,7 @@ export async function serviceregexlist(service_id:string){
return await getapi(`service/${service_id}/regexes`) as RegexFilter[];
}
const unescapedChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$&'()*+,-./:;<=>?@[\\]^_`{|}~ ";
export function getHumanReadableRegex(regexB64:string){
const regex = Buffer.from(regexB64, "base64")
let res = ""
for (let i=0; i < regex.length; i++){
const byte = String.fromCharCode(regex[i]);
if (unescapedChars.includes(byte)){
res+=byte
}else{
let hex_data = regex[i].toString(16)
if (hex_data.length === 1) hex_data = "0"+hex_data
res+="%"+hex_data
}
}
return res
}
const hexChars = "0123456789abcdefABCDEF"
export function getBinaryRegex(regexPercentageEncoded:string):number[]{
const regex = Buffer.from(regexPercentageEncoded)
let res = []
for (let i=0; i < regex.length; i++){
const byte = String.fromCharCode(regex[i]);
if ("%" === byte){
if(i+2 < regex.length){
const byte_1 = String.fromCharCode(regex[i+1]);
const byte_2 = String.fromCharCode(regex[i+2]);
if(hexChars.includes(byte_1) && hexChars.includes(byte_2)){
res.push(parseInt(byte_1+byte_2,16))
i += 2
}else{
res.push(regex[i])
}
}else{
res.push(regex[i])
}
}else{
res.push(regex[i])
}
}
return res
}
export function errorNotify(title:string, description:string ){
showNotification({
@@ -220,3 +177,7 @@ export function okNotify(title:string, description:string ){
export function b64encode(data:number[]|string){
return Buffer.from(data).toString('base64')
}
export function b64decode(regexB64:string){
return Buffer.from(regexB64, "base64").toString()
}