Implementing a Sortable Task Queue for Scanning Operations
To prevent loss of plugin data during Goby's plugin reloads, a data.json file is created within the plugin's directory to persistently store task information.
fs.writeFile(this.filePath, JSON.stringify({"data": []}, null, 6), (err) => {});
Retrieving Scan Configuration Data
For users to define custom scan tasks, essential scanning parameters such as port lists, vulnerability checks (POCs), and scan order options must be retrieved using dedicated APIs: getPortList, getVulnerabilityList, and getOrderList.
goby.getPortList().then((res) => {
config.port = res.data;
let options = '';
res.data.forEach(item => {
options += `<option value="${item.type}">${item.type}</option>`;
});
$('.port').html(options);
form.render('select');
$('.portcontent').val(res.data[0].value);
});
goby.getVulnerabilityList().then((res) => {
let options = '';
res.data.forEach(vuln => {
options += `<option value="${vuln}">${vuln}</option>`;
});
$('.vulnerability').html(options);
form.render('select');
});
goby.getOrderList().then((res) => {
let options = '';
res.data.forEach(order => {
options += `<option value="${order}">${order}</option>`;
});
$('.order').html(options);
form.render('select');
});
Event Binding for Task Lifecycle Menagement
To manage the task queue dynamically, events such as scan start, pause, and completion must trigger appropriate actions like launching the next queued task or refreshing the UI. The following snippet demonstrates refreshing the queue UI after a scan is paused, with a one-second delay to allow for file system updates.
goby.bindEvent('onPauseScan', () => {
setTimeout(() => {
init();
}, 1000);
});
Initiating a Scan Task
When starting a scan, the selected task configuration is passed to startScan. Upon success, the task ID is recorded and the queue state is updated in the presistent JSON file.
goby.startScan(queue.data[index]).then((res) => {
queue.data[index].taskId = res.data.taskId;
queue.data[index].state = 1;
fs.writeFile(this.filePath, JSON.stringify(queue, null, 6), (err) => {
if (err) {
reject(err);
} else {
resolve(res);
}
});
});
Managing the Task Queue in a Shared Context
To enable interaction with the task queue from custom modal windows, a global taskQueue instance is initialized in extension.js.
window.taskQueue = new TaskQueue();
This instance exposes methods such as adding, removing, and starting tasks. From a modal window, the parent context provides access to both the Goby API and the shared queue.
const goby = parent.goby;
const taskQueue = parent.taskQueue;
Queue operations can then be performed directly. For example, removing a task on user request:
$('.con').delegate('.delete', 'click', function() {
const queueId = $(this).parent().attr('queueId');
taskQueue.delete([queueId]).then(() => {
init();
});
});
Future enhancements to this plugin include scheduled scans and drag-and-drop reordering of tasks, enabling automated and user-friendly scan menagement.