Added mac logs, improved mac editing/viewing
This commit is contained in:
		
							parent
							
								
									04764af983
								
							
						
					
					
						commit
						f3498ddcac
					
				
							
								
								
									
										3
									
								
								app/assets/javascripts/mac_logs.js.coffee
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								app/assets/javascripts/mac_logs.js.coffee
									
									
									
									
									
										Normal file
									
								
							| @ -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://jashkenas.github.com/coffee-script/ | ||||
							
								
								
									
										3
									
								
								app/assets/stylesheets/mac_logs.css.scss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								app/assets/stylesheets/mac_logs.css.scss
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| // Place all the styles related to the MacLogs controller here. | ||||
| // They will automatically be included in application.css. | ||||
| // You can use Sass (SCSS) here: http://sass-lang.com/ | ||||
							
								
								
									
										7
									
								
								app/controllers/mac_logs_controller.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								app/controllers/mac_logs_controller.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | ||||
| class MacLogsController < ApplicationController | ||||
| 
 | ||||
| def index | ||||
|   @mac_logs = MacLog.desc.limit(1000) | ||||
| end | ||||
| 
 | ||||
| end | ||||
| @ -8,7 +8,8 @@ def index | ||||
|   @active_macs = Mac.where(:active => true, :hidden => false) | ||||
|   @active_macs += Mac.where(:active => true, :hidden => nil) | ||||
|   @hidden_macs = Mac.where(:active => true, :hidden => true) | ||||
|   @inactive_macs = Mac.where(:active => false) | ||||
| 
 | ||||
|   @all_macs = Mac.find(:all, :order => "LOWER(mac)") | ||||
| end | ||||
| 
 | ||||
|   # GET /macs/1 | ||||
| @ -45,8 +46,7 @@ end | ||||
|   def create | ||||
|     @mac = Mac.new(params[:mac]) | ||||
|     @mac.user_id = params[:user_id] | ||||
| 
 | ||||
|     Rails.logger.info @macs.inspect | ||||
|     @users = User.all.sort_by(&:name) | ||||
| 
 | ||||
|     respond_to do |format| | ||||
|       if @mac.save | ||||
| @ -64,11 +64,11 @@ end | ||||
|   def update | ||||
|     #Log who updated this | ||||
|     @mac = Mac.find(params[:id]) | ||||
|     @users = User.all.sort_by(&:name) | ||||
| 
 | ||||
|     respond_to do |format| | ||||
|       if @mac.update_attributes(params[:mac]) | ||||
|         Rails.logger.info @mac.inspect | ||||
|         format.html { redirect_to macs_path, :notice => 'User certification was successfully updated.' } | ||||
|         format.html { redirect_to macs_path, :notice => 'Mac was successfully updated.' } | ||||
|         format.json { head :no_content } | ||||
|       else | ||||
|         format.html { render :action => "edit" } | ||||
| @ -153,8 +153,7 @@ Rails.logger.info "starting scan..." | ||||
| 
 | ||||
