Skip to content

Instantly share code, notes, and snippets.

@mattburch
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattburch/95d2157b06dd7fef5bb2 to your computer and use it in GitHub Desktop.
Save mattburch/95d2157b06dd7fef5bb2 to your computer and use it in GitHub Desktop.
var deliverableUniquePortSummary = function(protocol) {
// Generates a of reports for deliverable template
// Usages: deliverableUniquePortSummary()
// Created by: Matt Burch
// Requires client-side updates: false
var PROJECT_ID = Session.get('projectId');
var unique = {};
function checkservice(list, p) {
for (i=0; i<list.length; i++) {
if (list[i] == p) {
return true;
}
};
return false;
};
var ports = Ports.find({'project_id' : PROJECT_ID}).fetch()
ports.forEach( function(port) {
service = port.service.toUpperCase() + "_" + port.protocol.toUpperCase();
if (port.port == 0){
return;
}
if (!(port.service)) {
port.service = "unknown"
}
if (!(service in unique)) {
unique[service] = [port.port]
}
else {
if (!checkservice(unique[service], port.port)) {
unique[service].push(port.port);
}
}
});
for (key in unique) {
port = key.split("_");
if (unique[key].length > 1) {
console.log(port[0] + " (VARIOUS/" + port[1] + ")");
}
else {
console.log(port[0] + " (" + unique[key] + "/" + port[1] + ")");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment