From b905455e8b160d9c999b40671f1e7380d5d70c1e Mon Sep 17 00:00:00 2001 From: Nikita Oleksov Date: Mon, 15 Dec 2014 23:52:09 +0700 Subject: [PATCH 1/5] Added searching --- .../javascript/ui/panel/ModuleSearching.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 extensions/admin_ui/media/javascript/ui/panel/ModuleSearching.js diff --git a/extensions/admin_ui/media/javascript/ui/panel/ModuleSearching.js b/extensions/admin_ui/media/javascript/ui/panel/ModuleSearching.js new file mode 100644 index 000000000..9970df7e1 --- /dev/null +++ b/extensions/admin_ui/media/javascript/ui/panel/ModuleSearching.js @@ -0,0 +1,45 @@ +function search_module(module_tree, searching_string) { + var json_object_clone = new Array(); + for ( var i = 0; i < module_tree.length; i++ ) + json_object_clone.push(module_tree[i].attributes); + if ( searching_string.search(/\w/) == -1 ) + return json_object_clone; + var json_object = jQuery.extend(true, [], json_object_clone); + searching_string = searching_string.replace(/"\s*"/g, " ").replace(/\s+/g, " ").match(/"[^"]+"|\S+/g); + searching_string.forEach(prepare_searching_string); + var result = json_object.filter(form_new_modules_tree); + result.forEach(recount_modules_and_expand_directories); + return result; + + function prepare_searching_string(string, index, array){ + array[index] = string.toLowerCase().replace(/"/g, ""); + } + + function check_name_of_module(str) { + return Boolean(this.toString().toLowerCase().replace(/\s\([0-9]+\)/g,"").indexOf(str) + 1); + } + + function form_new_modules_tree(element) { + if ( searching_string.some(check_name_of_module, element.text) ) + return true; + if ( element.children ) { + element.children = element.children.filter(form_new_modules_tree); + return Boolean(element.children.length); + } + return false; + } + + function recount_modules_and_expand_directories(element) { + if ( element.children ) { + element.expanded = true; + var count_of_modules = element.children.length; + for ( var i = 0; i < element.children.length; i++ ) + if ( element.children ) + count_of_modules += recount_modules_and_expand_directories(element.children[i]); + element.children.forEach(recount_modules_and_expand_directories); + element.text = element.text.replace(/([-_ 0-9a-zA-Z]+)\(([0-9]+)\)/, "$1(" + count_of_modules + ")") + return count_of_modules - 1; + } + return 0; + } +} From 1c2559fe4ac10120574f4322b11c405d5aa2623c Mon Sep 17 00:00:00 2001 From: Oleg Broslavsky Date: Tue, 16 Dec 2014 17:45:01 +0700 Subject: [PATCH 2/5] Search panel ui --- .../ui/panel/tabs/ZombieTabCommands.js | 84 +++++++++++++++---- 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js b/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js index 281ffe40c..19fa6a96b 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js +++ b/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js @@ -9,6 +9,8 @@ * Loaded in /ui/panel/index.html */ ZombieTab_Commands = function(zombie) { + var k = 0; + var originalRoot; var command_module_config = new Ext.Panel({ id: 'zombie-command-module-config-'+zombie.session, @@ -92,11 +94,43 @@ ZombieTab_Commands = function(zombie) { } }; - var command_module_tree = new Ext.tree.TreePanel({ - id: "zombie-command-modules"+zombie.session, - title: "Module Tree", - border: true, - region: 'west', + var command_module_tree_search = new Ext.form.TextField( { + emptyText: 'Search', + id: 'module-search-' + zombie.session, + style: { + width: '100%' + }, + listeners: { + specialkey : function(field,e){ + if(e.getKey() == e.ENTER){ + if( field.getValue() ){ + console.log(originalRoot); + var root = { + text: "Search results", + children: search_module(originalRoot, field.getValue()) + }; + console.log(originalRoot); + console.log(root); + command_module_tree.setRootNode(root); + }else { command_module_tree.setRootNode(originalRoot); + } + } + } + } + }); + + var command_module_tree_search_panel = new Ext.Panel({ + id: "zombie-command-modules-search-panel"+zombie.session, + items: [ command_module_tree_search ], + width: 190, + minSize: 190, + maxSize: 500, + region: 'north' +}); + +var command_module_tree = new Ext.tree.TreePanel({ + id: "zombie-command-modules"+zombie.session, + region: 'center', width: 190, minSize: 190, maxSize: 500, // if some command module names are even longer, adjust this value @@ -119,6 +153,7 @@ ZombieTab_Commands = function(zombie) { load: function(treeloader, node, response) { // Hide loading mask after tree is fully loaded treeloader.treeLoadingMask.hide(); + originalRoot = command_module_tree.root.childNodes; return true; } } @@ -133,18 +168,34 @@ ZombieTab_Commands = function(zombie) { }, 'activate' : function() { }, + 'deactivate' : function() { + }, 'select' : function() { }, 'keyup' : function() { }, 'render' : function(c) { - c.getEl().on('keyup', function() { - LoadCommandPanelEvent(Ext.getCmp('zombie-command-modules'+zombie.session).getSelectionModel().getSelectedNode(),true); - }); - } + c.getEl().on('keyup', function(a) { + LoadCommandPanelEvent(Ext.getCmp('zombie-command-modules'+zombie.session).getSelectionModel().getSelectedNode(),true); + }); + } } }); +var command_module_tree_container = new Ext.Panel({ + id: "zombie-command-modules-container"+zombie.session, + title: "Module Tree", + border: true, + width: 190, + minSize: 190, + maxSize: 500, + layout: 'border', + region: 'west', + split: true, + items: [ command_module_tree_search_panel,command_module_tree ], +}); + + var commands_statusbar = new Beef_StatusBar(zombie.session); ZombieTab_Commands.superclass.constructor.call(this, { @@ -160,13 +211,14 @@ ZombieTab_Commands = function(zombie) { collapsible: false, split: true }, - items: [command_module_tree, - new Ext.Panel({ - id: 'zombie-command-module-west-'+zombie.session, - region: 'center', - layout: 'border', - border: false, - items: [command_module_grid, command_module_config] + items: [ + command_module_tree_container, + new Ext.Panel({ + id: 'zombie-command-module-west-'+zombie.session, + region: 'center', + layout: 'border', + border: false, + items: [command_module_grid, command_module_config] })] }, From 294a7cb5c620a64cd7426c0220a30c36208ad0f3 Mon Sep 17 00:00:00 2001 From: Oleg Broslavsky Date: Tue, 16 Dec 2014 17:47:05 +0700 Subject: [PATCH 3/5] Add module search JS to uglifier --- extensions/admin_ui/api/handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/admin_ui/api/handler.rb b/extensions/admin_ui/api/handler.rb index 310f96630..4fa031267 100644 --- a/extensions/admin_ui/api/handler.rb +++ b/extensions/admin_ui/api/handler.rb @@ -33,7 +33,7 @@ module API #NOTE: order counts! make sure you know what you're doing if you add files esapi = %w(esapi/Class.create.js esapi/jquery-1.6.4.min.js esapi/jquery-encoder-0.1.0.js) ux = %w(ui/common/beef_common.js ux/PagingStore.js ux/StatusBar.js ux/TabCloseMenu.js) - panel = %w(ui/panel/common.js ui/panel/DistributedEngine.js ui/panel/PanelStatusBar.js ui/panel/tabs/ZombieTabDetails.js ui/panel/tabs/ZombieTabLogs.js ui/panel/tabs/ZombieTabCommands.js ui/panel/tabs/ZombieTabRider.js ui/panel/tabs/ZombieTabXssRays.js wterm/wterm.jquery.js ui/panel/tabs/ZombieTabIpec.js ui/panel/tabs/ZombieTabAutorun.js ui/panel/PanelViewer.js ui/panel/DataGrid.js ui/panel/MainPanel.js ui/panel/ZombieTab.js ui/panel/ZombieTabs.js ui/panel/zombiesTreeList.js ui/panel/ZombiesMgr.js ui/panel/Logout.js ui/panel/WelcomeTab.js) + panel = %w(ui/panel/common.js ui/panel/DistributedEngine.js ui/panel/PanelStatusBar.js ui/panel/tabs/ZombieTabDetails.js ui/panel/tabs/ZombieTabLogs.js ui/panel/tabs/ZombieTabCommands.js ui/panel/tabs/ZombieTabRider.js ui/panel/tabs/ZombieTabXssRays.js wterm/wterm.jquery.js ui/panel/tabs/ZombieTabIpec.js ui/panel/tabs/ZombieTabAutorun.js ui/panel/PanelViewer.js ui/panel/DataGrid.js ui/panel/MainPanel.js ui/panel/ZombieTab.js ui/panel/ZombieTabs.js ui/panel/zombiesTreeList.js ui/panel/ZombiesMgr.js ui/panel/Logout.js ui/panel/WelcomeTab.js ui/panel/ModuleSearching.js) global_js = esapi + ux + panel From 9268ba9f5e6bb01eab9edd5ae031f1c7ca62571a Mon Sep 17 00:00:00 2001 From: Oleg Broslavsky Date: Thu, 18 Dec 2014 17:47:08 +0700 Subject: [PATCH 4/5] Little code refactoring in module search files --- .../javascript/ui/panel/ModuleSearching.js | 55 +++++++++++++------ .../ui/panel/tabs/ZombieTabCommands.js | 24 ++++---- 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/extensions/admin_ui/media/javascript/ui/panel/ModuleSearching.js b/extensions/admin_ui/media/javascript/ui/panel/ModuleSearching.js index 9970df7e1..ffdbe12e1 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/ModuleSearching.js +++ b/extensions/admin_ui/media/javascript/ui/panel/ModuleSearching.js @@ -1,26 +1,42 @@ -function search_module(module_tree, searching_string) { - var json_object_clone = new Array(); +/* + * Keyword search for command module panel. + * Words in query are searched as separated queries. You can search for exact matching using double qoutes arround query + */ + +function search_module(module_tree, query_string) { + if ( query_string.search(/\w/) == -1 ) + return tree_array; + + // copy module tree w/o ExtJS service properties + var tree_array = new Array(); for ( var i = 0; i < module_tree.length; i++ ) - json_object_clone.push(module_tree[i].attributes); - if ( searching_string.search(/\w/) == -1 ) - return json_object_clone; - var json_object = jQuery.extend(true, [], json_object_clone); - searching_string = searching_string.replace(/"\s*"/g, " ").replace(/\s+/g, " ").match(/"[^"]+"|\S+/g); - searching_string.forEach(prepare_searching_string); - var result = json_object.filter(form_new_modules_tree); - result.forEach(recount_modules_and_expand_directories); - return result; + tree_array.push(module_tree[i].attributes); + + var json_object = jQuery.extend(true, [], tree_array); + + // split query string into separate words and exact phrases + query_string = query_string.replace(/"\s*"/g, " ").replace(/\s+/g, " ").match(/"[^"]+"|\S+/g); + query_string.forEach(prepare_query_string); - function prepare_searching_string(string, index, array){ + var result = json_object.filter(form_new_modules_tree); + result.forEach(recount_modules_and_expand_directories); + + return result; + + // remove quotes from phrases for exact match + function prepare_query_string(string, index, array){ array[index] = string.toLowerCase().replace(/"/g, ""); } - function check_name_of_module(str) { + // True if this.toString() contains str + function check_module_name(str) { return Boolean(this.toString().toLowerCase().replace(/\s\([0-9]+\)/g,"").indexOf(str) + 1); } + // func for JSON filter + // Build a new tree from modules which are appropriate for any part of query function form_new_modules_tree(element) { - if ( searching_string.some(check_name_of_module, element.text) ) + if ( query_string.some(check_module_name, element.text) ) return true; if ( element.children ) { element.children = element.children.filter(form_new_modules_tree); @@ -32,13 +48,16 @@ function search_module(module_tree, searching_string) { function recount_modules_and_expand_directories(element) { if ( element.children ) { element.expanded = true; - var count_of_modules = element.children.length; + var modules_in_directory = element.children.length; + // visit all for ( var i = 0; i < element.children.length; i++ ) if ( element.children ) - count_of_modules += recount_modules_and_expand_directories(element.children[i]); + modules_in_directory += recount_modules_and_expand_directories(element.children[i]); + // expand them element.children.forEach(recount_modules_and_expand_directories); - element.text = element.text.replace(/([-_ 0-9a-zA-Z]+)\(([0-9]+)\)/, "$1(" + count_of_modules + ")") - return count_of_modules - 1; + // and set new number of modules in directory + element.text = element.text.replace(/([-_ 0-9a-zA-Z]+)\(([0-9]+)\)/, "$1(" + modules_in_directory + ")") + return modules_in_directory - 1; } return 0; } diff --git a/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js b/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js index 19fa6a96b..81a5c149a 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js +++ b/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js @@ -104,16 +104,14 @@ ZombieTab_Commands = function(zombie) { specialkey : function(field,e){ if(e.getKey() == e.ENTER){ if( field.getValue() ){ - console.log(originalRoot); var root = { text: "Search results", children: search_module(originalRoot, field.getValue()) }; - console.log(originalRoot); - console.log(root); command_module_tree.setRootNode(root); - }else { command_module_tree.setRootNode(originalRoot); - } + } else + command_module_tree.setRootNode(originalRoot); + } } } @@ -126,14 +124,14 @@ ZombieTab_Commands = function(zombie) { minSize: 190, maxSize: 500, region: 'north' -}); + }); -var command_module_tree = new Ext.tree.TreePanel({ - id: "zombie-command-modules"+zombie.session, - region: 'center', + var command_module_tree = new Ext.tree.TreePanel({ + id: "zombie-command-modules"+zombie.session, + region: 'center', width: 190, minSize: 190, - maxSize: 500, // if some command module names are even longer, adjust this value + maxSize: 500, useArrows: true, autoScroll: true, animate: true, @@ -182,18 +180,18 @@ var command_module_tree = new Ext.tree.TreePanel({ } }); -var command_module_tree_container = new Ext.Panel({ + var command_module_tree_container = new Ext.Panel({ id: "zombie-command-modules-container"+zombie.session, title: "Module Tree", border: true, width: 190, minSize: 190, - maxSize: 500, + maxSize: 500, // if some command module names are even longer, adjust this value layout: 'border', region: 'west', split: true, items: [ command_module_tree_search_panel,command_module_tree ], -}); + }); var commands_statusbar = new Beef_StatusBar(zombie.session); From a96867b6cd17854e058ad787448eefa574c5d1f3 Mon Sep 17 00:00:00 2001 From: Oleg Broslavsky Date: Thu, 18 Dec 2014 17:52:07 +0700 Subject: [PATCH 5/5] One more fix to module search --- .../admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js b/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js index 81a5c149a..9329d6425 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js +++ b/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabCommands.js @@ -9,7 +9,6 @@ * Loaded in /ui/panel/index.html */ ZombieTab_Commands = function(zombie) { - var k = 0; var originalRoot; var command_module_config = new Ext.Panel({