phoseum-cli 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/phoseum-cli +123 -19
- data/lib/phoseum/phoseum-cli-lib.rb +102 -101
- data/lib/phoseum/phoseum-common-lib.rb +45 -11
- 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: bfc9c3e5f01d6ea982796a580be0195b76156127ab1b39c3c1bfdb0d1ada4f21
|
4
|
+
data.tar.gz: eb9e11b414ee5be39678593668f2fa8f02477e61b1cdbd85a0d69fbdf8728d6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c433b128e7140e01364e04309bec935cf66efcfebe785ffbe7f4cefbf0dcdf007cb2f8f7f6398eb7fcae87c751fb7f4213110422b03d621120c991369277d8a6
|
7
|
+
data.tar.gz: 1435d44fa6d8599e5ba9492fbce3bb5e30dba57e24c225f7ed6cbfd87ae56f7f3cca5820e9c94a7d259ca652e8875ec5ea503ebb1839969561cf99c5c5f28b7c
|
data/bin/phoseum-cli
CHANGED
@@ -391,6 +391,7 @@ case options
|
|
391
391
|
puts "Creating User".green if !$QUIET
|
392
392
|
if options[:create_user]
|
393
393
|
value=check_string_sanity(options[:create_user])
|
394
|
+
username_sanity(value)
|
394
395
|
what='add_user'
|
395
396
|
if !options[:role]
|
396
397
|
puts "You need to select one of the valid Roles".red
|
@@ -401,6 +402,7 @@ case options
|
|
401
402
|
print "\t"
|
402
403
|
confirm=STDIN.getpass('Confirm: ')
|
403
404
|
if new_password == confirm
|
405
|
+
password_sanity(new_password)
|
404
406
|
user_mgmt(what,value,new_password,options[:role])
|
405
407
|
end
|
406
408
|
end
|
@@ -443,15 +445,24 @@ case options
|
|
443
445
|
if options[:user]
|
444
446
|
what='user'
|
445
447
|
value=options[:user]
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
448
|
+
secretinfo = api_caller({"action" => "check-secret"},true)
|
449
|
+
if secretinfo['error']
|
450
|
+
err_msg = JSON.parse(secretinfo)
|
451
|
+
puts err_msg['error'].red
|
452
|
+
puts "You cannot delete users if you don't have the Server Secret."
|
453
|
+
exit 1
|
454
|
+
end
|
455
|
+
if secretinfo['success']
|
456
|
+
if confirm_action("Are you sure you want to delete the #{what} #{value}")
|
457
|
+
puts "Deleting #{what} #{value}".green if !$QUIET
|
458
|
+
if delete_user(value)
|
459
|
+
puts "#{value} successfully deleted.".green
|
460
|
+
else
|
461
|
+
puts "#{value} failed to be deleted.".red
|
462
|
+
end
|
450
463
|
else
|
451
|
-
puts "#{
|
464
|
+
puts "Deleting #{what} cancelled.".green
|
452
465
|
end
|
453
|
-
else
|
454
|
-
puts "Deleting #{what} cancelled.".green
|
455
466
|
end
|
456
467
|
end
|
457
468
|
if !what
|
@@ -460,25 +471,117 @@ case options
|
|
460
471
|
end
|
461
472
|
when -> (o) { o[:options] }
|
462
473
|
if options[:user]
|
474
|
+
user_work=check_string_sanity(options[:user])
|
463
475
|
tokeninfo = api_caller({"action" => "token-payload", "token" => "#{$config['TOKEN']}"})
|
464
476
|
if tokeninfo['error']
|
465
|
-
puts "Your token seems invalid, please login again".red
|
477
|
+
puts "Your token seems invalid, please login again (-l or -c)".red
|
466
478
|
exit 1
|
467
479
|
end
|
480
|
+
auth_user = ''
|
481
|
+
role_user = ''
|
468
482
|
if tokeninfo['success']
|
469
|
-
|
483
|
+
payload = tokeninfo['payload']
|
484
|
+
tkdata = JSON.parse(payload)
|
485
|
+
auth_user = tkdata[0]['data']['user'].clone
|
486
|
+
role_user = tkdata[0]['data']['role'].clone
|
487
|
+
puts "Current user is #{auth_user}".green
|
488
|
+
end
|
489
|
+
|
490
|
+
secretinfo = api_caller({"action" => "check-secret"},true)
|
491
|
+
if secretinfo['error']
|
492
|
+
err_msg = JSON.parse(secretinfo)
|
493
|
+
puts err_msg['error'].red
|
494
|
+
puts "You will only be able to change your own password."
|
495
|
+
if user_work != auth_user
|
496
|
+
puts "Requesting other user than your own at command line is wrong, aborting. (#{user_work} is not #{auth_user})".red
|
497
|
+
exit 1
|
498
|
+
end
|
499
|
+
end
|
500
|
+
if secretinfo['success']
|
501
|
+
puts secretinfo['success'].green
|
502
|
+
if role_user == "Super"
|
503
|
+
puts "You will be able to change any user on the system".green
|
504
|
+
else
|
505
|
+
if user_work != auth_user
|
506
|
+
puts "Having a regular user will now allow to change other users's options".yellow
|
507
|
+
puts "Requesting other user than your own at command line is wrong, aborting. (#{user_work} is not #{auth_user})".red
|
508
|
+
exit 1
|
509
|
+
end
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
if user_work == auth_user
|
514
|
+
print "Please type new password for user #{user_work} .\n\t"
|
515
|
+
new_password=STDIN.getpass('Password: ')
|
516
|
+
print "\t"
|
517
|
+
check_password=STDIN.getpass('Confirm: ')
|
518
|
+
if new_password != check_password
|
519
|
+
puts "Passwords won't match, try again.".red
|
520
|
+
exit 1
|
521
|
+
end
|
522
|
+
if change_user_password(auth_user,check_password)
|
523
|
+
puts "Password changed successfully".green
|
524
|
+
exit 0
|
525
|
+
else
|
526
|
+
puts "Could not change user password.".red
|
527
|
+
exit 1
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
if user_work != auth_user && secretinfo['success']
|
532
|
+
print "\n Change [P]assword, [U]sername, [R]ole from user #{user_work} :[P/U/R]: "
|
533
|
+
opt_action=STDIN.gets.chomp
|
534
|
+
if opt_action == "P"
|
535
|
+
print "Please type new password for user #{user_work} .\n\t"
|
536
|
+
new_password=STDIN.getpass('Password: ')
|
537
|
+
puts "testing #{new_password}"
|
538
|
+
print "\t"
|
539
|
+
check_password=STDIN.getpass('Confirm: ')
|
540
|
+
if new_password != check_password
|
541
|
+
puts "Passwords won't match, try again.".red
|
542
|
+
exit 1
|
543
|
+
end
|
544
|
+
password_sanity(new_password)
|
545
|
+
if change_user_password(options[:user],check_password,true)
|
546
|
+
puts "Password changed successfully".green
|
547
|
+
exit 0
|
548
|
+
else
|
549
|
+
puts "Could not change user password.".red
|
550
|
+
exit 1
|
551
|
+
end
|
552
|
+
end
|
553
|
+
if opt_action == "U"
|
554
|
+
print "\tPlease type new username for user #{user_work} : "
|
555
|
+
new_user_proto=STDIN.gets.chomp
|
556
|
+
new_user=check_string_sanity(new_user_proto)
|
557
|
+
username_sanity(new_user)
|
558
|
+
if change_username(user_work,new_user)
|
559
|
+
puts "Username changed successfully".green
|
560
|
+
exit 0
|
561
|
+
else
|
562
|
+
puts "Could not change username.".red
|
563
|
+
exit 1
|
564
|
+
end
|
565
|
+
end
|
566
|
+
if opt_action == "R"
|
567
|
+
print " Please select between roles [S]uper,[U]ser for user #{user_work} :[S/U]: "
|
568
|
+
new_role=STDIN.gets.chomp
|
569
|
+
if new_role == "S" || new_role == "U"
|
570
|
+
role_nominal = new_role == "S" ? "Super" : "User"
|
571
|
+
if change_role(user_work,role_nominal)
|
572
|
+
puts "Username changed successfully".green
|
573
|
+
exit 0
|
574
|
+
else
|
575
|
+
puts "Could not change username.".red
|
576
|
+
exit 1
|
577
|
+
end
|
578
|
+
else
|
579
|
+
puts "Unknown option: #{new_role} .".red
|
580
|
+
exit 1
|
581
|
+
end
|
582
|
+
end
|
470
583
|
end
|
471
|
-
# print "Please confirm #{options[:user]} password.\n\t"
|
472
|
-
# current_password=STDIN.getpass('Password: ')
|
473
|
-
# if token = user_login(options[:user],current_password)
|
474
|
-
# print "\n Change [P]assword, [U]sername, [R]ole :[P/U/R]: "
|
475
|
-
# confirm=STDIN.gets.chomp
|
476
|
-
# else
|
477
|
-
# puts "User Check Failed".red
|
478
|
-
# exit 1
|
479
|
-
# end
|
480
584
|
else
|
481
|
-
# if !what
|
482
585
|
puts "Got no user to work with. Exiting.".red
|
483
586
|
exit 1
|
484
587
|
end
|
@@ -533,6 +636,7 @@ case options
|
|
533
636
|
test
|
534
637
|
else
|
535
638
|
ARGV[0] = '--help'
|
639
|
+
local_version
|
536
640
|
option_parser(ARGV)
|
537
641
|
exit 1
|
538
642
|
end
|
@@ -1,4 +1,12 @@
|
|
1
1
|
|
2
|
+
# Provide some help and options!
|
3
|
+
#
|
4
|
+
# Example:
|
5
|
+
# >> options = option_parser(ARGV)
|
6
|
+
# => puts options[:option]
|
7
|
+
#
|
8
|
+
# Arguments:
|
9
|
+
# ARGV: (Array or command line parameters)
|
2
10
|
def option_parser(opts)
|
3
11
|
options = {}
|
4
12
|
OptionParser.new do |opts|
|
@@ -60,7 +68,7 @@ def option_parser(opts)
|
|
60
68
|
options[:role] = r
|
61
69
|
end
|
62
70
|
|
63
|
-
opts.on("-o", "--options", "Update options from
|
71
|
+
opts.on("-o", "--options", "Update options from User. Use with: [user]") do |o|
|
64
72
|
options[:options] = o
|
65
73
|
end
|
66
74
|
|
@@ -88,6 +96,15 @@ def option_parser(opts)
|
|
88
96
|
return options
|
89
97
|
end
|
90
98
|
|
99
|
+
# Give yes/no prompt!
|
100
|
+
#
|
101
|
+
# Example:
|
102
|
+
# >> confirm_action("message")
|
103
|
+
# => You must write 'YES' to confirm, otherwise NO is assumed
|
104
|
+
# => message :[YES/NO]:
|
105
|
+
#
|
106
|
+
# Arguments:
|
107
|
+
# msg: (String)
|
91
108
|
def confirm_action(msg)
|
92
109
|
puts "You must write 'YES' to confirm, otherwise NO is assumed".yellow
|
93
110
|
print "#{msg} :[YES/NO]: "
|
@@ -138,16 +155,6 @@ def client_checks
|
|
138
155
|
puts "I could not find a valid SERVERURL configuration. Contains: #{$config['SERVERURL']}".red
|
139
156
|
exit 1
|
140
157
|
end
|
141
|
-
if !$config['DEFAULT_SECRET']
|
142
|
-
puts "I could not find the DEFAULT_SECRET from Phoseum config, this will limit our actions.".red
|
143
|
-
exit 1
|
144
|
-
elsif $config['DEFAULT_SECRET'] == 'copy-secret-from-server'
|
145
|
-
puts "DEFAULT_SECRET from Phoseum config. Still on self generated value, copy a valid one from the server.".red
|
146
|
-
exit 1
|
147
|
-
elsif $config['DEFAULT_SECRET'] == ''
|
148
|
-
puts "I could not find the DEFAULT_SECRET from Phoseum config, Variable is empty.".red
|
149
|
-
exit 1
|
150
|
-
end
|
151
158
|
if !$config['SERVERURL']
|
152
159
|
puts "I could not find the SERVERURL from Phoseum config, this client is then useless.".red
|
153
160
|
exit 1
|
@@ -228,16 +235,31 @@ def search_image(sign,album='')
|
|
228
235
|
end
|
229
236
|
end
|
230
237
|
|
231
|
-
def
|
238
|
+
def api_caller(json_body,auth=false,cli=false)
|
232
239
|
headers = {}
|
233
|
-
if
|
234
|
-
|
235
|
-
|
236
|
-
|
240
|
+
if !auth
|
241
|
+
if $config['TOKEN']
|
242
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
243
|
+
else
|
244
|
+
return false
|
245
|
+
end
|
237
246
|
end
|
238
247
|
base = URI.parse("#{$config['SERVERURL']}")
|
239
248
|
request = Net::HTTP::Post.new(base,headers)
|
240
|
-
request.body = JSON.generate(
|
249
|
+
request.body = JSON.generate(json_body)
|
250
|
+
|
251
|
+
if auth
|
252
|
+
if cli
|
253
|
+
request.basic_auth("cli", "loginNOauth")
|
254
|
+
else
|
255
|
+
request.basic_auth("auth", $config['DEFAULT_SECRET'])
|
256
|
+
end
|
257
|
+
else
|
258
|
+
if cli
|
259
|
+
request.basic_auth("cli", "loginNOauth")
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
241
263
|
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
242
264
|
:timeout => $config['CALL_TIMEOUT'],
|
243
265
|
:use_ssl => base.scheme == "https",
|
@@ -248,108 +270,87 @@ def validate_token(token)
|
|
248
270
|
end
|
249
271
|
begin
|
250
272
|
list = JSON.parse(response.body)
|
251
|
-
|
252
|
-
return false
|
253
|
-
end
|
254
|
-
if list['success']
|
255
|
-
return true
|
256
|
-
end
|
273
|
+
return list
|
257
274
|
rescue
|
258
|
-
|
259
|
-
|
260
|
-
|
275
|
+
if !auth
|
276
|
+
puts "\nThe server sent out an Error:".red
|
277
|
+
puts clean_html(response.body)
|
278
|
+
exit 1
|
279
|
+
else
|
280
|
+
return '{"error": "Secret is invalid"}'
|
281
|
+
end
|
261
282
|
end
|
262
283
|
end
|
263
284
|
|
264
|
-
def
|
265
|
-
|
266
|
-
if
|
267
|
-
headers={ "bearer" => "#{$config['TOKEN']}" }
|
268
|
-
else
|
285
|
+
def validate_token(token)
|
286
|
+
result = api_caller({"action" => "check-token" })
|
287
|
+
if result['error']
|
269
288
|
return false
|
270
289
|
end
|
271
|
-
|
272
|
-
|
273
|
-
request.body = JSON.generate(json_body)
|
274
|
-
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
275
|
-
:timeout => $config['CALL_TIMEOUT'],
|
276
|
-
:use_ssl => base.scheme == "https",
|
277
|
-
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
278
|
-
:ca_file => $config['CA_TRUST']
|
279
|
-
) do |http|
|
280
|
-
http.request(request)
|
290
|
+
if result['success']
|
291
|
+
return true
|
281
292
|
end
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
293
|
+
end
|
294
|
+
|
295
|
+
def change_user_password(user,pass,auth=false)
|
296
|
+
result = api_caller({"action" => "change-password", "username" => user, "password" => pass},auth)
|
297
|
+
if result['error']
|
298
|
+
return false
|
299
|
+
end
|
300
|
+
if result['success']
|
301
|
+
return true
|
289
302
|
end
|
290
303
|
end
|
291
304
|
|
305
|
+
def change_username(user,new_user)
|
306
|
+
result = api_caller({"action" => "change-username", "username" => user, "new-username" => new_user},true)
|
307
|
+
if result['error']
|
308
|
+
return false
|
309
|
+
end
|
310
|
+
if result['success']
|
311
|
+
return true
|
312
|
+
end
|
313
|
+
end
|
292
314
|
|
293
|
-
def
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
request.basic_auth("cli", "loginNOauth")
|
298
|
-
request.body = JSON.generate({"action" => "version-check" })
|
299
|
-
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
300
|
-
:timeout => $config['CALL_TIMEOUT'],
|
301
|
-
:use_ssl => base.scheme == "https",
|
302
|
-
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
303
|
-
:ca_file => $config['CA_TRUST']
|
304
|
-
) do |http|
|
305
|
-
http.request(request)
|
315
|
+
def change_role(user,new_role)
|
316
|
+
result = api_caller({"action" => "change-role", "username" => user, "new-role" => new_role},true)
|
317
|
+
if result['error']
|
318
|
+
return false
|
306
319
|
end
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
#
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
puts
|
320
|
+
if result['success']
|
321
|
+
return true
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
def password_sanity(password)
|
326
|
+
if password.length < MIN_PASS
|
327
|
+
puts "New password is shorter than #{MIN_PASS} chars, please use a bigger password.".red
|
328
|
+
exit 1
|
329
|
+
end
|
330
|
+
if !password.test_password
|
331
|
+
puts "Password must be at least #{MIN_PASS} and contain at least one capital, one symbol, one number, one regular characters.".red
|
332
|
+
exit 1
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
def username_sanity(username)
|
337
|
+
if new_user.length < MIN_USER
|
338
|
+
puts "New Username is shorter than #{MIN_USER} chars, please use a bigger username.".red
|
319
339
|
exit 1
|
320
340
|
end
|
321
341
|
end
|
322
342
|
|
343
|
+
def cross_versions
|
344
|
+
return api_caller({"action" => "version-check" },true,true)
|
345
|
+
end
|
346
|
+
|
323
347
|
def delete_user(username)
|
324
|
-
|
325
|
-
if
|
326
|
-
headers={ "bearer" => "#{$config['TOKEN']}" }
|
327
|
-
else
|
348
|
+
result = api_caller({"action" => "delete-user", "username" => username},true)
|
349
|
+
if result['error']
|
328
350
|
return false
|
329
351
|
end
|
330
|
-
|
331
|
-
|
332
|
-
request.body = JSON.generate({"action" => "delete-user", "username" => username })
|
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
|
-
begin
|
342
|
-
list = JSON.parse(response.body)
|
343
|
-
if list['error']
|
344
|
-
return false
|
345
|
-
end
|
346
|
-
if list['success']
|
347
|
-
return true
|
348
|
-
end
|
349
|
-
rescue
|
350
|
-
puts "\nThe server sent out an Error:".red
|
351
|
-
puts clean_html(response.body)
|
352
|
-
exit 1
|
352
|
+
if result['success']
|
353
|
+
return true
|
353
354
|
end
|
354
355
|
end
|
355
356
|
|
@@ -358,4 +359,4 @@ def local_version
|
|
358
359
|
return
|
359
360
|
end
|
360
361
|
|
361
|
-
VERSION_SIGN="0.0.
|
362
|
+
VERSION_SIGN="0.0.20"
|
@@ -1,17 +1,51 @@
|
|
1
|
+
MIN_USER = 3
|
2
|
+
MIN_PASS = 7
|
3
|
+
|
1
4
|
class String
|
2
5
|
def remove_non_ascii(replacement='')
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
n=self.split("")
|
7
|
+
self.slice!(0..self.size)
|
8
|
+
n.each { |b|
|
9
|
+
if b.ord < 48 || b.ord > 57 && b.ord < 65 || b.ord > 90 && b.ord < 97 || b.ord > 122 then
|
10
|
+
self.concat(replacement)
|
11
|
+
else
|
12
|
+
self.concat(b)
|
13
|
+
end
|
14
|
+
}
|
15
|
+
self.to_s
|
16
|
+
end
|
14
17
|
|
18
|
+
def test_password()
|
19
|
+
symbol = false
|
20
|
+
number = false
|
21
|
+
capital= false
|
22
|
+
regular= false
|
23
|
+
all_valid= true
|
24
|
+
puts "Testing #{self}"
|
25
|
+
n=self.split("")
|
26
|
+
self.slice!(0..self.size)
|
27
|
+
n.each { |b|
|
28
|
+
# test symbols
|
29
|
+
if b.ord > 32 && b.ord < 48 || b.ord > 58 && b.ord < 65 || b.ord > 91 && b.ord < 97 || b.ord > 123 && b.ord < 126 then
|
30
|
+
symbol = true
|
31
|
+
# test capital letters
|
32
|
+
elsif b.ord > 65 && b.ord < 91 then
|
33
|
+
capital = true
|
34
|
+
# test numbers
|
35
|
+
elsif b.ord > 47 && b.ord < 58 then
|
36
|
+
number = true
|
37
|
+
# test regular alphabet
|
38
|
+
elsif b.ord > 96 && b.ord < 123 then
|
39
|
+
regular = true
|
40
|
+
else
|
41
|
+
# com character out of the acceptable ranges
|
42
|
+
all_valid = false
|
43
|
+
end
|
44
|
+
}
|
45
|
+
if symbol && capital && number && regular && all_valid
|
46
|
+
return true
|
47
|
+
end
|
48
|
+
end
|
15
49
|
end
|
16
50
|
|
17
51
|
def check_string_sanity(album)
|
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.20
|
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-10-
|
11
|
+
date: 2020-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|