change some pr issuses

This commit is contained in:
Clemens 2016-06-02 15:12:42 +02:00 committed by Maximilian Hils
parent a219d33430
commit 89fc438e32
5 changed files with 26 additions and 21 deletions

View File

@ -8,7 +8,7 @@ import re
import six import six
import tornado.websocket import tornado.websocket
from six.moves import cStringIO as StringIO from io import BytesIO
from mitmproxy.flow import FlowWriter, FlowReader from mitmproxy.flow import FlowWriter, FlowReader
from mitmproxy import filt from mitmproxy import filt
@ -163,25 +163,22 @@ class Flows(RequestHandler):
class DumpFlows(RequestHandler): class DumpFlows(RequestHandler):
def get(self): 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-Disposition", "attachment; filename=flows")
self.set_header("Content-Type", "application/octet-stream") self.set_header("Content-Type", "application/octet-stream")
self.set_header("Content-Transfer-Encoding", "binary")
sio = StringIO() bio = BytesIO()
fw = FlowWriter(sio) fw = FlowWriter(bio)
for f in self.state.flows: for f in self.state.flows:
fw.add(f) fw.add(f)
self.write(sio.getvalue()) self.write(bio.getvalue())
sio.close() bio.close()
def post(self): def post(self):
# self.state.clear() self.state.clear()
sio = StringIO(self.request.body) bio = BytesIO(self.request.body)
self.state.load_flows(FlowReader(sio).stream()) self.state.load_flows(FlowReader(bio).stream())
sio.close() bio.close()
class ClearAll(RequestHandler): class ClearAll(RequestHandler):
@ -393,7 +390,7 @@ class Application(tornado.web.Application):
settings = dict( settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "templates"), template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"), static_path=os.path.join(os.path.dirname(__file__), "static"),
xsrf_cookies=True, xsrf_cookies=False,
cookie_secret=os.urandom(256), cookie_secret=os.urandom(256),
debug=debug, debug=debug,
wauthenticator=wauthenticator, wauthenticator=wauthenticator,

View File

@ -1,6 +1,7 @@
import $ from "jquery"; import $ from "jquery";
import _ from "lodash"; import _ from "lodash";
import {AppDispatcher} from "./dispatcher.js"; import {AppDispatcher} from "./dispatcher.js";
import {getCookie} from "./utils.js";
export var ActionTypes = { export var ActionTypes = {
// Connection // Connection
@ -119,10 +120,18 @@ export var FlowActions = {
$.post("/clear"); $.post("/clear");
}, },
download: () => window.location = "/flows/dump", download: () => window.location = "/flows/dump",
upload: (file) => { upload: (file) => {
var xsrf = $.param({_xsrf: getCookie("_xsrf")});
//console.log(xsrf);
var filereader = new FileReader(); var filereader = new FileReader();
filereader.file = file; filereader.file = file;
filereader.onload = (e) => {$.post("/flows/dump", e.target.result); e.preventDefault();}; filereader.onload = (e) => {
fetch("/flows/dump?"+xsrf, {
method: 'post',
body: e.currentTarget.result
})
};
filereader.readAsBinaryString(file); filereader.readAsBinaryString(file);
} }
}; };

View File

@ -344,13 +344,13 @@ var FileMenu = React.createClass({
} }
}, },
handleOpenClick: function (e) { handleOpenClick: function (e) {
$('#uploadFileInput').trigger('click'); this.fileInput.click();
e.preventDefault(); e.preventDefault();
}, },
handleOpenFile: function (e) { handleOpenFile: function (e) {
if (e.target.files.length > 0) { if (e.target.files.length > 0) {
FlowActions.upload(e.target.files[0]); FlowActions.upload(e.target.files[0]);
$('#uploadFileInput').val(""); this.fileInput.value = "";
} }
e.preventDefault(); e.preventDefault();
}, },
@ -380,7 +380,7 @@ var FileMenu = React.createClass({
<i className="fa fa-fw fa-folder-open"></i> <i className="fa fa-fw fa-folder-open"></i>
Open... Open...
</a> </a>
<input id="uploadFileInput" className="hidden" type="file" onChange={this.handleOpenFile}/> <input ref={(ref) => this.fileInput = ref} className="hidden" type="file" onChange={this.handleOpenFile}/>
</li> </li>
<li> <li>

View File

@ -2,7 +2,7 @@
import _ from "lodash"; import _ from "lodash";
import $ from "jquery"; import $ from "jquery";
import {EventEmitter} from 'events'; import {EventEmitter} from 'events';
import { EventLogActions } from "../actions.js"
import {ActionTypes, StoreCmds} from "../actions.js"; import {ActionTypes, StoreCmds} from "../actions.js";
import {AppDispatcher} from "../dispatcher.js"; import {AppDispatcher} from "../dispatcher.js";
@ -118,8 +118,7 @@ _.extend(LiveStoreMixin.prototype, {
this.handle_fetch(message.data); this.handle_fetch(message.data);
}.bind(this)) }.bind(this))
.fail(function () { .fail(function () {
//EventLogActions.add_event("Could not fetch " + this.type); EventLogActions.add_event("Could not fetch " + this.type);
console.log("Could not fetch " + this.type); // store.js:121 Uncaught ReferenceError: EventLogActions is not defined
}.bind(this)); }.bind(this));
} }
}, },

View File

@ -76,7 +76,7 @@ export function reverseString(s) {
) + end; ) + end;
} }
function getCookie(name) { export function getCookie(name) {
var r = document.cookie.match(new RegExp("\\b" + name + "=([^;]*)\\b")); var r = document.cookie.match(new RegExp("\\b" + name + "=([^;]*)\\b"));
return r ? r[1] : undefined; return r ? r[1] : undefined;
} }