diff options
Diffstat (limited to 'web/src/js/filt/filt.peg')
-rw-r--r-- | web/src/js/filt/filt.peg | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/web/src/js/filt/filt.peg b/web/src/js/filt/filt.peg index f3235ccd..64780d8a 100644 --- a/web/src/js/filt/filt.peg +++ b/web/src/js/filt/filt.peg @@ -77,6 +77,16 @@ function domain(regex){ domainFilter.desc = "domain matches " + regex; return domainFilter; } +function destination(regex){ + regex = new RegExp(regex, "i"); + function destinationFilter(flow){ + return (!!flow.server_conn.address) + && + regex.test(flow.server_conn.address.address[0] + ":" + flow.server_conn.address.address[1]); + } + destinationFilter.desc = "destination address matches " + regex; + return destinationFilter; +} function errorFilter(flow){ return !!flow.error; } @@ -133,7 +143,16 @@ function responseFilter(flow){ return !!flow.response; } responseFilter.desc = "has response"; - +function source(regex){ + regex = new RegExp(regex, "i"); + function sourceFilter(flow){ + return (!!flow.client_conn.address) + && + regex.test(flow.client_conn.address.address[0] + ":" + flow.client_conn.address.address[1]); + } + sourceFilter.desc = "source address matches " + regex; + return sourceFilter; +} function contentType(regex){ regex = new RegExp(regex, "i"); function contentTypeFilter(flow){ @@ -205,36 +224,33 @@ BindingExpr { return binding(expr); } / Expr -Expr - = NullaryExpr - / UnaryExpr +/* All the filters except "~s" and "~src" are arranged in the ascending order as + given in the docs(http://docs.mitmproxy.org/en/latest/features/filters.html). + "~s" and "~src" are so arranged as "~s" caused problems in the evaluation of + "~src". */ -NullaryExpr - = BooleanLiteral +Expr + = "true" { return trueFilter; } + / "false" { return falseFilter; } / "~a" { return assetFilter; } + / "~c" ws+ s:IntegerLiteral { return responseCode(s); } + / "~d" ws+ s:StringLiteral { return domain(s); } + / "~dst" ws+ s:StringLiteral { return destination(s); } / "~e" { return errorFilter; } + / "~h" ws+ s:StringLiteral { return header(s); } + / "~hq" ws+ s:StringLiteral { return requestHeader(s); } + / "~hs" ws+ s:StringLiteral { return responseHeader(s); } / "~http" { return httpFilter; } + / "~m" ws+ s:StringLiteral { return method(s); } / "~marked" { return markedFilter; } / "~q" { return noResponseFilter; } + / "~src" ws+ s:StringLiteral { return source(s); } / "~s" { return responseFilter; } + / "~t" ws+ s:StringLiteral { return contentType(s); } / "~tcp" { return tcpFilter; } - - -BooleanLiteral - = "true" { return trueFilter; } - / "false" { return falseFilter; } - -UnaryExpr - = "~c" ws+ s:IntegerLiteral { return responseCode(s); } - / "~d" ws+ s:StringLiteral { return domain(s); } - / "~h" ws+ s:StringLiteral { return header(s); } - / "~hq" ws+ s:StringLiteral { return requestHeader(s); } - / "~hs" ws+ s:StringLiteral { return responseHeader(s); } - / "~m" ws+ s:StringLiteral { return method(s); } - / "~t" ws+ s:StringLiteral { return contentType(s); } / "~tq" ws+ s:StringLiteral { return requestContentType(s); } / "~ts" ws+ s:StringLiteral { return responseContentType(s); } - / "~u" ws+ s:StringLiteral { return url(s); } + / "~u" ws+ s:StringLiteral { return url(s); } / s:StringLiteral { return url(s); } IntegerLiteral "integer" |