rush_button 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af826aff85a9985a8e02601e68d81563eb0dffd9
4
+ data.tar.gz: 5c68aabbb453e1476c5c298e8e3a6fe58fa822f2
5
+ SHA512:
6
+ metadata.gz: a4608fcb7b482cdbfc10f5faf7a9496e6e8e55040a30001838ee75de49829dee9cbc4e667e17b202947ec6f4578a5d905f643a32e9d8262a521ac9bb22530152
7
+ data.tar.gz: 154933473f113d3ab75d0dc99651f5f4c53557c55052ee51c71f645f32dcf947843690cdff9ff683d2882a1fb8bc4f407b248d91bcd2cf4a7d681c029f1025ec
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+
15
+ # gem
16
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rush_button.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # RushButton
2
+
3
+ ## Requirements
4
+
5
+ This gem uses packet-fu, which requires libpcap.
6
+
7
+ Install:
8
+
9
+ $ sudo apt-get install libpcap-dev
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'rush_button'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install rush_button
26
+
27
+
28
+ ## Usage
29
+
30
+ ```
31
+ require "rush_button"
32
+ srv = RushButton::Server.new("INTERFACE")
33
+ srv.add("MA:CA:DD:RE:SS:!!") do
34
+ puts "|#{Time.now}| ARGHHHHHHH!"
35
+ end
36
+ srv.start
37
+ ```
38
+
39
+ Find Amazon Dash Button's MAC address:
40
+
41
+ $ buntle exec find_button INTERFACE
42
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rush_button"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/find_button ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rush_button"
4
+
5
+ iface = ARGV[0]
6
+ unless iface
7
+ puts "e.g. '$ sudo bundle exec find_button eth0'"
8
+ exit
9
+ end
10
+
11
+ if `echo $UID`.chomp != "0"
12
+ puts "Not root"
13
+ exit
14
+ end
15
+
16
+ dc = RushButton::DashCapture.new iface
17
+ puts "(Push Button)..."
18
+ loop do
19
+ puts "Amazon's MAC address => #{dc.capture}"
20
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ module RushButton
2
+ class DashButton
3
+ attr_reader :mac
4
+ def initialize mac_addr
5
+ @mac = mac_addr
6
+ end
7
+
8
+ def on_press &process
9
+ @process = process
10
+ return self
11
+ end
12
+
13
+ def press
14
+ return @process.call
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ require 'packetfu'
2
+ require 'net/http'
3
+
4
+ module RushButton
5
+ class DashCapture
6
+ include PacketFu
7
+
8
+ REFER_URL = "https://api.macvendors.com/"
9
+ VENDOR_NAME = "Amazon Technologies Inc."
10
+
11
+ def initialize iface
12
+ @capture = Capture.new(iface: iface, filter: Protocol::ARP, promisc: true)
13
+ end
14
+
15
+ def capture
16
+ loop do
17
+ packet = @capture.next
18
+ unless packet
19
+ sleep 1
20
+ next
21
+ end
22
+ if ARPPacket.can_parse? packet
23
+ src_mac = ARPPacket.parse(packet).eth_src_readable
24
+ vendor_mac = (src_mac.split(":"))[0..2].join(":")
25
+ puts "captured MAC: #{src_mac}" if $DEBUG
26
+ puts "refer to #{REFER_URL+vendor_mac}..." if $DEBUG
27
+ vendor_name = Net::HTTP.get URI.parse(REFER_URL+vendor_mac)
28
+ puts "vendor name: #{vendor_name}" if $DEBUG
29
+ if vendor_name == VENDOR_NAME
30
+ puts "this is Amazon!" if $DEBUG
31
+ return src_mac
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ module RushButton
2
+ module Protocol
3
+ ARP = "arp"
4
+ IP = "ip"
5
+ end
6
+ end
@@ -0,0 +1,26 @@
1
+ require 'packetfu'
2
+
3
+ module RushButton
4
+ class Server
5
+ include PacketFu
6
+ def initialize iface
7
+ @iface = iface
8
+ @buttons = []
9
+ end
10
+
11
+ def add mac_addr, &block
12
+ @buttons << DashButton.new(mac_addr).on_press(&block)
13
+ end
14
+
15
+ def start
16
+ puts "Dash Button capturing..." if $DEBUG
17
+ cap = Capture.new(iface:@iface, filter:Protocol::ARP, promisc:true)
18
+ cap.stream.each do |pkt|
19
+ if ARPPacket.can_parse?(pkt)
20
+ src_mac = ARPPacket.parse(pkt).eth_src_readable
21
+ @buttons.find {|e| e.mac == src_mac}&.press
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module RushButton
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "rush_button/version"
3
+
4
+ require "rush_button/protocol"
5
+ require "rush_button/dash_button"
6
+ require "rush_button/dash_capture"
7
+ require "rush_button/server"
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rush_button/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rush_button"
8
+ spec.version = RushButton::VERSION
9
+ spec.authors = ["graviton"]
10
+ spec.email = ["https://github.com/gravitonMain"]
11
+
12
+ spec.summary = %q{Library for Amazon Dash button.}
13
+ spec.description = %q{Library for Amazon Dash button.}
14
+ spec.homepage = "https://github.com/gravitonMain/rush_button"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "bin"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.15"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+
36
+ # add
37
+ spec.add_runtime_dependency 'packetfu', '~>1.1'
38
+ spec.add_development_dependency "pry", "~> 0.10"
39
+ end
data/sample/example.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "rush_button"
2
+
3
+ iface = ARGV[0]
4
+ mac_addr = ARGV[1]
5
+ srv = RushButton::Server.new(iface)
6
+ srv.add(mac_addr) do
7
+ puts "|#{Time.now}| Pressed!"
8
+ end
9
+ srv.start
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rush_button
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - graviton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: packetfu
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ description: Library for Amazon Dash button.
84
+ email:
85
+ - https://github.com/gravitonMain
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/find_button
98
+ - bin/setup
99
+ - lib/rush_button.rb
100
+ - lib/rush_button/dash_button.rb
101
+ - lib/rush_button/dash_capture.rb
102
+ - lib/rush_button/protocol.rb
103
+ - lib/rush_button/server.rb
104
+ - lib/rush_button/version.rb
105
+ - rush_button.gemspec
106
+ - sample/example.rb
107
+ homepage: https://github.com/gravitonMain/rush_button
108
+ licenses: []
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.6.12
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Library for Amazon Dash button.
130
+ test_files: []