patronus_fati 0.9.11 → 0.9.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5af36651b4ac2ef9bb6f2ed152fd34062c7d5e54
4
- data.tar.gz: 21d48319ada17b176a06044641f20f9c52c02ec1
3
+ metadata.gz: 9494304c05c4e1107313822eb7ca6671fe736a40
4
+ data.tar.gz: ed4c5b18d335e2d08611718d4d3957ebe9202a15
5
5
  SHA512:
6
- metadata.gz: 0b2c4b99ec27244d00a1882680848c01bd53b9b4ad2db6cb6ab253bdeb7031c2a367addac2c5b9567af2a065ae7b4a053b7e919183e3061b7b2485fafb003ee9
7
- data.tar.gz: c6d74a76140b8304237e36118637398048ae8fa9c9162f39970ff57172e38c882c9cfc5a93b96056488955744c65219f2b208b326c70a22a2c054ab83e888cfe
6
+ metadata.gz: 30cc6b08f1a9e44f54ed589ec15211e8debf8244f3e2969ef1384477dddd0c51b5d266cc5c46a98a4c79c9a272ce41a05ff0d2dd4a4512cd2f59584618342bdf
7
+ data.tar.gz: 30ee69e1c3d916d7e46068c2383f370dcee51d6362b331e5dbd3d8962b3fff92cb01584bb10761060e8e7db4ebeb6849909190e6a42d66496ebaaef67a012297
@@ -1,6 +1,4 @@
1
1
  module PatronusFati
2
- DisconnectError = Class.new(StandardError)
3
-
4
2
  class Connection
5
3
  attr_reader :port, :read_queue, :server, :write_queue
6
4
 
@@ -14,17 +12,18 @@ module PatronusFati
14
12
 
15
13
  def connect
16
14
  establish_connection
15
+ return unless connected?
17
16
 
18
17
  start_read_thread
19
18
  start_write_thread
20
19
  end
21
20
 
22
21
  def connected?
23
- !socket.nil?
22
+ !(socket.nil? || socket.closed?)
24
23
  end
25
24
 
26
25
  def disconnect
27
- return unless connected?
26
+ return unless socket
28
27
 
29
28
  Thread.kill(read_thread)
30
29
  Thread.kill(write_thread)
@@ -2,6 +2,7 @@ module PatronusFati::DataModels
2
2
  class AccessPoint
3
3
  include DataMapper::Resource
4
4
 
5
+ include PatronusFati::DataModels::AutoVendorLookup
5
6
  include PatronusFati::DataModels::ExpirationAttributes
6
7
  include PatronusFati::DataModels::ReportedAttributes
7
8
 
@@ -20,10 +21,7 @@ module PatronusFati::DataModels
20
21
  :child_key => :access_point_id
21
22
  has n, :ssids, :constraint => :destroy
22
23
 
23
- belongs_to :mac, :required => false
24
- before :save do
25
- self.mac = Mac.first_or_create(mac: bssid)
26
- end
24
+ vendor_attribute :bssid
27
25
 
28
26
  def self.current_expiration_threshold
29
27
  Time.now.to_i - PatronusFati::AP_EXPIRATION
@@ -48,7 +46,7 @@ module PatronusFati::DataModels
48
46
  .merge(
49
47
  active: active?,
50
48
  connected_clients: connected_clients.map(&:bssid),
51
- vendor: mac.vendor,
49
+ vendor: vendor,
52
50
  ssids: current_ssids.map(&:full_state)
53
51
  )
54
52
  end
@@ -2,6 +2,7 @@ module PatronusFati::DataModels
2
2
  class Client
3
3
  include DataMapper::Resource
4
4
 
5
+ include PatronusFati::DataModels::AutoVendorLookup
5
6
  include PatronusFati::DataModels::ExpirationAttributes
6
7
  include PatronusFati::DataModels::ReportedAttributes
7
8
 
@@ -15,10 +16,7 @@ module PatronusFati::DataModels
15
16
 
16
17
  has n, :probes, :constraint => :destroy
17
18
 
18
- belongs_to :mac, :required => false
19
- before :save do
20
- self.mac = Mac.first_or_create(mac: bssid)
21
- end
19
+ vendor_attribute :bssid
22
20
 