| 	# Scan the existing macs and update each record as necessary | ||||
| 	Mac.find(:all).each { |entry| | ||||
| 		Rails.logger.info "Existing MAC: "+entry.inspect | ||||
| 		mac = entry.mac | ||||
| 		mac = entry.mac.downcase | ||||
| 		ip = entry.ip | ||||
| 		if macs.has_key?(mac) | ||||
| 			if ! entry.active || ! entry.since | ||||
| @ -185,7 +184,7 @@ Rails.logger.info "starting scan..." | ||||
| 	macs.each { |mac, ip| | ||||
| 		Rails.logger.info "Activating new entry #{mac} at #{ip}" if options[:verbose] | ||||
| 		Mac.new(:mac => mac, :ip => ip, :active => 1, :since => Time.now, :refreshed => Time.now).save | ||||
| 		MacLog.new(:mac => mac, :ip => ip, :action => "activate").save | ||||
| 		Rails.logger.info MacLog.new(:mac => mac, :ip => ip, :action => "activate").save | ||||
| 	} | ||||
| 
 | ||||
| @log = MacLog.all | ||||
| @ -193,4 +192,19 @@ Rails.logger.info "starting scan..." | ||||
| end #def scan | ||||
| 
 | ||||
| 
 | ||||
| def import | ||||
| 
 | ||||
| require 'csv'     | ||||
| 
 | ||||
| csv_text = File.read('mac_log.csv') | ||||
| csv = CSV.parse(csv_text) | ||||
| 
 | ||||
| @output = [] | ||||
| 
 | ||||
| csv.each do |row| | ||||
|   @output += [row[1], Mac.create({:mac => row[0], :note => row[1], :hidden => row[2]}) ] | ||||
| end | ||||
| 
 | ||||
| end | ||||
| 
 | ||||
| end | ||||
|  | ||||
							
								
								
									
										2
									
								
								app/helpers/mac_logs_helper.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								app/helpers/mac_logs_helper.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| module MacLogsHelper | ||||
| end | ||||
| @ -1,4 +1,6 @@ | ||||
| class Mac < ActiveRecord::Base | ||||
|   belongs_to :user | ||||
|   attr_accessible :active, :ip, :mac, :refreshed, :since, :hidden, :note, :user_id | ||||
| 
 | ||||
|   validates_uniqueness_of :mac, :case_sensitive => false | ||||
| end | ||||
|  | ||||
| @ -1,3 +1,5 @@ | ||||
| class MacLog < ActiveRecord::Base | ||||
|   attr_accessible :action, :ip, :mac | ||||
| 
 | ||||
|   scope :desc, order("mac_logs.created_at DESC") | ||||
| end | ||||
|  | ||||
							
								
								
									
										10
									
								
								app/views/mac_logs/index.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								app/views/mac_logs/index.html.erb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| <table> | ||||
| <% @mac_logs.each do |mac_log| %> | ||||
|   <tr> | ||||
|   <td><%= mac_log.mac %></td> | ||||
|   <td><%= mac_log.ip %></td> | ||||
|   <td><%= mac_log.action %></td> | ||||
|   <td><%= mac_log.created_at %></td> | ||||
|   </tr> | ||||
| <% end %> | ||||
| </table> | ||||
							
								
								
									
										1
									
								
								app/views/macs/import.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								app/views/macs/import.html.erb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| <%= @output %> | ||||
| @ -1,29 +1,42 @@ | ||||
| <h2>What machines are on our network?</h2> | ||||
| <%= link_to "New Mac", new_mac_path %> | ||||
| 
 | ||||
| <ul> | ||||
| <% @active_macs.each do |mac| %> | ||||
| <li> | ||||
|   <%= mac.user.name unless mac.user.blank? %>   | ||||
|   <%= mac.mac if mac.user.blank? %> <!--  | ||||
|   <%= mac.since %>,  | ||||
|   <%= mac.refreshed %>, | ||||
|   <%= mac.active %>--> | | ||||
|   <%= mac.mac if mac.user.blank? && mac.note.blank? %>  | ||||
|   <%= mac.note if mac.user.blank? %> -  | ||||
|   <%= ((Time.now - mac.since) / 1.hour).round(1).to_s+" hours" %> | | ||||
|   <%= link_to 'Edit', edit_mac_path(mac) %> <br/> | ||||
| </li> | ||||
| <% end %> | ||||
| <hr> | ||||
| </ul> | ||||
| 
 | ||||
| <ul style="display: none;"> | ||||
| <% @hidden_macs.each do |mac| %> | ||||
| <li> | ||||
|   <%= mac.user.name unless mac.user.blank? %>   | ||||
|   <%= mac.mac if mac.user.blank? %>  | ||||
|   (<%= mac.note %>) <!-- | ||||
|   <%= mac.mac if mac.user.blank? && mac.note.blank? %> | ||||
|   <%= mac.note if mac.user.blank? %> -  | ||||
|   <%= ((Time.now - mac.since) / 1.hour).round(1).to_s+" hours" %> | | ||||
|   <%= link_to 'Edit', edit_mac_path(mac) %> <br/> | ||||
| </li> | ||||
| <% end %> | ||||
| </ul> | ||||
| 
 | ||||
| <!-- | ||||
| <% @all_macs.each do |mac| %> | ||||
|   <%= '<span class="hidden">' if mac.hidden? %> | ||||
|   <%= mac.mac.downcase %>  | ||||
|   (<%= mac.note %>)  | ||||
|   <%= mac.user.name unless mac.user.blank? %> | ||||
|   <%= mac.since %>,  | ||||
|   <%= mac.refreshed %>, | ||||
|   <%= mac.active %>--> | | ||||
|   <%= link_to 'Edit', edit_mac_path(mac) %> <br/> | ||||
| <% end %> | ||||
| <hr> | ||||
| <% @inactive_macs.each do |mac| %> | ||||
|   <%= mac.user.name unless mac.user.blank? %>   | ||||
|   <%= mac.mac if mac.user.blank? %>  | ||||
|   (<%= mac.note %>) <!-- | ||||
|   <%= mac.since %>,  | ||||
|   <%= mac.refreshed %>, | ||||
|   <%= mac.active %>--> | | ||||
|   <%= mac.active %> | | ||||
|   <%= link_to 'Edit', edit_mac_path(mac) %> <br/> | ||||
|   <%= '</span>' if mac.hidden? %> | ||||
| <% end %> | ||||
| --> | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -22,4 +22,4 @@ production: | ||||
|   adapter: sqlite3 | ||||
|   database: db/production.sqlite3 | ||||
|   pool: 5 | ||||
|   timeout: 5000 | ||||
|   timeout: 300000 | ||||
|  | ||||
| @ -28,8 +28,11 @@ Dooraccess::Application.routes.draw do | ||||
|   match 'door_logs/auto_download' => 'door_logs#auto_download', :as => :auto_download | ||||
| 
 | ||||
|   match 'macs/scan' => 'macs#scan' | ||||
|   match 'macs/import' => 'macs#import' | ||||
|   resources :macs | ||||
| 
 | ||||
|   resources :mac_logs | ||||
| 
 | ||||
|   root :to => "home#index" | ||||
| 
 | ||||
|   # The priority is based upon order of creation: | ||||
|  | ||||
							
								
								
									
										7
									
								
								test/functional/mac_logs_controller_test.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								test/functional/mac_logs_controller_test.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | ||||
| require 'test_helper' | ||||
| 
 | ||||
| class MacLogsControllerTest < ActionController::TestCase | ||||
|   # test "the truth" do | ||||
|   #   assert true | ||||
|   # end | ||||
| end | ||||
							
								
								
									
										4
									
								
								test/unit/helpers/mac_logs_helper_test.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								test/unit/helpers/mac_logs_helper_test.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| require 'test_helper' | ||||
| 
 | ||||
| class MacLogsHelperTest < ActionView::TestCase | ||||
| end | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user