Skip to content

Commit

Permalink
first and only commit for new nmap xml feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kacole2 committed Jan 8, 2014
1 parent 0db8ce6 commit a0ac2c5
Show file tree
Hide file tree
Showing 49 changed files with 647 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem "mini_magick"
gem 'therubyracer'
gem 'thin'
gem 'will_paginate-bootstrap'
gem 'ruby-nmap'

# Use postgresql as the database for Active Record
gem 'pg'
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ GEM
mime-types (1.25)
mini_magick (3.6.0)
subexec (~> 0.2.1)
mini_portile (0.5.2)
minitest (4.7.5)
multi_json (1.8.1)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
pg (0.17.0)
polyglot (0.3.3)
rack (1.5.2)
Expand All @@ -86,6 +89,10 @@ GEM
rdoc (3.12.2)
json (~> 1.4)
ref (1.0.5)
rprogram (0.3.2)
ruby-nmap (0.6.0)
nokogiri (~> 1.3)
rprogram (~> 0.3)
sass (3.2.12)
sass-rails (4.0.0)
railties (>= 4.0.0.beta, < 5.0)
Expand Down Expand Up @@ -140,6 +147,7 @@ DEPENDENCIES
mini_magick
pg
rails (= 4.0.0)
ruby-nmap
sass-rails (~> 4.0.0)
sdoc
therubyracer
Expand Down
Binary file added app/assets/images/nmapxmlicons/3com-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/adtran-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/aruba-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/avaya-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/brother-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/cisco-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/dell-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/f5-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/freebsd-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/hp-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/juniper-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/linux-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/mac-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/novell-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/unknown-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/vmware-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/windows-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/nmapxmlicons/xerox-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/javascripts/nmapfiles.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
84 changes: 84 additions & 0 deletions app/controllers/nmapfiles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
class NmapfilesController < ApplicationController
before_action :set_nmapfile, only: [:show, :update, :destroy]

# GET /nmapfiles
# GET /nmapfiles.json
def index
@jumpsquares = Jumpsquare.all
@jumpsizes = Jumpsize.all
#@nmapfiles = Nmapfile.all
@nmapfiles = Nmapfile.search(params[:search]).paginate(:page => params[:page], :per_page => @jumpsizes.first.itemsperpage).find(:all, :order => sort_order('lower(nmapfilename)'))
end

# GET /nmapfiles/1
# GET /nmapfiles/1.json
def show
end

# GET /nmapfiles/new
def new
@nmapfile = Nmapfile.new
end

# GET /nmapfiles/1/edit
def edit
end

# POST /nmapfiles
# POST /nmapfiles.json
def create
@nmapfile = Nmapfile.new(nmapfile_params)

