-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute_users.rb
executable file
·94 lines (82 loc) · 2.87 KB
/
execute_users.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env ruby
require 'open3'
require 'optparse'
options = {}
parser = OptionParser.new do |opts|
opts.banner = "Usage: " + __FILE__ + " -e, --email <email> -p, --password <password> -f, --first-name <First Name> -l, --last-name <Last Name> -n, --notes <notes> -r, --roles <role list> -c, --cookie-file <cookie file> -i, --uri <fEMR URI>"
#Set option for username
opts.on("-e", "--email <email>", String, "User email") do |opt|
options[:email] = opt
end
#Set option for user password
opts.on("-p", "--password <pw>", String, "User password") do |opt|
options[:password] = opt
end
#choose destination to store cookies
opts.on("-f", "--first-name <First Name>", String, "User First name") do |opt|
options[:firstname] = opt
end
#choose fEMR URI to hit
opts.on("-l", "--last-name <Last Name>", String, "User Last name") do |opt|
options[:lastname] = opt
end
opts.on("-n", "--notes <notes>", String, "Any notes about the user") do |opt|
options[:notes] = opt
end
opts.on("-r", "--roles x,y,z", Array, "Comma separated list without spaces of roles") do |opt|
options[:roles] = opt
end
opts.on("-c", "--cookie-file <Cookie File>", String, "File that has tha cookie") do |opt|
options[:cookiefile] = opt
end
opts.on("-i", "--uri <fEMR URI>", String, "URI fEMR is running at") do |opt|
options[:uri] = opt
end
#Option for help
opts.on_tail('-h', '--help', 'Displays Help') do
print opts
exit
end
ARGV.push('-h') if ARGV.empty?
end
parser.parse!
#Only required fields on this form are email, password, and first name
if (options[:email].nil?)
raise OptionParser::MissingArgument, "No email provided"
end
if (options[:password].nil?)
raise OptionParser::MissingArgument, "No password provided"
end
if (options[:firstname].nil?)
raise OptionParser::MissingArgument, "Need a first name"
end
if (options[:roles].nil?)
raise OptionParser::MissingArgument, "Provide at least 1 role"
end
if (options[:cookiefile].nil?)
raise OptionParser::MissingArgument, "Gimme a cookie file to work with"
end
if (options[:uri].nil?)
raise OptionParser::MissingArgument, "NEED URI"
end
begin
#Get rid of the @ sign
options[:email].sub!('@','%40')
#Create curl string without the roles appended
cmd = "curl --data \"email=#{options[:email]}&password=#{options[:password]}&passwordVerify=#{options[:password]}&firstName=#{options[:firstname]}&lastName=#{options[:lastname]}¬es=#{options[:notes]}"
#Append the damn roles
options[:roles].each { |role| cmd << "&roles%5B%5D=#{role}" }
#Throw the final quote on the end
cmd << "\""
#Add the cookie file
cmd << " --cookie #{options[:cookiefile]}"
#Add the URI
cmd << " #{options[:uri]}/admin/users/create"
#puts cmd
#??
#profit
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
# puts "stdout is:" + stdout.read
# puts "stderr is:" + stderr.read
end
end