Got door logs working
This commit is contained in:
3
app/assets/javascripts/door_logs.js.coffee
Normal file
3
app/assets/javascripts/door_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/door_logs.css.scss
Normal file
3
app/assets/stylesheets/door_logs.css.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the DoorLogs controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
94
app/controllers/door_logs_controller.rb
Normal file
94
app/controllers/door_logs_controller.rb
Normal file
@@ -0,0 +1,94 @@
|
||||
class DoorLogsController < ApplicationController
|
||||
# GET /door_logs
|
||||
# GET /door_logs.json
|
||||
def index
|
||||
@door_logs = DoorLog.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render :json => @door_logs }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /door_logs/1
|
||||
# GET /door_logs/1.json
|
||||
# def show
|
||||
# @door_log = DoorLog.find(params[:id])
|
||||
#
|
||||
# respond_to do |format|
|
||||
# format.html # show.html.erb
|
||||
# format.json { render :json => @door_log }
|
||||
# end
|
||||
# end
|
||||
|
||||
# GET /door_logs/1
|
||||
# GET /door_logs/1.json
|
||||
def download
|
||||
@results = DoorLog.download_from_door
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render :json => @results }
|
||||
end
|
||||
end
|
||||
|
||||
# # GET /door_logs/new
|
||||
# # GET /door_logs/new.json
|
||||
# def new
|
||||
# @door_log = DoorLog.new
|
||||
#
|
||||
# respond_to do |format|
|
||||
# format.html # new.html.erb
|
||||
# format.json { render :json => @door_log }
|
||||
# end
|
||||
# end
|
||||
|
||||
# GET /door_logs/1/edit
|
||||
# def edit
|
||||
# @door_log = DoorLog.find(params[:id])
|
||||
# end
|
||||
|
||||
# POST /door_logs
|
||||
# POST /door_logs.json
|
||||
# def create
|
||||
# @door_log = DoorLog.new(params[:door_log])
|
||||
#
|
||||
# respond_to do |format|
|
||||
# if @door_log.save
|
||||
# format.html { redirect_to @door_log, :notice => 'Door log was successfully created.' }
|
||||
# format.json { render :json => @door_log, :status => :created, :location => @door_log }
|
||||
# else
|
||||
# format.html { render :action => "new" }
|
||||
# format.json { render :json => @door_log.errors, :status => :unprocessable_entity }
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# PUT /door_logs/1
|
||||
# PUT /door_logs/1.json
|
||||
# def update
|
||||
# @door_log = DoorLog.find(params[:id])
|
||||
#
|
||||
# respond_to do |format|
|
||||
# if @door_log.update_attributes(params[:door_log])
|
||||
# format.html { redirect_to @door_log, :notice => 'Door log was successfully updated.' }
|
||||
# format.json { head :no_content }
|
||||
# else
|
||||
# format.html { render :action => "edit" }
|
||||
# format.json { render :json => @door_log.errors, :status => :unprocessable_entity }
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# DELETE /door_logs/1
|
||||
# DELETE /door_logs/1.json
|
||||
# def destroy
|
||||
# @door_log = DoorLog.find(params[:id])
|
||||
# @door_log.destroy
|
||||
#
|
||||
# respond_to do |format|
|
||||
# format.html { redirect_to door_logs_url }
|
||||
# format.json { head :no_content }
|
||||
# end
|
||||
# end
|
||||
end
|
||||
2
app/helpers/door_logs_helper.rb
Normal file
2
app/helpers/door_logs_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module DoorLogsHelper
|
||||
end
|
||||
40
app/models/door_log.rb
Normal file
40
app/models/door_log.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
class DoorLog < ActiveRecord::Base
|
||||
attr_accessible :data, :key
|
||||
require 'open-uri'
|
||||
|
||||
def self.download_from_door
|
||||
# do shit here
|
||||
source = open("http://192.168.1.177?e=1234").read
|
||||
results = source.scan(/authok/)
|
||||
if(results.size > 0) then
|
||||
@end_results = Array.new
|
||||
|
||||
#only continue if we've got an OK login
|
||||
source = open("http://192.168.1.177?z").read
|
||||
results = source.scan(/(.*): (.*)\r\n/)
|
||||
|
||||
results.each do |r|
|
||||
if(r[0] != "\000") then
|
||||
DoorLog.create!({:key => r[0], :data => r[1]})
|
||||
end
|
||||
end
|
||||
|
||||
#clear log
|
||||
open("http://192.168.1.177?y")
|
||||
#logout
|
||||
open("http://192.168.1.177?e=0000")
|
||||
|
||||
if(results.size > 0) then
|
||||
#only return true if we got some kind of decent response
|
||||
return results
|
||||
else
|
||||
# We didn't get a decent response.
|
||||
return false
|
||||
end
|
||||
else
|
||||
# We didn't get an OK login.
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
25
app/views/door_logs/_form.html.erb
Normal file
25
app/views/door_logs/_form.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<%= form_for(@door_log) do |f| %>
|
||||
<% if @door_log.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(@door_log.errors.count, "error") %> prohibited this door_log from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% @door_log.errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :key %><br />
|
||||
<%= f.text_field :key %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :data %><br />
|
||||
<%= f.number_field :data %>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
8
app/views/door_logs/download.html.erb
Normal file
8
app/views/door_logs/download.html.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<b>Download results:</b>
|
||||
<%= @results.inspect %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Back', door_logs_path %>
|
||||
6
app/views/door_logs/edit.html.erb
Normal file
6
app/views/door_logs/edit.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<h1>Editing door_log</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Show', @door_log %> |
|
||||
<%= link_to 'Back', door_logs_path %>
|
||||
22
app/views/door_logs/index.html.erb
Normal file
22
app/views/door_logs/index.html.erb
Normal file
@@ -0,0 +1,22 @@
|
||||
<h1>Listing door_logs</h1>
|
||||
|
||||
<%= link_to 'Download Door Logs', download_path %>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Data</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @door_logs.each do |door_log| %>
|
||||
<tr>
|
||||
<td><%= door_log.key %></td>
|
||||
<td><%= door_log.data %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
5
app/views/door_logs/new.html.erb
Normal file
5
app/views/door_logs/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>New door_log</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Back', door_logs_path %>
|
||||
15
app/views/door_logs/show.html.erb
Normal file
15
app/views/door_logs/show.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<b>Key:</b>
|
||||
<%= @door_log.key %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Data:</b>
|
||||
<%= @door_log.data %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_door_log_path(@door_log) %> |
|
||||
<%= link_to 'Back', door_logs_path %>
|
||||
@@ -7,7 +7,10 @@
|
||||
<%= csrf_meta_tags %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="header">
|
||||
<a href="/users">Users</a>
|
||||
<a href="/door_logs">Logs</a>
|
||||
</div>
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<h1>Listing users</h1>
|
||||
|
||||
<%= link_to 'New User', new_user_path %>
|
||||
<%= link_to 'Upload all users', upload_all_path %>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
@@ -26,4 +28,3 @@
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New User', new_user_path %>
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
<%= @user.card_permissions %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Upload to Door', upload_path(user) %>
|
||||
<%= link_to 'Edit', edit_user_path(@user) %> |
|
||||
<%= link_to 'Back', users_path %>
|
||||
|
||||
Reference in New Issue
Block a user