Add hover menu to FlowRow

This commit is contained in:
zokutyou2@gmail.com 2021-06-07 15:25:38 +09:00
parent 6d2b823a54
commit 2ce0f45fe4
5 changed files with 164 additions and 0 deletions

View File

@ -380,6 +380,16 @@ class FDst(_Rex):
r = "{}:{}".format(f.server_conn.address[0], f.server_conn.address[1])
return f.server_conn.address and self.re.search(r)
class FDstIP(_Rex):
code ="ip"
help = "Match destination ip address"
is_binary = False
def __call__(self, f):
if not f.server_conn or not f.server_conn.ip_address:
return False
return f.server_conn.ip_address and self.re.search(f.server_conn.ip_address[0])
class FReplay(_Action):
code = "replay"
@ -514,6 +524,7 @@ filter_rex: Sequence[Type[_Rex]] = [
FContentTypeResponse,
FDomain,
FDst,
FDstIP,
FHead,
FHeadRequest,
FHeadResponse,

View File

@ -48,5 +48,76 @@ exports[`FlowRow Component should render correctly 1`] = `
>
3s
</td>
<div
className="dropdown pull-left btn btn-default"
>
<a
className="special"
href="#"
onClick={[Function]}
>
Actions
</a>
<ul
className="dropdown-menu"
role="menu"
>
<li>
<a
href="#"
onClick={[Function]}
>
<i
className="fa fa-fw fa-plus"
/>
 Intercept
address
</a>
</li>
<li>
<a
href="#"
onClick={[Function]}
>
<i
className="fa fa-fw fa-plus"
/>
 Intercept
address/path
</a>
</li>
<li>
<a
href="#"
onClick={[Function]}
>
<i
className="fa fa-fw fa-plus"
/>
 Intercept all POST requests from this host
</a>
</li>
<li>
<a
href="#"
onClick={[Function]}
>
<i
className="fa fa-fw fa-plus"
/>
 Intercept all requests from
192.168.0.1
</a>
</li>
</ul>
</div>
</tr>
`;

View File

@ -4,6 +4,7 @@ import classnames from 'classnames'
import {defaultColumnNames} from './FlowColumns'
import { pure } from '../../utils'
import {getDisplayColumns} from './FlowTableHead'
import HoverMenu from './HoverMenu'
import { connect } from 'react-redux'
FlowRow.propTypes = {
@ -29,6 +30,7 @@ function FlowRow({ flow, selected, highlighted, onSelect, displayColumnNames })
{displayColumns.map(Column => (
<Column key={Column.name} flow={flow}/>
))}
<HoverMenu/>
</tr>
)
}

View File

@ -0,0 +1,69 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { update as updateSettings } from "../../ducks/settings"
import Dropdown from '../common/Dropdown'
class HoverMenu extends Component {
constructor(props, context) {
super(props, context)
}
onClick(e, example) {
e.preventDefault();
let intercept = this.props.intercept
if (intercept && intercept.includes(example)) {
return
}
if (!intercept) {
intercept = example
} else {
intercept = `${intercept} | ${example}`
}
this.props.updateSettings({ intercept })
}
render() {
const { flow } = this.props
if (!flow) {
return null
}
return (
<Dropdown className="pull-left btn btn-default" btnClass="special" icon="fa-ellipsis-v" text="Actions">
<a href="#" onClick={(e) =>{
this.onClick(e, flow.request.host)
}}>
<i className="fa fa-fw fa-plus"></i>
&nbsp;Intercept {flow.request.host}
</a>
<a href="#" onClick={(e) =>{
this.onClick(e, flow.request.host + flow.request.path)
}}>
<i className="fa fa-fw fa-plus"></i>
&nbsp;Intercept {flow.request.host + flow.request.path}
</a>
<a href="#" onClick={(e) =>{
this.onClick(e, `~m POST & ${flow.request.host}`)
}}>
<i className="fa fa-fw fa-plus"></i>
&nbsp;Intercept all POST requests from this host
</a>
<a href="#" onClick={(e) =>{
this.onClick(e, `~ip ${flow.server_conn.ip_address[0]}`)
}}>
<i className="fa fa-fw fa-plus"></i>
&nbsp;Intercept all requests from {flow.server_conn.ip_address[0]}
</a>
</Dropdown>
)
}
}
export default connect(
state => ({
flow: state.flows.byId[state.flows.selected[0]],
intercept: state.settings.intercept,
}),
{
updateSettings,
}
)(HoverMenu)

View File

@ -111,6 +111,16 @@ function destination(regex){
destinationFilter.desc = "destination address matches " + regex;
return destinationFilter;
}
function ip(regex) {
regex = new RegExp(regex, "i");
function ipFilter(flow){
return (!!flow.server_conn.ip_address)
&&
regex.test(flow.server_conn.ip_address[0] + ":" + flow.server_conn.ip_address[1]);
}
ipFilter.desc = "destination ip address matches " + regex;
return ipFilter;
}
function errorFilter(flow){
return !!flow.error;
}
@ -267,6 +277,7 @@ Expr
/ "~c" ws+ s:IntegerLiteral { return responseCode(s); }
/ "~d" ws+ s:StringLiteral { return domain(s); }
/ "~dst" ws+ s:StringLiteral { return destination(s); }
/ "~ip" ws+ s:StringLiteral { return ip(s); }
/ "~e" { return errorFilter; }
/ "~h" ws+ s:StringLiteral { return header(s); }
/ "~hq" ws+ s:StringLiteral { return requestHeader(s); }