Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add request authentication (refs #23), lint codebase (fixes #38)

  • Loading branch information...
commit 74f09748d50a75ba48b5bce916f1e606defe336d 1 parent d61ec10
@mhils authored
Showing with 673 additions and 628 deletions.
  1. +5 −0 .project
  2. +6 −0 .settings/com.eclipsesource.jshint.ui.prefs
  3. +2 −2 gui/js/HoneyProxy/MainLayout.js
  4. +1 −1  gui/js/HoneyProxy/TableSorter.js
  5. +1 −1  gui/js/HoneyProxy/config.js
  6. +16 −14 gui/js/HoneyProxy/dirdump.js
  7. +2 −1  gui/js/HoneyProxy/flows/CssFlow.js
  8. +1 −0  gui/js/HoneyProxy/flows/DocumentFlow.js
  9. +1 −0  gui/js/HoneyProxy/flows/HtmlFlow.js
  10. +1 −0  gui/js/HoneyProxy/flows/JsFlow.js
  11. +5 −5 gui/js/HoneyProxy/flows/NotModifiedFlow.js
  12. +2 −2 gui/js/HoneyProxy/flows/PrettyFlow.js
  13. +4 −4 gui/js/HoneyProxy/flows/RedirectFlow.js
  14. +1 −0  gui/js/HoneyProxy/flows/XmlFlow.js
  15. +7 −12 gui/js/HoneyProxy/flows/flowModels.js
  16. +1 −0  gui/js/HoneyProxy/main.js
  17. +3 −2 gui/js/HoneyProxy/models/Flow.js
  18. +6 −5 gui/js/HoneyProxy/models/Request.js
  19. +2 −1  gui/js/HoneyProxy/models/Response.js
  20. +7 −7 gui/js/HoneyProxy/models/Traffic.js
  21. +14 −14 gui/js/HoneyProxy/models/sharedFlowProperties.js
  22. +61 −62 gui/js/HoneyProxy/search.js
  23. +1 −1  gui/js/HoneyProxy/traffic.js
  24. +1 −0  gui/js/HoneyProxy/tutorial.js
  25. +78 −72 gui/js/HoneyProxy/util/_DynamicTemplatedMixin.js
  26. +1 −1  gui/js/HoneyProxy/util/_DynamicTemplatedWidget.js
  27. +2 −1  gui/js/HoneyProxy/util/_UpdateNodeTextMixin.js
  28. +4 −4 gui/js/HoneyProxy/util/flowlist.js
  29. +3 −1 gui/js/HoneyProxy/util/formatSize.js
  30. +31 −0 gui/js/HoneyProxy/util/requestAuthenticator.js
  31. +42 −44 gui/js/HoneyProxy/util/sampleFlow.js
  32. +3 −3 gui/js/HoneyProxy/util/versionCheck.js
  33. +15 −19 gui/js/HoneyProxy/utilities.js
  34. +27 −26 gui/js/HoneyProxy/views/DetailPane.js
  35. +34 −33 gui/js/HoneyProxy/views/DetailPane/DetailsPane.js
  36. +38 −44 gui/js/HoneyProxy/views/DetailPane/PreviewPane.js
  37. +42 −42 gui/js/HoneyProxy/views/DetailPane/RawPane.js
  38. +32 −34 gui/js/HoneyProxy/views/DetailPane/_DetailViewPane.js
  39. +5 −5 gui/js/HoneyProxy/views/FlowView.js
  40. +29 −33 gui/js/HoneyProxy/views/HeaderPane.js
  41. +62 −63 gui/js/HoneyProxy/views/ReportEditor.js
  42. +8 −10 gui/js/HoneyProxy/views/ReportOutput.js
  43. +3 −1 gui/js/HoneyProxy/views/ReportPane.js
  44. +1 −0  gui/js/HoneyProxy/views/TrafficPane.js
  45. +8 −10 gui/js/HoneyProxy/views/TrafficSidebar.js
  46. +8 −10 gui/js/HoneyProxy/views/TrafficTable.js
  47. +3 −2 gui/js/HoneyProxy/views/TrafficView.js
  48. +43 −36 gui/js/HoneyProxy/websocket.js
View
5 .project
@@ -10,6 +10,11 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>com.eclipsesource.jshint.ui.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
View
6 .settings/com.eclipsesource.jshint.ui.prefs
@@ -0,0 +1,6 @@
+eclipse.preferences.version=1
+excluded=//*.ejs
+globals=$\: false, _\: false, Backbone\: false, require\: false, define\: false, console\: true, window\: false, document\: false, localStorage\: false, WebSocket\: false
+included=gui/js/HoneyProxy//*
+options=es5\: true, laxbreak\:true, latedef\: true, newcap\: true, noarg\: true, noempty\:true, nonew\:true, undef\:true, unused\: true
+projectSpecificOptions=true
View
4 gui/js/HoneyProxy/MainLayout.js
@@ -12,7 +12,7 @@ define([
"./traffic",
"dojo/domReady!"
], function(exports,query, BorderContainer, TabContainer, StackContainer, ContentPane, HeaderPane, TrafficPane, ReportPane, TrafficView, traffic) {
-
+
//appLayout covers everything
var appLayout = new BorderContainer({
design: "headline",
@@ -61,7 +61,7 @@ define([
el: $("#trafficTable .data tbody")[0]
});
- trafficView.$el.on("click", "tr", function(e) {
+ trafficView.$el.on("click", "tr", function() {
trafficPane.selectFlow($(this).data("flow-id"));
});
View
2  gui/js/HoneyProxy/TableSorter.js
@@ -4,8 +4,8 @@
* of the closure library in the future as it's too big/bloated
* for our needs.
*/
+/*global goog: false*/
define(["dojo/domReady!"],function(){
-
var trafficTableSorter = new goog.ui.TableSorter();
trafficTableSorter.decorate(goog.dom.getElement('traffictable'));
View
2  gui/js/HoneyProxy/config.js
@@ -11,7 +11,7 @@ define(["dojo/json","dojo/text!/api/config"], function(JSON,configstr){
};
Config.prototype.set = function(id,val){
this.storage[id] = val;
- }
+ };
var config = new Config(JSON.parse(configstr));
View
30 gui/js/HoneyProxy/dirdump.js
@@ -1,17 +1,19 @@
/**
* Add a small link to the directory listener if dirdump is active.
*/
-define(["dijit/form/Button","./config","./MainLayout"],function(Button,config,MainLayout){
- if(config.get("dumpdir") === true) {
-
- new Button({
- label: "Show dumped files",
- iconClass: "dijitIcon dijitIconFolderOpen",
- onClick: function(){
- window.open("/dump");
- }
- }).placeAt(MainLayout.header.toolbarNode);
-
- }
- return config.get("dumpdir");
-});
+define([ "dijit/form/Button", "./config", "./MainLayout" ],
+ function(Button, config, MainLayout) {
+
+ if (config.get("dumpdir") === true) {
+
+ new Button({
+ label: "Show dumped files",
+ iconClass: "dijitIcon dijitIconFolderOpen",
+ onClick: function() {
+ window.open("/dump");
+ }
+ }).placeAt(MainLayout.header.toolbarNode);
+
+ }
+ return config.get("dumpdir");
+ });
View
3  gui/js/HoneyProxy/flows/CssFlow.js
@@ -2,6 +2,7 @@
* Flow subclass responsible for proper display of CSS files.
*/
define(["./PrettyFlow"],function(PrettyFlow){
+
return PrettyFlow.extend({}, {
matches : function(data) {
if (data.contentType)
@@ -14,4 +15,4 @@ define(["./PrettyFlow"],function(PrettyFlow){
return "css";
}
});
-})
+});
View
1  gui/js/HoneyProxy/flows/DocumentFlow.js
@@ -4,6 +4,7 @@
* this.
*/
define(["../models/Flow"],function(Flow){
+
return Flow.extend(
{},
{
View
1  gui/js/HoneyProxy/flows/HtmlFlow.js
@@ -2,6 +2,7 @@
* Flow subclass responsible for proper display of CSS files.
*/
define(["./PrettyFlow"],function(PrettyFlow){
+
return PrettyFlow.extend({
}, {
View
1  gui/js/HoneyProxy/flows/JsFlow.js
@@ -2,6 +2,7 @@
* Flow subclass responsible for proper display of JavaScript
*/
define(["dojo/Deferred","./PrettyFlow","./DocumentFlow"],function(Deferred,PrettyFlow, DocumentFlow){
+
return PrettyFlow.extend({
getPreview : function(){
var deferred = new Deferred();
View
10 gui/js/HoneyProxy/flows/NotModifiedFlow.js
@@ -8,7 +8,7 @@ define(["require",
"dojo/Deferred",
"../models/Flow",
"../util/flowlist"],function(require,on,query,domConstruct,Deferred,Flow,flowlist){
-
+
function preview(parentPreviewFunc){
return function(){
var deferred = new Deferred();
@@ -22,17 +22,17 @@ define(["require",
});
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(flowlist(flows),similarFlows);
} else {
- domConstruct.place("<p>No similar flows found.</p>",similarFlows)
+ domConstruct.place("<p>No similar flows found.</p>",similarFlows);
}
- var parentPreview = parentPreviewFunc.apply(this,arguments).then(function(content){
+ parentPreviewFunc.apply(this,arguments).then(function(content){
var span = domConstruct.create("span");
domConstruct.place(content,span);
domConstruct.place(similarFlows,span);
@@ -41,7 +41,7 @@ define(["require",
});
}).bind(this));
return deferred;
- }
+ };
}
return Flow.extend({
View
4 gui/js/HoneyProxy/flows/PrettyFlow.js
@@ -17,10 +17,10 @@ define(["dojo/Deferred","./DocumentFlow","highlight","dojo/dom-construct","dojo/
} else if (contentLength < askPretty) {
var span = domConstruct.create("span");
var prettifyButton = domConstruct.create("div",{className:"pre-menu-item", innerHTML: "Prettify (slow)"},span);
- on(prettifyButton,"click",function(evt){
+ on(prettifyButton,"click",function(){
hljs.highlightBlock(pre);
domConstruct.destroy(prettifyButton);
- })
+ });
domConstruct.place(pre,span);
return span;
}
View
8 gui/js/HoneyProxy/flows/RedirectFlow.js
@@ -8,9 +8,9 @@ define([
"../models/Flow",
"../util/flowlist"
],function(require, Deferred, domConstruct, Flow, flowlist){
-
+
function preview(parentPreviewFunc){
- return function(domPromise){
+ return function(){
var deferred = new Deferred();
var flow = this;
@@ -35,7 +35,7 @@ define([
domConstruct.place("<p>No subsequent requests found.</p>",nextFlows);
}
- var parentPreview = parentPreviewFunc.apply(this,arguments).then(function(content){
+ parentPreviewFunc.apply(this,arguments).then(function(content){
var container = domConstruct.create("div");
domConstruct.place(content,container);
domConstruct.place(nextFlows,container);
@@ -47,7 +47,7 @@ define([
return parentPreviewFunc.apply(this,arguments);
}
return deferred;
- }
+ };
}
return Flow.extend({
View
1  gui/js/HoneyProxy/flows/XmlFlow.js
@@ -2,6 +2,7 @@
* Flow subclass responsible for proper display of XML
*/
define(["./PrettyFlow"],function(PrettyFlow){
+
return PrettyFlow.extend({
}, {
View
19 gui/js/HoneyProxy/flows/flowModels.js
@@ -1,12 +1,7 @@
-define(["./RedirectFlow",
- "./NotModifiedFlow",
- "./ImageFlow",
- "./HtmlFlow",
- "./XmlFlow",
- "./JsFlow",
- "./CssFlow",
- "./PrettyFlow",
- "./DocumentFlow"],
- function(NotModifiedFlow,ImageFlow,HtmlFlow,XmlFlow,JsFlow,CssFlow,PrettyFlow,DocumentFlow){
- return [NotModifiedFlow,ImageFlow,HtmlFlow,XmlFlow,JsFlow,CssFlow,PrettyFlow,DocumentFlow];
-});
+define([ "./RedirectFlow", "./NotModifiedFlow", "./ImageFlow", "./HtmlFlow",
+ "./XmlFlow", "./JsFlow", "./CssFlow", "./PrettyFlow", "./DocumentFlow" ],
+ function(NotModifiedFlow, ImageFlow, HtmlFlow, XmlFlow, JsFlow, CssFlow,
+ PrettyFlow, DocumentFlow) {
+ return [ NotModifiedFlow, ImageFlow, HtmlFlow, XmlFlow, JsFlow, CssFlow,
+ PrettyFlow, DocumentFlow ];
+ });
View
1  gui/js/HoneyProxy/main.js
@@ -12,6 +12,7 @@ require({
"HoneyProxy/websocket",
"HoneyProxy/traffic",
"HoneyProxy/util/versionCheck",
+ "HoneyProxy/util/requestAuthenticator",
"HoneyProxy/tutorial",
"HoneyProxy/search",
"HoneyProxy/dirdump",
View
5 gui/js/HoneyProxy/models/Flow.js
@@ -11,6 +11,7 @@
* be in the model though.
*/
define(["./Request","./Response","dojo/Deferred","dojo/dom-construct"],function(Request,Response,Deferred,domConstruct){
+
return Backbone.Model.extend({
/**
* @return {number} the id of the current flow
@@ -98,6 +99,6 @@ define(["./Request","./Response","dojo/Deferred","dojo/dom-construct"],function(
*/
matches: function(){
return false; //favor subclasses
- },
+ }
});
-})
+});
View
11 gui/js/HoneyProxy/models/Request.js
@@ -1,8 +1,9 @@
/**
- * Proxy object for better access to Flows.
- * Be aware that both Request and Response objects are stateless!
+ * Proxy object for better access to Flows. Be aware that both Request and
+ * Response objects are stateless!
*/
define(["dojo/Deferred","../utilities","./sharedFlowProperties"],function(Deferred,utilities,sharedFlowProperties){
+
var Request = function(flow){
this._flow = flow;
};
@@ -45,7 +46,7 @@ define(["dojo/Deferred","../utilities","./sharedFlowProperties"],function(Deferr
var self = this;
var deferred = new Deferred();
this.getContent().then(function(data){
- var formData = utilities.parseParameters(data)
+ var formData = utilities.parseParameters(data);
self._flow.set("formDataParsed",formData);
deferred.resolve(formData);
});
@@ -72,10 +73,10 @@ define(["dojo/Deferred","../utilities","./sharedFlowProperties"],function(Deferr
},
get rawFirstLine() {
return [this.method,this.path,"HTTP/" + this.httpversion.join(".")]
- .join(" ")+"\n";
+ .join(" ")+"\n";
}
};
- //depends on https://github.com/documentcloud/underscore/pull/694
+ // depends on https://github.com/documentcloud/underscore/pull/694
_.extend(Request.prototype,sharedFlowProperties);
return Request;
View
3  gui/js/HoneyProxy/models/Response.js
@@ -3,6 +3,7 @@
* Be aware that both Request and Response objects are stateless!
*/
define(["../utilities","./sharedFlowProperties"],function(utilities,sharedFlowProperties){
+
var Response = function(flow){
this._flow = flow;
};
@@ -26,7 +27,7 @@ define(["../utilities","./sharedFlowProperties"],function(utilities,sharedFlowPr
},
get rawFirstLine() {
return ["HTTP/" + this.httpversion.join("."),this.code,this.msg]
- .join(" ")+"\n";
+ .join(" ")+"\n";
}
};
_.extend(Response.prototype,sharedFlowProperties);
View
14 gui/js/HoneyProxy/models/Traffic.js
@@ -13,7 +13,7 @@ define(["./Flow","../utilities","../flows/flowModels","dojo/Deferred"],function(
//based on http://stackoverflow.com/a/8843181/934719
return new (Function.bind.apply(Cls,
[0].concat(Array.prototype.slice.call(args)))
- );
+ )();
}
return function factory() {
@@ -29,7 +29,7 @@ define(["./Flow","../utilities","../flows/flowModels","dojo/Deferred"],function(
model = model || fallback;
return newCall(model,arguments);
- }
+ };
}
@@ -45,8 +45,8 @@ define(["./Flow","../utilities","../flows/flowModels","dojo/Deferred"],function(
return {
contentType : utilities.getContentTypeFromHeaders(data.response.headers),
path : data.request.path,
- responseCode: data.response.code,
- }
+ responseCode: data.response.code
+ };
});
/**
* HoneyProxy Traffic Model - Stores a list of flows.
@@ -55,13 +55,13 @@ define(["./Flow","../utilities","../flows/flowModels","dojo/Deferred"],function(
var Traffic = Backbone.Collection.extend({
initialize: function(){
this.firstFlow = new Deferred();
- function firstFlowTrigger() {
+ var firstFlowTrigger = function() {
if(this.length > 0) {
- this.firstFlow.resolve("firstflow")
+ this.firstFlow.resolve("firstflow");
this.off("newflow",firstFlowTrigger);
this.off("reset",firstFlowTrigger);
}
- }
+ };
this.on("add",firstFlowTrigger);
this.on("reset",firstFlowTrigger);
},
View
28 gui/js/HoneyProxy/models/sharedFlowProperties.js
@@ -1,8 +1,8 @@
/**
- * Contains shared methods of Request and Response objects.
- * Stateless.
+ * Contains shared methods of Request and Response objects. Stateless.
*/
define(["dojo/Deferred","dojo/request","../util/formatSize"],function(Deferred,request,formatSize){
+
var sharedFlowProperties = {
get httpversion() {
return this.data.httpversion || [1,0] /* stay compatible with mitmproxy 0.8 */;
@@ -24,10 +24,10 @@ define(["dojo/Deferred","dojo/request","../util/formatSize"],function(Deferred,r
},
getContentURL: function(action){
var url =
- "/files"
- +"/"+this._flow.get("id")
- +"/"+this._attr
- +"/"+action;
+ "/files"+
+ "/"+this._flow.get("id")+
+ "/"+this._attr+
+ "/"+action;
return url;
},
get viewUrl() {
@@ -38,7 +38,7 @@ define(["dojo/Deferred","dojo/request","../util/formatSize"],function(Deferred,r
},
getContent: function() {
if(this.contentLength > 1024 * 1024 * 1){
- if(confirm("This request is pretty big and might cause performance issues ("+this.contentLengthFormatted+") if we load it. Press abort to continue anyway."))
+ if(window.confirm("This request is pretty big and might cause performance issues ("+this.contentLengthFormatted+") if we load it. Press abort to continue anyway."))
{
return (new Deferred())
.resolve("--- big chunk of data ---");
@@ -89,13 +89,13 @@ define(["dojo/Deferred","dojo/request","../util/formatSize"],function(Deferred,r
var attr = this._attr + "RawHeader";
if(!this._flow.has(attr)){
//set request header
- var rawHeader = this.rawFirstLine;
- var headers = this.headers;
- for(var i=0;i<headers.length;i++){
- rawHeader += headers[i][0]+": "+headers[i][1]+"\n";
- }
- rawHeader += "\n"; //terminate with \n\n
- this._flow.set(attr,rawHeader);
+ var rawHeader = this.rawFirstLine;
+ var headers = this.headers;
+ for(var i=0;i<headers.length;i++){
+ rawHeader += headers[i][0]+": "+headers[i][1]+"\n";
+ }
+ rawHeader += "\n"; //terminate with \n\n
+ this._flow.set(attr,rawHeader);
}
return this._flow.get(attr);
}
View
123 gui/js/HoneyProxy/search.js
@@ -1,41 +1,41 @@
/**
- * HoneyProxy search & highlight feature.
- * Parses search strings, and handles search requests.
+ * HoneyProxy search & highlight feature. Parses search strings, and handles
+ * search requests.
*
- * Terminology:
- * A filter is an expression that filters flows for a given criteria.
- * Searching means applying a filter to the flows and hiding all flows that don't match.
- * Highlighting means applying a filter to the flows and marking all flows that match.
+ * Terminology: A filter is an expression that filters flows for a given
+ * criteria. Searching means applying a filter to the flows and hiding all flows
+ * that don't match. Highlighting means applying a filter to the flows and
+ * marking all flows that match.
*/
-define(["./traffic"],function(traffic){
+define([ "./traffic" ], function(traffic) {
//var parseExp = /([\w\.]+)(==|<|>|~=)(.+)/;
function parseSearchString(string) {
- var parts = [string.trim()];
+ var parts = [ string.trim() ];
//.replace(/\s*(==|<|>|~=)\s*/g,"$1")]
//.split(" "); //alternatively use a textfield and \n as sep.
var conditions = [];
- _.each(parts,function(part) {
- if(part == "")
+ _.each(parts, function(part) {
+ if (part === "")
return;
var negate = false;
- var type = "contains";
+ var type = "contains";
- if(part.charAt(0) == "!"){
+ if (part.charAt(0) == "!") {
negate = true;
part = part.substring(1);
}
- if(part.indexOf("similarTo:") == 0){
+ if (part.indexOf("similarTo:") === 0) {
type = "similarTo";
- part = part.substring(10)
+ part = part.substring(10);
}
- if(part.charAt(0) == "="){
+ if (part.charAt(0) == "=") {
type = "containsStrict";
part = part.substring(1);
}
- if(part.charAt(0) == "~"){
+ if (part.charAt(0) == "~") {
type = "regexp";
part = part.substring(1);
}
@@ -54,10 +54,10 @@ define(["./traffic"],function(traffic){
};
*/
var condition = {
- "field": "any",
- "value": part,
- "type": type,
- "not": negate
+ "field": "any",
+ "value": part,
+ "type": type,
+ "not": negate
};
conditions.push(condition);
});
@@ -65,89 +65,88 @@ define(["./traffic"],function(traffic){
}
/**
- * Handles incoming search results. adds and removes the
- * given filterClass.
+ * Handles incoming search results. adds and removes the given filterClass.
*/
- function handleSearchResults(filterClass,negate,ids,matched){
- console.debug("Search performed:",arguments);
- function handleFlow(flow){
+ function handleSearchResults(filterClass, negate, ids, matched) {
+ console.debug("Search performed:", arguments);
+ function handleFlow(flow) {
if ((flow.get("id") == matched[0]) ^ negate) {
- flow.addFilterClass(filterClass)
+ flow.addFilterClass(filterClass);
} else {
flow.removeFilterClass(filterClass);
}
- if(flow.get("id") == matched[0])
+ if (flow.get("id") == matched[0])
matched.shift();
}
- if(ids === undefined)
+ if (ids === undefined)
traffic.each(handleFlow);
else
- _.each(ids,function(id){
+ _.each(ids, function(id) {
handleFlow(traffic.get(id));
- })
+ });
}
/**
* @param filterClass
- * the filterClass that should be applied to the flows
- * @param negate
- * true, if filterClass should be applied to flows that match,
- * false, if filterClass should be applied to flows that don't.
+ * the filterClass that should be applied to the flows
+ * @param negate
+ * true, if filterClass should be applied to flows that match, false,
+ * if filterClass should be applied to flows that don't.
*/
- function search(filterClass,string,negate,ids) {
+ function search(filterClass, string, negate, ids) {
//disable filter if content is empty.
- if(string.trim() == "") {
- return handleSearchResults(filterClass,false,undefined,[]);
+ if (string.trim() === "") {
+ return handleSearchResults(filterClass, false, undefined, []);
}
var conditions = parseSearchString(string);
- $.getJSON("/api/search",{
+ $.getJSON("/api/search", {
idsOnly: true,
"in": JSON.stringify(ids),
includeContent: $("#includeContent").prop("checked"),
filter: JSON.stringify(conditions)
- }, handleSearchResults.bind(0,filterClass,negate,ids));
+ }, handleSearchResults.bind(0, filterClass, negate, ids));
}
- require(["dojo/domReady!"], function(){
+ require([ "dojo/domReady!" ], function() {
/**
- * DOM part of the search/highlight feature.
- * Basically just reacting on VK_ENTER and blur events,
- * also applies existing filters to incoming requests.
- * One could argue that this is a feature which should be present
- * in the HoneyProxy controller, but that would make the whole thing
- * just complicated.
+ * DOM part of the search/highlight feature. Basically just reacting on
+ * VK_ENTER and blur events, also applies existing filters to incoming
+ * requests. One could argue that this is a feature which should be present
+ * in the HoneyProxy controller, but that would make the whole thing just
+ * complicated.
*/
- function _search($el,ids){
- $el.data("active",$el.val().trim() !== "");
- return search("filter-"+($el.data("filterclass").split(" ").join(" filter-")),$el.val(),$el.data("negate"),ids);
+ function _search($el, ids) {
+ $el.data("active", $el.val().trim() !== "");
+ return search("filter-"
+ + ($el.data("filterclass").split(" ").join(" filter-")), $el.val(), $el
+ .data("negate"), ids);
}
var searchFields = $(".search");
- searchFields.on("keypress",function(e){
- if(e.which == 13) {
+ searchFields.on("keypress", function(e) {
+ if (e.which == 13) {
_search($(this));
- }
- }).on("blur",function(){
+ }
+ }).on("blur", function() {
_search($(this));
});
- $(document).on("click",".searchlink",function(e){
+ $(document).on("click", ".searchlink", function(e) {
$("#filter").val($(e.target).data("search")).blur();
});
-
+
$("#includeContent").on("change",
- searchFields.trigger.bind(
- searchFields,"blur"));
+ searchFields.trigger.bind(searchFields, "blur"));
- traffic.on("add",function(flow){
+ traffic.on("add", function(flow) {
//premium handling of the filter to avoid flickering
- if($("#filter").data("active")===true)
+ if ($("#filter").data("active") === true)
flow.addFilterClass("filter-hide");
- searchFields.each(function(index,el){
+ searchFields.each(function(index, el) {
var $el = $(el);
- if($el.data("active") === true) {
- _search($el,[flow.get("id")]);
+ if ($el.data("active") === true) {
+ _search($el, [ flow.get("id") ]);
}
});
});
View
2  gui/js/HoneyProxy/traffic.js
@@ -1,6 +1,6 @@
define(["./models/Traffic"],function(Traffic){
- var traffic = new Traffic;
+ var traffic = new Traffic();
return traffic;
});
View
1  gui/js/HoneyProxy/tutorial.js
@@ -2,6 +2,7 @@
* Handles the quick start tutorial that is shown if no requests are recorded yet.
*/
define(["./config","./traffic","dojo/when","dojo/domReady!"],function(config,traffic,when){
+
when(traffic.firstFlow,function(){
$("#tutorial").hide();
});
View
150 gui/js/HoneyProxy/util/_DynamicTemplatedMixin.js
@@ -1,76 +1,82 @@
/**
- * Use templating within dojo.
- * not in use
+ * Use templating within dojo. not in use
*/
-define(["dojo/_base/declare",
- "dojo/_base/lang",
- "dojo/dom-construct",
- "dijit/_TemplatedMixin"],
- function(declare,lang,domConstruct,_TemplatedMixin) {
- var _DynamicTemplatedMixin = declare(null,{
- // templateString: [protected] String
- // A string that represents the widget template.
- // Use in conjunction with dojo.cache() to load from a file.
- templateString: null,
- /*=====
- // _attachPoints: [private] String[]
- // List of widget attribute names associated with data-dojo-attach-point=... in the
- // template, ex: ["containerNode", "labelNode"]
- _attachPoints: [],
+define(
+ [ "dojo/_base/declare", "dojo/_base/lang", "dojo/dom-construct",
+ "dijit/_TemplatedMixin" ],
+ function(declare, lang, domConstruct, _TemplatedMixin) {
+
+ var _DynamicTemplatedMixin = declare(
+ null,
+ {
+ // templateString: [protected] String
+ // A string that represents the widget template.
+ // Use in conjunction with dojo.cache() to load from a file.
+ templateString: null,
+ /*=====
+ // _attachPoints: [private] String[]
+ // List of widget attribute names associated with data-dojo-attach-point=... in the
+ // template, ex: ["containerNode", "labelNode"]
+ _attachPoints: [],
- // _attachEvents: [private] Handle[]
- // List of connections associated with data-dojo-attach-event=... in the
- // template
- _attachEvents: [],
- =====*/
- templateCompileFunction: function(tmpl){
- return function(){
- return tmpl;
- }
- },
- templateRenderFunction: function(compiled){
- return compiled(this);
- },
- constructor: function(){
- this._attachPoints = [];
- this._attachEvents = [];
- },
- _stringRepl: function(tmpl){
- return this.templateRenderFunction(tmpl);
- },
- getCachedTemplate: function(templateString) {
- if (!(this.templateCompileFunction in _DynamicTemplatedMixin._templateCache))
- _DynamicTemplatedMixin._templateCache[this.templateCompileFunction] = {};
- var cache = _DynamicTemplatedMixin._templateCache[this.templateCompileFunction];
- if (templateString in cache)
- return cache[templateString];
- var template = this.templateCompileFunction(templateString);
- return (cache[templateString] = template);
- },
- buildRendering: function(){
- this.domNode = domConstruct.create(this.nodeTag ? this.nodeTag : "div");
-
- this.inherited(arguments);
-
- this.refresh();
-
- this._beforeFillContent(); // hook for _WidgetsInTemplateMixin
- this._fillContent(this.srcNodeRef);
- },
- _beforeFillContent: _TemplatedMixin.prototype._beforeFillContent.bind(this),
- _fillContent: _TemplatedMixin.prototype._fillContent.bind(this),
- refresh: function() {
- this._attachPoints = [];
- this._attachEvents = [];
- var template = this.getCachedTemplate(this.templateString);
- var content = domConstruct.toDom(this._stringRepl(template));
- domConstruct.place(content,this.domNode,"only");
- _TemplatedMixin.prototype._attachTemplateNodes.call(this,content, function(n,p){ return n.getAttribute(p); });
- }
+ // _attachEvents: [private] Handle[]
+ // List of connections associated with data-dojo-attach-event=... in the
+ // template
+ _attachEvents: [],
+ =====*/
+ templateCompileFunction: function(tmpl) {
+ return function() {
+ return tmpl;
+ };
+ },
+ templateRenderFunction: function(compiled) {
+ return compiled(this);
+ },
+ constructor: function() {
+ this._attachPoints = [];
+ this._attachEvents = [];
+ },
+ _stringRepl: function(tmpl) {
+ return this.templateRenderFunction(tmpl);
+ },
+ getCachedTemplate: function(templateString) {
+ if (!(this.templateCompileFunction in _DynamicTemplatedMixin._templateCache))
+ _DynamicTemplatedMixin._templateCache[this.templateCompileFunction] = {};
+ var cache = _DynamicTemplatedMixin._templateCache[this.templateCompileFunction];
+ if (templateString in cache)
+ return cache[templateString];
+ var template = this.templateCompileFunction(templateString);
+ return (cache[templateString] = template);
+ },
+ buildRendering: function() {
+ this.domNode = domConstruct.create(this.nodeTag ? this.nodeTag
+ : "div");
+
+ this.inherited(arguments);
+
+ this.refresh();
+
+ this._beforeFillContent(); // hook for _WidgetsInTemplateMixin
+ this._fillContent(this.srcNodeRef);
+ },
+ _beforeFillContent: _TemplatedMixin.prototype._beforeFillContent
+ .bind(this),
+ _fillContent: _TemplatedMixin.prototype._fillContent.bind(this),
+ refresh: function() {
+ this._attachPoints = [];
+ this._attachEvents = [];
+ var template = this.getCachedTemplate(this.templateString);
+ var content = domConstruct.toDom(this._stringRepl(template));
+ domConstruct.place(content, this.domNode, "only");
+ _TemplatedMixin.prototype._attachTemplateNodes.call(this, content,
+ function(n, p) {
+ return n.getAttribute(p);
+ });
+ }
+ });
+
+ //{templateFunc: {templateString: compiledFunction}}
+ _DynamicTemplatedMixin._templateCache = {};
+
+ return _DynamicTemplatedMixin;
});
-
- //{templateFunc: {templateString: compiledFunction}}
- _DynamicTemplatedMixin._templateCache = {};
-
- return _DynamicTemplatedMixin;
-});
View
2  gui/js/HoneyProxy/util/_DynamicTemplatedWidget.js
@@ -9,6 +9,6 @@ define([
],function(declare, _WidgetBase, _, _DynamicTemplatedMixin){
return declare([_WidgetBase, _DynamicTemplatedMixin], {
- templateCompileFunction: _.template,
+ templateCompileFunction: _.template
});
});
View
3  gui/js/HoneyProxy/util/_UpdateNodeTextMixin.js
@@ -1,5 +1,6 @@
define([], function() {
- var _mixin = function(){};
+
+ var _mixin = function(){};
_mixin.prototype.updateNodeText = function(nodeId,text){
this[nodeId+"Node"].textContent = text;
};
View
8 gui/js/HoneyProxy/util/flowlist.js
@@ -8,7 +8,8 @@ define([
"lodash",
"../MainLayout"
],function(require, domConstruct, on, _, MainLayout){
- return function(flows, filter) {
+
+ return function(flows) {
var ul = domConstruct.create("ul", {
className: "flowlist"
});
@@ -17,8 +18,7 @@ define([
var li = domConstruct.create("li", {
'data-flow-id': flow.id
}, ul);
- li.textContent = flow.response.contentLengthFormatted + " - "
- + flow.request.date;
+ li.textContent = flow.response.contentLengthFormatted + " - " + flow.request.date;
});
if(ul.children.length > 0){
@@ -29,6 +29,6 @@ define([
}
return ul;
- }
+ };
});
View
4 gui/js/HoneyProxy/util/formatSize.js
@@ -1,10 +1,12 @@
define([],function(){
+
return function(size){
+
var prefix = ["B","KB","MB","GB","TB"];
while(size > 1024 && prefix.length > 1){
prefix.shift();
size = size / 1024;
}
return (Math.floor(size*100)/100.0)+prefix.shift();
- }
+ };
});
View
31 gui/js/HoneyProxy/util/requestAuthenticator.js
@@ -0,0 +1,31 @@
+/**
+ * All HoneyProxy API calls that have side effects (e.g. writing data to disk)
+ * need to pass the valid auth token to prevent CSRF attacks.
+ * This token can be obtained by calling /api/authtoken
+ *
+ * If you are calling sensitive functions,
+ * make sure that the promise returned by this module has been fulfilled.
+ *
+ * To make this clear:
+ * HoneyProxy has NO built-in protection against MITM attacks.
+ * Run it on localhost for sensitive operations or tunnel appropriately.
+ */
+require(["dojo/request","dojo/request/notify","dojo/Deferred"],function(request, notify, Deferred){
+
+ var def = new Deferred();
+
+ request("/api/authtoken").then(function(token){
+ notify("send", function(req){
+ if(req.options.method !== "GET") {
+ console.log("send",req);
+ console.warn(token);
+ }
+
+ });
+ def.resolve(true);
+ },function(){
+ def.reject(arguments);
+ });
+
+ return {"active": def};
+});
View
86 gui/js/HoneyProxy/util/sampleFlow.js
@@ -1,47 +1,45 @@
/*
* A sample flow - used for autocompletion in the reporteditor
*/
-define(["../models/Flow"],function(Flow){
- return new Flow(
- {
- "id": 1,
- "version": [0,9],
- "request": {
- "contentChecksums": {},
- "headers": [
- ["Host","example.com"]
- ],
- "timestamp": 1234567890.123,
- "contentLength": 0,
- "method": "GET",
- "client_conn": {
- "error": null,
- "requestcount": 1,
- "address": ["127.0.0.1",64000]
- },
- "host": "example.com",
- "path": "/foo",
- "scheme": "http",
- "port": 80,
- "httpversion": [1, 1]
- },
- "response": {
- "headers": [
- ["Content-Length","42"]
- ],
- "cert": null,
- "code": 200,
- "contentChecksums": {
- "Checksum": {
- "sha256": "sha2563fac9fbad9adf6db2a3f508f60c5a92e7d1d3b011a29222da2ee95caaa",
- "md5": "md55abdbf686beaccbf3c12180549aaa"
- }
- },
- "msg": "OK",
- "timestamp": 1234567932.123,
- "contentLength": 42,
- "httpversion": [1,1]
- },
- "error": null
- });
-});
+define(
+ [ "../models/Flow" ],
+ function(Flow) {
+ return new Flow(
+ {
+ "id": 1,
+ "version": [ 0, 9 ],
+ "request": {
+ "contentChecksums": {},
+ "headers": [ [ "Host", "example.com" ] ],
+ "timestamp": 1234567890.123,
+ "contentLength": 0,
+ "method": "GET",
+ "client_conn": {
+ "error": null,
+ "requestcount": 1,
+ "address": [ "127.0.0.1", 64000 ]
+ },
+ "host": "example.com",
+ "path": "/foo",
+ "scheme": "http",
+ "port": 80,
+ "httpversion": [ 1, 1 ]
+ },
+ "response": {
+ "headers": [ [ "Content-Length", "42" ] ],
+ "cert": null,
+ "code": 200,
+ "contentChecksums": {
+ "Checksum": {
+ "sha256": "sha2563fac9fbad9adf6db2a3f508f60c5a92e7d1d3b011a29222da2ee95caaa",
+ "md5": "md55abdbf686beaccbf3c12180549aaa"
+ }
+ },
+ "msg": "OK",
+ "timestamp": 1234567932.123,
+ "contentLength": 42,
+ "httpversion": [ 1, 1 ]
+ },
+ "error": null
+ });
+ });
View
6 gui/js/HoneyProxy/util/versionCheck.js
@@ -11,11 +11,11 @@ define(["dojo/request"],function(request){
var release = "stable";
var releaseId = 1; //change in /web/version.json, /gui/js/HoneyProxy/util/versionCheck.js and /libhproxy/version.py
- var currentReleaseId = data[release]["releaseId"];
+ var currentReleaseId = data[release].releaseId;
if (currentReleaseId > releaseId && currentReleaseId > (localStorage.getItem("HoneyProxyReleaseId") || 0)) {
- var msg = "Update Notice: Version "+data[release]["version"]+" is available.\nOpen download page?\n\nRelease Notes:\n"+data[release]["message"];
- if (confirm(msg)) {
+ var msg = "Update Notice: Version "+data[release].version+" is available.\nOpen download page?\n\nRelease Notes:\n"+data[release].message;
+ if (window.confirm(msg)) {
//Go directly to GitHub in case honeyproxy.org got compromised and serves a fake update message.
//This way, an attacker would need to compromise both our GitHub account and honeyproxy.org
window.open("https://github.com/mhils/HoneyProxy", '_blank');
View
34 gui/js/HoneyProxy/utilities.js
@@ -1,4 +1,4 @@
-define([],function(){
+define([], function() {
return {
/**
* Get the ContentType out of an array of headers (without charset).
@@ -6,8 +6,8 @@ define([],function(){
* A [[headnerName,value],[headerName,value]] array of headers.
* @returns
*/
- getContentTypeFromHeaders : function getContentTypeFromHeaders(headers){
- var contentType = _.find(headers, function(header){
+ getContentTypeFromHeaders: function getContentTypeFromHeaders(headers) {
+ var contentType = _.find(headers, function(header) {
return !!header[0].match(/^Content-Type$/i);
});
return contentType ? contentType[1].split(";")[0] : undefined;
@@ -15,17 +15,15 @@ define([],function(){
/**
* Parse a query string and return its components
*/
- parseParameters : function(queryString)
- {
- function _parse(pairStr)
- {
- var param = {};
- var pair = pairStr.split("=", 2);
- param.name = pair[0];
- param.value = (pair.length === 1) ? "" : pair[1];
- return param;
- }
- return queryString.split("&").map(_parse);
+ parseParameters: function(queryString) {
+ function _parse(pairStr) {
+ var param = {};
+ var pair = pairStr.split("=", 2);
+ param.name = pair[0];
+ param.value = (pair.length === 1) ? "" : pair[1];
+ return param;
+ }
+ return queryString.split("&").map(_parse);
},
/**
* Dojo Polyfill for
@@ -33,12 +31,10 @@ define([],function(){
* http://bugs.dojotoolkit.org/ticket/10291
* Works for >=IE9
*/
- textContentPolyfill : function(nodeName)
- {
- return function(text){
+ textContentPolyfill: function(nodeName) {
+ return function(text) {
this[nodeName].textContent = text;
- }
+ };
}
};
});
-
View
53 gui/js/HoneyProxy/views/DetailPane.js
@@ -1,36 +1,37 @@
/**
* Shows details when clicking on a flow.
*/
-define(["dojo/_base/declare",
- "dijit/layout/TabContainer",
- "dojo/_base/array",
- "./DetailPane/RawPane",
- "./DetailPane/PreviewPane",
- "./DetailPane/DetailsPane"],function(declare,TabContainer,array,RawPane,PreviewPane,DetailsPane) {
- return declare([TabContainer], {
- postCreate: function(){
+define([ "dojo/_base/declare", "dijit/layout/TabContainer", "dojo/_base/array",
+ "./DetailPane/RawPane", "./DetailPane/PreviewPane",
+ "./DetailPane/DetailsPane" ], function(
+ declare, TabContainer, array, RawPane, PreviewPane, DetailsPane) {
+
+ return declare([ TabContainer ], {
+ postCreate: function() {
this.inherited(arguments);
- var preview = PreviewPane();
- var raw = RawPane();
- var details = DetailsPane();
- this.addChild(preview);
- this.addChild(details);
- this.addChild(raw);
-
- this.domNode.classList.add("detailPane");
- //Scroll to top when switching tab.
- this.watch("selectedChildWidget",function(){
- this.containerNode.scrollTop = 0;
- });
-
+ var preview = new PreviewPane();
+ var raw = new RawPane();
+ var details = new DetailsPane();
+ this.addChild(preview);
+ this.addChild(details);
+ this.addChild(raw);
+
+ this.domNode.classList.add("detailPane");
+ //Scroll to top when switching tab.
+ this.watch("selectedChildWidget", function() {
+ this.containerNode.scrollTop = 0;
+ });
+
},
style: "height: 100%; width: 100%;",
- setModel: function(model){
- if(this.get("model") == model)
+ setModel: function(
+ model) {
+ if (this.get("model") == model)
return;
- this.set("model",model);
- array.forEach(this.getChildren(),function(c){
- c.set("model",model);
+ this.set("model", model);
+ array.forEach(this.getChildren(), function(
+ c) {
+ c.set("model", model);
});
}
});
View
67 gui/js/HoneyProxy/views/DetailPane/DetailsPane.js
@@ -1,34 +1,35 @@
-define([
- "dojo/_base/declare",
- "./_DetailViewPane",
- "dojo/dom-construct",
- "dojo/text!./templates/DetailsPane.ejs"
-], function(declare, _DetailViewPane, domConstruct, template) {
-
- return declare([_DetailViewPane], {
- templateString: template,
- title: "Details",
- loadContent: function(){
- var model = this.get("model");
- if(model.request.hasFormData) {
- var requestContentNode = this.requestContentNode;
- var headerRow = domConstruct.place("<tr></tr>",requestContentNode,"only");
- var loading = domConstruct.place("<td colspan=2>Loading...</td>",headerRow,"last");
- model.request.getFormData().then(function(formData){
- fragment = document.createDocumentFragment();
- for(var i=0;i<formData.length;i++) {
- //FIXME: Replace underscore.js escaping.
- fragment.appendChild(domConstruct.toDom(
- "<tr><td>"+_.escape(decodeURIComponent(formData[i].name))+"</td><td>"+_.escape(decodeURIComponent(formData[i].value))+"</td></tr>"
- ));
- }
- domConstruct.empty(loading);
- domConstruct.place(fragment,requestContentNode,"last");
- });
- } else {
- domConstruct.empty(this.requestContentNode);
- }
- }
- });
-
+define([ "dojo/_base/declare", "./_DetailViewPane", "dojo/dom-construct",
+ "dojo/text!./templates/DetailsPane.ejs" ], function(declare, _DetailViewPane,
+ domConstruct, template) {
+
+ return declare([ _DetailViewPane ], {
+ templateString: template,
+ title: "Details",
+ loadContent: function() {
+ var model = this.get("model");
+ if (model.request.hasFormData) {
+ var requestContentNode = this.requestContentNode;
+ var headerRow = domConstruct.place("<tr></tr>", requestContentNode,
+ "only");
+ var loading = domConstruct.place("<td colspan=2>Loading...</td>",
+ headerRow, "last");
+ model.request.getFormData().then(
+ function(formData) {
+ var fragment = document.createDocumentFragment();
+ for ( var i = 0; i < formData.length; i++) {
+ //FIXME: Replace underscore.js escaping.
+ fragment.appendChild(domConstruct.toDom("<tr><td>"
+ + _.escape(decodeURIComponent(formData[i].name)) + "</td><td>"+
+ _.escape(decodeURIComponent(formData[i].value))+
+ "</td></tr>"));
+ }
+ domConstruct.empty(loading);
+ domConstruct.place(fragment, requestContentNode, "last");
+ });
+ } else {
+ domConstruct.empty(this.requestContentNode);
+ }
+ }
+ });
+
});
View
82 gui/js/HoneyProxy/views/DetailPane/PreviewPane.js
@@ -1,45 +1,39 @@
-define([
- "dojo/_base/declare",
- "./_DetailViewPane",
- "dojo/dom-construct",
- "dojo/Deferred",
- "dojo/text!./templates/PreviewPane.ejs"
-], function(declare, _DetailViewPane, domConstruct, Deferred, template) {
-
- return declare([_DetailViewPane], {
- templateString: template,
- title: "Preview",
- loadContent: function(){
-
- var model = this.get("model");
-
- //Check if there is still a pending request for generating a preview.
- //If so, cancel it.
- var lastRequest = this.get("previewRequest");
- if(lastRequest)
- lastRequest.cancel("outdated");
-
- var previewPane = this;
-
- var previewFunc = model.response.hasContent ?
- model.getPreview.bind(model) :
- model.getPreviewEmpty.bind(model);
-
- var deferred = new Deferred();
-
- var previewRequest = previewFunc().then(function(previewHTML){
- previewPane.set("previewHTML",previewHTML);
- deferred.resolve(true);
- });
- this.set("previewRequest",previewRequest);
- return deferred;
- },
-
- previewHTML: undefined,
- _setPreviewHTMLAttr: function(previewHTML){
- domConstruct.place(previewHTML,this.previewHTMLNode,"only");
- this._set("previewHTML",previewHTML);
- }
- });
-
+define([ "dojo/_base/declare", "./_DetailViewPane", "dojo/dom-construct",
+ "dojo/Deferred", "dojo/text!./templates/PreviewPane.ejs" ], function(declare,
+ _DetailViewPane, domConstruct, Deferred, template) {
+ return declare([ _DetailViewPane ], {
+ templateString: template,
+ title: "Preview",
+ loadContent: function() {
+
+ var model = this.get("model");
+
+ //Check if there is still a pending request for generating a preview.
+ //If so, cancel it.
+ var lastRequest = this.get("previewRequest");
+ if (lastRequest)
+ lastRequest.cancel("outdated");
+
+ var previewPane = this;
+
+ var previewFunc = model.response.hasContent ? model.getPreview
+ .bind(model) : model.getPreviewEmpty.bind(model);
+
+ var deferred = new Deferred();
+
+ var previewRequest = previewFunc().then(function(previewHTML) {
+ previewPane.set("previewHTML", previewHTML);
+ deferred.resolve(true);
+ });
+ this.set("previewRequest", previewRequest);
+ return deferred;
+ },
+
+ previewHTML: undefined,
+ _setPreviewHTMLAttr: function(previewHTML) {
+ domConstruct.place(previewHTML, this.previewHTMLNode, "only");
+ this._set("previewHTML", previewHTML);
+ }
+ });
+
});
View
84 gui/js/HoneyProxy/views/DetailPane/RawPane.js
@@ -1,43 +1,43 @@
-define([
- "dojo/_base/declare",
- "./_DetailViewPane",
- "dojo/promise/all",
- "../../utilities",
- "dojo/text!./templates/RawPane.ejs"
-], function(declare, _DetailViewPane, all, util, template) {
-
- return declare([_DetailViewPane], {
- templateString: template,
- title: "Raw",
- loadContent: function(){
- var model = this.get("model");
- //Check if there is still a pending request for loading content.
- //If so, cancel it.
- var lastReqDef = this.get("lastReqDeferred");
- if(lastReqDef)
- lastReqDef.cancel("outdated");
- var lastRespDef = this.get("lastRespDeferred");
- if(lastRespDef)
- lastRespDef.cancel("outdated");
-
- var rawPane = this;
-
- var reqDef = model.request.getContent().then(function(content){
- rawPane.set("requestContent",content != "" ? content : "<empty request content>");
- });
- var respDef = model.response.getContent().then(function(content){
- rawPane.set("responseContent",content != "" ? content : "<empty response content>");
- });
-
- this.set("lastReqDeferred",reqDef);
- this.set("lastRespDeferred",respDef);
-
- return all([reqDef, respDef]);
- },
- requestContent: undefined,
- _setRequestContentAttr: util.textContentPolyfill("requestContentNode"),
- responseContent: undefined,
- _setResponseContentAttr: util.textContentPolyfill("responseContentNode")
- });
-
+define([ "dojo/_base/declare", "./_DetailViewPane", "dojo/promise/all",
+ "../../utilities", "dojo/text!./templates/RawPane.ejs" ], function(declare,
+ _DetailViewPane, all, util, template) {
+
+ return declare([ _DetailViewPane ], {
+ templateString: template,
+ title: "Raw",
+ loadContent: function() {
+ var model = this.get("model");
+ //Check if there is still a pending request for loading content.
+ //If so, cancel it.
+ var lastReqDef = this.get("lastReqDeferred");
+ if (lastReqDef)
+ lastReqDef.cancel("outdated");
+ var lastRespDef = this.get("lastRespDeferred");
+ if (lastRespDef)
+ lastRespDef.cancel("outdated");
+
+ var rawPane = this;
+
+ var reqDef = model.request.getContent().then(
+ function(content) {
+ rawPane.set("requestContent", content !== "" ? content
+ : "<empty request content>");
+ });
+ var respDef = model.response.getContent().then(
+ function(content) {
+ rawPane.set("responseContent", content !== "" ? content
+ : "<empty response content>");
+ });
+
+ this.set("lastReqDeferred", reqDef);
+ this.set("lastRespDeferred", respDef);
+
+ return all([ reqDef, respDef ]);
+ },
+ requestContent: undefined,
+ _setRequestContentAttr: util.textContentPolyfill("requestContentNode"),
+ responseContent: undefined,
+ _setResponseContentAttr: util.textContentPolyfill("responseContentNode")
+ });
+
});
View
66 gui/js/HoneyProxy/views/DetailPane/_DetailViewPane.js
@@ -1,34 +1,32 @@
-define([
- "dojo/_base/declare",
- "../../util/_DynamicTemplatedWidget",
-], function(declare, _DynamicTemplatedWidget) {
-
- return declare([_DynamicTemplatedWidget], {
- templateRenderFunction: function(compiled){
- return this.get("model") ? compiled(this) : "<div></div>";
- },
- //TODO: Maybe subscribe to attr change of "selected"
- //rather than using undocumented underscore functions.
- //Let's see how this is handled in dojo 2.0
- _onShow: function(){
- if(this.get("model") !== this.get("loadedModel"))
- return this._loadContent();
- return true;
- },
- _loadContent: function(){
- this.set("loadedModel",this.get("model"));
- this.refresh();
- return this.loadContent();
- },
- _setModelAttr: function(/*Flow*/ model){
- if(model) {
- this._set("model",model);
- if(this.get("selected")) {
- this._onShow();
- }
- }
-
- }
- });
-
-});
+define([ "dojo/_base/declare", "../../util/_DynamicTemplatedWidget" ],
+ function(declare, _DynamicTemplatedWidget) {
+
+ return declare([ _DynamicTemplatedWidget ], {
+ templateRenderFunction: function(compiled) {
+ return this.get("model") ? compiled(this) : "<div></div>";
+ },
+ // TODO: Maybe subscribe to attr change of "selected"
+ // rather than using undocumented underscore functions.
+ // Let's see how this is handled in dojo 2.0
+ _onShow: function() {
+ if (this.get("model") !== this.get("loadedModel"))
+ return this._loadContent();
+ return true;
+ },
+ _loadContent: function() {
+ this.set("loadedModel", this.get("model"));
+ this.refresh();
+ return this.loadContent();
+ },
+ _setModelAttr: function(/* Flow */model) {
+ if (model) {
+ this._set("model", model);
+ if (this.get("selected")) {
+ this._onShow();
+ }
+ }
+
+ }
+ });
+
+ });
View
10 gui/js/HoneyProxy/views/FlowView.js
@@ -14,12 +14,12 @@ define(["dojo/text!../templates/flow.ejs"],function(flowTmpl){
//iterate through all parent classes to get their categories and add them as classes
var superCls = this.model;
- var categories = []
+ var categories = [];
while(superCls !== undefined){
if(superCls.constructor.hasOwnProperty("getCategory"))
{
var cat = "category-"+superCls.constructor.getCategory();
- if(categories.length == 0 || (cat != categories[categories.length -1] && cat != "category-none"))
+ if(categories.length === 0 || (cat != categories[categories.length -1] && cat != "category-none"))
categories.push(cat);
}
superCls = superCls.constructor.__super__;
@@ -27,7 +27,7 @@ define(["dojo/text!../templates/flow.ejs"],function(flowTmpl){
this.$el.addClass(categories.join(" "));
this.$el.data("flow-id",this.model.id);
this.$el.addClass("request-scheme-"+this.model.request.scheme);
- for(cls in this.model.getFilterClasses()){
+ for(var cls in this.model.getFilterClasses()){
this.$el.addClass(cls);
}
@@ -43,12 +43,12 @@ define(["dojo/text!../templates/flow.ejs"],function(flowTmpl){
for(var i=0;i<children.length && !inserted;i++) {
var child = $(children[i]);
if (child.attr("class") > cls) {
- child.before('<div class="'+cls+'"></div>')
+ child.before('<div class="'+cls+'"></div>');
inserted = true;
}
}
if(!inserted)
- this.$filterEl.append('<div class="'+cls+'"></div>')
+ this.$filterEl.append('<div class="'+cls+'"></div>');
return this.$el.addClass(cls);
},
onFilterClassRemove: function(cls){
View
62 gui/js/HoneyProxy/views/HeaderPane.js
@@ -1,34 +1,30 @@
-define([
- "require",
- "dojo/_base/declare",
- "dijit/form/Button",
- "../util/_DynamicTemplatedWidget",
- "../MainLayout",
- "dojo/text!./templates/HeaderPane.ejs"
-], function(require, declare, Button, _DynamicTemplatedWidget, MainLayout, template) {
-
- return declare([_DynamicTemplatedWidget], {
- templateString: template,
- nodeTag: "header",
- postCreate: function(){
- this.inherited(arguments);
-
- new Button({
- label: "Show Traffic",
- iconClass: "dijitIcon dijitIconTable",
- onClick: function(){
- MainLayout.showPane(0);
- }
- }).placeAt(this.toolbarNode);
-
- new Button({
- label: "Generate Report",
- iconClass: "dijitIcon dijitIconChart",
- onClick: function(){
- MainLayout.showPane(1);
- }
- }).placeAt(this.toolbarNode);
- }
- });
-
+define([ "require", "dojo/_base/declare", "dijit/form/Button",
+ "../util/_DynamicTemplatedWidget", "../MainLayout",
+ "dojo/text!./templates/HeaderPane.ejs" ], function(require, declare, Button,
+ _DynamicTemplatedWidget, MainLayout, template) {
+
+ return declare([ _DynamicTemplatedWidget ], {
+ templateString: template,
+ nodeTag: "header",
+ postCreate: function() {
+ this.inherited(arguments);
+
+ new Button({
+ label: "Show Traffic",
+ iconClass: "dijitIcon dijitIconTable",
+ onClick: function() {
+ MainLayout.showPane(0);
+ }
+ }).placeAt(this.toolbarNode);
+
+ new Button({
+ label: "Generate Report",
+ iconClass: "dijitIcon dijitIconChart",
+ onClick: function() {
+ MainLayout.showPane(1);
+ }
+ }).placeAt(this.toolbarNode);
+ }
+ });
+
});
View
125 gui/js/HoneyProxy/views/ReportEditor.js
@@ -1,64 +1,63 @@
-define([
- "lodash",
- "dojo/_base/declare",
- "codemirror/all",
- "dijit/form/Button",
- "../util/sampleFlow",
- "../util/_DynamicTemplatedWidget",
- "dojo/text!./templates/ReportEditor.ejs"
-], function(_, declare, CodeMirrorPromise, Button, sampleFlow, _DynamicTemplatedWidget, template) {
-
- return declare([_DynamicTemplatedWidget], {
- templateString: template,
- _onShow: function(){
- this.codeMirror && this.codeMirror.refresh();
- },
- postCreate: function(){
- this.inherited(arguments);
-
- var reportCodeNode = this.reportCodeNode;
- CodeMirrorPromise.then((function(CodeMirror){
- CodeMirror.commands.autocomplete = function(cm) {
- CodeMirror.simpleHint(cm, CodeMirror.javascriptHint, {
- completeSingle: false,
- additionalContext: {
- //Only expose the important attributes of flow. Most attrs are confusing and for internal use only.
- "flow": {
- "request":sampleFlow.request,
- "response":sampleFlow,
- "getSimilarFlows":sampleFlow.getSimilarFlows
- },
- "traffic":window.HoneyProxy.traffic,
- "_":_
- }
- });
- };
- CodeMirror.commands.autoformat = function(cm) {
- var range = { from: cm.getCursor(true), to: cm.getCursor(false) };
- cm.autoIndentRange(range.from, range.to);
- };
- this.codeMirror = CodeMirror.fromTextArea(reportCodeNode,{
- lineNumbers: true,
- mode: "javascript",
- matchBrackets: true,
- extraKeys: {
- "Enter": "newlineAndIndentContinueComment",
- "Ctrl-Space": "autocomplete",
- "Shift-Ctrl-F":"autoformat"
- },
- onCursorActivity: function() {
- this.codeMirror.matchHighlight("CodeMirror-matchhighlight");
- }
- });
- }).bind(this));
-
- this.startButton = new Button({
- iconClass: "dijitIcon dijitIconFunction"
- },this.startButtonNode);
- },
- getCode: function(){
- return this.codeMirror ? this.codeMirror.getValue() : "";
- }
- });
-
+define([ "lodash", "dojo/_base/declare", "codemirror/all", "dijit/form/Button",
+ "../util/sampleFlow", "../util/_DynamicTemplatedWidget",
+ "dojo/text!./templates/ReportEditor.ejs" ], function(_, declare,
+ CodeMirrorPromise, Button, sampleFlow, _DynamicTemplatedWidget, template) {
+
+ return declare([ _DynamicTemplatedWidget ], {
+ templateString: template,
+ _onShow: function() {
+ if (this.codeMirror)
+ this.codeMirror.refresh();
+ },
+ postCreate: function() {
+ this.inherited(arguments);
+
+ var reportCodeNode = this.reportCodeNode;
+ CodeMirrorPromise.then((function(CodeMirror) {
+ CodeMirror.commands.autocomplete = function(cm) {
+ CodeMirror.simpleHint(cm, CodeMirror.javascriptHint, {
+ completeSingle: false,
+ additionalContext: {
+ //Only expose the important attributes of flow. Most attrs are confusing and for internal use only.
+ "flow": {
+ "request": sampleFlow.request,
+ "response": sampleFlow,
+ "getSimilarFlows": sampleFlow.getSimilarFlows
+ },
+ "traffic": window.HoneyProxy.traffic,
+ "_": _
+ }
+ });
+ };
+ CodeMirror.commands.autoformat = function(cm) {
+ var range = {
+ from: cm.getCursor(true),
+ to: cm.getCursor(false)
+ };
+ cm.autoIndentRange(range.from, range.to);
+ };
+ this.codeMirror = CodeMirror.fromTextArea(reportCodeNode, {
+ lineNumbers: true,
+ mode: "javascript",
+ matchBrackets: true,
+ extraKeys: {
+ "Enter": "newlineAndIndentContinueComment",
+ "Ctrl-Space": "autocomplete",
+ "Shift-Ctrl-F": "autoformat"
+ },
+ onCursorActivity: function() {
+ this.codeMirror.matchHighlight("CodeMirror-matchhighlight");
+ }
+ });
+ }).bind(this));
+
+ this.startButton = new Button({
+ iconClass: "dijitIcon dijitIconFunction"
+ }, this.startButtonNode);
+ },
+ getCode: function() {
+ return this.codeMirror ? this.codeMirror.getValue() : "";
+ }
+ });
+
});
View
18 gui/js/HoneyProxy/views/ReportOutput.js
@@ -1,11 +1,9 @@
-define([
- "dojo/_base/declare",
- "../util/_DynamicTemplatedWidget",
- "dojo/text!./templates/ReportOutput.ejs"
-], function(declare, _DynamicTemplatedWidget, template) {
-
- return declare([_DynamicTemplatedWidget], {
- templateString: template
- });
-
+define([ "dojo/_base/declare", "../util/_DynamicTemplatedWidget",
+ "dojo/text!./templates/ReportOutput.ejs" ], function(declare,
+ _DynamicTemplatedWidget, template) {
+
+ return declare([ _DynamicTemplatedWidget ], {
+ templateString: template
+ });
+
});
View
4 gui/js/HoneyProxy/views/ReportPane.js
@@ -1,6 +1,7 @@
/**
* Main View
*/
+/*jshint unused:false */
define(["require",
"dojo/_base/declare",
"dojo/dom-construct",
@@ -35,12 +36,13 @@ define(["require",
//TODO: Wrap into a correct Controller
on(reportEditor.startButton,"click",function(){
+
require(["../traffic"],function(traffic){
-
var code = reportEditor.getCode();
var outNode = reportOutput.outputNode;
domConstruct.empty(outNode);
try {
+ /*jshint evil:true */
eval(code);
} catch(e) {
//TODO: This is ugly.
View
1  gui/js/HoneyProxy/views/TrafficPane.js
@@ -9,6 +9,7 @@ define(["require",
"./DetailPane",
"./TrafficSidebar"
],function(require,declare,BorderContainer,ContentPane,TrafficTable,DetailPane,TrafficSidebar) {
+
return declare([BorderContainer], {
design: "sidebar",
postCreate: function(){
View
18 gui/js/HoneyProxy/views/TrafficSidebar.js
@@ -1,11 +1,9 @@
-define([
- "dojo/_base/declare",
- "../util/_DynamicTemplatedWidget",
- "dojo/text!./templates/TrafficSidebar.ejs"
-], function(declare, _DynamicTemplatedWidget, template) {
-
- return declare([_DynamicTemplatedWidget], {
- templateString: template
- });
-
+define([ "dojo/_base/declare", "../util/_DynamicTemplatedWidget",
+ "dojo/text!./templates/TrafficSidebar.ejs" ], function(declare,
+ _DynamicTemplatedWidget, template) {
+
+ return declare([ _DynamicTemplatedWidget ], {
+ templateString: template
+ });
+
});
View
18 gui/js/HoneyProxy/views/TrafficTable.js
@@ -1,11 +1,9 @@
-define([
- "dojo/_base/declare",
- "../util/_DynamicTemplatedWidget",
- "dojo/text!./templates/TrafficTable.ejs"
-], function(declare, _DynamicTemplatedWidget, template) {
-
- return declare([_DynamicTemplatedWidget], {
- templateString: template
- });
-
+define([ "dojo/_base/declare", "../util/_DynamicTemplatedWidget",
+ "dojo/text!./templates/TrafficTable.ejs" ], function(declare,
+ _DynamicTemplatedWidget, template) {
+
+ return declare([ _DynamicTemplatedWidget ], {
+ templateString: template
+ });
+
});
View
5 gui/js/HoneyProxy/views/TrafficView.js
@@ -1,8 +1,9 @@
/**
* Our main traffic table showing all flows.
*/
-define(["./FlowView"],function(FlowView){
+define([ "./FlowView" ], function(FlowView) {
+
return Backbone.Marionette.CollectionView.extend({
- itemView: FlowView
+ itemView: FlowView
});
});
View
79 gui/js/HoneyProxy/websocket.js
@@ -1,42 +1,45 @@
-define(["./config","dojo/json","dojo/topic","dojo/Deferred"],function(config,JSON,topic,Deferred){
+define([ "./config", "dojo/json", "dojo/topic", "dojo/Deferred" ], function(
+ config, JSON, topic, Deferred) {
/**
- * HoneyProxy Websocket Client.
- * Connect to the WS URL, perform authentication and listen for new flows or responses to sync requests.
+ * HoneyProxy Websocket Client. Connect to the WS URL, perform authentication
+ * and listen for new flows or responses to sync requests.
*/
var websocket = {
- send: function(jsonMsg){
+ send: function(jsonMsg) {
this.ws.send(JSON.stringify(jsonMsg));
},
onmessage: function onmessage(o) {
var e = JSON.parse(o.data);
- switch(e.msg) {
- case "Authenticated.":
- websocket.authenticated.resolve("authenticated");
- break;
- case "read":
- if(e.id in Backbone._syncrequests)
- {
- var req = Backbone._syncrequests[e.id];
- clearTimeout(req.onError);
- req.success(e.data);
- }
- break;
- case "newflow":
- topic.publish("HoneyProxy/newFlow",e.data);
- break;
- default:
- console.warn("unsupported message",e)
- break;
+ switch (e.msg) {
+ case "Authenticated.":
+ websocket.authenticated.resolve("authenticated");
+ break;
+ case "read":
+ if (e.id in Backbone._syncrequests) {
+ var req = Backbone._syncrequests[e.id];
+ window.clearTimeout(req.onError);
+ req.success(e.data);
+ }
+ break;
+ case "newflow":
+ topic.publish("HoneyProxy/newFlow", e.data);
+ break;
+ default:
+ console.warn("unsupported message", e);
+ break;
}
console.log(e);
},
authenticated: new Deferred(),
- init: function(){
+ init: function() {
this.ws = new WebSocket(config.get("ws"));
- this.ws.onopen = (function(e){
- this.send({action:"auth",key:config.get("auth")});
+ this.ws.onopen = (function() {
+ this.send({
+ action: "auth",
+ key: config.get("auth")
+ });
console.log("Connection established");
}).bind(this);
websocket.ws.onmessage = this.onmessage.bind(this);
@@ -46,25 +49,29 @@ define(["./config","dojo/json","dojo/topic","dojo/Deferred"],function(config,JSO
websocket.init();
/**
- * Backbone.sync implementation using WebSockets.
- * Supplies an id for each request and waits for a response with this id.
- * TODO: Use the JSON API instead.
- * WebSocket should be used for communicating newly arrived flows,
+ * Backbone.sync implementation using WebSockets. Supplies an id for each
+ * request and waits for a response with this id. TODO: Use the JSON API
+ * instead. WebSocket should be used for communicating newly arrived flows,
* but it's clearly not made for a 1:1 request/response model.
*/
Backbone._syncrequests = {};
Backbone.sync = function(method, model, options) {
- if(method != "read")
- {
+ if (method != "read") {
console.warn("only read is supported");
return;
}
-
- id = model.id ? model.id : "all";
- var msg = {action:"read", id: id};
- Backbone._syncrequests[id] = {onError: window.setTimeout(function(){options.error("WebSocket Timeout.");},5000),
- success: options.success};
+ var id = model.id ? model.id : "all";
+ var msg = {
+ action: "read",
+ id: id
+ };
+ Backbone._syncrequests[id] = {
+ onError: window.setTimeout(function() {
+ options.error("WebSocket Timeout.");
+ }, 5000),
+ success: options.success
+ };
websocket.send(msg);
};
Please sign in to comment.
Something went wrong with that request. Please try again.