rbzk 0.1.5 → 0.1.6
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/README.md +304 -254
- data/lib/rbzk/cli/commands.rb +37 -42
- data/lib/rbzk/version.rb +1 -1
- 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: dc6b7b78fa88e4e3cbea5a63aff9a333e1dea98a796de0cc2ab1a8d875f10a64
|
4
|
+
data.tar.gz: ab1527c24665247a5de3393fdf83a9aa0f4c74fe9fe933554ed105968584b56e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee91215cdd36830c39e259ab1e42384c8f155d896cb52254105aaf6d36b4167fc7becbd9b4cb632631e32ef23ce2ac57c2de3ecc32990857a56b74a25e26b2d2
|
7
|
+
data.tar.gz: 9bad7c48f98845263d7183362ae7d19a453035747100605e05f6523a0dafd5d9ce9e264dcbfdf2950c297dcff448027716f9edc1a41c18196d89acf4e5942e8e
|
data/README.md
CHANGED
@@ -24,7 +24,9 @@ Or install it yourself as:
|
|
24
24
|
$ gem install rbzk
|
25
25
|
```
|
26
26
|
|
27
|
-
## Usage
|
27
|
+
## Library Usage
|
28
|
+
|
29
|
+
The `rbzk` gem provides a `RBZK::ZK` class to interact with ZKTeco devices.
|
28
30
|
|
29
31
|
### Basic Connection
|
30
32
|
|
@@ -32,7 +34,8 @@ $ gem install rbzk
|
|
32
34
|
require 'rbzk'
|
33
35
|
|
34
36
|
# Create a new ZK instance
|
35
|
-
|
37
|
+
# Replace with your device's IP address
|
38
|
+
zk = RBZK::ZK.new('192.168.1.201', port: 4370, timeout: 60, password: 0)
|
36
39
|
|
37
40
|
# Connect to the device
|
38
41
|
begin
|
@@ -46,329 +49,376 @@ begin
|
|
46
49
|
exit 1
|
47
50
|
end
|
48
51
|
|
49
|
-
# Disable the device to ensure exclusive access
|
52
|
+
# Disable the device to ensure exclusive access for sensitive operations
|
50
53
|
puts 'Disabling device...'
|
51
54
|
conn.disable_device
|
52
55
|
|
53
|
-
# Your operations here
|
56
|
+
# --- Your operations here ---
|
57
|
+
puts "Device Firmware Version: #{conn.get_firmware_version}"
|
58
|
+
puts "Serial Number: #{conn.get_serialnumber}"
|
59
|
+
# --- End of operations ---
|
54
60
|
|
55
61
|
# Re-enable the device when done
|
56
62
|
puts 'Enabling device...'
|
57
63
|
conn.enable_device
|
58
|
-
rescue => e
|
59
|
-
puts "Error: #{e.message}"
|
64
|
+
rescue RBZK::ZKError => e # Catch specific RBZK errors
|
65
|
+
puts "ZK Error: #{e.message}"
|
66
|
+
rescue => e # Catch other potential errors
|
67
|
+
puts "Generic Error: #{e.message}"
|
60
68
|
ensure
|
61
69
|
# Always disconnect when done
|
62
70
|
conn.disconnect if conn && conn.connected?
|
71
|
+
puts "Disconnected."
|
63
72
|
end
|
64
73
|
```
|
65
74
|
|
66
|
-
###
|
75
|
+
### Device Information
|
67
76
|
|
68
77
|
```ruby
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
conn.enable_device
|
92
|
-
rescue => e
|
93
|
-
puts "Error: #{e.message}"
|
94
|
-
ensure
|
95
|
-
conn.disconnect if conn && conn.connected?
|
96
|
-
end
|
78
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
79
|
+
# (See Basic Connection example)
|
80
|
+
|
81
|
+
puts "--- Device Information ---"
|
82
|
+
puts "Firmware Version: #{conn.get_firmware_version}"
|
83
|
+
puts "Serial Number: #{conn.get_serialnumber}"
|
84
|
+
puts "MAC Address: #{conn.get_mac}"
|
85
|
+
puts "Device Name: #{conn.get_device_name}"
|
86
|
+
puts "Platform: #{conn.get_platform}"
|
87
|
+
puts "Fingerprint Algorithm Version: #{conn.get_fp_version}"
|
88
|
+
# puts "Face Algorithm Version: #{conn.get_face_version}" # If applicable
|
89
|
+
puts "Device Time: #{conn.get_time}"
|
90
|
+
|
91
|
+
# Get user, fingerprint, and record counts/capacities
|
92
|
+
conn.read_sizes # Updates internal counts
|
93
|
+
puts "User Count: #{conn.instance_variable_get(:@users)}"
|
94
|
+
puts "Fingerprint Count: #{conn.instance_variable_get(:@fingers)}"
|
95
|
+
puts "Attendance Record Count: #{conn.instance_variable_get(:@records)}"
|
96
|
+
puts "User Capacity: #{conn.instance_variable_get(:@users_cap)}"
|
97
|
+
puts "Fingerprint Capacity: #{conn.instance_variable_get(:@fingers_cap)}"
|
98
|
+
puts "Record Capacity: #{conn.instance_variable_get(:@rec_cap)}"
|
97
99
|
```
|
98
100
|
|
99
|
-
###
|
101
|
+
### Device Control
|
100
102
|
|
101
103
|
```ruby
|
102
|
-
|
104
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
conn.disable_device
|
106
|
+
# Restart the device
|
107
|
+
# conn.restart
|
108
|
+
# puts "Device restarting..."
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
puts "User ID: #{log.user_id}"
|
113
|
-
puts "Timestamp: #{log.timestamp}"
|
114
|
-
puts "Status: #{log.status}"
|
115
|
-
puts "Punch: #{log.punch}"
|
116
|
-
puts "UID: #{log.uid}"
|
117
|
-
puts "---"
|
118
|
-
end
|
119
|
-
|
120
|
-
conn.enable_device
|
121
|
-
rescue => e
|
122
|
-
puts "Error: #{e.message}"
|
123
|
-
ensure
|
124
|
-
conn.disconnect if conn && conn.connected?
|
125
|
-
end
|
126
|
-
```
|
110
|
+
# Power off the device (use with caution)
|
111
|
+
# conn.poweroff
|
112
|
+
# puts "Device powering off..."
|
127
113
|
|
128
|
-
|
114
|
+
# Test a voice prompt (e.g., "Thank you")
|
115
|
+
# conn.test_voice(RBZK::Constants::EF_THANKYOU) # Check Constants for available voice enums
|
116
|
+
# puts "Tested voice prompt."
|
129
117
|
|
130
|
-
|
131
|
-
|
118
|
+
# Unlock the door for 5 seconds
|
119
|
+
conn.unlock(5)
|
120
|
+
puts "Door unlocked for 5 seconds."
|
132
121
|
|
133
|
-
|
134
|
-
|
135
|
-
|
122
|
+
# Get door lock state
|
123
|
+
state = conn.get_lock_state
|
124
|
+
puts "Door is #{state ? 'Open' : 'Closed'}."
|
125
|
+
```
|
136
126
|
|
137
|
-
|
138
|
-
time = conn.get_time
|
139
|
-
puts "Device time: #{time}"
|
127
|
+
### LCD Operations
|
140
128
|
|
141
|
-
|
142
|
-
|
129
|
+
```ruby
|
130
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
131
|
+
|
132
|
+
# Write text to LCD (line number, text)
|
133
|
+
conn.write_lcd(1, "Hello from RBZK!")
|
134
|
+
puts "Text written to LCD line 1."
|
135
|
+
conn.write_lcd(2, Time.now.strftime("%H:%M:%S"))
|
136
|
+
puts "Text written to LCD line 2."
|
137
|
+
|
138
|
+
# Clear the LCD display
|
139
|
+
# sleep 5 # Keep text for 5 seconds
|
140
|
+
# conn.clear_lcd
|
141
|
+
# puts "LCD cleared."
|
142
|
+
```
|
143
143
|
|
144
|
-
|
145
|
-
info = conn.get_free_sizes
|
146
|
-
puts "Users: #{info[:users]}"
|
147
|
-
puts "Fingers: #{info[:fingers]}"
|
148
|
-
puts "Capacity: #{info[:capacity]}"
|
149
|
-
puts "Logs: #{info[:logs]}"
|
150
|
-
puts "Passwords: #{info[:passwords]}"
|
144
|
+
### User Management
|
151
145
|
|
152
|
-
|
153
|
-
conn.test_voice
|
146
|
+
#### Getting Users
|
154
147
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
148
|
+
```ruby
|
149
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
150
|
+
|
151
|
+
puts '--- Get Users ---'
|
152
|
+
users = conn.get_users
|
153
|
+
users.each do |user|
|
154
|
+
privilege = 'User'
|
155
|
+
privilege = 'Admin' if user.privilege == RBZK::Constants::USER_ADMIN
|
156
|
+
|
157
|
+
puts "UID: #{user.uid}"
|
158
|
+
puts "Name: #{user.name}"
|
159
|
+
puts "Privilege: #{privilege}"
|
160
|
+
puts "Password: #{user.password}" # Be mindful of displaying passwords
|
161
|
+
puts "Group ID: #{user.group_id}"
|
162
|
+
puts "User ID (PIN2): #{user.user_id}"
|
163
|
+
puts "Card: #{user.card}"
|
164
|
+
puts "---"
|
159
165
|
end
|
160
166
|
```
|
161
167
|
|
162
|
-
|
168
|
+
#### Add/Update User
|
163
169
|
|
164
170
|
```ruby
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
conn.enable_device
|
189
|
-
rescue => e
|
190
|
-
puts "Error: #{e.message}"
|
191
|
-
ensure
|
192
|
-
conn.disconnect if conn && conn.connected?
|
171
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
172
|
+
|
173
|
+
puts '--- Add/Update User ---'
|
174
|
+
# For a new user, UID can often be omitted if the device assigns it.
|
175
|
+
# To update an existing user, provide their UID.
|
176
|
+
# conn.read_sizes # Ensure @next_uid is populated if device assigns UIDs
|
177
|
+
# new_uid = conn.instance_variable_get(:@next_uid) # Example for new user
|
178
|
+
|
179
|
+
user_attributes = {
|
180
|
+
uid: 123, # Specify UID to update, or omit for device to assign (check device behavior)
|
181
|
+
name: 'John Doe',
|
182
|
+
privilege: RBZK::Constants::USER_DEFAULT,
|
183
|
+
password: '1234',
|
184
|
+
group_id: '1',
|
185
|
+
user_id: 'JD123', # Custom User ID / PIN2
|
186
|
+
card: 7890
|
187
|
+
}
|
188
|
+
|
189
|
+
if conn.set_user(**user_attributes)
|
190
|
+
puts "User #{user_attributes[:name]} (UID: #{user_attributes[:uid] || 'auto'}) added/updated successfully."
|
191
|
+
conn.refresh_data # Good practice to refresh data after modifications
|
192
|
+
else
|
193
|
+
puts "Failed to add/update user."
|
193
194
|
end
|
194
195
|
```
|
195
196
|
|
196
|
-
|
197
|
-
|
198
|
-
RBZK provides a powerful command-line interface for interacting with ZKTeco devices. The CLI is built using Thor, which provides a clean, intuitive interface similar to Git and other modern command-line tools.
|
197
|
+
#### Delete User
|
199
198
|
|
200
|
-
|
201
|
-
|
202
|
-
After installing the gem, you can use the `rbzk` command directly:
|
203
|
-
|
204
|
-
```bash
|
205
|
-
# Install the gem
|
206
|
-
gem install rbzk
|
207
|
-
|
208
|
-
# Use the command
|
209
|
-
bin/rbzk info 192.168.100.201
|
210
|
-
```
|
199
|
+
```ruby
|
200
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
211
201
|
|
212
|
-
|
202
|
+
puts '--- Delete User ---'
|
203
|
+
uid_to_delete = 123 # UID of the user to delete
|
213
204
|
|
214
|
-
|
215
|
-
|
205
|
+
if conn.delete_user(uid: uid_to_delete)
|
206
|
+
puts "User with UID #{uid_to_delete} deleted successfully."
|
207
|
+
conn.refresh_data
|
208
|
+
else
|
209
|
+
puts "Failed to delete user with UID #{uid_to_delete} (may not exist)."
|
210
|
+
end
|
216
211
|
```
|
217
212
|
|
218
|
-
###
|
219
|
-
|
220
|
-
```bash
|
221
|
-
# Get help
|
222
|
-
bin/rbzk help
|
223
|
-
|
224
|
-
# Get help for a specific command
|
225
|
-
bin/rbzk help logs
|
226
|
-
```
|
213
|
+
### Attendance Log Management
|
227
214
|
|
228
|
-
####
|
215
|
+
#### Getting Attendance Logs
|
229
216
|
|
230
|
-
```
|
231
|
-
#
|
232
|
-
|
217
|
+
```ruby
|
218
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
219
|
+
|
220
|
+
puts '--- Get Attendance Logs ---'
|
221
|
+
logs = conn.get_attendance_logs
|
222
|
+
if logs.empty?
|
223
|
+
puts "No attendance logs found."
|
224
|
+
else
|
225
|
+
logs.each_with_index do |log, index|
|
226
|
+
puts "Log ##{index + 1}:"
|
227
|
+
puts " Device UID: #{log.uid}" # Internal device UID for the record
|
228
|
+
puts " User ID (PIN2): #{log.user_id}"
|
229
|
+
# Status: Check-in, Check-out, etc. (Refer to ZK documentation for specific status codes)
|
230
|
+
puts " Status: #{log.status}"
|
231
|
+
# Punch: Fingerprint, Password, Card, etc. (Refer to ZK documentation)
|
232
|
+
puts " Punch Type: #{log.punch}"
|
233
|
+
puts " Timestamp: #{log.timestamp.strftime('%Y-%m-%d %H:%M:%S')}"
|
234
|
+
puts "---"
|
235
|
+
end
|
236
|
+
end
|
233
237
|
```
|
234
238
|
|
235
|
-
####
|
239
|
+
#### Clear Attendance Logs
|
236
240
|
|
237
|
-
```
|
238
|
-
#
|
239
|
-
|
241
|
+
```ruby
|
242
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
243
|
+
|
244
|
+
# puts '--- Clear Attendance Logs ---'
|
245
|
+
# puts "WARNING: This will delete all attendance logs from the device."
|
246
|
+
# print "Are you sure? (yes/N): "
|
247
|
+
# confirmation = gets.chomp
|
248
|
+
# if confirmation.downcase == 'yes'
|
249
|
+
# if conn.clear_attendance
|
250
|
+
# puts "Attendance logs cleared successfully."
|
251
|
+
# conn.refresh_data
|
252
|
+
# else
|
253
|
+
# puts "Failed to clear attendance logs."
|
254
|
+
# end
|
255
|
+
# else
|
256
|
+
# puts "Operation cancelled."
|
257
|
+
# end
|
240
258
|
```
|
241
259
|
|
242
|
-
|
243
|
-
|
244
|
-
```bash
|
245
|
-
# Get all attendance logs
|
246
|
-
bin/rbzk logs 192.168.100.201 [options]
|
260
|
+
### Fingerprint Template Management
|
247
261
|
|
248
|
-
|
249
|
-
bin/rbzk logs 192.168.100.201 --today [options]
|
262
|
+
*(Note: Fingerprint template data is binary and device-specific. Handling it requires careful understanding of the ZK protocol and template formats.)*
|
250
263
|
|
251
|
-
|
252
|
-
bin/rbzk logs 192.168.100.201 --yesterday [options]
|
264
|
+
#### Get All Fingerprint Templates
|
253
265
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
```bash
|
267
|
-
# Clear attendance logs (will prompt for confirmation)
|
268
|
-
bin/rbzk clear_logs 192.168.100.201 [options]
|
266
|
+
```ruby
|
267
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
268
|
+
|
269
|
+
puts '--- Get All Fingerprint Templates ---'
|
270
|
+
templates = conn.get_templates
|
271
|
+
if templates.empty?
|
272
|
+
puts "No fingerprint templates found."
|
273
|
+
else
|
274
|
+
templates.each do |fp_template|
|
275
|
+
puts "UID: #{fp_template.uid}, Finger ID: #{fp_template.fid}, Valid: #{fp_template.valid}, Size: #{fp_template.size}"
|
276
|
+
end
|
277
|
+
end
|
269
278
|
```
|
270
279
|
|
271
|
-
####
|
280
|
+
#### Get a Specific User's Fingerprint Template
|
272
281
|
|
273
|
-
```
|
274
|
-
#
|
275
|
-
bin/rbzk test_voice 192.168.100.201 [options]
|
276
|
-
```
|
277
|
-
|
278
|
-
### Global Options
|
282
|
+
```ruby
|
283
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
279
284
|
|
280
|
-
|
285
|
+
user_uid = '123' # The user's main UID (often a string from device)
|
286
|
+
finger_id = 0 # Finger index (0-9)
|
281
287
|
|
288
|
+
begin
|
289
|
+
fp_template = conn.get_user_template(user_uid, finger_id)
|
290
|
+
if fp_template
|
291
|
+
puts "Template for UID #{user_uid}, Finger ID #{finger_id}: Size #{fp_template.size}, Valid: #{fp_template.valid}"
|
292
|
+
# fp_template.template contains the binary data
|
293
|
+
else
|
294
|
+
puts "Template not found for UID #{user_uid}, Finger ID #{finger_id}."
|
295
|
+
end
|
296
|
+
rescue RBZK::ZKErrorResponse => e
|
297
|
+
puts "Error getting template: #{e.message}"
|
298
|
+
end
|
282
299
|
```
|
283
|
-
--ip=IP # Device IP address (default: from config or 192.168.100.201)
|
284
|
-
--port=PORT # Device port (default: from config or 4370)
|
285
|
-
--timeout=SECONDS # Connection timeout in seconds (default: from config or 30)
|
286
|
-
--password=PASSWORD # Device password (default: from config or 0)
|
287
|
-
--verbose # Enable verbose output (default: from config or false)
|
288
|
-
--force-udp # Use UDP instead of TCP (default: from config or false)
|
289
|
-
--no-ping # Skip ping check (default: from config or true)
|
290
|
-
--encoding=ENCODING # Character encoding (default: from config or UTF-8)
|
291
|
-
```
|
292
|
-
|
293
|
-
### Configuration
|
294
|
-
|
295
|
-
RBZK supports persistent configuration through a configuration file. This allows you to set default values for IP address and other options without having to specify them every time.
|
296
|
-
|
297
|
-
#### Configuration File Location
|
298
300
|
|
299
|
-
|
301
|
+
#### Set a User's Fingerprint Template
|
300
302
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
#
|
309
|
-
|
310
|
-
|
311
|
-
#
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
#
|
318
|
-
|
303
|
+
*(This is an advanced operation. You need valid template data.)*
|
304
|
+
```ruby
|
305
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
306
|
+
# And `valid_template_data` is a binary string of a valid fingerprint template
|
307
|
+
|
308
|
+
# user_uid = '123'
|
309
|
+
# finger_id = 0
|
310
|
+
# valid_flag = 1 # 1 for valid, 0 for invalid/duplicate
|
311
|
+
# valid_template_data = "BINARY_TEMPLATE_DATA_HERE" # Replace with actual binary data
|
312
|
+
|
313
|
+
# begin
|
314
|
+
# if conn.set_user_template(valid_template_data, user_uid, finger_id, valid_flag)
|
315
|
+
# puts "Fingerprint template set successfully for UID #{user_uid}, Finger ID #{finger_id}."
|
316
|
+
# conn.refresh_data
|
317
|
+
# else
|
318
|
+
# puts "Failed to set fingerprint template."
|
319
|
+
# end
|
320
|
+
# rescue RBZK::ZKErrorResponse => e
|
321
|
+
# puts "Error setting template: #{e.message}"
|
322
|
+
# end
|
319
323
|
```
|
320
324
|
|
321
|
-
|
322
|
-
|
323
|
-
### Examples
|
325
|
+
#### Delete/Clear Fingerprint Templates
|
324
326
|
|
325
|
-
```
|
326
|
-
#
|
327
|
-
|
328
|
-
|
329
|
-
#
|
330
|
-
|
331
|
-
|
332
|
-
#
|
333
|
-
|
334
|
-
|
335
|
-
#
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
#
|
340
|
-
|
341
|
-
|
342
|
-
#
|
343
|
-
|
344
|
-
|
345
|
-
#
|
346
|
-
|
327
|
+
```ruby
|
328
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
329
|
+
|
330
|
+
# Delete a specific fingerprint for a user
|
331
|
+
# user_uid_for_fp_delete = '123'
|
332
|
+
# finger_id_to_delete = 0
|
333
|
+
# if conn.delete_user_template(user_uid_for_fp_delete, finger_id_to_delete)
|
334
|
+
# puts "Template for UID #{user_uid_for_fp_delete}, FID #{finger_id_to_delete} deleted."
|
335
|
+
# conn.refresh_data
|
336
|
+
# else
|
337
|
+
# puts "Failed to delete template."
|
338
|
+
# end
|
339
|
+
|
340
|
+
# Clear all fingerprint templates for a specific user
|
341
|
+
# user_uid_to_clear_fps = '123'
|
342
|
+
# if conn.clear_user_template(user_uid_to_clear_fps) # Method name might vary, e.g., delete_user_fingerprints
|
343
|
+
# puts "All templates for UID #{user_uid_to_clear_fps} cleared."
|
344
|
+
# conn.refresh_data
|
345
|
+
# else
|
346
|
+
# puts "Failed to clear user templates."
|
347
|
+
# end
|
348
|
+
|
349
|
+
# Clear ALL fingerprint templates on the device (Use with extreme caution!)
|
350
|
+
# puts "WARNING: This will delete ALL fingerprint templates from the device."
|
351
|
+
# print "Are you sure? (yes/N): "
|
352
|
+
# confirmation_clear_all_fp = gets.chomp
|
353
|
+
# if confirmation_clear_all_fp.downcase == 'yes'
|
354
|
+
# if conn.clear_templates # Or clear_fingerprints
|
355
|
+
# puts "All fingerprint templates cleared from device."
|
356
|
+
# conn.refresh_data
|
357
|
+
# else
|
358
|
+
# puts "Failed to clear all fingerprint templates."
|
359
|
+
# end
|
360
|
+
# else
|
361
|
+
# puts "Operation cancelled."
|
362
|
+
# end
|
347
363
|
```
|
348
364
|
|
349
|
-
###
|
350
|
-
|
351
|
-
The command line interface uses the `terminal-table` gem for prettier output if it's available. To enable this feature, install the gem:
|
365
|
+
### Device Time
|
352
366
|
|
353
|
-
```
|
354
|
-
|
367
|
+
```ruby
|
368
|
+
# Assuming 'conn' is an active and connected RBZK::ZK instance
|
369
|
+
|
370
|
+
# Get device time
|
371
|
+
current_device_time = conn.get_time
|
372
|
+
puts "Current device time: #{current_device_time}"
|
373
|
+
|
374
|
+
# Set device time (to current system time)
|
375
|
+
# new_time = Time.now
|
376
|
+
# if conn.set_time(new_time)
|
377
|
+
# puts "Device time set to #{new_time} successfully."
|
378
|
+
# else
|
379
|
+
# puts "Failed to set device time."
|
380
|
+
# end
|
355
381
|
```
|
356
382
|
|
357
|
-
|
383
|
+
## Command Line Interface (CLI)
|
358
384
|
|
359
|
-
|
385
|
+
The `rbzk` gem also provides a command-line tool named `rbzk` for quick interactions with your ZKTeco devices.
|
360
386
|
|
361
|
-
|
362
|
-
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
363
|
-
|
364
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
365
|
-
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
366
|
-
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
387
|
+
### Global Options
|
367
388
|
|
368
|
-
|
389
|
+
These options can be used with most commands:
|
369
390
|
|
370
|
-
|
391
|
+
* `--ip <IP_ADDRESS>`: IP address of the device.
|
392
|
+
* `--port <PORT>`: Port number (default: 4370).
|
393
|
+
* `--timeout <SECONDS>`: Connection timeout in seconds (default: 30 or 60).
|
394
|
+
* `--password <PASSWORD>`: Device communication password (default: 0).
|
395
|
+
* `--verbose`: Enable verbose output.
|
396
|
+
* `--force-udp`: Force UDP mode for communication.
|
397
|
+
* `--no-ping`: Skip the initial ping check.
|
398
|
+
* `--encoding <ENCODING>`: String encoding (default: UTF-8).
|
371
399
|
|
372
|
-
|
400
|
+
### Available Commands
|
373
401
|
|
374
|
-
|
402
|
+
Here are some of the primary commands available:
|
403
|
+
|
404
|
+
* `rbzk info [--ip IP]`: Get detailed device information.
|
405
|
+
* `rbzk refresh [--ip IP]`: Refresh the device's internal data (useful after making changes).
|
406
|
+
* `rbzk users [--ip IP]`: List all users on the device.
|
407
|
+
* `rbzk logs [--ip IP] [options]`: Get attendance logs.
|
408
|
+
* `--today`: Get today's logs.
|
409
|
+
* `--yesterday`: Get yesterday's logs.
|
410
|
+
* `--week`: Get logs for the current week.
|
411
|
+
* `--month`: Get logs for the current month.
|
412
|
+
* `--start-date YYYY-MM-DD`: Filter logs from a specific start date.
|
413
|
+
* `--end-date YYYY-MM-DD`: Filter logs up to a specific end date.
|
414
|
+
* `--limit N`: Limit the number of logs displayed (0 for all).
|
415
|
+
* Aliases: `rbzk logs-today`, `rbzk logs-yesterday`, `rbzk logs-week`, `rbzk logs-month`.
|
416
|
+
* `rbzk logs-all [--ip IP]`: Get all attendance logs without any limit.
|
417
|
+
* `rbzk logs-custom <START_DATE> <END_DATE> [--ip IP]`: Get logs for a custom date range (YYYY-MM-DD).
|
418
|
+
* `rbzk clear-logs [--ip IP]`: Clear all attendance logs from the device (prompts for confirmation).
|
419
|
+
* `rbzk unlock [--ip IP] [--time SECONDS]`: Unlock the connected door (default 3 seconds).
|
420
|
+
* `rbzk door-state [--ip IP]`: Get the current state of the door lock (Open/Closed).
|
421
|
+
* `rbzk write-lcd <LINE_NUMBER> <TEXT> [--ip IP]`: Write text to the device's LCD screen.
|
422
|
+
* `rbzk clear-lcd [--ip IP]`: Clear the device's LCD screen.
|
423
|
+
* `rbzk add-user [--ip IP] [options]`: Add or update a user.
|
424
|
+
* `--uid <UID
|
data/lib/rbzk/cli/commands.rb
CHANGED
@@ -5,6 +5,7 @@ require 'thor'
|
|
5
5
|
require 'yaml'
|
6
6
|
require 'fileutils'
|
7
7
|
require 'date'
|
8
|
+
require 'time'
|
8
9
|
require 'rbzk'
|
9
10
|
require 'rbzk/cli/config'
|
10
11
|
require 'terminal-table'
|
@@ -100,43 +101,33 @@ module RBZK
|
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
103
|
-
desc "logs [IP]", "Get attendance logs"
|
104
|
-
method_option :today, type: :boolean, desc: "Get only today's logs"
|
105
|
-
method_option :yesterday, type: :boolean, desc: "Get only yesterday's logs"
|
106
|
-
method_option :week, type: :boolean, desc: "Get this week's logs"
|
107
|
-
method_option :month, type: :boolean, desc: "Get this month's logs"
|
108
|
-
method_option :start_date, type: :string, desc: "Start date for custom range (YYYY-MM-DD)"
|
109
|
-
method_option :end_date, type: :string, desc: "End date for custom range (YYYY-MM-DD)"
|
110
|
-
method_option :limit, type: :numeric, default: 25, desc: "Limit the number of logs displayed (default: 25, use 0 for all)"
|
111
|
-
|
112
104
|
# Add aliases for common log commands
|
113
105
|
desc "logs-today [IP]", "Get today's attendance logs"
|
114
106
|
map "logs-today" => "logs"
|
115
107
|
|
116
108
|
def logs_today(ip = nil)
|
117
|
-
|
118
|
-
invoke :logs, [ ip ], today: true
|
109
|
+
invoke :logs, [ ip ], { today: true }.merge(options)
|
119
110
|
end
|
120
111
|
|
121
112
|
desc "logs-yesterday [IP]", "Get yesterday's attendance logs"
|
122
113
|
map "logs-yesterday" => "logs"
|
123
114
|
|
124
115
|
def logs_yesterday(ip = nil)
|
125
|
-
invoke :logs, [ ip ], yesterday: true
|
116
|
+
invoke :logs, [ ip ], { yesterday: true }.merge(options)
|
126
117
|
end
|
127
118
|
|
128
119
|
desc "logs-week [IP]", "Get this week's attendance logs"
|
129
120
|
map "logs-week" => "logs"
|
130
121
|
|
131
122
|
def logs_week(ip = nil)
|
132
|
-
invoke :logs, [ ip ], week: true
|
123
|
+
invoke :logs, [ ip ], { week: true }.merge(options)
|
133
124
|
end
|
134
125
|
|
135
126
|
desc "logs-month [IP]", "Get this month's attendance logs"
|
136
127
|
map "logs-month" => "logs"
|
137
128
|
|
138
129
|
def logs_month(ip = nil)
|
139
|
-
invoke :logs, [ ip ], month: true
|
130
|
+
invoke :logs, [ ip ], { month: true }.merge(options)
|
140
131
|
end
|
141
132
|
|
142
133
|
desc "logs-all [IP]", "Get all attendance logs without limit"
|
@@ -190,10 +181,19 @@ module RBZK
|
|
190
181
|
def logs_custom(start_date, end_date, ip = nil)
|
191
182
|
# Use IP from options if not provided as argument
|
192
183
|
ip ||= options[:ip] || @config['ip']
|
193
|
-
invoke :logs, [ ip ], start_date: start_date, end_date: end_date
|
184
|
+
invoke :logs, [ ip ], { start_date: start_date, end_date: end_date }.merge(options)
|
194
185
|
end
|
195
186
|
|
196
|
-
desc "logs [IP]", "Get
|
187
|
+
desc "logs [IP]", "Get attendance logs"
|
188
|
+
method_option :today, type: :boolean, desc: "Get only today's logs"
|
189
|
+
method_option :yesterday, type: :boolean, desc: "Get only yesterday's logs"
|
190
|
+
method_option :week, type: :boolean, desc: "Get this week's logs"
|
191
|
+
method_option :month, type: :boolean, desc: "Get this month's logs"
|
192
|
+
method_option :start_date, type: :string, desc: "Start date for custom range (YYYY-MM-DD)"
|
193
|
+
method_option :end_date, type: :string, desc: "End date for custom range (YYYY-MM-DD)"
|
194
|
+
method_option :start_time, type: :string, desc: "Start time for custom range (HH:MM)"
|
195
|
+
method_option :end_time, type: :string, desc: "End time for custom range (HH:MM)"
|
196
|
+
method_option :limit, type: :numeric, default: 25, desc: "Limit the number of logs displayed (default: 25, use 0 for all)"
|
197
197
|
|
198
198
|
def logs(ip = nil)
|
199
199
|
# Use IP from options if not provided as argument
|
@@ -208,21 +208,21 @@ module RBZK
|
|
208
208
|
# Filter logs based on options
|
209
209
|
title = if options[:today]
|
210
210
|
today = Date.today
|
211
|
-
logs =
|
211
|
+
logs = filter_logs_by_datetime(logs, today, today, options[:start_time], options[:end_time])
|
212
212
|
"Today's Attendance Logs (#{today})"
|
213
213
|
elsif options[:yesterday]
|
214
214
|
yesterday = Date.today - 1
|
215
|
-
logs =
|
215
|
+
logs = filter_logs_by_datetime(logs, yesterday, yesterday, options[:start_time], options[:end_time])
|
216
216
|
"Yesterday's Attendance Logs (#{yesterday})"
|
217
217
|
elsif options[:week]
|
218
218
|
today = Date.today
|
219
219
|
start_of_week = today - today.wday
|
220
|
-
logs =
|
220
|
+
logs = filter_logs_by_datetime(logs, start_of_week, today, options[:start_time], options[:end_time])
|
221
221
|
"This Week's Attendance Logs (#{start_of_week} to #{today})"
|
222
222
|
elsif options[:month]
|
223
223
|
today = Date.today
|
224
224
|
start_of_month = Date.new(today.year, today.month, 1)
|
225
|
-
logs =
|
225
|
+
logs = filter_logs_by_datetime(logs, start_of_month, today, options[:start_time], options[:end_time])
|
226
226
|
"This Month's Attendance Logs (#{start_of_month} to #{today})"
|
227
227
|
elsif options[:start_date] && options[:end_date]
|
228
228
|
begin
|
@@ -232,8 +232,8 @@ module RBZK
|
|
232
232
|
# Print debug info
|
233
233
|
puts "Filtering logs from #{start_date} to #{end_date}..." if options[:verbose]
|
234
234
|
|
235
|
-
# Use the
|
236
|
-
logs =
|
235
|
+
# Use the filter_logs_by_datetime method
|
236
|
+
logs = filter_logs_by_datetime(logs, start_date, end_date, options[:start_time], options[:end_time])
|
237
237
|
|
238
238
|
"Attendance Logs (#{start_date} to #{end_date})"
|
239
239
|
rescue ArgumentError
|
@@ -248,8 +248,8 @@ module RBZK
|
|
248
248
|
# Print debug info
|
249
249
|
puts "Filtering logs from #{start_date} onwards..." if options[:verbose]
|
250
250
|
|
251
|
-
# Use the
|
252
|
-
logs =
|
251
|
+
# Use the filter_logs_by_datetime method
|
252
|
+
logs = filter_logs_by_datetime(logs, start_date, end_date, options[:start_time], options[:end_time])
|
253
253
|
|
254
254
|
"Attendance Logs (#{start_date} to #{end_date})"
|
255
255
|
rescue ArgumentError
|
@@ -265,8 +265,8 @@ module RBZK
|
|
265
265
|
# Print debug info
|
266
266
|
puts "Filtering logs from #{start_date} to #{end_date}..." if options[:verbose]
|
267
267
|
|
268
|
-
# Use the
|
269
|
-
logs =
|
268
|
+
# Use the filter_logs_by_datetime method
|
269
|
+
logs = filter_logs_by_datetime(logs, start_date, end_date, options[:start_time], options[:end_time])
|
270
270
|
|
271
271
|
"Attendance Logs (#{start_date} to #{end_date})"
|
272
272
|
rescue ArgumentError
|
@@ -783,31 +783,26 @@ module RBZK
|
|
783
783
|
end
|
784
784
|
end
|
785
785
|
|
786
|
-
def
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
786
|
+
def filter_logs_by_datetime(logs, start_date, end_date, start_time = nil, end_time = nil)
|
787
|
+
start_datetime_str = "#{start_date.strftime('%Y-%m-%d')} #{start_time || '00:00:00'}"
|
788
|
+
end_datetime_str = "#{end_date.strftime('%Y-%m-%d')} #{end_time || '23:59:59'}"
|
789
|
+
|
790
|
+
start_datetime = Time.parse(start_datetime_str)
|
791
|
+
end_datetime = Time.parse(end_datetime_str)
|
791
792
|
|
792
793
|
if options[:verbose]
|
793
|
-
puts "Filtering logs from #{
|
794
|
-
puts "Total logs before filtering: #{
|
794
|
+
puts "Filtering logs from #{start_datetime} to #{end_datetime}..."
|
795
|
+
puts "Total logs before filtering: #{logs.size}"
|
795
796
|
end
|
796
797
|
|
797
|
-
|
798
|
-
|
799
|
-
logs.each do |log|
|
800
|
-
log_date_str = log.timestamp.strftime('%Y-%m-%d')
|
801
|
-
if log_date_str >= start_date_str && log_date_str <= end_date_str
|
802
|
-
filtered_logs << log
|
803
|
-
end
|
798
|
+
filtered_logs = logs.select do |log|
|
799
|
+
log.timestamp >= start_datetime && log.timestamp <= end_datetime
|
804
800
|
end
|
805
801
|
|
806
802
|
if options[:verbose]
|
807
|
-
puts "Filtered logs: #{filtered_logs.size} of #{
|
803
|
+
puts "Filtered logs: #{filtered_logs.size} of #{logs.size}"
|
808
804
|
end
|
809
805
|
|
810
|
-
# Return the filtered logs
|
811
806
|
filtered_logs
|
812
807
|
end
|
813
808
|
|
data/lib/rbzk/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbzk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Khaled AbuShqear
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-09-26 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bytes
|