23
21
  def self.current_expiration_threshold
24
22
  Time.now.to_i - PatronusFati::CLIENT_EXPIRATION
@@ -39,7 +37,7 @@ module PatronusFati::DataModels
39
37
  active: active?,
40
38
  connected_access_points: connected_access_points.map(&:bssid),
41
39
  probes: probes.map(&:essid),
42
- vendor: mac.vendor
40
+ vendor: vendor
43
41
  )
44
42
  end
45
43
  end
@@ -17,6 +17,26 @@ module PatronusFati
17
17
  end
18
18
  end
19
19
 
20
+ module AutoVendorLookup
21
+ def self.included(klass)
22
+ klass.extend AVLClassMethods
23
+ klass.property :vendor, DataMapper::Property::String, :length => 255
24
+
25
+ klass.before(:save) do
26
+ next if self.vendor || self.class.vendor_attribute.nil?
27
+ result = Louis.lookup(attributes[self.class.vendor_attribute])
28
+ self.vendor = result['long_vendor'] || result['short_vendor']
29
+ end
30
+ end
31
+
32
+ module AVLClassMethods
33
+ def vendor_attribute(attr = nil)
34
+ @@vendor_attribute = attr if attr && properties[attr]
35
+ @@vendor_attribute
36
+ end
37
+ end
38
+ end
39
+
20
40
  module ExpirationAttributes
21
41
  def self.included(klass)
22
42
  klass.extend EAClassMethods
@@ -3,7 +3,6 @@ module PatronusFati::DataModels
3
3
  include DataMapper::Resource
4
4
 
5
5
  include PatronusFati::DataModels::ExpirationAttributes
6
- include PatronusFati::DataModels::ReportedAttributes
7
6
 
8
7
  property :id, Serial
9
8
 
@@ -37,12 +37,17 @@ module PatronusFati::DataObservers
37
37
  after :save do
38
38
  next unless @change_type
39
39
 
40
- mac.update_cached_counts!
40
+ fs = self.full_state
41
+
42
+ # During the initial creation we haven't had the opportunity to see any
43
+ # broadcast SSIDs yet. If we sent up an empty one it would delete the
44
+ # existing SSIDs.
45
+ fs.delete(:ssids) if @change_type == :new
41
46
 
42
47
  PatronusFati.event_handler.event(
43
48
  :access_point,
44
49
  @change_type,
45
- self.full_state,
50
+ fs,
46
51
  @change_list || {}
47
52
  )
48
53
 
@@ -36,8 +36,6 @@ module PatronusFati::DataObservers
36
36
  after :save do
37
37
  next unless @change_type
38
38
 
