Created
April 17, 2012 10:00
-
-
Save sebmck/2405042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket = io.connect "http://#{document.location.host}" | |
socket.on 'connect', -> | |
$('#loading').text 'Authenticating' | |
$.get '/login_info', (data) -> | |
socket.emit 'login', | |
username: data.username | |
password: data.password | |
socket.on 'disconnect', -> | |
$('#container').hide() | |
$('#loading').show().text 'Disconnect: State has been saved serverside' | |
socket.on 'login', (data) -> | |
if data.status | |
$('#loading').hide() | |
$('#container').show() | |
else | |
$('#loading').text 'Authentication Fail' | |
socket.on 'port', (data) -> | |
console.log data | |
results = $(".results[data-id=#{data.scanId}]") | |
activeTargets = -> | |
results.children(".active-targets") | |
inactiveTargets = -> | |
results.children(".inactive-targets") | |
inactiveScan = -> | |
inactiveTargets().find(".scan-result[data-id=#{data.targetId}]") | |
activeScan = -> | |
activeTargets().find(".scan-result[data-id=#{data.targetId}]") | |
if data.status is 'open' and inactiveScan().length | |
inactiveScan().detach().appendTo activeTargets() | |
if activeScan().length | |
scan = activeScan() | |
else | |
scan = inactiveScan() | |
if data.status is 'open' | |
summary = scan.children('summary') | |
summary.append $('<ul>') if !summary.children('ul').length | |
summary.children('ul').append $('<li>').text data.port | |
result = scan.find(".port-result[data-id=#{data.portId}]") | |
result.children('summary').addClass data.status | |
latency = $('<p>') | |
latency.append $('<strong>').text 'Latency: ' | |
latency.append $('<span>').text "#{data.latency} ms" | |
result.append latency | |
socket.on 'parsed', (data) -> | |
if data.targets.length is 0 | |
alert 'ERROR: after parsing targets is empty' | |
if data.ports.length is 0 | |
alert 'ERROR: after parsing ports is empty' | |
if data.ports.length is 0 or data.targets.length is 0 | |
return false | |
tabDefault = data.targets.map (target) -> | |
if target.host | |
target.host | |
else | |
target.ip | |
tabDefault = _.uniq(tabDefault).join ', ' | |
tabName = prompt('Tab Name', tabDefault) | |
$('nav ul').append $('<li>').text(tabName || tabDefault).attr 'data-id', data.id | |
scanResult = $('<div>').addClass('results').attr 'data-id', data.id | |
inactive = $('<details>').addClass 'inactive-targets' | |
inactive.attr 'open', '' | |
inactiveSummary = $('<summary>') | |
inactiveSummary.append $('<h2>').text 'Inactive' | |
inactive.append inactiveSummary | |
active = $('<details>').addClass 'active-targets' | |
active.attr 'open', '' | |
activeSummary = $('<summary>') | |
activeSummary.append $('<h2>').text 'Active' | |
active.append activeSummary | |
scanResult.append active | |
data.targets.forEach (target, index) -> | |
targetSummary = $('<summary>').append $('<strong>').text target.ip | |
targetSummary.append $('<span>').text target.host if target.host | |
targetResult = $('<details>').addClass('scan-result').attr 'data-id', index | |
targetResult.append targetSummary | |
info = $('<details>').attr 'open', '' | |
infoSummary = $('<summary>') | |
infoSummary.append $('<h3>').text 'Info' | |
info.append infoSummary | |
info.append $('<p>').text 'extra info about host goes here' | |
targetResult.append info | |
ports = $('<details>').attr 'open', '' | |
portsSummary = $('<summary>') | |
portsSummary.append $('<h3>').text 'Results' | |
ports.append portsSummary | |
data.ports.forEach (port, index) -> | |
portResult = $('<details>').addClass('port-result').attr 'data-id', index | |
portSummary = $('<summary>') | |
portSummary.append $('<span>').text port | |
portResult.append portSummary | |
ports.append portResult | |
targetResult.append ports | |
inactive.append targetResult | |
scanResult.append inactive | |
$('section').prepend scanResult | |
$('nav ul li:last-child').click() | |
$('form').submit -> | |
socket.emit 'run scan', { | |
id: $('nav ul li:last-child').data('id') + 1 || 0 | |
ports: $('input.ports').val() | |
target: $('input.ip').val() | |
timeout: $('input.timeout').val() | |
} | |
$('input:not([type=submit])').val '' | |
false | |
$('nav ul li').live 'click', -> | |
$('.sort-by, section, nav').show() | |
$('nav ul li.active').removeClass 'active' | |
$(this).addClass 'active' | |
$('.results').hide() | |
$(".results[data-id=#{$(this).data('id')}]").show() | |
$('input.timeout').change -> | |
$('#timeout-counter').text "#{$(this).val()}ms" | |
$('.sort-by ul li.active').click -> | |
$(this).parent().toggleClass 'hidden' | |
$('.sort-by ul li:not(.active)').click -> | |
$(this).parent().children('.active').removeClass 'active' | |
$(this).addClass 'active' | |
$(this).parent().toggleClass 'hidden' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment