rbzk 0.1.7 → 0.1.9
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 +4 -4
- data/lib/rbzk/cli/commands.rb +77 -28
- data/lib/rbzk/exceptions.rb +6 -0
- data/lib/rbzk/version.rb +1 -1
- data/lib/rbzk/zk.rb +499 -652
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 30de1318989db7b9f80b389d3ca68436938ac0a05b19946e605f852bff717cb1
|
|
4
|
+
data.tar.gz: c9eb7a35862c70f94a9b7e35ad0ca61866c073de69bb8b9f06f84cb2737c22bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b9fa15daacc07d2b86b931ea453f16f4d29071bc760d2cd888a464a02b5281f90ceb855c29a2ec5a4eafaec6a0df5129163d4ef5c4c8c6739be08aa92d8121ca
|
|
7
|
+
data.tar.gz: 381807e8e37f62cf560dd61f3e6798d1727f4911df14454d59163c9894e6ca4df99b4cf499fcb2f85eddf9f5c7ad13ee2f34f70d647f25d2419ac98e1813ed03
|
data/lib/rbzk/cli/commands.rb
CHANGED
|
@@ -63,7 +63,7 @@ module RBZK
|
|
|
63
63
|
table = ::Terminal::Table.new do |t|
|
|
64
64
|
t.title = 'Device Information'
|
|
65
65
|
device_info.each do |key, value|
|
|
66
|
-
t << [key, value]
|
|
66
|
+
t << [ key, value ]
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
@@ -108,28 +108,28 @@ module RBZK
|
|
|
108
108
|
map 'logs-today' => 'logs'
|
|
109
109
|
|
|
110
110
|
def logs_today(ip = nil)
|
|
111
|
-
invoke :logs, [ip], { today: true }.merge(options)
|
|
111
|
+
invoke :logs, [ ip ], { today: true }.merge(options)
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
desc 'logs-yesterday [IP]', "Get yesterday's attendance logs"
|
|
115
115
|
map 'logs-yesterday' => 'logs'
|
|
116
116
|
|
|
117
117
|
def logs_yesterday(ip = nil)
|
|
118
|
-
invoke :logs, [ip], { yesterday: true }.merge(options)
|
|
118
|
+
invoke :logs, [ ip ], { yesterday: true }.merge(options)
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
desc 'logs-week [IP]', "Get this week's attendance logs"
|
|
122
122
|
map 'logs-week' => 'logs'
|
|
123
123
|
|
|
124
124
|
def logs_week(ip = nil)
|
|
125
|
-
invoke :logs, [ip], { week: true }.merge(options)
|
|
125
|
+
invoke :logs, [ ip ], { week: true }.merge(options)
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
desc 'logs-month [IP]', "Get this month's attendance logs"
|
|
129
129
|
map 'logs-month' => 'logs'
|
|
130
130
|
|
|
131
131
|
def logs_month(ip = nil)
|
|
132
|
-
invoke :logs, [ip], { month: true }.merge(options)
|
|
132
|
+
invoke :logs, [ ip ], { month: true }.merge(options)
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
desc 'logs-all [IP]', 'Get all attendance logs without limit'
|
|
@@ -153,7 +153,7 @@ module RBZK
|
|
|
153
153
|
# Pretty table output
|
|
154
154
|
table = ::Terminal::Table.new do |t|
|
|
155
155
|
t.title = 'All Attendance Logs (Showing All Records)'
|
|
156
|
-
t.headings = ['UID', 'User ID', 'Time', 'Status', 'Punch Type']
|
|
156
|
+
t.headings = [ 'UID', 'User ID', 'Time', 'Status', 'Punch Type' ]
|
|
157
157
|
|
|
158
158
|
# Show all logs in the table
|
|
159
159
|
logs.each do |log|
|
|
@@ -185,7 +185,7 @@ module RBZK
|
|
|
185
185
|
def logs_custom(start_date, end_date, ip = nil)
|
|
186
186
|
# Use IP from options if not provided as argument
|
|
187
187
|
ip ||= options[:ip] || @config['ip']
|
|
188
|
-
invoke :logs, [ip], { start_date: start_date, end_date: end_date }.merge(options)
|
|
188
|
+
invoke :logs, [ ip ], { start_date: start_date, end_date: end_date }.merge(options)
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
desc 'logs [IP]', 'Get attendance logs'
|
|
@@ -298,7 +298,7 @@ module RBZK
|
|
|
298
298
|
# Pretty table output
|
|
299
299
|
table = ::Terminal::Table.new do |t|
|
|
300
300
|
t.title = title || 'Attendance Logs'
|
|
301
|
-
t.headings = ['UID', 'User ID', 'Time', 'Status', 'Punch Type']
|
|
301
|
+
t.headings = [ 'UID', 'User ID', 'Time', 'Status', 'Punch Type' ]
|
|
302
302
|
|
|
303
303
|
# Show logs in the table based on limit
|
|
304
304
|
display_logs.each do |log|
|
|
@@ -427,17 +427,38 @@ module RBZK
|
|
|
427
427
|
with_connection(ip, options) do |conn|
|
|
428
428
|
puts 'Adding/updating user...'
|
|
429
429
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
430
|
+
# Disable device for exclusive access during modification
|
|
431
|
+
begin
|
|
432
|
+
puts '✓ Disabling device...'
|
|
433
|
+
conn.disable_device
|
|
434
|
+
rescue StandardError
|
|
435
|
+
nil
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
begin
|
|
439
|
+
result = conn.set_user(
|
|
440
|
+
uid: options[:uid],
|
|
441
|
+
name: options[:name] || '',
|
|
442
|
+
privilege: options[:privilege] || 0,
|
|
443
|
+
password: options[:password] || '',
|
|
444
|
+
group_id: options[:group_id] || '',
|
|
445
|
+
user_id: options[:user_id] || '',
|
|
446
|
+
card: options[:card] || 0
|
|
447
|
+
)
|
|
448
|
+
puts '✓ User added/updated successfully!' if result
|
|
449
|
+
rescue RBZK::ZKError => e
|
|
450
|
+
# Reraise to let the with_connection handler print device messages
|
|
451
|
+
raise e
|
|
452
|
+
ensure
|
|
453
|
+
# Re-enable device after modification (always)
|
|
454
|
+
begin
|
|
455
|
+
puts '✓ Re-enabling device...'
|
|
456
|
+
conn.enable_device
|
|
457
|
+
rescue StandardError => e
|
|
458
|
+
# Do not raise - just log a warning if verbose
|
|
459
|
+
puts "Warning: failed to re-enable device: #{e.message}" if options[:verbose]
|
|
460
|
+
end
|
|
461
|
+
end
|
|
441
462
|
end
|
|
442
463
|
end
|
|
443
464
|
|
|
@@ -487,7 +508,7 @@ module RBZK
|
|
|
487
508
|
# Use Terminal::Table for pretty output
|
|
488
509
|
table = ::Terminal::Table.new do |t|
|
|
489
510
|
t.title = 'Fingerprint Templates'
|
|
490
|
-
t.headings = ['UID', 'Finger ID', 'Valid', 'Size']
|
|
511
|
+
t.headings = [ 'UID', 'Finger ID', 'Valid', 'Size' ]
|
|
491
512
|
|
|
492
513
|
templates.each do |template|
|
|
493
514
|
t << [
|
|
@@ -527,10 +548,9 @@ module RBZK
|
|
|
527
548
|
|
|
528
549
|
# Extract parameters from options
|
|
529
550
|
uid = options[:uid] || 0
|
|
530
|
-
user_id = options[:user_id] || ''
|
|
531
551
|
finger_id = options[:finger_id] || 0
|
|
532
552
|
|
|
533
|
-
template = conn.get_user_template(uid
|
|
553
|
+
template = conn.get_user_template(uid, finger_id)
|
|
534
554
|
|
|
535
555
|
if template
|
|
536
556
|
puts '✓ Found fingerprint template:'
|
|
@@ -645,6 +665,34 @@ module RBZK
|
|
|
645
665
|
end
|
|
646
666
|
end
|
|
647
667
|
|
|
668
|
+
desc 'enable-device [IP]', 'Enable the device'
|
|
669
|
+
map 'enable-device' => :enable_device
|
|
670
|
+
|
|
671
|
+
def enable_device(ip = nil)
|
|
672
|
+
# Use IP from options if not provided as argument
|
|
673
|
+
ip ||= options[:ip] || @config['ip']
|
|
674
|
+
|
|
675
|
+
with_connection(ip, options) do |conn|
|
|
676
|
+
puts 'Enabling device...'
|
|
677
|
+
result = conn.enable_device
|
|
678
|
+
puts '✓ Device enabled successfully!' if result
|
|
679
|
+
end
|
|
680
|
+
end
|
|
681
|
+
|
|
682
|
+
desc 'disable-device [IP]', 'Disable the device'
|
|
683
|
+
map 'disable-device' => :disable_device
|
|
684
|
+
|
|
685
|
+
def disable_device(ip = nil)
|
|
686
|
+
# Use IP from options if not provided as argument
|
|
687
|
+
ip ||= options[:ip] || @config['ip']
|
|
688
|
+
|
|
689
|
+
with_connection(ip, options) do |conn|
|
|
690
|
+
puts 'Disabling device...'
|
|
691
|
+
result = conn.disable_device
|
|
692
|
+
puts '✓ Device disabled successfully!' if result
|
|
693
|
+
end
|
|
694
|
+
end
|
|
695
|
+
|
|
648
696
|
desc 'poweroff [IP]', 'Power off the device'
|
|
649
697
|
|
|
650
698
|
def poweroff(ip = nil)
|
|
@@ -743,6 +791,8 @@ module RBZK
|
|
|
743
791
|
rescue RBZK::ZKNetworkError => e
|
|
744
792
|
puts "✗ Network Error: #{e.message}"
|
|
745
793
|
puts 'Please check the IP address and ensure the device is reachable.'
|
|
794
|
+
rescue RBZK::ZKErrorExists => e
|
|
795
|
+
puts "✗ Device Error: #{e.message}"
|
|
746
796
|
rescue RBZK::ZKErrorResponse => e
|
|
747
797
|
puts "✗ Device Error: #{e.message}"
|
|
748
798
|
puts 'The device returned an error response.'
|
|
@@ -771,7 +821,7 @@ module RBZK
|
|
|
771
821
|
# Use Terminal::Table for pretty output
|
|
772
822
|
table = ::Terminal::Table.new do |t|
|
|
773
823
|
t.title = 'Users'
|
|
774
|
-
t.headings = ['UID', 'User ID', 'Name', 'Privilege', 'Password', 'Group ID', 'Card']
|
|
824
|
+
t.headings = [ 'UID', 'User ID', 'Name', 'Privilege', 'Password', 'Group ID', 'Card' ]
|
|
775
825
|
|
|
776
826
|
users.each do |user|
|
|
777
827
|
t << [
|
|
@@ -815,11 +865,10 @@ module RBZK
|
|
|
815
865
|
|
|
816
866
|
def format_privilege(privilege)
|
|
817
867
|
case privilege
|
|
818
|
-
when
|
|
819
|
-
when
|
|
820
|
-
when
|
|
821
|
-
when
|
|
822
|
-
when 14 then 'Super Admin'
|
|
868
|
+
when RBZK::Constants::USER_DEFAULT then 'User'
|
|
869
|
+
when RBZK::Constants::USER_ENROLLER then 'Enroller'
|
|
870
|
+
when RBZK::Constants::USER_MANAGER then 'Manager'
|
|
871
|
+
when RBZK::Constants::USER_ADMIN then 'Admin'
|
|
823
872
|
else "Unknown (#{privilege})"
|
|
824
873
|
end
|
|
825
874
|
end
|
data/lib/rbzk/exceptions.rb
CHANGED
data/lib/rbzk/version.rb
CHANGED