added basic file up_download functionality (not finish yet)
This commit is contained in:
parent
3e6a74f4ee
commit
dfc033ab5f
|
@ -87,6 +87,9 @@ class WebState(flow.State):
|
|||
data=[]
|
||||
)
|
||||
|
||||
def load_flows(self, flows):
|
||||
super(WebState, self).load_flows(flows)
|
||||
|
||||
|
||||
class Options(object):
|
||||
attributes = [
|
||||
|
|
|
@ -8,6 +8,8 @@ import re
|
|||
|
||||
import six
|
||||
import tornado.websocket
|
||||
from six.moves import cStringIO as StringIO
|
||||
from mitmproxy.flow import FlowWriter, FlowReader
|
||||
|
||||
from mitmproxy import filt
|
||||
from mitmproxy import version
|
||||
|
@ -159,6 +161,26 @@ class Flows(RequestHandler):
|
|||
data=[_strip_content(f.get_state()) for f in self.state.flows]
|
||||
))
|
||||
|
||||
class DumpFlows(RequestHandler):
|
||||
def get(self):
|
||||
self.set_header("Content-Description", "File Transfer")
|
||||
self.set_header("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
self.set_header("Content-Disposition", "attachment; filename=flows")
|
||||
self.set_header("Content-Type", "application/octet-stream")
|
||||
self.set_header("Content-Transfer-Encoding", "binary")
|
||||
|
||||
sio = StringIO()
|
||||
fw = FlowWriter(sio)
|
||||
for f in self.state.flows:
|
||||
fw.add(f)
|
||||
self.write(sio.getvalue())
|
||||
|
||||
sio.close()
|
||||
|
||||
def post(self):
|
||||
sio = StringIO(self.request.body)
|
||||
self.state.load_flows(FlowReader(sio).stream())
|
||||
sio.close()
|
||||
|
||||
class ClearAll(RequestHandler):
|
||||
|
||||
|
@ -356,6 +378,7 @@ class Application(tornado.web.Application):
|
|||
(r"/updates", ClientConnection),
|
||||
(r"/events", Events),
|
||||
(r"/flows", Flows),
|
||||
(r"/flows/dump", DumpFlows),
|
||||
(r"/flows/accept", AcceptFlows),
|
||||
(r"/flows/(?P<flow_id>[0-9a-f\-]+)", FlowHandler),
|
||||
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/accept", AcceptFlow),
|
||||
|
|
|
@ -117,6 +117,13 @@ export var FlowActions = {
|
|||
},
|
||||
clear: function(){
|
||||
$.post("/clear");
|
||||
},
|
||||
download: () => window.location = "/flows/dump",
|
||||
upload: (file) => {
|
||||
var filereader = new FileReader();
|
||||
filereader.file = file;
|
||||
filereader.onload = (e) => $.post("/flows/dump", e.target.result);
|
||||
filereader.readAsBinaryString(file);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -345,11 +345,14 @@ var FileMenu = React.createClass({
|
|||
},
|
||||
handleOpenClick: function (e) {
|
||||
e.preventDefault();
|
||||
console.error("unimplemented: handleOpenClick");
|
||||
},
|
||||
handleOpenChange: function (e) {
|
||||
e.preventDefault();
|
||||
FlowActions.upload(e.target.files[0]);
|
||||
},
|
||||
handleSaveClick: function (e) {
|
||||
e.preventDefault();
|
||||
console.error("unimplemented: handleSaveClick");
|
||||
FlowActions.download();
|
||||
},
|
||||
handleShutdownClick: function (e) {
|
||||
e.preventDefault();
|
||||
|
@ -369,10 +372,7 @@ var FileMenu = React.createClass({
|
|||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" onClick={this.handleOpenClick}>
|
||||
<i className="fa fa-fw fa-folder-open"></i>
|
||||
Open...
|
||||
</a>
|
||||
<input type="file" onChange={this.handleOpenChange}/>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" onClick={this.handleSaveClick}>
|
||||
|
@ -388,18 +388,6 @@ var FileMenu = React.createClass({
|
|||
</a>
|
||||
</li>
|
||||
{/*
|
||||
<li>
|
||||
<a href="#" onClick={this.handleOpenClick}>
|
||||
<i className="fa fa-fw fa-folder-open"></i>
|
||||
Open
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" onClick={this.handleSaveClick}>
|
||||
<i className="fa fa-fw fa-save"></i>
|
||||
Save
|
||||
</a>
|
||||
</li>
|
||||
<li role="presentation" className="divider"></li>
|
||||
<li>
|
||||
<a href="#" onClick={this.handleShutdownClick}>
|
||||
|
|
Loading…
Reference in New Issue