phoseum-cli 0.0.7 → 0.0.12
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/bin/phoseum-cli +117 -52
- data/lib/phoseum/phoseum-cli-lib.rb +106 -9
- 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: 7421fbbac2cf512f6be93770f895e789840cb887864d8b2d45839726cc65204f
|
4
|
+
data.tar.gz: f0fac7c15624a6652ec739c44e3af2fd6c64980da1cf5eceb41f188aa4734255
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0779e4712800a3a8312128db722b25b99a2084b1a7eb1faa1f609ba83b27d423dd3f7174f1f787618452ffbd0617f722c0db9758356fc94d4f1b7d3daaaf7d69'
|
7
|
+
data.tar.gz: b299ad615f973916909dcb52f7ef1e4dc9b52a5c6d80d773a2985db5400394036cc8e0802ccaffcc74d35f04eab139079ac9d89bc01b704bd826af80549d22a2
|
data/bin/phoseum-cli
CHANGED
@@ -24,16 +24,16 @@ $MULTI = options[:multiple] ? true : false
|
|
24
24
|
client_checks
|
25
25
|
|
26
26
|
def upload(album)
|
27
|
-
|
28
|
-
if $config['TOKEN']
|
29
|
-
headers={ "bearer" => "#{$config['TOKEN']}" }
|
30
|
-
else
|
27
|
+
headers = {}
|
28
|
+
if !validate_token($config['TOKEN'])
|
31
29
|
if token = user_login()
|
32
30
|
headers = { "bearer" => token }
|
33
31
|
else
|
34
32
|
puts "Login Failed".red
|
35
33
|
exit 1
|
36
34
|
end
|
35
|
+
else
|
36
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
37
37
|
end
|
38
38
|
|
39
39
|
list=Dir.entries("./")
|
@@ -65,7 +65,7 @@ def upload(album)
|
|
65
65
|
# last resort solution for accents and unrecognizable characters
|
66
66
|
# but then will need to remove extension, pass the filter, then add extension again.
|
67
67
|
# human_name = check_string_sanity(filename)
|
68
|
-
human_name = filename
|
68
|
+
human_name = filename.gsub!(/(.*)\.JPG|JPEG|PNG|GIF$/i,'\1')
|
69
69
|
|
70
70
|
somefound = search_image(image.signature)
|
71
71
|
if somefound
|
@@ -108,6 +108,7 @@ def upload(album)
|
|
108
108
|
else
|
109
109
|
puts "\n#{msg_resp['error']}".red
|
110
110
|
error += 1
|
111
|
+
break
|
111
112
|
end
|
112
113
|
rescue
|
113
114
|
puts "\nThe server sent out an Error:".red
|
@@ -153,15 +154,16 @@ end
|
|
153
154
|
|
154
155
|
def health(what='',name='')
|
155
156
|
headers = {}
|
156
|
-
|
157
|
-
|
158
|
-
else
|
157
|
+
|
158
|
+
if !validate_token($config['TOKEN']) || !$config['TOKEN']
|
159
159
|
if token = user_login()
|
160
160
|
headers = { "bearer" => token }
|
161
161
|
else
|
162
162
|
puts "Login Failed".red
|
163
163
|
exit 1
|
164
164
|
end
|
165
|
+
else
|
166
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
165
167
|
end
|
166
168
|
some_uri=''
|
167
169
|
if what == "album"
|
@@ -232,6 +234,10 @@ def user_mgmt(action,user,pass='',role='')
|
|
232
234
|
post_body={}
|
233
235
|
if action == "add_user"
|
234
236
|
post_body=JSON.generate({"action" => "create-user", "user" => "#{user}", "password" => "#{pass}", "role" => "#{role}"})
|
237
|
+
if !$config['DEFAULT_SECRET']
|
238
|
+
puts "You must have a DEFAULT_SECRET setting to be able to create a user".red
|
239
|
+
exit 1
|
240
|
+
end
|
235
241
|
end
|
236
242
|
base = URI.parse("#{$config['SERVERURL']}")
|
237
243
|
puts "\nConnecting to: #{$config['SERVERURL']}".yellow if !$QUIET
|
@@ -263,29 +269,28 @@ def user_mgmt(action,user,pass='',role='')
|
|
263
269
|
exit 0
|
264
270
|
end
|
265
271
|
|
266
|
-
def user_login()
|
272
|
+
def user_login(puser='',ppass='')
|
267
273
|
post_body={}
|
268
|
-
user=''
|
269
|
-
pass=''
|
274
|
+
user= !puser ? '' : puser
|
275
|
+
pass= !ppass ? '' : ppass
|
270
276
|
if $config['USER']
|
271
277
|
user=$config['USER']
|
272
278
|
else
|
273
279
|
print "Username: "
|
274
|
-
user=STDIN.
|
280
|
+
user=STDIN.gets.chomp
|
275
281
|
end
|
276
282
|
if $config['PASS']
|
277
283
|
pass=$config['PASS']
|
278
|
-
puts "
|
284
|
+
puts "\nKeeping your password on the configuration file is UNSAFE".red
|
279
285
|
else
|
280
|
-
|
281
|
-
pass=STDIN.noecho(&:gets).chomp
|
286
|
+
pass=STDIN.getpass('Password: ')
|
282
287
|
end
|
283
288
|
post_body=JSON.generate({"action" => "user-login", "user" => "#{user}", "password" => "#{pass}"})
|
284
289
|
base = URI.parse("#{$config['SERVERURL']}")
|
285
290
|
puts "\nLogging to: #{$config['SERVERURL']}".yellow if !$QUIET
|
286
291
|
request = Net::HTTP::Post.new(base)
|
287
292
|
request.body = post_body
|
288
|
-
request.basic_auth("
|
293
|
+
request.basic_auth("cli", "loginNOauth")
|
289
294
|
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
290
295
|
:timeout => $config['CALL_TIMEOUT'],
|
291
296
|
:use_ssl => base.scheme == "https",
|
@@ -322,37 +327,40 @@ end
|
|
322
327
|
|
323
328
|
|
324
329
|
def delete(what='',path='')
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
if confirm == "YES"
|
329
|
-
headers={}
|
330
|
-
if $config['TOKEN']
|
331
|
-
headers={ "bearer" => "#{$config['TOKEN']}" }
|
330
|
+
if !validate_token($config['TOKEN'])
|
331
|
+
if token = user_login()
|
332
|
+
headers = { "bearer" => token }
|
332
333
|
else
|
333
|
-
|
334
|
-
|
335
|
-
else
|
336
|
-
puts "Login Failed".red
|
337
|
-
exit 1
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
base = URI.parse("#{$config['SERVERURL']}/#{path}")
|
342
|
-
puts "Connecting to: #{$config['SERVERURL']}".yellow if !$QUIET
|
343
|
-
request = Net::HTTP::Delete.new(base,headers)
|
344
|
-
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
345
|
-
:timeout => $config['CALL_TIMEOUT'],
|
346
|
-
:use_ssl => base.scheme == "https",
|
347
|
-
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
348
|
-
:ca_file => $config['CA_TRUST']
|
349
|
-
) do |http|
|
350
|
-
http.request(request)
|
334
|
+
puts "Login Failed".red
|
335
|
+
exit 1
|
351
336
|
end
|
352
|
-
list = JSON.parse(response.body)
|
353
|
-
puts list
|
354
337
|
else
|
355
|
-
|
338
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
339
|
+
end
|
340
|
+
base = URI.parse("#{$config['SERVERURL']}/#{path}")
|
341
|
+
puts "Connecting to: #{$config['SERVERURL']}".yellow if !$QUIET
|
342
|
+
request = Net::HTTP::Delete.new(base,headers)
|
343
|
+
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
344
|
+
:timeout => $config['CALL_TIMEOUT'],
|
345
|
+
:use_ssl => base.scheme == "https",
|
346
|
+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
347
|
+
:ca_file => $config['CA_TRUST']
|
348
|
+
) do |http|
|
349
|
+
http.request(request)
|
350
|
+
end
|
351
|
+
begin
|
352
|
+
list = JSON.parse(response.body)
|
353
|
+
if list['error']
|
354
|
+
puts list['error'].red
|
355
|
+
exit 1
|
356
|
+
else
|
357
|
+
puts list['success'].green
|
358
|
+
exit 0
|
359
|
+
end
|
360
|
+
rescue
|
361
|
+
puts "\nThe server sent out an Error:".red
|
362
|
+
puts clean_html(response.body)
|
363
|
+
exit 1
|
356
364
|
end
|
357
365
|
end
|
358
366
|
|
@@ -373,10 +381,10 @@ case options
|
|
373
381
|
puts "You need to select one of the valid Roles".red
|
374
382
|
exit 1
|
375
383
|
else
|
376
|
-
print "Please type the password twice for user #{value}.\n\
|
377
|
-
new_password=STDIN.
|
378
|
-
print "\
|
379
|
-
confirm=STDIN.
|
384
|
+
print "Please type the password twice for user #{value}.\n\t"
|
385
|
+
new_password=STDIN.getpass('Password: ')
|
386
|
+
print "\t"
|
387
|
+
confirm=STDIN.getpass('Confirm: ')
|
380
388
|
if new_password == confirm
|
381
389
|
user_mgmt(what,value,new_password,options[:role])
|
382
390
|
end
|
@@ -387,13 +395,70 @@ case options
|
|
387
395
|
if options[:album]
|
388
396
|
value=check_string_sanity(options[:album])
|
389
397
|
what='album'
|
398
|
+
if value == "/" or value == '' or value.nil?
|
399
|
+
puts "It is Not possible to delete base album".red
|
400
|
+
exit 1
|
401
|
+
end
|
402
|
+
if !confirm_action("Are you sure you want to delete the #{what} #{value}")
|
403
|
+
puts "Deleting #{what} cancelled.".green
|
404
|
+
end
|
390
405
|
end
|
391
|
-
if
|
392
|
-
|
406
|
+
if options[:image]
|
407
|
+
if _found = check_image_exists(options[:image])
|
408
|
+
if _found =~ /^Signature Found at \[\"(.*)\"\]/
|
409
|
+
capt = _found.match(/^Signature Found at \[\"(.*)\"\]/).captures
|
410
|
+
capt_part = capt[0].match(/.*(Albums.*)$/).captures
|
411
|
+
value = capt_part[0]
|
412
|
+
else
|
413
|
+
img_data = JSON.parse(_found)
|
414
|
+
value="#{img_data['web_path']}/#{img_data['image']}"
|
415
|
+
end
|
416
|
+
what='image'
|
417
|
+
else
|
418
|
+
puts "Image not found on server".red
|
419
|
+
exit 1
|
420
|
+
end
|
421
|
+
if confirm_action("Are you sure you want to delete the #{what} #{value}")
|
422
|
+
puts "Deleting #{what} #{value}".green if !$QUIET
|
423
|
+
delete(what,value)
|
424
|
+
else
|
425
|
+
puts "Deleting #{what} cancelled.".green
|
426
|
+
end
|
427
|
+
end
|
428
|
+
if options[:user]
|
429
|
+
what='user'
|
430
|
+
value=options[:user]
|
431
|
+
if confirm_action("Are you sure you want to delete the #{what} #{value}")
|
432
|
+
puts "Deleting #{what} #{value}".green if !$QUIET
|
433
|
+
if delete_user(value)
|
434
|
+
puts "#{value} successfully deleted.".green
|
435
|
+
else
|
436
|
+
puts "#{value} failed to be deleted.".red
|
437
|
+
end
|
438
|
+
else
|
439
|
+
puts "Deleting #{what} cancelled.".green
|
440
|
+
end
|
441
|
+
end
|
442
|
+
if !what
|
443
|
+
puts "Got no object to delete. Exiting.".red
|
444
|
+
exit 1
|
445
|
+
end
|
446
|
+
when -> (o) { o[:options] }
|
447
|
+
if options[:user]
|
448
|
+
print "Please confirm #{options[:user]} password.\n\t"
|
449
|
+
current_password=STDIN.getpass('Password: ')
|
450
|
+
if token = user_login(options[:user],current_password)
|
451
|
+
print "\n Change [P]assword, [U]sername, [R]ole :[P/U/R]: "
|
452
|
+
confirm=STDIN.gets.chomp
|
453
|
+
else
|
454
|
+
puts "User Check Failed".red
|
455
|
+
exit 1
|
456
|
+
end
|
457
|
+
else
|
458
|
+
# if !what
|
459
|
+
puts "Got no user to work with. Exiting.".red
|
393
460
|
exit 1
|
394
461
|
end
|
395
|
-
puts "Deleting Album #{value}".green if !$QUIET
|
396
|
-
delete(what,value)
|
397
462
|
when -> (u) { u[:upload] }
|
398
463
|
puts "Preparing to upload images to API server".green if !$QUIET
|
399
464
|
if !options.key?(:album)
|
@@ -44,6 +44,10 @@ def option_parser(opts)
|
|
44
44
|
options[:role] = r
|
45
45
|
end
|
46
46
|
|
47
|
+
opts.on("-o", "--options", "Update options from object. Use with: [user]") do |o|
|
48
|
+
options[:options] = o
|
49
|
+
end
|
50
|
+
|
47
51
|
opts.on("-q", "--quiet", "Avoid regular info, useful for JSON output") do |q|
|
48
52
|
options[:quiet] = q
|
49
53
|
end
|
@@ -56,6 +60,10 @@ def option_parser(opts)
|
|
56
60
|
options[:upload] = u
|
57
61
|
end
|
58
62
|
|
63
|
+
opts.on("-U", "--User USERNAME", "Username for delete or change password / role. Use with: [delete, options]") do |usr|
|
64
|
+
options[:user] = usr
|
65
|
+
end
|
66
|
+
|
59
67
|
opts.on("-h", "-h", "That is this...") do |h|
|
60
68
|
options[:help] = h
|
61
69
|
end
|
@@ -64,6 +72,17 @@ def option_parser(opts)
|
|
64
72
|
return options
|
65
73
|
end
|
66
74
|
|
75
|
+
def confirm_action(msg)
|
76
|
+
puts "You must write 'YES' to confirm, otherwise NO is assumed".yellow
|
77
|
+
print "#{msg} :[YES/NO]: "
|
78
|
+
confirm=STDIN.gets.chomp
|
79
|
+
if confirm == "YES"
|
80
|
+
return true
|
81
|
+
else
|
82
|
+
return false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
67
86
|
class String
|
68
87
|
# colorization
|
69
88
|
def colorize(color_code)
|
@@ -96,15 +115,13 @@ class String
|
|
96
115
|
end
|
97
116
|
|
98
117
|
def client_checks
|
99
|
-
|
100
118
|
if $config['SERVERURL'] == ''
|
101
|
-
|
102
|
-
|
119
|
+
puts "I could not find a valid SERVERURL configuration. CFG is empty.".red
|
120
|
+
exit 1
|
103
121
|
elsif $config['SERVERURL'] !~ /\A#{URI::regexp(['https', 'http'])}\z/
|
104
122
|
puts "I could not find a valid SERVERURL configuration. Contains: #{$config['SERVERURL']}".red
|
105
123
|
exit 1
|
106
124
|
end
|
107
|
-
|
108
125
|
if !$config['DEFAULT_SECRET']
|
109
126
|
puts "I could not find the DEFAULT_SECRET from Phoseum config, this will limit our actions.".red
|
110
127
|
exit 1
|
@@ -132,19 +149,32 @@ def clean_html(msg)
|
|
132
149
|
return msg
|
133
150
|
end
|
134
151
|
|
135
|
-
def
|
136
|
-
|
137
|
-
|
138
|
-
|
152
|
+
def check_image_exists(fpath)
|
153
|
+
flocal = fpath.split('/')
|
154
|
+
filename = flocal.last
|
155
|
+
album = fpath.clone
|
156
|
+
album.gsub!(/#{filename}/,'')
|
157
|
+
|
158
|
+
if ffile = search_image(filename,album)
|
159
|
+
return ffile
|
139
160
|
else
|
161
|
+
return false
|
162
|
+
end
|
163
|
+
exit 0
|
164
|
+
end
|
165
|
+
|
166
|
+
def search_image(sign,album='')
|
167
|
+
if !validate_token($config['TOKEN'])
|
140
168
|
if token = user_login()
|
141
169
|
headers = { "bearer" => token }
|
142
170
|
else
|
143
171
|
puts "Login Failed".red
|
144
172
|
exit 1
|
145
173
|
end
|
174
|
+
else
|
175
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
146
176
|
end
|
147
|
-
some_uri="?signature=#{sign}"
|
177
|
+
some_uri= album == '' ? "?signature=#{sign}" : "?signature=#{sign}&inside_album=#{album}"
|
148
178
|
base = URI.parse("#{$config['SERVERURL']}#{some_uri}")
|
149
179
|
request = Net::HTTP::Get.new(base,headers)
|
150
180
|
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
@@ -158,6 +188,7 @@ def search_image(sign)
|
|
158
188
|
begin
|
159
189
|
list = JSON.parse(response.body)
|
160
190
|
if list['warning']
|
191
|
+
# puts list['warning']
|
161
192
|
return list['warning']
|
162
193
|
end
|
163
194
|
if list['success']
|
@@ -169,3 +200,69 @@ def search_image(sign)
|
|
169
200
|
exit 1
|
170
201
|
end
|
171
202
|
end
|
203
|
+
|
204
|
+
def validate_token(token)
|
205
|
+
headers = {}
|
206
|
+
if $config['TOKEN']
|
207
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
208
|
+
else
|
209
|
+
return false
|
210
|
+
end
|
211
|
+
base = URI.parse("#{$config['SERVERURL']}")
|
212
|
+
request = Net::HTTP::Post.new(base,headers)
|
213
|
+
request.body = JSON.generate({"action" => "check-token" })
|
214
|
+
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
215
|
+
:timeout => $config['CALL_TIMEOUT'],
|
216
|
+
:use_ssl => base.scheme == "https",
|
217
|
+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
218
|
+
:ca_file => $config['CA_TRUST']
|
219
|
+
) do |http|
|
220
|
+
http.request(request)
|
221
|
+
end
|
222
|
+
begin
|
223
|
+
list = JSON.parse(response.body)
|
224
|
+
if list['error']
|
225
|
+
return false
|
226
|
+
end
|
227
|
+
if list['success']
|
228
|
+
return true
|
229
|
+
end
|
230
|
+
rescue
|
231
|
+
puts "\nThe server sent out an Error:".red
|
232
|
+
puts clean_html(response.body)
|
233
|
+
exit 1
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def delete_user(username)
|
238
|
+
headers = {}
|
239
|
+
if $config['TOKEN']
|
240
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
241
|
+
else
|
242
|
+
return false
|
243
|
+
end
|
244
|
+
base = URI.parse("#{$config['SERVERURL']}")
|
245
|
+
request = Net::HTTP::Post.new(base,headers)
|
246
|
+
request.body = JSON.generate({"action" => "delete-user", "username" => username })
|
247
|
+
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
248
|
+
:timeout => $config['CALL_TIMEOUT'],
|
249
|
+
:use_ssl => base.scheme == "https",
|
250
|
+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
251
|
+
:ca_file => $config['CA_TRUST']
|
252
|
+
) do |http|
|
253
|
+
http.request(request)
|
254
|
+
end
|
255
|
+
begin
|
256
|
+
list = JSON.parse(response.body)
|
257
|
+
if list['error']
|
258
|
+
return false
|
259
|
+
end
|
260
|
+
if list['success']
|
261
|
+
return true
|
262
|
+
end
|
263
|
+
rescue
|
264
|
+
puts "\nThe server sent out an Error:".red
|
265
|
+
puts clean_html(response.body)
|
266
|
+
exit 1
|
267
|
+
end
|
268
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phoseum-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julio C Hegedus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|