forked from Veallym0n/PyFiddler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.html
262 lines (239 loc) · 12.9 KB
/
main.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!doctype html>
<html>
<head>
<title>PyFiddler </title>
<script src="http://cdn.bootcss.com/jquery/3.0.0-alpha1/jquery.js"></script>
<link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<style>
#tblog td {word-break:break-all;}
.mag {margin-left:5px; margin-bottom:5px; }
</style>
<script>
bkstat = {brs:'off',brq:'off'}
function changebk(t){
var b = $(t).attr('data-btype')
if(bkstat[b]=='off'){
bkstat[b]='on'
$(t).text('Release Request').removeClass('btn-primary').addClass('btn-danger')
}else{
bkstat[b]='off'
$(t).text('Block Request').removeClass('btn-danger').addClass('btn-primary')
}
$.get('ctrl',bkstat,function(d){
})
}
function release(t){
if(t==0){
var rlst = 'request'
var uuid = $('#req_info').attr('data-uuid')
var method = $('#Fmethod').val()
var url = $('#Furl').val()
var headers = $('#req_info #Fheaders').val()
var body = $('#req_info #Fbody').val()
var vargs = {uuid:uuid,rlst:rlst,method:method,url:url,headers:headers,body:body}
$.post('release',vargs,function(d){
})
}else if(t==1){
var rlst = 'response'
var uuid = $('#res_info').attr('data-uuid')
var code = $('#Fcode').val()
var reason = $('#FReason').val()
var headers = $('#res_info #Fheaders').val()
var body = $('#res_info #Fbody').val()
var vargs = {uuid:uuid,rlst:rlst,code:code,reason:reason,headers:headers,body:body}
$.post('release',vargs,function(d){
})
}else if(t==2){
$.get('releaseall')
}
}
function initws(){
var ws = new WebSocket('ws://'+new URL(document.URL).host+'/ws')
ws.onmessage = function(e){
var data = JSON.parse(e.data)
var uuid = data[0]
var item = data[1]
if($('tr[data-uuid='+uuid+']').length){
var color = codecolor(item.code)
var ellist = $('tr[data-uuid='+uuid+'] td')
var item = [item.Type,item.id,item.method,item.code,item.protocol,item.url,item.bodylen,item.cType]
ellist.each(function(i,d){$(d).text(item[i])})
$('tr[data-uuid='+uuid+']').removeClass().addClass(color)
}else{
var pad = ' class="'+codecolor(item.code)+'" '
var info = [item.Type,item.id,item.method,item.code,item.protocol,item.url,item.bodylen,item.cType]
var html = $('<tr '+pad+'data-uuid="'+uuid+'"><td>'+info.join('</td><td>')+'</td></tr>')
$('#tblog tbody').append(html)
html.on('click',function(){
fetchDetail($(this).attr('data-uuid'))
$('#tblog tbody tr').removeClass('info')
$(this).addClass('info')
$('#control-panel').fadeIn()
})
}
}
}
function codecolor(code){
if(code>=100 && code<200){
return 'text-muted'
}else if(code>=200 && code<300){
return 'text-success'
}else if(code>=300 && code<400){
return 'text-warning'
}else if(code>=400){
return 'text-danger'
}
}
function genReqForm(uuid,d){
var render = $('#req_info').attr('data-uuid',uuid)
render.html(null)
var Fmethod = $('<input id="Fmethod" class="mag form-control input-sm" placeholder="Method">').val(d.method).css('width','80px')
render.append(Fmethod)
var Furl = $('<input id="Furl" class="mag form-control input-sm" placeholder="URI">').val(d.url).css('width','60%')
render.append(Furl).append(' <span class="mag label label-info">HTTP/1.1</span><br />')
var Fheaders = $('<textarea id="Fheaders" class="mag form-control" wrap="soft"></textarea>').css('width','100%').css('height','150px').css('font-size','10px').css('white-space','nowrap')
d.req.headers.forEach(function(h){
Fheaders.text(Fheaders.text()+h[0]+': '+h[1]+'\r\n')
})
render.append(Fheaders)
var Fbody = $('<textarea placeholder="body" id="Fbody" class="mag form-control" wrap="soft"></textarea>').css('width','100%').css('height','100px').css('font-size','10px').css('white-space','nowrap').val(d.req.body)
render.append(Fbody)
var btnreleasehtml = $('<br><b class="mag btn btn-primary" onclick="release(0)">Save and Release</b>')
var btnclonehtml = $('<b class="mag btn btn-info" onclick="Clone(this)">Clone</b>').attr('data-uuid',uuid)
render.append(btnreleasehtml)
render.append(btnclonehtml)
if(d.Type!='request'){
$('#req_info .btn:first').attr('disabled','disabled')
$('#req_info input').attr('readonly','readonly')
$('#req_info textarea').attr('readonly','readonly')
}
}
function genResForm(uuid,d){
var render = $('#res_info').attr('data-uuid',uuid)
render.html(null)
render.append('<span class="label label-info mag">HTTP/1.1</span>')
var Fcode = $('<input id="Fcode" class="mag form-control input-sm" placeholder="Fcode">').val(d.code).css('width','50px')
render.append(Fcode)
var Freason = $('<input id="FReason" class="mag form-control input-sm" placeholder="Reason">').val(d.res.reason).css('width','150px')
render.append(Freason).append('<br>')
var Fheaders = $('<textarea id="Fheaders" class="mag form-control" wrap="soft"></textarea>').css('width','100%').css('height','150px').css('font-size','10px').css('white-space','nowrap')
d.res.headers.forEach(function(h){
Fheaders.text(Fheaders.text()+h[0]+': '+h[1]+'\r\n')
})
render.append(Fheaders)
var Fbody = $('<textarea placeholder="body" id="Fbody" class="mag form-control" wrap="soft"></textarea>').css('width','100%').css('height','100px').css('font-size','10px').css('white-space','nowrap').val(d.res.body)
render.append(Fbody)
var btnhtml = '<br><b class="mag btn btn-primary" onclick="release(1)">Save and Release</b>'
render.append(btnhtml)
if(d.Type!='response'){
$('#res_info .btn:first').attr('disabled','disabled')
$('#res_info input').attr('readonly','readonly')
$('#res_info textarea').attr('readonly','readonly')
}
}
function fetchDetail(uuid){
$.getJSON('detail',{uuid:uuid}, function(d){
if(d.Type=='request') {
genReqForm(uuid,d)
}else{
genReqForm(uuid,d)
genResForm(uuid,d)
}
})
}
function Clone(o){
var uuid = $(o).attr('data-uuid')
$.getJSON('clone',{uuid:uuid}, function(d){
})
}
function logTable(){
var codep = {404:'text-danger','304':'text-warning','200':'text-success','204':'text-muted','403':'text-danger'}
$.getJSON('show',function(d){
$('#tblog tbody').html('')
for(var uuid in d){
var item = d[uuid]
var pad = ' class="'+codecolor(item.code)+'" '
var info = [item.Type,item.id,item.method,item.code,item.protocol,item.url,item.bodylen,item.cType]
var html = '<tr '+pad+'data-uuid="'+uuid+'"><td>'+info.join('</td><td>')+'</td></tr>'
$('#tblog tbody').append(html)
}
$('#tblog tbody tr').on('click',function(e){
fetchDetail($(this).attr('data-uuid'))
$('#tblog tbody tr').removeClass('info')
$(this).addClass('info')
$('#control-panel').fadeIn()
})
})
}
function clearlog(){
$.get('clearlog',function(d){
$('#tblog tbody').html('')
})
}
$(document).ready(function(){
logTable()
initws()
$('.panel-heading').on('click',function(){$(this).next('.panel-body').slideToggle('fast')})
})
</script>
</head>
<body>
<div class="container-fluid" style="padding:10px 5px 0px 5px">
<div class="alert alert-info">
<span style="font-size:16px">PyFiddler</span>
<span> | <i class="btn btn-primary btn-xs" onclick="clearlog()">clear log</i></span>
<span> | <i class="btn btn-success btn-xs" onclick="release(2)">Release All</i></span>
<span> | <i class="btn btn-primary btn-xs" data-btype="brq" onclick="changebk(this)">Block Request</i></span>
<span> | <i class="btn btn-primary btn-xs" data-btype="brs" onclick="changebk(this)">Block Response</i></span>
</div>
<div class="row" style="margin: 0px 0px 0px 0px">
<div class="col-md-6 col-lg-6">
<div class="panel panel-primary">
<div class="panel-heading">Sniffer Logger</div>
<div class="panel-body" style="max-height:900px;overflow:auto">
<table class="table table-bordered table-hover table-striped table-condensed" style="font-size:10px;table-layout:fixed" id="tblog">
<thead>
<tr>
<td style="width:60px">status</td>
<td style="width:35px"># ID</td>
<td style="width:70px">method</td>
<td style="width:38px">code</td>
<td style="width:40px">proto</td>
<td style="">url</td>
<td style="width:52px">length</td>
<td style="width:138px">type</td>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<div class="col-md-6 col-lg-6">
<div class="panel panel-success">
<div class="panel-heading">Control</div>
<div class="panel-body">
<div class="panel panel-default">
<div class="panel-heading">Request</div>
<div class="panel-body">
<div class="form-inline">
<div class="form-group" id="req_info" style="font-size:10px;width:100%"></div>
</div>
</div>
</div>
<hr>
<div class="panel panel-default">
<div class="panel-heading">Response</div>
<div class="panel-body">
<div class="form-inline">
<div class="form-group" id="res_info" style="font-size:10px;width:100%"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>