forked from AlexisDanizan/Offline-Nmap-Viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnmapwebapp.js
121 lines (111 loc) · 3.5 KB
/
nmapwebapp.js
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
$(function () {
var Nmap = Backbone.Model.extend({
parse: function (data) {
console.log(typeof data);
if(typeof data === 'object'){
return data;
}else{
data = data.substr(data.indexOf("<nmaprun"));
var x2js = new X2JS();
//console.log(JSON.stringify(x2js.xml_str2json(data)));
var json = JSON.parse(JSON.stringify(x2js.xml_str2json(data)));
return json;
}
}
});
var NmapList = Backbone.Collection.extend({
model: Nmap,
localStorage: new Backbone.LocalStorage("nmap-backbone"),
});
var Nmaps = new NmapList();
var NmapListView = Backbone.View.extend({
tagName: "tr",
template: _.template($('#nmap-list-template').html()),
events: {
"click .open-item": "show",
"click .close-item": "clear",
},
initialize: function () {
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'destroy', this.remove);
},
render: function () {
//console.log(this.model.toJSON());
this.$el.html(this.template(this.model.toJSON()));
return this;
},
show: function () {
$("td.selected").toggleClass("selected");
this.$("td").toggleClass("selected");
new NmapView({model: this.model});
},
clear: function () {
this.model.destroy();
}
});
var NmapView = Backbone.View.extend({
el: $("#nmap-item"),
template: _.template($('#nmap-item-template').html()),
events: {
},
initialize: function () {
this.render();
//this.listenTo(this.model, 'change', this.render);
},
render: function () {
this.$el.html(this.template(this.model.toJSON()));
}
});
var AppView = Backbone.View.extend({
el: $("#menu-container"),
template: _.template($('#menu-template').html()),
events: {
"click #format": "format",
"click #clear" : "clear",
},
initialize: function() {
//this.listenTo(Nmaps, 'add', this.render);
Nmaps.fetch();
this.render();
},
render: function() {
this.$el.html( this.template());
//console.log(Nmaps.length);
if(Nmaps.length){
this.renderAllNmap();
}
},
renderNmap: function (nmap) {
//console.log(nmap);
var view = new NmapListView({model: nmap});
//console.log(view.render().el);
$("#nmap-list").append(view.render().el);
},
renderAllNmap: function () {
Nmaps.each(this.renderNmap, this);
},
format: function () {
var nmap = new Nmap($("#nmap-result").val(),{parse: true});
console.log(nmap);
Nmaps.add(nmap);
console.log("added");
nmap.save();
console.log("saved");
this.renderNmap(nmap);
},
clear: function () {
$("#nmap-result").val('');
}
});
var Router = Backbone.Router.extend({
routes: {
"*actions": "default"
},
default: function () {
new AppView();
console.log("default");
}
});
var router = new Router;
Backbone.history.start();
});