automate-em 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LGPL3-LICENSE +165 -0
- data/README.textile +48 -0
- data/Rakefile +40 -0
- data/app/models/control_system.rb +20 -0
- data/app/models/controller_device.rb +21 -0
- data/app/models/controller_http_service.rb +17 -0
- data/app/models/controller_logic.rb +5 -0
- data/app/models/controller_zone.rb +10 -0
- data/app/models/dependency.rb +20 -0
- data/app/models/server.rb +12 -0
- data/app/models/setting.rb +38 -0
- data/app/models/trusted_device.rb +63 -0
- data/app/models/user_zone.rb +10 -0
- data/app/models/zone.rb +16 -0
- data/db/migrate/20111001022500_init.rb +147 -0
- data/db/migrate/20111017213801_one_time_key.rb +9 -0
- data/db/migrate/20111021071632_encrypt_setting.rb +9 -0
- data/db/migrate/20111110075444_servers.rb +15 -0
- data/db/migrate/20111114074538_default_port.rb +9 -0
- data/db/migrate/20111122073055_makebreak.rb +9 -0
- data/db/migrate/20111211062846_create_controller_http_services.rb +18 -0
- data/lib/automate-em.rb +155 -0
- data/lib/automate-em/constants.rb +6 -0
- data/lib/automate-em/core/communicator.rb +318 -0
- data/lib/automate-em/core/modules.rb +373 -0
- data/lib/automate-em/core/resolver_pool.rb +76 -0
- data/lib/automate-em/core/system.rb +356 -0
- data/lib/automate-em/device/datagram_server.rb +111 -0
- data/lib/automate-em/device/device.rb +140 -0
- data/lib/automate-em/device/device_connection.rb +689 -0
- data/lib/automate-em/device/tcp_control.rb +210 -0
- data/lib/automate-em/engine.rb +36 -0
- data/lib/automate-em/interfaces/OLD CODE/deferred.rb +67 -0
- data/lib/automate-em/interfaces/OLD CODE/telnet/ansi.rb +137 -0
- data/lib/automate-em/interfaces/OLD CODE/telnet/telnet.rb +137 -0
- data/lib/automate-em/interfaces/html5.rb +302 -0
- data/lib/automate-em/logic/logic.rb +76 -0
- data/lib/automate-em/service/http_service.rb +584 -0
- data/lib/automate-em/service/service.rb +48 -0
- data/lib/automate-em/status.rb +89 -0
- data/lib/automate-em/utilities.rb +195 -0
- data/lib/automate-em/version.rb +3 -0
- data/lib/generators/module/USAGE +8 -0
- data/lib/generators/module/module_generator.rb +47 -0
- data/lib/tasks/automate-em_tasks.rake +5 -0
- data/test/automate-em_test.rb +7 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +56 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- metadata +328 -0
data/LGPL3-LICENSE
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.textile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
h1. automate-em
|
2
|
+
|
3
|
+
A framework for building automation and control.
|
4
|
+
|
5
|
+
|
6
|
+
h2. Creating a control project
|
7
|
+
|
8
|
+
# Create a new rails project
|
9
|
+
#* Configure your database etc
|
10
|
+
# Add @gem "automate-em"@ to your gem file
|
11
|
+
#* Also add @gem 'login', :git => 'git://github.com/stakach/advanced-authenticator.git'@
|
12
|
+
#* This dependency will be removed soon to allow for any authentication system to be utilised
|
13
|
+
# From a console type:
|
14
|
+
## @bundle install@
|
15
|
+
## @rake railties:install:migrations FROM=login_engine@
|
16
|
+
## @rake railties:install:migrations FROM=automate@
|
17
|
+
## @rake db:migrate@
|
18
|
+
|
19
|
+
You now have a blank control project
|
20
|
+
|
21
|
+
|
22
|
+
h2. Generating module scaffolding
|
23
|
+
|
24
|
+
From a console
|
25
|
+
|
26
|
+
# type: @rails g module module/scope/and_name@
|
27
|
+
#* An example would be: @rails g module NEC/Projectors/NP2000@
|
28
|
+
#* This will create a file at @app/modules/nec/projectors/np2000.rb@
|
29
|
+
# You will be asked what type of module you would like to generate
|
30
|
+
#* Type: @device@ for a generic device module (a raw TCP or UDP protocol including telnet)
|
31
|
+
#* Type: @service@ for any module that will be interfacing with a HTTP(S) service
|
32
|
+
#* Type: @logic@ to generate a controller/interfacing module
|
33
|
+
|
34
|
+
Note: The scope (@NEC/Projectors@ in the example above) is optional and can be as deep or shallow as makes sense.
|
35
|
+
|
36
|
+
h2. Writing Modules
|
37
|
+
|
38
|
+
Please see: "writing modules":https://github.com/stakach/automate-em/wiki/writing-modules
|
39
|
+
|
40
|
+
|
41
|
+
h2. Database Configuration
|
42
|
+
|
43
|
+
Please see: "system configuration":https://github.com/stakach/automate-em/wiki/system-configuration
|
44
|
+
|
45
|
+
|
46
|
+
h2. Running
|
47
|
+
|
48
|
+
From a command console type: @rake automate@
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'AutomateEm'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib'
|
34
|
+
t.libs << 'test'
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
36
|
+
t.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class ControlSystem < ActiveRecord::Base
|
2
|
+
has_many :devices, :class_name => "ControllerDevice", :order => 'priority ASC', :dependent => :destroy
|
3
|
+
has_many :logics, :class_name => "ControllerLogic", :order => 'priority ASC', :dependent => :destroy
|
4
|
+
has_many :services, :class_name => "ControllerHttpService", :order => 'priority ASC', :dependent => :destroy
|
5
|
+
|
6
|
+
has_many :controller_zones, :dependent => :destroy
|
7
|
+
has_many :zones, :through => :controller_zones
|
8
|
+
has_many :user_zones, :through => :zones
|
9
|
+
has_many :groups, :through => :user_zones
|
10
|
+
has_many :users, :through => :groups
|
11
|
+
|
12
|
+
has_many :trusted_devices, :dependent => :destroy
|
13
|
+
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
|
18
|
+
validates_presence_of :name
|
19
|
+
validates_uniqueness_of :name
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class ControllerDevice < ActiveRecord::Base
|
2
|
+
belongs_to :control_system
|
3
|
+
belongs_to :dependency
|
4
|
+
has_many :settings, :as => :object, :dependent => :destroy
|
5
|
+
|
6
|
+
|
7
|
+
before_validation :check_port
|
8
|
+
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
|
13
|
+
def check_port
|
14
|
+
if self[:port].nil?
|
15
|
+
self[:port] = dependency.default_port
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
validates_presence_of :control_system, :dependency, :ip, :port
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ControllerHttpService < ActiveRecord::Base
|
2
|
+
belongs_to :control_system
|
3
|
+
belongs_to :dependency
|
4
|
+
has_many :settings, :as => :object, :dependent => :destroy
|
5
|
+
|
6
|
+
before_validation :check_uri
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def check_uri
|
11
|
+
if self[:uri].nil?
|
12
|
+
self[:uri] = dependency.default_uri
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
validates_presence_of :control_system, :dependency, :uri
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Dependency < ActiveRecord::Base
|
2
|
+
has_many :devices, :class_name => "ControllerDevice", :dependent => :destroy
|
3
|
+
has_many :logics, :class_name => "ControllerLogic", :dependent => :destroy
|
4
|
+
has_many :services, :class_name => "ControllerHttpService", :dependent => :destroy
|
5
|
+
|
6
|
+
has_many :settings, :as => :object, :dependent => :destroy
|
7
|
+
|
8
|
+
scope :for_controller, lambda {|controller|
|
9
|
+
includes(:controller_devices, :controller_logics, :controller_http_services)
|
10
|
+
.where("(controller_devices.dependency_id = dependencies.id AND controller_devices.control_system_id = ?) OR (controller_logics.dependency_id = dependencies.id AND controller_logics.control_system_id = ?) OR (controller_http_services.dependency_id = dependencies.id AND controller_http_services.control_system_id = ?)", controller.id, controller.id, controller.id)
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
|
17
|
+
validates_presence_of :classname, :filename, :module_name, :actual_name
|
18
|
+
validates_uniqueness_of :filename
|
19
|
+
validates_uniqueness_of :actual_name
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require 'base64'
|
3
|
+
require 'encryptor'
|
4
|
+
|
5
|
+
|
6
|
+
class Setting < ActiveRecord::Base
|
7
|
+
belongs_to :object, :polymorphic => true
|
8
|
+
|
9
|
+
after_initialize :decrypt_setting
|
10
|
+
before_save :do_encrypt_setting
|
11
|
+
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
|
16
|
+
def decrypt_setting
|
17
|
+
return unless self[:encrypt_setting]
|
18
|
+
|
19
|
+
if self[:text_value].blank?
|
20
|
+
self[:text_value] = ""
|
21
|
+
else
|
22
|
+
self[:text_value] = Encryptor.decrypt(Base64.decode64(self[:text_value]), {:key => CONTROL_CONFIG[:encrypt_key], :algorithm => 'aes-256-cbc'})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def do_encrypt_setting
|
27
|
+
return unless self[:encrypt_setting]
|
28
|
+
|
29
|
+
if self[:text_value].blank?
|
30
|
+
self[:text_value] = ""
|
31
|
+
else
|
32
|
+
self[:text_value] = Base64.encode64(Encryptor.encrypt(self[:text_value], {:key => CONTROL_CONFIG[:encrypt_key], :algorithm => 'aes-256-cbc'}))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
validates_presence_of :name, :object, :value_type
|
38
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'digest/sha1' # For one time key
|
2
|
+
|
3
|
+
#
|
4
|
+
# This is a list of devices that are trusted
|
5
|
+
# A one time key is used to authenticate and re-generated for the next logon
|
6
|
+
#
|
7
|
+
class TrustedDevice < ActiveRecord::Base
|
8
|
+
belongs_to :user
|
9
|
+
belongs_to :control_system
|
10
|
+
|
11
|
+
|
12
|
+
before_create :generate_keys
|
13
|
+
|
14
|
+
|
15
|
+
#
|
16
|
+
# Generates a one-time key that will allow this device to login without interaction
|
17
|
+
#
|
18
|
+
def generate_key
|
19
|
+
self[:last_authenticated] = Time.now
|
20
|
+
self[:next_key] = Digest::SHA1.hexdigest "#{Time.now.to_f.to_s}#{id}"
|
21
|
+
save!
|
22
|
+
end
|
23
|
+
|
24
|
+
def accept_key
|
25
|
+
self[:one_time_key] = self[:next_key]
|
26
|
+
save!
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Attempts to login using a one time key and generates a new one if it is accepted
|
31
|
+
#
|
32
|
+
def self.try_to_login(key, gen = false)
|
33
|
+
entry = TrustedDevice.where("one_time_key = ? or next_key = ?", key, key).first
|
34
|
+
if entry.nil?
|
35
|
+
return nil
|
36
|
+
else
|
37
|
+
if !entry.expires.nil? && (entry.expires <=> Time.now) > 0 # We are past the expired time
|
38
|
+
entry.destroy
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
if entry.one_time_key != entry.next_key && entry.next_key == key # so the accept failed?
|
42
|
+
entry.one_time_key = entry.next_key # Perform an implicit accept
|
43
|
+
entry.save # Prevents the same key being used again
|
44
|
+
end
|
45
|
+
|
46
|
+
entry.generate_key if gen # Key accepted, generate a new one
|
47
|
+
return entry
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
|
55
|
+
def generate_keys
|
56
|
+
self[:last_authenticated] = Time.now
|
57
|
+
self[:one_time_key] = Digest::SHA1.hexdigest "#{Time.now.to_f.to_s}#not so strong"
|
58
|
+
self[:next_key] = Digest::SHA1.hexdigest "#{self[:last_authenticated].to_f.to_s}different"
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
validates_presence_of :user, :control_system, :reason
|
63
|
+
end
|