Got uploading working

This commit is contained in:
2012-08-24 21:14:51 -07:00
commit b28efe046c
70 changed files with 1854 additions and 0 deletions

BIN
app/assets/images/rails.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@@ -0,0 +1,15 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

View 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/

View File

@@ -0,0 +1,13 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/

View File

@@ -0,0 +1,69 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a {
color: #000;
&:visited {
color: #666;
}
&:hover {
color: #fff;
background-color: #000;
}
}
div {
&.field, &.actions {
margin-bottom: 10px;
}
}
#notice {
color: green;
}
.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}
#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
ul li {
font-size: 12px;
list-style: square;
}
}

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -0,0 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery
end

View File

@@ -0,0 +1,104 @@
class UsersController < ApplicationController
# GET /users
# GET /users.json
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @users }
end
end
# GET /users/1
# GET /users/1.json
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @user }
end
end
# PUT /users/1/upload
def upload
@user = User.find(params[:id])
@upload_result = @user.upload_to_door
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @upload_result }
end
end
# PUT /users/upload_all
def upload_all
@upload_result = User.upload_all_to_door
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @upload_result }
end
end
# GET /users/new
# GET /users/new.json
def new
@user = User.new
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @user }
end
end
# GET /users/1/edit
def edit
@user = User.find(params[:id])
end
# POST /users
# POST /users.json
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
format.html { redirect_to @user, :notice => 'User was successfully created.' }
format.json { render :json => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
end
end
# PUT /users/1
# PUT /users/1.json
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to @user, :notice => 'User was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user = User.find(params[:id])
@user.destroy
respond_to do |format|
format.html { redirect_to users_url }
format.json { head :no_content }
end
end
end

View File

@@ -0,0 +1,2 @@
module ApplicationHelper
end

View File

@@ -0,0 +1,2 @@
module UsersHelper
end

0
app/mailers/.gitkeep Normal file
View File

0
app/models/.gitkeep Normal file
View File

68
app/models/user.rb Normal file
View File

@@ -0,0 +1,68 @@
class User < ActiveRecord::Base
require 'open-uri'
attr_accessible :card_id, :card_number, :card_permissions, :name
validates_uniqueness_of :card_id, :card_number
def upload_to_door
# do shit here
source = open("http://192.168.1.177?e=1234").read
results = source.scan(/authok/)
if(results.size > 0) then
#only continue if we've got an OK login
usernum = self.card_id.to_s.rjust(3, '0')
userperm = self.card_permissions.to_s.rjust(3, '0')
cardnum = self.card_number.rjust(8, '0')
source = open("http://192.168.1.177?m#{usernum}&p#{userperm}&t#{cardnum}").read
results = source.scan(/cur/)
#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 true
else
# We didn't get a decent response.
return false
end
else
# We didn't get an OK login.
return false
end
end
def self.upload_all_to_door
@users = User.all
@end_results = Array.new
source = open("http://192.168.1.177?e=1234").read
results = source.scan(/authok/)
if(results.size > 0) then
@users.each do |u|
#only continue if we've got an OK login
usernum = u.card_id.to_s.rjust(3, '0')
userperm = u.card_permissions.to_s.rjust(3, '0')
cardnum = u.card_number.rjust(8, '0')
source = open("http://192.168.1.177?m#{usernum}&p#{userperm}&t#{cardnum}").read
results = source.scan(/cur/)
if(results.size > 0) then
#only return true if we got some kind of decent response
@end_results.push([usernum,"OK"])
else
@end_results.push([usernum,"FAIL"])
end
end
#logout
open("http://192.168.1.177?e=0000")
else
@end_results.push([usernum,"FAIL"])
end
return @end_results
end
end

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Dooraccess</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@@ -0,0 +1,33 @@
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :card_id, "Card DB ID" %><br />
<%= f.number_field :card_id, :in => 10...201 %>
</div>
<div class="field">
<%= f.label :card_number, "Card Number" %><br />
<%= f.text_field :card_number %>
</div>
<div class="field">
<%= f.label :card_permissions %><br />
<%= f.select :card_permissions, [["Enabled",1],["Disabled",255]] %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,6 @@
<h1>Editing user</h1>
<%= render 'form' %>
<%= link_to 'Show', @user %> |
<%= link_to 'Back', users_path %>

View File

@@ -0,0 +1,29 @@
<h1>Listing users</h1>
<table>
<tr>
<th>Name</th>
<th>Card DB ID</th>
<th>Card Number</th>
<th>Permissions</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.card_id %></td>
<td><%= user.card_number %></td>
<td><%= user.card_permissions %></td>
<td><%= link_to 'Upload', upload_path(user) %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New User', new_user_path %>

View File

@@ -0,0 +1,5 @@
<h1>New user</h1>
<%= render 'form' %>
<%= link_to 'Back', users_path %>

View File

@@ -0,0 +1,25 @@
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @user.name %>
</p>
<p>
<b>Card DB ID:</b>
<%= @user.card_id %>
</p>
<p>
<b>Card Number:</b>
<%= @user.card_number %>
</p>
<p>
<b>Card Permissions:</b>
<%= @user.card_permissions %>
</p>
<%= link_to 'Edit', edit_user_path(@user) %> |
<%= link_to 'Back', users_path %>

View File

@@ -0,0 +1,15 @@
<p id="notice"><%= notice %></p>
<% if @upload_result %>
<p>
<b>Upload result:</b>
<%= @user.name %> uploaded successfully.
</p>
<% else %>
<p>
<b>Upload result:</b>
Error uploading <%= @user.name %>.
</p>
<% end %>
<%= link_to 'Back', users_path %>

View File

@@ -0,0 +1,13 @@
<p id="notice"><%= notice %></p>
<p>
<b>Upload results:</b>
<ul>
<% @upload_result.each do |r| %>
<li><%= r[0] %> <%= r[1] %></li>
<% end %>
</ul>
</p>
<%= link_to 'Back', users_path %>