Skip to content

Commit

Permalink
update Redirect Flow, refactor flow list
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Nov 29, 2012
1 parent b3a7a64 commit 9aea173
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 51 deletions.
1 change: 1 addition & 0 deletions gui/js/HoneyProxy/MainLayout.js
Expand Up @@ -67,6 +67,7 @@ define([
main.selectChild(main.getChildren()[index]);
};
exports.trafficView = trafficView;
exports.trafficPane = trafficPane;

return exports;
});
33 changes: 13 additions & 20 deletions gui/js/HoneyProxy/flows/NotModifiedFlow.js
Expand Up @@ -6,47 +6,40 @@ define(["require",
"dojo/query",
"dojo/dom-construct",
"dojo/Deferred",
"../models/Flow"],function(require,on,query,domConstruct,Deferred,Flow){
"../models/Flow",
"../util/flowlist"],function(require,on,query,domConstruct,Deferred,Flow,flowlist){

function preview(parentPreviewFunc){
return function(){
var deferred = new Deferred();
var flow = this;

require(["../traffic","../MainLayout"],function(traffic,MainLayout){
require(["../traffic"],(function(traffic){
flow.getSimilarFlows(3,function(ids){
var similarFlows = domConstruct.create("span");
var ul = domConstruct.create("ul",{className:"flowlist"});

_.each(ids,function(i){
var f = traffic.get(i);
if(f.response.contentLength > 0){
var li = domConstruct.create(
"li",{'data-flow-id': i},ul);
li.innerText = f.response.contentLengthFormatted + " - " + f.request.date;
}

var flows = _.map(ids, function(i) {
return traffic.get(i);
});
if(ul.children.length > 0){
flows = _.filter(flows, function(f) {
return (f.response.contentLength > 0);
})

var similarFlows = domConstruct.create("span");
if(flows.length > 0){
domConstruct.place("<h3>Similar Flows with Content:</h3>",similarFlows);
domConstruct.place(ul,similarFlows);
domConstruct.place(flowlist(flows),similarFlows);
} else {
domConstruct.place("<p>No similar flows found.</p>",similarFlows)
}

on(ul,"li:click",function(e){
console.log("NotModifiedFlow.li:click",this,arguments);
MainLayout.selectFlow($(e.target).data("flow-id"));
});

var parentPreview = parentPreviewFunc.apply(this,arguments).then(function(content){
var span = domConstruct.create("span");
domConstruct.place(content,span);
domConstruct.place(similarFlows,span);
deferred.resolve(span);
});
});
});
}).bind(this));
return deferred;
}
}
Expand Down
66 changes: 35 additions & 31 deletions gui/js/HoneyProxy/flows/RedirectFlow.js
@@ -1,48 +1,52 @@
/**
* Flow subclass responsible for proper display of images
*/
define(["../models/Flow","require"],function(Flow,require){
define([
"require",
"dojo/Deferred",
"dojo/dom-construct",
"../models/Flow",
"../util/flowlist"
],function(require, Deferred, domConstruct, Flow, flowlist){

function preview(parentPreviewFunc){
return function(domPromise){
var deferred = new Deferred();
var flow = this;
var location = flow.response.getHeader(/^Location$/i);
console.warn(flow);
window.flow = flow;
var div_id = _.uniqueId("redirectLocation");
var out = $("<div>").attr("id", div_id);

var location = flow.response.getHeader(/^Location$/i);

if(location) {
require(["../traffic","../MainLayout"],function(traffic,MainLayout){
var i = flow.id;
while(i < traffic.length && i < flow.id + 100) {
require(["../traffic"],(function(traffic){
var flows = [];
for(var i = flow.id + 1; i < Math.min(traffic.length,flow.id + 100); i++) {
var nextFlow = traffic.get(i);
if(location.indexOf(nextFlow.request.path) >= 0)
if ((flow.response.timestamp + 3) < nextFlow.request.timestamp)
break;
nextFlow = undefined;
if(location.indexOf(nextFlow.request.path) >= 0)
flows.push(nextFlow);
}
domPromise.then(function(){
var container = $("#"+div_id);
var ul = $("<ul>").addClass("flowlist");

if(nextFlow){
ul.append(
$("<li>")
.text(nextFlow.response.contentLengthFormatted + " - " + nextFlow.request.date)
.data("flow-id",nextFlow.id)
);
ul.on("click","li",function(e){
MainLayout.selectFlow($(e.target).data("flow-id"));
});
container.append("<h3>Possible subsequent requests:</h3>").append(ul);
} else {
container.append("<p>No subsequent requests found.</p>");
}
window.redirectFlows = flows;
var nextFlows = domConstruct.create("span");
if(flows.length > 0){
domConstruct.place("<h3>Possible subsequent requests:</h3>",nextFlows);
domConstruct.place(flowlist(flows),nextFlows);
} else {
domConstruct.place("<p>No subsequent requests found.</p>",nextFlows);
}

var parentPreview = parentPreviewFunc.apply(this,arguments).then(function(content){
var container = domConstruct.create("div");
domConstruct.place(content,container);
domConstruct.place(nextFlows,container);
deferred.resolve(container);
});
});

}).bind(this));
} else {
return parentPreviewFunc.apply(this,arguments);
}
var parentPreview = parentPreviewFunc.apply(this,arguments);
return parentPreview + $("<div>").append(out).html();
return deferred;
}
}

Expand Down
34 changes: 34 additions & 0 deletions gui/js/HoneyProxy/util/flowlist.js
@@ -0,0 +1,34 @@
/**
* Utility function that creats a flow list of the given flow ids
*/
define([
"require",
"dojo/dom-construct",
"dojo/on",
"lodash",
"../MainLayout"
],function(require, domConstruct, on, _, MainLayout){
return function(flows, filter) {
var ul = domConstruct.create("ul", {
className: "flowlist"
});

_.each(flows, function(flow) {
var li = domConstruct.create("li", {
'data-flow-id': flow.id
}, ul);
li.textContent = flow.response.contentLengthFormatted + " - "
+ flow.request.date;
});

if(ul.children.length > 0){
on(ul,"li:click",function(e){
//TODO: Use dojo attr (flow-id vs flowId seems unreliable)
MainLayout.trafficPane.selectFlow(e.target.dataset.flowId);
});
}

return ul;
}

});

0 comments on commit 9aea173

Please sign in to comment.