phoseum-cli 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 79b0cc59910f35dcbdd5a260cb32aae60678cc168e2adeb45a6ecee9f4cbd34a
4
+ data.tar.gz: 57538eade56ae69d9fe3e093032265914d557dbe9fd7fa0eac17af22e478e670
5
+ SHA512:
6
+ metadata.gz: 9e23015f5dbef4a6e07fef4ba1fb77fcd7b9431fa23349d592edd97b4eca56971b891a82623dc4fd56cc3771907e3f33becae531c1d23c1747add6ccc8e886a6
7
+ data.tar.gz: eb073ffac401ca46c43bf93166db6ae6f59d3c43508bf0bdbbd87636e432e4c948100cdc858c8ae24cd5285eeddb215b0752c1ef758f1560b7edb5e786d7c207
@@ -0,0 +1,412 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "phoseum/phoseum-common-lib"
4
+ $config = load_config('cli')
5
+ require "phoseum/phoseum-cli-lib"
6
+
7
+ load_gem('uri')
8
+ load_gem('json')
9
+ load_gem('date')
10
+ load_gem('nokogiri')
11
+ load_gem('mini_magick')
12
+
13
+ require 'optparse'
14
+ require 'net/https'
15
+ require 'io/console'
16
+
17
+ options = option_parser(ARGV)
18
+
19
+ BOUNDARY = "AaB03x"
20
+ $QUIET = options[:quiet] ? true : false
21
+ $DEBUG = options[:verbose] ? true : false
22
+
23
+ client_checks
24
+
25
+ def upload(album)
26
+
27
+ if $config['TOKEN']
28
+ headers={ "bearer" => "#{$config['TOKEN']}" }
29
+ else
30
+ if token = user_login()
31
+ headers = { "bearer" => token }
32
+ else
33
+ puts "Login Failed".red
34
+ exit 1
35
+ end
36
+ end
37
+
38
+ list=Dir.entries("./")
39
+ total_found = list.count
40
+ skipped=0
41
+ done_ok=0
42
+ loaded=0
43
+ error=0
44
+ warn=0
45
+ total_size=0
46
+ list.each do |filename|
47
+ if filename =~ /.*\.JPG|JPEG|PNG|GIF$/i
48
+ loaded += 1
49
+ print "(#{loaded}/#{total_found}): #{filename} : " if !$QUIET
50
+ begin
51
+ image = MiniMagick::Image.open(filename)
52
+ rescue
53
+ puts "Filename: #{filename} | Does not appear to be a valid file, skipping".red if !$QUIET
54
+ next
55
+ end
56
+
57
+ if image.size > 1000000
58
+ imgSZ = [((image.size / 1024) / 1024),"MB"].join(' ')
59
+ else
60
+ imgSZ = [(image.size / 1024),"KB"].join(' ')
61
+ end
62
+ total_size = (total_size + image.size)
63
+
64
+ uri = URI.parse($config['SERVERURL'])
65
+ post_body = []
66
+ post_body << "--#{BOUNDARY}\r\n"
67
+ post_body << "Content-Disposition: form-data; name=\"datafile\"; filename=\"#{File.basename(filename)}\"\r\n"
68
+ post_body << "Content-Type: #{image.mime_type}\r\n"
69
+ post_body << "\r\n"
70
+ post_body << File.read(filename)
71
+ post_body << "\r\n--#{BOUNDARY}--\r\n"
72
+ http = Net::HTTP.new(uri.host, uri.port)
73
+ headers = headers.merge({ "filename" => filename, "album" => "#{album}" })
74
+ request = Net::HTTP::Post.new(uri, headers)
75
+ request.body = post_body.join
76
+ request["Content-Type"] = "multipart/form-data, boundary=#{BOUNDARY}"
77
+ response = Net::HTTP.start(uri.hostname, $config['PORT'],
78
+ :timeout => $config['CALL_TIMEOUT'],
79
+ :use_ssl => uri.scheme == "https",
80
+ :verify_mode => OpenSSL::SSL::VERIFY_PEER,
81
+ :ca_file => $config['CA_TRUST']
82
+ ) do |http|
83
+ http.request(request)
84
+ end
85
+ print "Format: #{image.type} | Dim.: W = #{image.width} H = #{image.height} | Size: #{imgSZ} : ".yellow if !$QUIET
86
+
87
+
88
+ begin
89
+ msg_resp = JSON.parse(response.body)
90
+ if msg_resp['success']
91
+ puts "#{msg_resp['success']}".green
92
+ done_ok += 1
93
+ elsif msg_resp['warning']
94
+ puts "#{msg_resp['warning']}".yellow
95
+ warn += 1
96
+ else
97
+ puts "#{msg_resp['error']}".red
98
+ error += 1
99
+ end
100
+ rescue
101
+ puts "Error on Server".red if $DEBUG
102
+ puts Nokogiri::HTML(response.body).text
103
+ exit 1
104
+ end
105
+
106
+ else
107
+ skipped += 1
108
+ end
109
+ end
110
+ size_mb = ((total_size / 1024) / 1024)
111
+ puts "\nUpload report:\n\tRead:\t#{loaded}\n\tOK:\t#{done_ok}\n\tWarn:\t#{warn}\n\tError:\t#{error}\n\tSkip:\t#{skipped}\n\n\tSize Total: #{size_mb} MB" if !$QUIET
112
+ exit 0
113
+ end
114
+
115
+ def test
116
+ list=Dir.entries("./")
117
+ list.each do |filename|
118
+ if filename =~ /.*\.JPG|JPEG|PNG|GIF$/i
119
+ begin
120
+ image = MiniMagick::Image.open(filename)
121
+ rescue
122
+ puts "Filename: #{filename} | Does not appear to be a valid file, skipping".red if !$QUIET
123
+ next
124
+ end
125
+
126
+ if image.size > 1000000
127
+ imgSZ = [((image.size / 1024) / 1024),"MB"].join(' ')
128
+ else
129
+ imgSZ = [(image.size / 1024),"KB"].join(' ')
130
+ end
131
+
132
+ puts "Name: #{filename} | Format: #{image.type} | Dimension = #{image.dimensions} pxl | Size: #{imgSZ}".yellow if !$QUIET
133
+ if $DEBUG
134
+ puts JSON.pretty_generate(image.data)
135
+ end
136
+
137
+ end
138
+ end
139
+ exit 0
140
+ end
141
+
142
+ def health(what='',name='')
143
+ headers = {}
144
+ if $config['TOKEN']
145
+ headers={ "bearer" => "#{$config['TOKEN']}" }
146
+ else
147
+ if token = user_login()
148
+ headers = { "bearer" => token }
149
+ else
150
+ puts "Login Failed".red
151
+ exit 1
152
+ end
153
+ end
154
+ some_uri=''
155
+ if what == "album"
156
+ some_uri="?album=#{name}"
157
+ end
158
+ base = URI.parse("#{$config['SERVERURL']}#{some_uri}")
159
+ puts "Connecting to: #{$config['SERVERURL']}".yellow if !$QUIET
160
+ request = Net::HTTP::Get.new(base,headers)
161
+ response = Net::HTTP.start(base.hostname, $config['PORT'],
162
+ :timeout => $config['CALL_TIMEOUT'],
163
+ :use_ssl => base.scheme == "https",
164
+ :verify_mode => OpenSSL::SSL::VERIFY_PEER,
165
+ :ca_file => $config['CA_TRUST']
166
+ ) do |http|
167
+ http.request(request)
168
+ end
169
+ begin
170
+ list = JSON.parse(response.body)
171
+ # puts list
172
+ if list['error']
173
+ puts list['error'].red
174
+ exit 1
175
+ end
176
+ if list['success']
177
+ data=list['success']
178
+ end
179
+ rescue
180
+ puts "Error on Login".red if $DEBUG
181
+ puts Nokogiri::HTML(response.body).text
182
+ exit 1
183
+ end
184
+
185
+ if list['success']
186
+ data=list['success']
187
+
188
+ if data['Albums']
189
+ puts " >> Albums Available at this level (#{data['Albums'].count})".green if !$QUIET
190
+ data['Albums'].each do |album|
191
+ if $DEBUG
192
+ puts JSON.pretty_generate(album)
193
+ else
194
+ created = DateTime.strptime(album['created'],'%s')
195
+ puts "Name: #{album['name']} | Web Path: #{album['web_path']} | description: #{album['description']} | created: #{created} "
196
+ end
197
+ end
198
+ end
199
+
200
+ if data['Photos']
201
+ puts " >> Photos Available on this Album (#{data['Photos'].count})".green if !$QUIET
202
+ data['Photos'].each do |photo|
203
+ if $DEBUG
204
+ puts JSON.pretty_generate(photo)
205
+ else
206
+ added = DateTime.strptime(photo['added'],'%s')
207
+ puts "Name: #{photo['name']} | Filename: #{photo['image']} | Format: #{photo['full_info']['format']} | Dim.(WxH): #{photo['full_info']['geometry']['width']} x #{photo['full_info']['geometry']['height']} | Size: #{photo['size']} | Included: #{added}"
208
+ end
209
+ end
210
+ end
211
+
212
+ if !data['Albums'] && !data['Photos']
213
+ puts data
214
+ end
215
+
216
+ end
217
+ exit 0
218
+ end
219
+
220
+ def user_mgmt(action,user,pass='',role='')
221
+ post_body={}
222
+ if action == "add_user"
223
+ post_body=JSON.generate({"action" => "create-user", "user" => "#{user}", "password" => "#{pass}", "role" => "#{role}"})
224
+ end
225
+ base = URI.parse("#{$config['SERVERURL']}")
226
+ puts "\nConnecting to: #{$config['SERVERURL']}".yellow if !$QUIET
227
+ request = Net::HTTP::Post.new(base)
228
+ request.body = post_body
229
+ request.basic_auth("auth", $config['DEFAULT_SECRET'])
230
+ response = Net::HTTP.start(base.hostname, $config['PORT'],
231
+ :timeout => $config['CALL_TIMEOUT'],
232
+ :use_ssl => base.scheme == "https",
233
+ :verify_mode => OpenSSL::SSL::VERIFY_PEER,
234
+ :ca_file => $config['CA_TRUST']
235
+ ) do |http|
236
+ http.request(request)
237
+ end
238
+ begin
239
+ list = JSON.parse(response.body)
240
+ # puts list
241
+ if list['error']
242
+ puts list['error'].red
243
+ exit 1
244
+ end
245
+ if list['success']
246
+ data=list['success']
247
+ puts data
248
+ end
249
+ rescue
250
+ puts "Error on Login".red if $DEBUG
251
+ puts Nokogiri::HTML(response.body).text
252
+ end
253
+ exit 0
254
+ end
255
+
256
+ def user_login()
257
+ post_body={}
258
+ user=''
259
+ pass=''
260
+ if $config['USER']
261
+ user=$config['USER']
262
+ else
263
+ print "Username: "
264
+ user=STDIN.noecho(&:gets).chomp
265
+ end
266
+ if $config['PASS']
267
+ pass=$config['PASS']
268
+ puts "Keeping your password on the configuration file is UNSAFE".red
269
+ else
270
+ print "\nPassword: "
271
+ pass=STDIN.noecho(&:gets).chomp
272
+ end
273
+ post_body=JSON.generate({"action" => "user-login", "user" => "#{user}", "password" => "#{pass}"})
274
+ base = URI.parse("#{$config['SERVERURL']}")
275
+ puts "\nLogging to: #{$config['SERVERURL']}".yellow if !$QUIET
276
+ request = Net::HTTP::Post.new(base)
277
+ request.body = post_body
278
+ request.basic_auth("auth", $config['DEFAULT_SECRET'])
279
+ response = Net::HTTP.start(base.hostname, $config['PORT'],
280
+ :timeout => $config['CALL_TIMEOUT'],
281
+ :use_ssl => base.scheme == "https",
282
+ :verify_mode => OpenSSL::SSL::VERIFY_PEER,
283
+ :ca_file => $config['CA_TRUST']
284
+ ) do |http|
285
+ http.request(request)
286
+ end
287
+ begin
288
+ list = JSON.parse(response.body)
289
+ if list['error']
290
+ puts list['error'].red
291
+ return false
292
+ end
293
+ if list['success']
294
+ data=list['success']
295
+ puts data if !$QUIET
296
+ $config['TOKEN']=list['token']
297
+ home_cfg=File.expand_path('~/.phoseum/cli-config.yml')
298
+ file_to_write = home_cfg
299
+ File.open(file_to_write, 'w') do |f|
300
+ f.write(Psych.dump($config))
301
+ end
302
+ puts "Newly received token is: #{list['token']}" if $DEBUG
303
+ return list['token']
304
+ end
305
+ rescue
306
+ puts Nokogiri::HTML(response.body).text
307
+ return false
308
+ end
309
+ return false
310
+ end
311
+
312
+
313
+ def delete(what='',path='')
314
+ puts "You must write 'YES' to confirm, otherwise NO is assumed".yellow
315
+ print "Are you sure you want to delete the Album #{path} :[YES/NO]: "
316
+ confirm=STDIN.gets.chomp
317
+ if confirm == "YES"
318
+ headers={}
319
+ if $config['TOKEN']
320
+ headers={ "bearer" => "#{$config['TOKEN']}" }
321
+ else
322
+ if token = user_login()
323
+ headers = { "bearer" => token }
324
+ else
325
+ puts "Login Failed".red
326
+ exit 1
327
+ end
328
+ end
329
+
330
+ base = URI.parse("#{$config['SERVERURL']}/#{path}")
331
+ puts "Connecting to: #{$config['SERVERURL']}".yellow if !$QUIET
332
+ request = Net::HTTP::Delete.new(base,headers)
333
+ response = Net::HTTP.start(base.hostname, $config['PORT'],
334
+ :timeout => $config['CALL_TIMEOUT'],
335
+ :use_ssl => base.scheme == "https",
336
+ :verify_mode => OpenSSL::SSL::VERIFY_PEER,
337
+ :ca_file => $config['CA_TRUST']
338
+ ) do |http|
339
+ http.request(request)
340
+ end
341
+ list = JSON.parse(response.body)
342
+ puts list
343
+ else
344
+ puts "Deleting cancelled.".green
345
+ end
346
+ end
347
+
348
+ case options
349
+ when -> (c) { c[:check] }
350
+ puts "Checking API server availability".green if !$QUIET
351
+ if options[:album]
352
+ value=check_string_sanity(options[:album])
353
+ what='album'
354
+ end
355
+ health(what,value)
356
+ when -> (cre) { cre[:create_user] }
357
+ puts "Creating User".green if !$QUIET
358
+ if options[:create_user]
359
+ value=check_string_sanity(options[:create_user])
360
+ what='add_user'
361
+ if !options[:role]
362
+ puts "You need to select one of the valid Roles".red
363
+ exit 1
364
+ else
365
+ print "Please type the password twice for user #{value}.\n\tPassword: "
366
+ new_password=STDIN.noecho(&:gets).chomp
367
+ print "\n\tConfirm: "
368
+ confirm=STDIN.noecho(&:gets).chomp
369
+ if new_password == confirm
370
+ user_mgmt(what,value,new_password,options[:role])
371
+ end
372
+ end
373
+ end
374
+ when -> (d) { d[:delete] }
375
+ value=''
376
+ if options[:album]
377
+ value=check_string_sanity(options[:album])
378
+ what='album'
379
+ end
380
+ if value == "/" or value == '' or value.nil?
381
+ puts "It is Not possible to delete base album".red
382
+ exit 1
383
+ end
384
+ puts "Deleting Album #{value}".green if !$QUIET
385
+ delete(what,value)
386
+ when -> (u) { u[:upload] }
387
+ puts "Preparing to upload images to API server".green if !$QUIET
388
+ if !options.key?(:album)
389
+ puts "* I got no Album destination, please consider giving an album name or '/' to add on the base tree *".red
390
+ ARGV[0] = '--help'
391
+ option_parser(ARGV)
392
+ exit 1
393
+ else
394
+ album_clean=check_string_sanity(options[:album])
395
+ puts "Using Album destination: #{album_clean}".light_blue if !$QUIET
396
+ upload(album_clean)
397
+ end
398
+ when -> (l) { l[:login] }
399
+ puts "Start login process".green if !$QUIET
400
+ if user_login
401
+ puts "Login successful".green
402
+ else
403
+ puts "Login failed".red
404
+ end
405
+ when -> (t) { t[:test] }
406
+ puts "Making local analysis of files on directory".green if !$QUIET
407
+ test
408
+ else
409
+ ARGV[0] = '--help'
410
+ option_parser(ARGV)
411
+ exit 1
412
+ end
@@ -0,0 +1,125 @@
1
+
2
+ def option_parser(opts)
3
+ options = {}
4
+ OptionParser.new do |opts|
5
+ opts.banner = "Usage: phoseum-cli [options]\n\nRead about details on album names and types of images supported on official website:\nphoseum.org\n\n".green
6
+
7
+ opts.on("-a", "--album-path STRING", "Choose destination album. Use with: [update, delete, check]") do |a|
8
+ options[:album] = a
9
+ end
10
+
11
+ opts.on("-c", "--check", "Check against Phoseum API Server. Use with: [album-path, image, <alone>]") do |c|
12
+ options[:check] = c
13
+ end
14
+
15
+ opts.on("-C", "--create-user USERNAME", "Create user on the application") do |cre|
16
+ options[:create_user] = cre
17
+ end
18
+
19
+ opts.on("-d", "--delete", "Delete Album or Image. Use with: [album-path, image]") do |d|
20
+ options[:delete] = d
21
+ end
22
+
23
+ opts.on("-f", "--file-cfg FILENAME", "Use alternative configuration file") do |f|
24
+ options[:filecfg] = f
25
+ end
26
+
27
+ opts.on("-i", "--image FILENAME", "Manipulate one image. Use with: [check, upload, delete]") do |i|
28
+ options[:image] = i
29
+ end
30
+
31
+ opts.on("-l", "--login", "Make a login to save a new token") do |l|
32
+ options[:login] = l
33
+ end
34
+
35
+ opts.on("-v", "--verbose", "Run verbosely (DEBUG mode)") do |v|
36
+ options[:verbose] = v
37
+ end
38
+
39
+ opts.on("-r", "--role ROLE", "Role for user: [User, Super]. Use with 'create-user'") do |r|
40
+ options[:role] = r
41
+ end
42
+
43
+ opts.on("-q", "--quiet", "Avoid regular info, useful for JSON output") do |q|
44
+ options[:quiet] = q
45
+ end
46
+
47
+ opts.on("-t", "--test", "Test local files. Used to identify on local directory what will be uploaded.") do |t|
48
+ options[:test] = t
49
+ end
50
+
51
+ opts.on("-u", "--upload", "Upload files to Phoseum API Server. Use with: [album-path, image]") do |u|
52
+ options[:upload] = u
53
+ end
54
+
55
+ opts.on("-h", "-h", "That is this...") do |h|
56
+ options[:help] = h
57
+ end
58
+
59
+ end.parse!
60
+ return options
61
+ end
62
+
63
+ class String
64
+ # colorization
65
+ def colorize(color_code)
66
+ "\e[#{color_code}m#{self}\e[0m"
67
+ end
68
+
69
+ def red
70
+ colorize(31)
71
+ end
72
+
73
+ def green
74
+ colorize(32)
75
+ end
76
+
77
+ def yellow
78
+ colorize(33)
79
+ end
80
+
81
+ def blue
82
+ colorize(34)
83
+ end
84
+
85
+ def pink
86
+ colorize(35)
87
+ end
88
+
89
+ def light_blue
90
+ colorize(36)
91
+ end
92
+ end
93
+
94
+ def client_checks
95
+
96
+ if $config['SERVERURL'] == ''
97
+ puts "I could not find a valid SERVERURL configuration. CFG is empty.".red
98
+ exit 1
99
+ elsif $config['SERVERURL'] !~ /\A#{URI::regexp(['https'])}\z/
100
+ puts "I could not find a valid SERVERURL configuration. Contains: #{$config['SERVERURL']}".red
101
+ exit 1
102
+ end
103
+
104
+ if !$config['DEFAULT_SECRET']
105
+ puts "I could not find the DEFAULT_SECRET from Phoseum config, this will limit our actions.".red
106
+ exit 1
107
+ elsif $config['DEFAULT_SECRET'] == 'copy-secret-from-server'
108
+ puts "DEFAULT_SECRET from Phoseum config. Still on self generated value, copy a valid one from the server.".red
109
+ exit 1
110
+ elsif $config['DEFAULT_SECRET'] == ''
111
+ puts "I could not find the DEFAULT_SECRET from Phoseum config, Variable is empty.".red
112
+ exit 1
113
+ end
114
+
115
+ if !$config['SERVERURL']
116
+ puts "I could not find the SERVERURL from Phoseum config, this client is then useless.".red
117
+ exit 1
118
+ end
119
+
120
+ if !$config['PORT']
121
+ puts "I could not find the PORT from Phoseum config, this client is then useless.".red
122
+ exit 1
123
+ end
124
+
125
+ end
@@ -0,0 +1,166 @@
1
+ class String
2
+ def remove_non_ascii(replacement='')
3
+ n=self.split("")
4
+ self.slice!(0..self.size)
5
+ n.each { |b|
6
+ if b.ord < 48 || b.ord > 57 && b.ord < 65 || b.ord > 90 && b.ord < 97 || b.ord > 122 then
7
+ self.concat(replacement)
8
+ else
9
+ self.concat(b)
10
+ end
11
+ }
12
+ self.to_s
13
+ end
14
+
15
+ end
16
+
17
+ def check_string_sanity(album)
18
+ album.gsub!(/^\//,'')
19
+ album.gsub!(/^#{$config['ALBUM_URL']}/,'')
20
+ album.gsub!(/^\//,'')
21
+ folders=album.split("/")
22
+ r_folders=''
23
+ folders.each do |f|
24
+ r_folders= [r_folders,f.remove_non_ascii].join("/")
25
+ end
26
+ r_folders = r_folders.gsub!(/^\//,'')
27
+ return r_folders
28
+ end
29
+
30
+ def load_gem(gem_name)
31
+ found_gem = false
32
+ begin
33
+ found_gem = Gem::Specification.find_by_name(gem_name)
34
+ rescue Gem::LoadError
35
+ puts "Could not find gem '#{gem_name}'. Please run 'gem install #{gem_name}' as user #{ENV["USER"]}"
36
+ exit 1
37
+ else
38
+ require(gem_name)
39
+ end
40
+ end
41
+
42
+ CA_PHOSEUM = "-----BEGIN CERTIFICATE-----
43
+ MIID9zCCAt+gAwIBAgIJAMKPNoBSyDt9MA0GCSqGSIb3DQEBCwUAMIGRMQswCQYD
44
+ VQQGEwJOTDEVMBMGA1UECAwMWnVpZC1Ib2xsYW5kMSAwHgYDVQQKDBdTcGVjdHJv
45
+ TkVUIEhhY2tpbmcgQ29ycDEMMAoGA1UECwwDSUNUMRYwFAYDVQQDDA0qLnNjaWVu
46
+ Y2UubmV0MSMwIQYJKoZIhvcNAQkBFhRzcGVjdHJvbWFuQHlhaG9vLmNvbTAeFw0x
47
+ NTEwMDUxNDQ1MjJaFw00NTA5MjcxNDQ1MjJaMIGRMQswCQYDVQQGEwJOTDEVMBMG
48
+ A1UECAwMWnVpZC1Ib2xsYW5kMSAwHgYDVQQKDBdTcGVjdHJvTkVUIEhhY2tpbmcg
49
+ Q29ycDEMMAoGA1UECwwDSUNUMRYwFAYDVQQDDA0qLnNjaWVuY2UubmV0MSMwIQYJ
50
+ KoZIhvcNAQkBFhRzcGVjdHJvbWFuQHlhaG9vLmNvbTCCASIwDQYJKoZIhvcNAQEB
51
+ BQADggEPADCCAQoCggEBAJeWOJx0h1yzLdPx0tYv9IP2YtUzkGYonM5X8hEgOkRh
52
+ jxL+WwSWvaHjGUkvowzveh5gEeRAET+TkGslxG8yefaFJ9J2+0/83gqcd4A2iFpd
53
+ wp8aHqFs7Qg8Y4TIY8Ww1OTeXqqxuRnsn3oF5HS8U2W5atkd7kpdUOYPw8siSuQV
54
+ xVKoDQMVo6ZE+RPspRRuEwnyk3zQHnaEcgCGtssVFuvhsObCB55rWMafxP4UbGvX
55
+ WzqxmVcHDAgHXl/neAhg1EPhrRqYDf6pIo207eWvuqAVCtFQfXf4YtzuCml7GHrM
56
+ TGCRDf/g9KBdtvispd4VCVKEUFKx3okqQIzW3dsXPy0CAwEAAaNQME4wHQYDVR0O
57
+ BBYEFF6zq/J7W2EIi41YOsDoo/AmMVZYMB8GA1UdIwQYMBaAFF6zq/J7W2EIi41Y
58
+ OsDoo/AmMVZYMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBACgmgSHr
59
+ YffpiSMbZUzMtC8rcexeoMDw1X9UobdanPU0FBgYruj4yjdoEIsrlaXTgHf3PEki
60
+ NWShCsRCAOZIPQkEzwN/0wom+JhB6xbURPiwSrG6TEhz8YFBn94eiHz1OycHxpf6
61
+ QD85+tN847Q0V0KXmrwoQkIEVXT4of/NRhzHQlCkHuDoT5oQdkN7W3cZFqWkXGRM
62
+ t6fZ03zeXlSH5HLmysm2DU2uB182orzWYABdwLmINR44isw8/6RS1mx8BGI+08l8
63
+ sfxrWyWaDOPnwLWbFWTqnv94w4frHyHoRY+lBPZ4DT8MAFxYXI5Rf/hBUGav5NM4
64
+ yivphjaSSCTRqyE=
65
+ -----END CERTIFICATE-----"
66
+
67
+ def load_config(who)
68
+ load_gem('yaml')
69
+ if who == "api"
70
+ local_dir=Dir.pwd
71
+ home_cfg=File.expand_path("#{local_dir}/cfg")
72
+ file_to_load = [home_cfg,"phoseum-api-config.yml"].join('/')
73
+ if !Dir.exist?(home_cfg)
74
+ gen_config(who)
75
+ puts "New configuration was generated at #{file_to_load}. Please complete missing information and run again"
76
+ exit 1
77
+ end
78
+ if !File.file?(file_to_load)
79
+ puts "API CFG Not found: #{file_to_load} "
80
+ exit 1
81
+ end
82
+ elsif who == "cli"
83
+ home_cfg=File.expand_path('~/.phoseum/')
84
+ file_to_load = [home_cfg,"cli-config.yml"].join('/')
85
+ if !Dir.exist?(home_cfg)
86
+ gen_config(who)
87
+ puts "New configuration was generated at #{file_to_load}. Please complete missing information and run again"
88
+ exit 1
89
+ end
90
+ if !File.file?(file_to_load)
91
+ puts "CLI CFG Not found: #{file_to_load} "
92
+ exit 1
93
+ end
94
+ else
95
+ puts "Not sure which configuration to load. Abort."
96
+ exit 1
97
+ end
98
+
99
+ begin
100
+ config_data = YAML.load_file(file_to_load)
101
+ puts "Opening configuration from #{file_to_load}" if config_data['DEBUG']
102
+ rescue
103
+ puts "Failed loading configuration from #{file_to_load}"
104
+ exit 1
105
+ end
106
+ return config_data
107
+ end
108
+
109
+ def gen_config(who)
110
+
111
+ local_config={}
112
+ file_to_write=''
113
+
114
+ case who
115
+ when "cli"
116
+ local_config['SERVERURL']=""
117
+ local_config['DEBUG']=false
118
+ local_config['PORT']=2207
119
+ local_config['CALL_TIMEOUT']=120
120
+ local_config['DEFAULT_SECRET']="copy-secret-from-server"
121
+ local_config['TOKEN']="make-a-successful-login"
122
+
123
+ home_cfg=File.expand_path('~/.phoseum/')
124
+ local_config['CA_TRUST']=[home_cfg,"CA-PHOSEUM"].join('/')
125
+
126
+ if !Dir.exist?(home_cfg)
127
+ Dir.mkdir(home_cfg)
128
+ File.open("#{home_cfg}/CA-PHOSEUM", 'w') do |ca|
129
+ ca.write(CA_PHOSEUM)
130
+ end
131
+ end
132
+ file_to_write = [home_cfg,"cli-config.yml"].join('/')
133
+ puts "Creating config at #{file_to_write}"
134
+
135
+ when "api"
136
+ local_config['THREADED']=false
137
+ local_dir=Dir.pwd
138
+ local_config['BASEALBUM']="#{local_dir}/Albums"
139
+ local_config['ALBUM_URL']="Albums"
140
+ local_config['STORE_DIR']="#{local_dir}"
141
+ local_config['DEBUG']=true
142
+ local_config['PORT']=2207
143
+ local_config['EXT_URL']=""
144
+ local_config['MAX_IMG_SIZE']=50000000
145
+ local_config['RESIZE']="640x640"
146
+ local_config['RESAMPLE']="72x72"
147
+ local_config['CALL_TIMEOUT']=120
148
+ home_cfg="#{local_dir}/cfg"
149
+ if !Dir.exist?(home_cfg)
150
+ Dir.mkdir(home_cfg)
151
+ end
152
+ file_to_write = [home_cfg,"phoseum-api-config.yml"].join('/')
153
+ puts "Creating config at #{file_to_write}"
154
+
155
+ new_secret = SecureRandom.base64(32)
156
+ local_config['DEFAULT_SECRET'] = new_secret
157
+ puts "\nGenerating new secret: #{new_secret}"
158
+
159
+ end
160
+
161
+ File.open(file_to_write, 'w') do |f|
162
+ f.write(Psych.dump(local_config))
163
+ end
164
+ return true
165
+
166
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phoseum-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Julio C Hegedus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yaml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: uri
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.10'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.10.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.10'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.10.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: json
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.3'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.3'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.3.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: date
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '3.0'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 3.0.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: nokogiri
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.10'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.10.10
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.10'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.10.10
113
+ - !ruby/object:Gem::Dependency
114
+ name: mini_magick
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '4.10'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 4.10.1
123
+ type: :runtime
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '4.10'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 4.10.1
133
+ description: The client for use with Phoseum system
134
+ email: spectroman@yahoo.com
135
+ executables:
136
+ - phoseum-cli
137
+ extensions: []
138
+ extra_rdoc_files: []
139
+ files:
140
+ - bin/phoseum-cli
141
+ - lib/phoseum/phoseum-cli-lib.rb
142
+ - lib/phoseum/phoseum-common-lib.rb
143
+ homepage: https://phoseum.org
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
147
+ post_install_message: "**** Make sure to have ImageMagick installed on your system
148
+ \n**** Configurations pending:\n**** If phoseum-cli is not found to execute, you
149
+ may need to link to a visible path\n**** you can request to install 'gem install
150
+ --no-user-install phoseum-cli' or\n**** link i.e.: (ln -s /home/someuser/.gem/ruby/version/bin/phoseum-cli
151
+ /usr/local/bin)\n**** Run phoseum-cli for the first time to auto-generate configuration\n****
152
+ add on your configuration the DEFAULT_SECRET from your server\n**** see documentation
153
+ at https://phoseum.org"
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubygems_version: 3.1.4
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Client for Phoseum
172
+ test_files: []