respond_to do |format|
if @nmapfile.save
format.html { redirect_to @nmapfile, notice: 'nmap file was successfully created.' }
format.json { render action: 'show', status: :created, location: @nmapfile }
else
format.html { render action: 'new' }
format.json { render json: @nmapfile.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /nmapfiles/1
# PATCH/PUT /nmapfiles/1.json
def update
respond_to do |format|
if @nmapfile.update(nmapfile_params)
format.html { redirect_to @nmapfile, notice: 'Nmapfile was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @nmapfile.errors, status: :unprocessable_entity }
end
end
end

# DELETE /nmapfiles/1
# DELETE /nmapfiles/1.json
def destroy
@nmapfile.remove_nmapxml!
FileUtils.remove_dir("#{Rails.root}/public/uploads/nmapfile/nmapxml/#{@nmapfile.id}", :force => true)
@nmapfile.destroy
respond_to do |format|
format.html { redirect_to nmapfiles_url }
format.json { head :no_content }
end
end

def xmlviewer
@jumpsquares = Jumpsquare.all
@nmapfile = Nmapfile.find(params[:nmapfile_id])
end

private
# Use callbacks to share common setup or constraints between actions.
def set_nmapfile
@nmapfile = Nmapfile.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def nmapfile_params
params.require(:nmapfile).permit(:nmapfilename, :nmapfilerecords, :nmapfilematches, :nmapxml)
end
end
2 changes: 2 additions & 0 deletions app/helpers/nmapfiles_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module NmapfilesHelper
end
13 changes: 13 additions & 0 deletions app/models/nmapfile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Nmapfile < ActiveRecord::Base
mount_uploader :nmapxml, NmapxmlUploader
validates_presence_of :nmapfilename, :nmapxml

def self.search(search)
if search
where('nmapfilename ILIKE ?', "%#{search}%")
else
scoped
end
end

end
66 changes: 66 additions & 0 deletions app/uploaders/nmapxml_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# encoding: utf-8
require 'carrierwave/processing/mime_types'
class NmapxmlUploader < CarrierWave::Uploader::Base

# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
include CarrierWave::MimeTypes

# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
# must use ID for delete to work correctly
# "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.nmapfilename + "." + rand(1...10000).to_s}"
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end

# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end

# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# end

# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(xml)
end


version :preprocessed do
#process :preprocess
process :set_content_type
def full_filename(for_file)
super.chomp(File.extname(super)) + '.xml'
end

def set_content_type(*args)
self.file.instance_variable_set(:@content_type, "application/xml")
end
end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "scan.xml" if original_filename
# end

end
2 changes: 1 addition & 1 deletion app/views/jumpsquares/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class="form-group">
<%= f.label :ipordns, "Enter the IP Address or DNS Name of the host server:", :class => "col-lg-4 control-label" %>
<div class="col-lg-7">
<%= f.text_field :ipordns, :class => "form-control" %>
<%= f.text_field :ipordns, :value => params[:ipordns], :class => "form-control" %>
</div>
</div>
<div class="form-group">
Expand Down
2 changes: 2 additions & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<li><%= link_to "JumpSquare", new_jumpsquare_path %></li>
<li><%= link_to "Tag", new_tag_path %></li>
<li><%= link_to "AppType", new_apptype_path %></li>
<li><%= link_to "Nmap Scan XML", new_nmapfile_path %></li>
</ul>
</li>

Expand All @@ -45,6 +46,7 @@
<li><%= link_to "AppTypes", apptypes_path %></li>
<li><%= link_to "Tags", tags_path %></li>
<li><%= link_to "JumpSquare Size", jumpsizes_path %></li>
<li><%= link_to "Nmap Scans", nmapfiles_path %></li>
</ul>
</li>

Expand Down
50 changes: 50 additions & 0 deletions app/views/nmapfiles/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<div class="row">
<div class="col-lg-6 col-lg-offset-3">
<div class="well">
<%= form_for @nmapfile, html: { multipart: true, :class => "form-horizontal" } do |f| %>
<% if @nmapfile.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@nmapfile.errors.count, "error") %> prohibited this Application Type from being saved:</h2>

<ul>
<% @nmapfile.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<fieldset>
<legend>Nmap XML</legend>
<div class="form-group">
<%= f.label "Descriptive Name:", :class => "col-lg-3 control-label" %>
<div class="col-lg-7">
<%= f.text_field :nmapfilename, :class => "form-control" %>
</div>
</div>

<div class="form-group">
<%= f.label "Upload Nmap XML File:", :class => "col-lg-3 control-label" %>
<div class="col-lg-7">
<%= f.file_field :nmapxml %>
</div>
</div>

<br>
<center>
<div class="form-group">
<%= f.submit class: 'btn btn-primary' %>
</div>
<%= link_to 'Back', nmapfiles_path %> |
<%= link_to 'View Nmap Scans', nmapfiles_path %> |
<%= link_to 'Home', :userroot %>
</center>
</fieldset>

</div>
</div>
</div>
<% end %>

</html>
4 changes: 4 additions & 0 deletions app/views/nmapfiles/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<% provide(:title, 'Editing Nmap XML') %>


<%= render 'form' %>
Loading

0 comments on commit a0ac2c5

Please sign in to comment.