git-svn-id: https://beef.googlecode.com/svn/trunk@626 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
203 lines
6.0 KiB
JavaScript
203 lines
6.0 KiB
JavaScript
/*
|
|
* The zombie panel located on the left hand side of the interface.
|
|
*/
|
|
zombiesTreeList = function(id) {
|
|
|
|
var title = id.slice(0,1).toUpperCase() + id.slice(1);
|
|
|
|
zombiesTreeList.superclass.constructor.call(this, {
|
|
id:'zombie-tree-'+id,
|
|
region:'west',
|
|
title: title,
|
|
split:true,
|
|
rootVisible:false,
|
|
lines:false,
|
|
autoScroll:true,
|
|
root: new Ext.tree.TreeNode('My Zombies'),
|
|
collapseFirst:false
|
|
});
|
|
|
|
this.online_hooked_browsers_treenode = this.root.appendChild(
|
|
new Ext.tree.TreeNode({
|
|
text:'Online Browsers',
|
|
cls:'online-zombies-node',
|
|
expanded:true
|
|
})
|
|
);
|
|
|
|
this.offline_hooked_browsers_treenode = this.root.appendChild(
|
|
new Ext.tree.TreeNode({
|
|
text:'Offline Browsers',
|
|
cls:'offline-zombies-node',
|
|
expanded:false
|
|
})
|
|
);
|
|
|
|
};
|
|
|
|
/*
|
|
* The Tree panel that contains the zombie list.
|
|
*/
|
|
Ext.extend(zombiesTreeList, Ext.tree.TreePanel, {
|
|
|
|
//saves the configuration for the tree
|
|
tree_configuration: {
|
|
'sub-branch' : 'domain',
|
|
'distributed' : false
|
|
},
|
|
|
|
//store the list of online hooked browsers in an array
|
|
online_hooked_browsers_array: new Array,
|
|
|
|
//store the list of offline hooked browsers in an array
|
|
offline_hooked_browsers_array: new Array,
|
|
|
|
//store the distributed engine rules
|
|
distributed_engine_rules: null,
|
|
|
|
listeners: {
|
|
//creates a new hooked browser tab when a hooked browser is clicked
|
|
click: function(node, e) {
|
|
if(!node.leaf) return;
|
|
|
|
if(!mainPanel.get(node.attributes.session)) {
|
|
mainPanel.add(new ZombieTab(node.attributes));
|
|
}
|
|
|
|
mainPanel.activate(node.attributes.session);
|
|
}
|
|
},
|
|
|
|
/*
|
|
* Adds a new hooked browser to the tree.
|
|
* @param: {Literal Object} the hooked browser object generated by the zombie manager.
|
|
* @param: {Boolean} true if the hooked browser is online, false if offline.
|
|
*/
|
|
addZombie : function(hooked_browser, online) {
|
|
var hb_id, mother_node, node;
|
|
|
|
if(online) {
|
|
hb_id = 'zombie-online-' + hooked_browser.session;
|
|
mother_node = this.online_hooked_browsers_treenode;
|
|
} else {
|
|
hb_id = 'zombie-offline-' + hooked_browser.session;
|
|
mother_node = this.offline_hooked_browsers_treenode;
|
|
}
|
|
//window.console.log(this.online_hooked_browsers_array)
|
|
var exists = this.getNodeById(hb_id);
|
|
if(exists) return;
|
|
|
|
//save a new online HB
|
|
if(online && Ext.pluck(this.online_hooked_browsers_array, 'session').indexOf(hooked_browser.session)==-1) {
|
|
this.online_hooked_browsers_array.push(hooked_browser);
|
|
}
|
|
|
|
//save a new offline HB
|
|
if(!online && this.offline_hooked_browsers_array.indexOf(hooked_browser)==-1) {
|
|
this.offline_hooked_browsers_array.push(hooked_browser);
|
|
}
|
|
|
|
//apply CSS styles and configuring the hooked browser for the tree
|
|
Ext.apply(hooked_browser, {
|
|
iconCls: 'feed-icon',
|
|
leaf:true,
|
|
id: hb_id
|
|
});
|
|
|
|
//creates a new node for that hooed browser
|
|
node = new Ext.tree.TreeNode(hooked_browser);
|
|
|
|
//creates a sub-branch for that HB if necessary
|
|
mother_node = this.addSubFolder(mother_node, hooked_browser[this.tree_configuration['sub-branch']]);
|
|
|
|
if(online) {
|
|
//add the hooked browser to the online branch
|
|
Ext.apply(hooked_browser, {cls: 'zombie-online'});
|
|
mother_node.appendChild(node);
|
|
} else {
|
|
//add the hooked browser to the offline branch
|
|
Ext.apply(hooked_browser, {cls: 'zombie-offline'});
|
|
mother_node.appendChild(node);
|
|
}
|
|
|
|
return node;
|
|
},
|
|
|
|
/*
|
|
* Adds a sub-branch or sub-folder to the tree.
|
|
* @param: {Ext.tree.TreeNode} the mother node.
|
|
* @param: {String} the name of the new sub branch.
|
|
*/
|
|
addSubFolder: function(mother_node, folder) {
|
|
if(!folder) return mother_node;
|
|
|
|
if(mother_node.hasChildNodes()) {
|
|
for(i in mother_node.childNodes) {
|
|
node = mother_node.childNodes[i];
|
|
|
|
if(typeof node == 'object' && node.attributes.text == folder)
|
|
return node;
|
|
}
|
|
} else {
|
|
sub_folder_node = new Ext.tree.TreeNode({
|
|
id: 'sub-folder-'+folder,
|
|
text: folder
|
|
});
|
|
|
|
mother_node.appendChild(sub_folder_node);
|
|
mother_node = sub_folder_node;
|
|
}
|
|
|
|
return mother_node;
|
|
},
|
|
|
|
/*
|
|
* Remove any duplicated hooked browsers in branches.
|
|
* @param: {Literal Object} object containing the list of hooked browsers.
|
|
*/
|
|
compareAndRemove: function(zombies) {
|
|
var arr = ['online', 'offline'];
|
|
|
|
Ext.each(arr, function(branch_type) {
|
|
var new_set_zombies = zombies[branch_type];
|
|
var new_set_zombies_array = new Array;
|
|
|
|
//converts the new set of zombies to an array
|
|
Ext.iterate(new_set_zombies, function(key, hooked_browser) { new_set_zombies_array.push(hooked_browser); });
|
|
|
|
//retrieves all the new hooked browsers' session id
|
|
var new_set_zombies_sessions = Ext.pluck(new_set_zombies_array, 'session');
|
|
if(!new_set_zombies_sessions) return;
|
|
|
|
//retrieves the branch that will be updated
|
|
var branch_node = eval('this.'+branch_type+'_hooked_browsers_treenode');
|
|
|
|
//retrieves the list of known hooked browsers in that branch
|
|
var hooked_browser_array = eval('this.'+branch_type+'_hooked_browsers_array');
|
|
if(hooked_browser_array.length == 0) return;
|
|
|
|
//we compare the list of known HBs to the new set of HBs retrieved. If a HB is missing
|
|
//we delete it from the tree.
|
|
Ext.iterate(hooked_browser_array, function(known_hooked_browser, key) {
|
|
if(!known_hooked_browser) return;
|
|
|
|
var hb_session = known_hooked_browser["session"];
|
|
|
|
if(new_set_zombies_sessions.indexOf(hb_session)==-1) {
|
|
var node = this.getNodeById('zombie-'+branch_type+'-'+hb_session);
|
|
if(node) {
|
|
//remove the node from the tree
|
|
branch_node.removeChild(node);
|
|
|
|
//because ExtJs has a bug with node.destroy() this is a hack to make it work for beef.
|
|
node.setId("hooked-browser-node-destroyed");
|
|
|
|
//update the array of hooked browser
|
|
hooked_browser_array = hooked_browser_array.slice(key, key+1);
|
|
eval('this.'+branch_type+'_hooked_browsers_array = hooked_browser_array');
|
|
}
|
|
}
|
|
}, this);
|
|
}, this);
|
|
}
|
|
}); |