mirror of
https://github.com/mitmproxy/mitmproxy.git
synced 2024-11-27 23:30:28 +00:00
[dns] use snake_case in web flows
This commit is contained in:
parent
1a4f5f61e7
commit
ea6f9727da
@ -390,6 +390,17 @@ class Question(BypassInitStateObject):
|
||||
else:
|
||||
raise ResolveError(ResponseCode.NOTIMP)
|
||||
|
||||
def to_json(self) -> dict:
|
||||
"""
|
||||
Converts the question into json for mitmweb.
|
||||
Sync with web/src/flow.ts.
|
||||
"""
|
||||
return {
|
||||
"name": self.name,
|
||||
"type": self.type.name,
|
||||
"class": self.class_.name,
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class ResourceRecord(BypassInitStateObject):
|
||||
@ -415,8 +426,8 @@ class ResourceRecord(BypassInitStateObject):
|
||||
if self.type is Type.TXT:
|
||||
return self.text
|
||||
except:
|
||||
return f"(invalid {self.type.name} data)"
|
||||
return self.data.hex()
|
||||
return f"0x{self.data.hex()} (invalid {self.type.name} data)"
|
||||
return f"0x{self.data.hex()}"
|
||||
|
||||
@property
|
||||
def text(self) -> str:
|
||||
@ -452,7 +463,7 @@ class ResourceRecord(BypassInitStateObject):
|
||||
|
||||
def to_json(self) -> dict:
|
||||
"""
|
||||
Converts the resource record into json for the mitmweb.
|
||||
Converts the resource record into json for mitmweb.
|
||||
Sync with web/src/flow.ts.
|
||||
"""
|
||||
return {
|
||||
@ -737,24 +748,20 @@ class Message(BypassInitStateObject):
|
||||
|
||||
def to_json(self) -> dict:
|
||||
"""
|
||||
Converts the message into json for the mitmweb.
|
||||
Converts the message into json for mitmweb.
|
||||
Sync with web/src/flow.ts.
|
||||
"""
|
||||
return {
|
||||
"id": self.id,
|
||||
"query": self.query,
|
||||
"opCode": self.op_code.name,
|
||||
"authoritativeAnswer": self.authoritative_answer,
|
||||
"op_code": self.op_code.name,
|
||||
"authoritative_answer": self.authoritative_answer,
|
||||
"truncation": self.truncation,
|
||||
"recursionDesired": self.recursion_desired,
|
||||
"recursionAvailable": self.recursion_available,
|
||||
"responseCode": self.response_code.name,
|
||||
"responseCodeHttpEquiv": self.response_code.http_equiv_status_code,
|
||||
"questions": [{
|
||||
"name": question.name,
|
||||
"type": question.type.name,
|
||||
"class": question.class_.name,
|
||||
} for question in self.questions],
|
||||
"recursion_desired": self.recursion_desired,
|
||||
"recursion_available": self.recursion_available,
|
||||
"response_code": self.response_code.name,
|
||||
"status_code": self.response_code.http_equiv_status_code,
|
||||
"questions": [question.to_json() for question in self.questions],
|
||||
"answers": [rr.to_json() for rr in self.answers],
|
||||
"authorities": [rr.to_json() for rr in self.authorities],
|
||||
"additionals": [rr.to_json() for rr in self.additionals],
|
||||
|
4
mitmproxy/tools/web/static/app.js
vendored
4
mitmproxy/tools/web/static/app.js
vendored
File diff suppressed because one or more lines are too long
@ -18,10 +18,10 @@ class TestResourceRecord:
|
||||
assert str(dns.ResourceRecord.CNAME("test", "some.other.host")) == "some.other.host"
|
||||
assert str(dns.ResourceRecord.PTR("test", "some.other.host")) == "some.other.host"
|
||||
assert str(dns.ResourceRecord.TXT("test", "unicode text 😀")) == "unicode text 😀"
|
||||
assert str(dns.ResourceRecord("test", dns.Type.A, dns.Class.IN, dns.ResourceRecord.DEFAULT_TTL, b'')) == "(invalid A data)"
|
||||
assert str(dns.ResourceRecord("test", dns.Type.A, dns.Class.IN, dns.ResourceRecord.DEFAULT_TTL, b'')) == "0x (invalid A data)"
|
||||
assert str(
|
||||
dns.ResourceRecord("test", dns.Type.SOA, dns.Class.IN, dns.ResourceRecord.DEFAULT_TTL, b'\x00\x01\x02\x03')
|
||||
) == "00010203"
|
||||
) == "0x00010203"
|
||||
|
||||
def test_setter(self):
|
||||
rr = dns.ResourceRecord("test", dns.Type.ANY, dns.Class.IN, dns.ResourceRecord.DEFAULT_TTL, b'')
|
||||
@ -58,7 +58,7 @@ class TestQuestion:
|
||||
dns.Question("dns.google", dns.Type.A, dns.Class.IN),
|
||||
lambda rr: rr.ipv4_address == ipaddress.IPv4Address("8.8.8.8")
|
||||
)
|
||||
if platform.system() != "Windows":
|
||||
if platform.system() == "Linux": # will fail on Windows, apparently returns empty on Mac
|
||||
await succeed_with(
|
||||
dns.Question("dns.google", dns.Type.AAAA, dns.Class.IN),
|
||||
lambda rr: rr.ipv6_address == ipaddress.IPv6Address("2001:4860:4860::8888")
|
||||
|
@ -113,30 +113,26 @@ method.headerName = 'Method'
|
||||
method.sortKey = flow => {
|
||||
switch (flow.type) {
|
||||
case "http": return flow.websocket ? (flow.client_conn.tls_established ? "WSS" : "WS") : flow.request.method
|
||||
case "dns": return flow.request.opCode
|
||||
case "dns": return flow.request.op_code
|
||||
default: return flow.type.toUpperCase()
|
||||
}
|
||||
}
|
||||
|
||||
export const status: FlowColumn = ({flow}) => {
|
||||
let color = 'darkred';
|
||||
let httpStatusCode =
|
||||
flow.type === "http" ? flow.response?.status_code :
|
||||
flow.type === "dns" ? flow.response?.responseCodeHttpEquiv :
|
||||
undefined
|
||||
let color = 'darkred'
|
||||
|
||||
if (httpStatusCode == undefined)
|
||||
if ((flow.type !== "http" && flow.type != "dns") || !flow.response)
|
||||
return <td className="col-status"/>
|
||||
|
||||
if (100 <= httpStatusCode && httpStatusCode < 200) {
|
||||
if (100 <= flow.response.status_code && flow.response.status_code < 200) {
|
||||
color = 'green'
|
||||
} else if (200 <= httpStatusCode && httpStatusCode < 300) {
|
||||
} else if (200 <= flow.response.status_code && flow.response.status_code < 300) {
|
||||
color = 'darkgreen'
|
||||
} else if (300 <= httpStatusCode && httpStatusCode < 400) {
|
||||
} else if (300 <= flow.response.status_code && flow.response.status_code < 400) {
|
||||
color = 'lightblue'
|
||||
} else if (400 <= httpStatusCode && httpStatusCode < 500) {
|
||||
} else if (400 <= flow.response.status_code && flow.response.status_code < 500) {
|
||||
color = 'red'
|
||||
} else if (500 <= httpStatusCode && httpStatusCode < 600) {
|
||||
} else if (500 <= flow.response.status_code && flow.response.status_code < 600) {
|
||||
color = 'red'
|
||||
}
|
||||
|
||||
@ -148,7 +144,7 @@ status.headerName = 'Status'
|
||||
status.sortKey = flow => {
|
||||
switch (flow.type) {
|
||||
case "http": return flow.response?.status_code
|
||||
case "dns": return flow.response?.responseCode
|
||||
case "dns": return flow.response?.response_code
|
||||
default: return undefined
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ const Summary: React.FC<{
|
||||
message: DNSMessage
|
||||
}> = ({message}) => (
|
||||
<div>
|
||||
{message.query ? message.opCode : message.responseCode}
|
||||
{message.query ? message.op_code : message.response_code}
|
||||
|
||||
#{message.id}
|
||||
|
||||
@ -19,7 +19,7 @@ const Questions: React.FC<{
|
||||
message: DNSMessage
|
||||
}> = ({message}) => (
|
||||
<table>
|
||||
<caption>{message.recursionDesired ? "Recursive " : ""}Question</caption>
|
||||
<caption>{message.recursion_desired ? "Recursive " : ""}Question</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
@ -78,7 +78,7 @@ const Message: React.FC<{
|
||||
</div>
|
||||
<Questions message={message} />
|
||||
<hr/>
|
||||
<ResourceRecords name={`${message.authoritativeAnswer ? "Authoritative " : ""}${message.recursionAvailable ? "Recursive " : ""}Answer`} values={message.answers} />
|
||||
<ResourceRecords name={`${message.authoritative_answer ? "Authoritative " : ""}${message.recursion_available ? "Recursive " : ""}Answer`} values={message.answers} />
|
||||
<hr/>
|
||||
<ResourceRecords name="Authority" values={message.authorities} />
|
||||
<hr/>
|
||||
|
@ -116,6 +116,12 @@ export interface WebSocketData {
|
||||
timestamp_end?: number
|
||||
}
|
||||
|
||||
export interface DNSQuestion {
|
||||
name: string
|
||||
type: string
|
||||
class: string
|
||||
}
|
||||
|
||||
export interface DNSResourceRecord {
|
||||
name: string
|
||||
type: string
|
||||
@ -127,18 +133,14 @@ export interface DNSResourceRecord {
|
||||
export interface DNSMessage {
|
||||
id: number
|
||||
query: boolean
|
||||
opCode: string
|
||||
authoritativeAnswer: boolean
|
||||
op_code: string
|
||||
authoritative_answer: boolean
|
||||
truncation: boolean
|
||||
recursionDesired: boolean
|
||||
recursionAvailable: boolean
|
||||
responseCode: string
|
||||
responseCodeHttpEquiv: number
|
||||
questions: {
|
||||
name: string
|
||||
type: string
|
||||
class: string
|
||||
}[]
|
||||
recursion_desired: boolean
|
||||
recursion_available: boolean
|
||||
response_code: string
|
||||
status_code: number
|
||||
questions: DNSQuestion[]
|
||||
answers: DNSResourceRecord[]
|
||||
authorities: DNSResourceRecord[]
|
||||
additionals: DNSResourceRecord[]
|
||||
|
Loading…
Reference in New Issue
Block a user