39
- mac.update_cached_counts!
40
-
41
39
  PatronusFati.event_handler.event(
42
40
  :client,
43
41
  @change_type,
@@ -33,9 +33,6 @@ module PatronusFati::DataObservers
33
33
  after :save do
34
34
  next unless @change_type
35
35
 
36
- client.mac.update_cached_counts!
37
- access_point.mac.update_cached_counts!
38
-
39
36
  if @change_type == :new
40
37
  if disconnected_at.nil?
41
38
  PatronusFati.event_handler.event(
@@ -7,47 +7,29 @@ module PatronusFati::DataObservers
7
7
  before :save do
8
8
  next unless self.valid?
9
9
 
10
- # We're about to report this, make sure the attribute gets saved
11
- old_ro_val = reported_online
12
- self.reported_online = true
13
-
14
- @change_list = {
15
- ssids: [
16
- [],
17
- [full_state]
18
- ]
19
- }
20
-
21
- unless self.new?
22
- dirty = self.dirty_attributes.map { |a| a.first.name }.map(&:to_s)
23
- dirty.delete('last_seen_at')
24
-
25
- # If there weren't any meaningful changes, don't print out anything
26
- # after we save.
27
- if dirty.empty?
28
- @change_list = nil
29
- self.reported_online = old_ro_val
30
- next
31
- end
32
-
33
- tmp_obj = Hash[original_attributes.map { |k,v| [k.name, v] }]
34
- @change_list[:ssids][0] = PatronusFati::DataModels::Ssid.new(tmp_obj).full_state
35
- end
10
+ @old_ssids = self.access_point.ssids.active.map(&:full_state)
11
+ .sort_by { |s| s[:essid] }
36
12
  end
37
13
 
38
14
  after :save do
39
- next unless @change_list
15
+ new_ssids = self.access_point.ssids.active.map(&:full_state)
16
+ .sort_by { |s| s[:essid] }
40
17
 
41
- access_point.mac.update_cached_counts!
18
+ change_list = {
19
+ ssids: [
20
+ @old_ssids,
21
+ new_ssids
22
+ ]
23
+ }
42
24
 
43
25
  PatronusFati.event_handler.event(
44
26
  :access_point,
45
27
  :changed,
46
28
  self.access_point.full_state,
47
- @change_list
29
+ change_list
48
30
  )
49
31
 
50
- @change_list = nil
32
+ @old_ssids = nil
51
33
  end
52
34
  end
53
35
  end
@@ -2,14 +2,19 @@ module PatronusFati::MessageProcessor::Alert
2
2
  include PatronusFati::MessageProcessor
3
3
 
4
4
  def self.process(obj)
5
- src_mac = PatronusFati::DataModels::Mac.first_or_create(mac: obj[:source])
6
- dst_mac = PatronusFati::DataModels::Mac.first_or_create(mac: obj[:dest])
7
- other_mac = PatronusFati::DataModels::Mac.first_or_create(mac: obj[:other])
8
-
9
- PatronusFati::DataModels::Alert.first_or_create({created_at: obj.sec, \
10
- message: obj[:text]}, {created_at: obj.sec, message: obj[:text], \
11
- src_mac: src_mac, dst_mac: dst_mac, other_mac: other_mac})
5
+ PatronusFati.event_handler.event(:alert, :new, process_obj(obj))
12
6
 
13
7
  nil
14
8
  end
9
+
10
+ def self.process_obj(obj)
11
+ {
12
+ created_at: obj[:sec],
13
+ message: obj[:text],
14
+
15
+ source: obj[:source],
16
+ destination: obj[:dest],
17
+ other: obj[:other]
18
+ }
19
+ end
15
20
  end
@@ -12,15 +12,18 @@ module PatronusFati
12
12
  ap.update(:reported_online => false)
13
13
  PatronusFati.event_handler.event(:access_point, :offline, {'bssid' => ap.bssid, 'uptime' => ap.uptime})
14
14
  ap.disconnect_clients!
15
+ ap.destroy
15
16
  end
16
17
 
17
18
  PatronusFati::DataModels::Client.inactive.reported_online.each do |cli|
18
19
  cli.update(:reported_online => false)
19
20
  PatronusFati.event_handler.event(:client, :offline, {'bssid' => cli.bssid, 'uptime' => cli.uptime})
20
21
  cli.disconnect!
22
+ cli.destroy
21
23
  end
22
24
 
23
25
  PatronusFati::DataModels::Connection.inactive.connected.map(&:disconnect!)
26
+ PatronusFati::DataModels::Ssid.inactive.destroy
24
27
  end
25
28
  end
26
29
 
@@ -1,3 +1,3 @@
1
1
  module PatronusFati
2
- VERSION = '0.9.11'
2
+ VERSION = '0.9.12'
3
3
  end
data/lib/patronus_fati.rb CHANGED
@@ -34,15 +34,12 @@ require 'patronus_fati/message_processor'
34
34
  require 'patronus_fati/data_models/common'
35
35
 
36
36
  require 'patronus_fati/data_models/access_point'
37
- require 'patronus_fati/data_models/alert'
38
37
  require 'patronus_fati/data_models/client'
39
38
  require 'patronus_fati/data_models/connection'
40
- require 'patronus_fati/data_models/mac'
41
39
  require 'patronus_fati/data_models/probe'
42
40
  require 'patronus_fati/data_models/ssid'
43
41
 
44
42
  require 'patronus_fati/data_observers/access_point_observer'
45
- require 'patronus_fati/data_observers/alert_observer'
46
43
  require 'patronus_fati/data_observers/client_observer'
47
44
  require 'patronus_fati/data_observers/connection_observer'
48
45
  require 'patronus_fati/data_observers/ssid_observer'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patronus_fati
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.11
4
+ version: 0.9.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stelfox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-18 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dm-constraints
@@ -287,15 +287,12 @@ files:
287
287
  - lib/patronus_fati/data_mapper/crypt_flags.rb
288
288
  - lib/patronus_fati/data_mapper/null_table_prefix.rb
289
289
  - lib/patronus_fati/data_models/access_point.rb
290
- - lib/patronus_fati/data_models/alert.rb
291
290
  - lib/patronus_fati/data_models/client.rb
292
291
  - lib/patronus_fati/data_models/common.rb
293
292
  - lib/patronus_fati/data_models/connection.rb
294
- - lib/patronus_fati/data_models/mac.rb
295
293
  - lib/patronus_fati/data_models/probe.rb
296
294
  - lib/patronus_fati/data_models/ssid.rb
297
295
  - lib/patronus_fati/data_observers/access_point_observer.rb
298
- - lib/patronus_fati/data_observers/alert_observer.rb
299
296
  - lib/patronus_fati/data_observers/client_observer.rb
300
297
  - lib/patronus_fati/data_observers/connection_observer.rb
301
298
  - lib/patronus_fati/data_observers/probe_observer.rb
@@ -1,24 +0,0 @@
1
- module PatronusFati::DataModels
2
- class Alert
3
- include DataMapper::Resource
4
-
5
- property :id, Serial
6
- property :created_at, Integer, :default => Proc.new { Time.now.to_i }
7
- property :message, String, :length => 255
8
-
9
- belongs_to :src_mac, :model => 'Mac', :required => false
10
- belongs_to :dst_mac, :model => 'Mac', :required => false
11
- belongs_to :other_mac, :model => 'Mac', :required => false
12
-
13
- def full_state
14
- {
15
- created_at: created_at,
16
- message: message,
17
-
18
- source: src_mac.mac,
19
- destination: dst_mac.mac,
20
- other: other_mac.mac
21
- }
22
- end
23
- end
24
- end
@@ -1,48 +0,0 @@
1
- module PatronusFati::DataModels
2
- class Mac
3
- include DataMapper::Resource
4
-
5
- property :id, Serial
6
-
7
- property :mac, String, :length => 17, :unique => true
8
- property :vendor, String, :length => 255
9
-
10
- property :alert_count, Integer, :default => 0
11
- property :clients_connected, Integer, :default => 0
12
- property :active_ssids, Integer, :default => 0
13
- property :is_client, Boolean, :default => false
14
- property :connections_to_ap, Integer, :default => 0
15
-
16
- has n, :access_points
17
- has n, :clients
18
-
19
- has n, :dst_alerts, :model => 'Alert', :child_key => :dst_mac_id
20
- has n, :other_alerts, :model => 'Alert', :child_key => :other_mac_id
21
- has n, :src_alerts, :model => 'Alert', :child_key => :src_mac_id
22
-
23
- before :save do
24
- next if self.vendor
25
-
26
- result = Louis.lookup(mac)
27
- self.vendor = result['long_vendor'] || result['short_vendor']
28
- end
29
-
30
- def is_ap?
31
- access_points.active.any?
32
- end
33
-
34
- def is_client?
35
- clients.active.any?
36
- end
37
-
38
- def update_cached_counts!
39
- update(
40
- alert_count: (dst_alerts | other_alerts | src_alerts).count,
41
- active_ssids: access_points.ssids.active.count,
42
- clients_connected: access_points.connections.connected.count,
43
- connections_to_ap: clients.connections.connected.count,
44
- is_client: is_client?
45
- )
46
- end
47
- end
48
- end
@@ -1,12 +0,0 @@
1
- module PatronusFati::DataObservers
2
- class AlertObserver
3
- include DataMapper::Observer
4
-
5
- observe PatronusFati::DataModels::Alert
6
-
7
- after :save do
8
- [src_mac, dst_mac, other_mac].uniq.map(&:update_cached_counts!)
9
- PatronusFati.event_handler.event(:alert, :new, self.full_state)
10
- end
11
- end
12
- end