-
Notifications
You must be signed in to change notification settings - Fork 1
/
swipe.rb
60 lines (42 loc) · 1.79 KB
/
swipe.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'usb'
require 'cgi'
device = USB.devices.find{|u| u.idProduct == 0x0002 && u.idVendor == 0x0801}
interface = device.interfaces.first
endpoint = interface.endpoints.first
handle = device.open
handle.usb_detach_kernel_driver_np(0,0) rescue nil
# handle.set_configuration(1)
handle.usb_claim_interface(0)
loop do
puts "Paddle Number: "
paddle = STDIN.gets.chomp
# Clear out any pending swipes
loop do
begin
size = handle.usb_interrupt_read(0x81,data,-1)
rescue
break
end
end
puts "Please Swipe..."
data = (0..1024).to_a.pack("c*")
size = handle.usb_interrupt_read(0x81,data,0)
track1_status,track2_status,track3_status,track1_len,track2_len,track3_len,type,track1_data,track2_data,track3_data = data.unpack("CCCCCCCa109a109a109")
puts track1_data
puts track2_data
puts track3_data
match = /^%B(.*)\^(.*)\^(..)(..)(...)(.*)\?/.match(track1_data)
next unless match
cardnum,name,yy,mm,service_code,extra = match.captures
puts "Card Number: #{cardnum}"
puts "Name: #{name}"
puts "Exp: #{mm}/#{yy}"
puts "Service Code: #{service_code}"
puts "Extra Data: #{extra}"
exp = "#{mm}/#{yy}"
#"?swipe[track3_data]=#{CGI.escape(track3_data)}&swipe[track2_data]=#{CGI.escape(track2_data)}&swipe[track1_data]=#{CGI.escape(track1_data)}&swipe[number]=#{CGI.escape(cardnum)}&swipe[name]=#{CGI.escape(name)}&swipe[exp]=#{CGI.escape(exp)}&swipe[service_code]=#{CGI.escape(service_code)}&swipe[extra]=#{CGI.escape(extra)}"
postdata = "?paddle=#{CGI.escape(paddle)}&swipe[number]=#{CGI.escape(cardnum)}&swipe[name]=#{CGI.escape(name)}&swipe[exp]=#{CGI.escape(exp)}&swipe[service_code]=#{CGI.escape(service_code)}&swipe[extra]=#{CGI.escape(extra)}"
command = ARGV.clone
command << '"' + command.pop + postdata + '"'
system command.flatten.join(' ')
end