equitrac_utilities 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 +7 -0
- data/lib/equitrac_utilities.rb +6 -0
- data/lib/equitrac_utilities/connection.rb +93 -0
- data/lib/equitrac_utilities/user_actions.rb +93 -0
- data/lib/equitrac_utilities/version.rb +5 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 18c56d5baffe1fc3d4fed4283391c508869b24faaa73ad76406211ffc906a166
|
4
|
+
data.tar.gz: f36337e3cecaf50ec47dee44180a69ae5df8cfb51bb233912865c9192af30542
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3545e140782698895a8671b1c6f343bc3a7a6335e63ced8f80e23be8145df845710c9e063b94feafc9fb23be325462654e1a16626d8383825af91ed79febe167
|
7
|
+
data.tar.gz: b04e946ccdf95b44a6f182519d5bc7ef5fe740e4148b92ba1e546ff9b3aadbe801aa06a4884c6ec7509e5468f90c0de2c759dcf3a9b0c9f6ac568693c919415b
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'timeout'
|
3
|
+
require 'equitrac_utilities/user_actions'
|
4
|
+
|
5
|
+
module EquitracUtilities
|
6
|
+
|
7
|
+
# The EquitracUtilities, makes it east to work with Equitac EQCmd.exe commands
|
8
|
+
# @since 0.1.0
|
9
|
+
#
|
10
|
+
# @note You should use environment variables to initialize your server.
|
11
|
+
class Connection
|
12
|
+
|
13
|
+
attr_reader :hostname, :username, :servicename, :eqcmd_path, :ssh_options
|
14
|
+
|
15
|
+
include EquitracUtilities::UserActions
|
16
|
+
|
17
|
+
# Make connection to the Equitrac server
|
18
|
+
# @note Hostname, Username and Servicename are required
|
19
|
+
# @param params [Hash] The server configuration parameters. Options available `:hostname`, `:username`, `:servicename`, `:eqcmd_path`, `:ssh_options`
|
20
|
+
def initialize(params={})
|
21
|
+
config = defaults.merge(params)
|
22
|
+
@hostname = config[:hostname]
|
23
|
+
@username = config[:username]
|
24
|
+
@servicename = config[:servicename]
|
25
|
+
@eqcmd_path = config[:eqcmd_path]
|
26
|
+
@ssh_options = config[:ssh_options]
|
27
|
+
|
28
|
+
raise ArgumentError, 'hostname missing' if hostname.nil? or hostname.empty?
|
29
|
+
raise ArgumentError, 'username missing' if username.nil? or username.empty?
|
30
|
+
raise ArgumentError, 'servicename missing' if servicename.nil? or servicename.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
# @note Run a command against the Equitrac server
|
34
|
+
#
|
35
|
+
# @param command [Symbol] choose command to perform these include: :user_query, :user_exists? (t/f), :user_add, :user_delete, :user_lock, :user_unlock, :user_modify
|
36
|
+
# @param attributes [Hash] attributes needed to perform command
|
37
|
+
# @return [String] the restult from the ssh command
|
38
|
+
def run(command:, attributes:)
|
39
|
+
unless attributes[:user_id].nil? or attributes[:user_id].empty? or attributes[:user_id].eql? ''
|
40
|
+
# Prep command
|
41
|
+
action = send(command, attributes)
|
42
|
+
ssh_cmd = build_full_command(action)
|
43
|
+
# Execute command
|
44
|
+
answer = send_eqcmd(ssh_cmd)
|
45
|
+
# Post processing answer
|
46
|
+
return post_processing(command, answer)
|
47
|
+
end
|
48
|
+
return "user_id missing -- #{attributes}"
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def build_full_command(action)
|
54
|
+
# sample:
|
55
|
+
"#{eqcmd_path} -s#{servicename} #{action}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def send_eqcmd(command)
|
59
|
+
output = nil
|
60
|
+
# quicker timeout config - https://gist.github.com/makaroni4/8792775
|
61
|
+
# Timeout::timeout(10) do
|
62
|
+
Net::SSH.start(hostname, username, ssh_options) do |ssh|
|
63
|
+
# Capture all stderr and stdout output from a remote process
|
64
|
+
output = ssh.exec!(command)
|
65
|
+
end
|
66
|
+
# end
|
67
|
+
# EQ56 returns unicode jibberish & looks like
|
68
|
+
# "C\u0000a\u0000n\u0000'\u0000t\u0000 \u0000f\u0000i\u0000n\u0000d"
|
69
|
+
convert_eq56_unicode_to_ascii(output)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Clean return from ssh execution
|
73
|
+
#
|
74
|
+
# @param string [String] the string that need to be clean
|
75
|
+
# @return [String] the clean string
|
76
|
+
def convert_eq56_unicode_to_ascii(string)
|
77
|
+
string.gsub("\u0000",'').gsub(/\\/,'')
|
78
|
+
end
|
79
|
+
|
80
|
+
def post_processing(command, answer)
|
81
|
+
return process_user_exists?(answer) if command.eql? :user_exists?
|
82
|
+
answer
|
83
|
+
end
|
84
|
+
|
85
|
+
def defaults
|
86
|
+
{ hostname: ENV['EQ_HOSTNAME'],
|
87
|
+
username: ENV['EQ_USERNAME'],
|
88
|
+
servicename: ENV['EQ_SERVICENAME'],
|
89
|
+
eqcmd_path: ( ENV['EQ_EQCMD_PATH'] || 'C:\Program Files\Equitrac\Express\Tools\EQCmd.exe' ),
|
90
|
+
ssh_options: (eval(ENV['EQ_SSH_OPTIONS'].to_s) || {}) }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module EquitracUtilities
|
2
|
+
|
3
|
+
# @note Equitrac Administration Guide - https://download.equitrac.com/271828/EE5.6/Docs/Administration_Guide.pdf
|
4
|
+
module UserActions
|
5
|
+
|
6
|
+
# Get Equitrac User Info
|
7
|
+
#
|
8
|
+
# @param attr [Hash] this attribute MUST include: { user_id: "userid" }
|
9
|
+
# @return [String] Formatted for EQCmd.exe command execution
|
10
|
+
def user_query(attr)
|
11
|
+
"query ur #{attr[:user_id]}"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Query to test if user exists in Equitrac System
|
15
|
+
# @note This required post-answer_post_processing
|
16
|
+
#
|
17
|
+
# @param attr [Hash] this attribute MUST include: { user_id: "userid" }
|
18
|
+
# @return [String] Formatted for EQCmd.exe command execution
|
19
|
+
def user_exists?(attr)
|
20
|
+
user_query(attr)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Process to test if user exists in Equitrac System
|
24
|
+
#
|
25
|
+
# @param test [Hash] this attribute MUST include: { user_id: "userid" }
|
26
|
+
# @return [Boolean] True or False depending on if the user was found or not
|
27
|
+
def process_user_exists?(test)
|
28
|
+
return false if test.include?("Can't find")
|
29
|
+
return true if test.include?("User_ID")
|
30
|
+
raise
|
31
|
+
end
|
32
|
+
|
33
|
+
# Add a user to the system
|
34
|
+
# @note user_id, initial_balance, user_name, department_name, and primary_pin required
|
35
|
+
#
|
36
|
+
# @param attributes [Hash] this attribute MUST include { user_id: "userid", init_bal: 0, username: "Test USER", dept_name: "Testdept", primary_pin: "99999"}
|
37
|
+
# @return [String] Formatted for EQCmd.exe command execution
|
38
|
+
def user_add(attributes)
|
39
|
+
defaults = { min_bal: 0.0, secondary_pin: '""',quota: 0,
|
40
|
+
alternate_pin: '""', home_server: '""', locked: 0,
|
41
|
+
location: '""', additional_info: 0, home_folder: '""'}
|
42
|
+
attr = defaults.merge( attributes )
|
43
|
+
|
44
|
+
"add ur #{attr[:user_id]} #{attr[:init_bal]} \"#{attr[:user_name]}\" " +
|
45
|
+
"#{attr[:min_bal]} #{attr[:email]} #{attr[:dept_name]}" +
|
46
|
+
" #{attr[:primary_pin]} #{attr[:secondary_pin]} #{attr[:quota]}" +
|
47
|
+
" #{attr[:alternate_pin]} #{attr[:home_server]} #{attr[:locked]}" +
|
48
|
+
" #{attr[:location]} #{attr[:additional_info]} #{attr[:home_folder]}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Process to delete a user from the Equitrac System
|
52
|
+
#
|
53
|
+
# @param attr [Hash] this attribute MUST include: { user_id: "userid" }
|
54
|
+
# @return [String] Formatted for EQCmd.exe command execution
|
55
|
+
def user_delete(attr)
|
56
|
+
"delete ur #{attr[:user_id]}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# Process to lock a user in the Equitrac System
|
60
|
+
#
|
61
|
+
# @param attr [Hash] this attribute MUST include: { user_id: "userid" }
|
62
|
+
# @return [String] Formatted for EQCmd.exe command execution
|
63
|
+
def user_lock(attr)
|
64
|
+
"lock ur #{attr[:user_id]}"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Process to unlock a user in the Equitrac System
|
68
|
+
#
|
69
|
+
# @param attr [Hash] this attribute MUST include: { user_id: "userid" }
|
70
|
+
# @return [String] Formatted for EQCmd.exe command execution
|
71
|
+
def user_unlock(attr)
|
72
|
+
"unlock ur #{attr[:user_id]}"
|
73
|
+
end
|
74
|
+
|
75
|
+
# Process to lock a user in the Equitrac System
|
76
|
+
#
|
77
|
+
# @param attr [Hash] this attribute MUST include: { user_id: "userid" }
|
78
|
+
# @return [String] Formatted for EQCmd.exe command execution
|
79
|
+
def user_modify(attributes)
|
80
|
+
defaults = {user_name: "!", min_bal: "!",
|
81
|
+
email: "!", dept_name: "!", pimary_pin: "!",
|
82
|
+
secondary_pin: "!", quota: "!", alternate_pin: "!",
|
83
|
+
home_server: "!", locked: "!", location: "!",
|
84
|
+
default_bc: "!", additional_info: "!", home_folder: "!"}
|
85
|
+
attr = defaults.merge( attributes )
|
86
|
+
"modify ur #{attr[:user_id]} \"#{attr[:user_name]}\" #{attr[:min_bal]}" +
|
87
|
+
" #{attr[:email]} #{attr[:dept_name]} #{attr[:primary_pin]}" +
|
88
|
+
" #{attr[:secondary_pin]} #{attr[:quota]} #{attr[:alternate_pin]}" +
|
89
|
+
" #{attr[:home_server]} #{attr[:locked]} #{attr[:location]}" +
|
90
|
+
" #{attr[:default_bc]} #{attr[:additional_info]} #{attr[:home_folder]}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: equitrac_utilities
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bill Tihen
|
8
|
+
- Lee Weisbecker
|
9
|
+
- Elliott Herbert
|
10
|
+
autorequire:
|
11
|
+
bindir: exe
|
12
|
+
cert_chain: []
|
13
|
+
date: 2018-05-25 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: net-ssh
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '4.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '4.0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: bundler
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.16'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.16'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '10.0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '10.0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '3.0'
|
71
|
+
description: uses ssh to connect to an Equitrac server and send user commands
|
72
|
+
email:
|
73
|
+
- btihen@gmail.com
|
74
|
+
- leeweisbecker@gmail.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- lib/equitrac_utilities.rb
|
80
|
+
- lib/equitrac_utilities/connection.rb
|
81
|
+
- lib/equitrac_utilities/user_actions.rb
|
82
|
+
- lib/equitrac_utilities/version.rb
|
83
|
+
homepage: https://github.com/LAS-IT/equitrac_utilities
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.7.6
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Simple ruby wrapper for equitrac user management
|
107
|
+
test_files: []
|