Class: Roebe::Passwords
- Inherits:
-
Base
show all
- Defined in:
- lib/roebe/classes/passwords.rb
Overview
Constant Summary
collapse
- ERSTE_BANK =
'/home/x/data/personal/yaml/erste_bank/erste_bank.yml'
- LJUST =
38
Constants inherited
from Base
Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #exit_program, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #ogrey, #olive, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #orev, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #string_italic, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow
#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #set_commandline_arguments
Constructor Details
#initialize(i = ARGV, run_already = true) ⇒ Passwords
37
38
39
40
41
42
43
44
|
# File 'lib/roebe/classes/passwords.rb', line 37
def initialize(
i = ARGV,
run_already = true
)
reset
set_commandline_arguments(i)
run if run_already
end
|
Class Method Details
.password_for(i = :meduni, shall_we_modify_the_xorg_buffer = true) ⇒ Object
#
Passwords.password_for
#
641
642
643
644
645
646
647
648
649
650
651
652
653
|
# File 'lib/roebe/classes/passwords.rb', line 641
def self.password_for(
i = :meduni,
shall_we_modify_the_xorg_buffer = true
)
_ = new(i, false)
if shall_we_modify_the_xorg_buffer.to_s.include? 'do_not'
shall_we_modify_the_xorg_buffer = false
end
unless shall_we_modify_the_xorg_buffer
_.do_not_modify_the_xorg_buffer
end
_.run
end
|
Instance Method Details
#add_to_buffer(i) ⇒ Object
607
608
609
610
611
|
# File 'lib/roebe/classes/passwords.rb', line 607
def add_to_buffer(i)
if do_we_want_to_modify_the_xorg_buffer?
@internal_hash[:internal_xorg_buffer] << i
end
end
|
#add_to_the_second_hash(i) ⇒ Object
#
add_to_the_second_hash
#
94
95
96
|
# File 'lib/roebe/classes/passwords.rb', line 94
def add_to_the_second_hash(i)
@internal_hash[:additional_data_to_display].merge!(i)
end
|
#additional_data_to_display? ⇒ Boolean
#
additional_data_to_display?
#
108
109
110
|
# File 'lib/roebe/classes/passwords.rb', line 108
def additional_data_to_display?
@internal_hash[:additional_data_to_display]
end
|
#boku(dataset = dataset?
) ⇒ Object
Also known as:
boku_wien
557
558
559
560
561
|
# File 'lib/roebe/classes/passwords.rb', line 557
def boku(
dataset = dataset?
)
dataset and dataset['BOKU']
end
|
#clear_the_second_hash ⇒ Object
Also known as:
reset_the_second_hash
#
clear_the_second_hash
#
101
102
103
|
# File 'lib/roebe/classes/passwords.rb', line 101
def clear_the_second_hash
@internal_hash[:additional_data_to_display].clear
end
|
#colourize_this_left_right(i) ⇒ Object
Also known as:
left_right
#
colourize_this_left_right
Only pass input to this when it has a ‘:’ character.
#
487
488
489
490
491
492
493
|
# File 'lib/roebe/classes/passwords.rb', line 487
def colourize_this_left_right(i)
splitted = i.split(': ')
left, right = splitted
return leading_indent?+
simp(left).ljust(LJUST)+
sfancy(right)
end
|
#dataset? ⇒ Boolean
Also known as:
data?
248
249
250
|
# File 'lib/roebe/classes/passwords.rb', line 248
def dataset?
@internal_hash[:dataset]
end
|
#display_with_indent(i) ⇒ Object
575
576
577
|
# File 'lib/roebe/classes/passwords.rb', line 575
def display_with_indent(i)
e "#{leading_indent?}#{i}"
end
|
#do_not_modify_the_xorg_buffer ⇒ Object
#
do_not_modify_the_xorg_buffer
#
221
222
223
|
# File 'lib/roebe/classes/passwords.rb', line 221
def do_not_modify_the_xorg_buffer
@internal_hash[:do_we_want_to_modify_the_xorg_buffer] = false
end
|
#do_we_want_to_modify_the_xorg_buffer? ⇒ Boolean
#
do_we_want_to_modify_the_xorg_buffer?
#
166
167
168
|
# File 'lib/roebe/classes/passwords.rb', line 166
def do_we_want_to_modify_the_xorg_buffer?
@internal_hash[:do_we_want_to_modify_the_xorg_buffer]
end
|
#fh(dataset = dataset?
) ⇒ Object
530
531
532
533
534
|
# File 'lib/roebe/classes/passwords.rb', line 530
def fh(
dataset = dataset?
)
dataset and dataset['fachhochschule_biocampus']
end
|
#file_passwords? ⇒ Boolean
478
479
480
|
# File 'lib/roebe/classes/passwords.rb', line 478
def file_passwords?
BeautifulUrl.file_passwords
end
|
#indent_level_is(i = 2) ⇒ Object
582
583
584
|
# File 'lib/roebe/classes/passwords.rb', line 582
def indent_level_is(i = 2)
@internal_hash[:leading_indent] = ' ' * i
end
|
#indented_display_left_right(first_part = 'URL', second_part = 'remote_URL', pointer = nil) ⇒ Object
#
indented_display_left_right
#
589
590
591
592
593
594
595
596
597
598
599
600
601
602
|
# File 'lib/roebe/classes/passwords.rb', line 589
def indented_display_left_right(
first_part = 'URL',
second_part = 'remote_URL',
pointer = nil
)
ljust_to_use_here = 16
display_with_indent(
"#{steelblue(
first_part.ljust(ljust_to_use_here)
)} "\
"#{orange(right_arrow?)} "\
"#{mediumseagreen(pointer[second_part])}"
)
end
|
#internal_xorg_buffer? ⇒ Boolean
Also known as:
xorg_buffer?
#
internal_xorg_buffer?
#
616
617
618
|
# File 'lib/roebe/classes/passwords.rb', line 616
def internal_xorg_buffer?
@internal_hash[:internal_xorg_buffer]
end
|
#leading_indent? ⇒ Boolean
115
116
117
|
# File 'lib/roebe/classes/passwords.rb', line 115
def leading_indent?
@internal_hash[:leading_indent]
end
|
#meduni_wien(dataset = dataset?
) ⇒ Object
566
567
568
569
570
|
# File 'lib/roebe/classes/passwords.rb', line 566
def meduni_wien(
dataset = dataset?
)
dataset and dataset['meduni_wien']
end
|
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
# File 'lib/roebe/classes/passwords.rb', line 277
def (
i = commandline_arguments?
)
if i.is_a? Array
i.each {|entry| (entry) }
else
i = '--help' if i.to_s.empty?
case i when /rubygem$/i,
/ruby$/i
set_use_this_search_key(:rubygems)
when /univie(_|-)?unet/i,
/univie/i,
/^uni$/i,
/^-?-?uniwien$/i,
/Uni(_|-)?Wien$/i,
/^-?-?haupt$/i
set_use_this_search_key(:univie)
add_to_the_second_hash(
'remote_URL' => BeautifulUrl['uniwien_homepage']
)
when /^-?-?meduni$/i,
/^-?-?med$/i,
/^-?-?Meduni(_|-)?Wien$/i
set_use_this_search_key(:meduni_wien)
add_to_the_second_hash(
'remote_URL' => BeautifulUrl['meduni_wien_homepage']
)
when /^-?-?help$/i,''
show_help_then_exit
when /-?-?nawi/,
/show(_|-)?password(_|-)?from(_|-)?the(_|-)?nawi(_|-)?server$/i,
/show(_|-)?nawi$/i,
/passwort(_|-)?chemie$/i,
/NAWI(_|-)?Server$/i
set_use_this_search_key(:nawi)
add_to_the_second_hash(
'remote_URL' => BeautifulUrl['chemie_forum_oeh_wien_fileserver']
)
when /^-?-?tu$/i,
/^-?-?tuwien$/,
/^-?-?tumail$/,
/^-?-?TU(_|-)?Wien$/i
set_use_this_search_key(:tu_wien)
add_to_the_second_hash(
'remote_URL' => BeautifulUrl['tu_wien_homepage']
)
when /-?-?BOKU$/i,
/-?-?BOKU(_|-)?Wien$/i
set_use_this_search_key(:BOKU)
add_to_the_second_hash(
'eduroam' => '[email protected]'
)
when /^-?-?all$/i,
/-?-?show(_|-)?all$/i
show_all
exit
when /^-?-?FEEDBACK$/i,
/DATA/i,
/DEBUG/i
pp dataset?
exit
when 'fh'
e 'No longer in use as of 2023.' exit
when /vetmed$/i,
/vetmed(_|-)?uni$/i,
/vetmed(_|-)?Wien$/i,
'vuni',
/^vet\??$/i
set_use_this_search_key(:vetmeduni)
add_to_the_second_hash(
'remote_URL' => BeautifulUrl['vetmeduni_wien_homepage']
)
when 'erste',
/erste_bank/
e grey('Trying to read in the content from ')+
sfile(ERSTE_BANK)+
grey(' next:')
e
e " #{steelblue(File.readlines(ERSTE_BANK)[1..6][3].strip)}"
e
exit
when 'vrm'
e '!m03sen!'
exit
when /^-?-?open$/i
open_this_file
when /^-?-?available(-|_)?entries\??$/,
/^-?-?available\??$/
keys = dataset?.keys
e
e grey('The available entries ('+keys.size.to_s+' in total) are:')
e
keys.each {|this_key|
e " #{steelblue(this_key)}"
}
e
exit
when /^-?-?file\??$/i,
/^-?-?passwords(-|_)?file$/
e
e " #{sfile(passwords_file?)}"
e
exit
when /^-?-?show(-|_)?file$/i
e sfile(File.read(passwords_file?))
end
end
end
|
#open_this_file ⇒ Object
255
256
257
|
# File 'lib/roebe/classes/passwords.rb', line 255
def open_this_file
esystem "#{editor_to_use?} #{__FILE__}"
end
|
#passwords_file? ⇒ Boolean
Also known as:
location?, file_location?
213
214
215
|
# File 'lib/roebe/classes/passwords.rb', line 213
def passwords_file?
@internal_hash[:passwords_file]
end
|
#report_this_dataset(i, title_to_use = nil) ⇒ Object
Also known as:
report_this_datastructure, report_this
#
report_this_dataset
The typical input to this method is a Hash, containing the relevant data that is to be shown to the user.
#
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
|
# File 'lib/roebe/classes/passwords.rb', line 676
def report_this_dataset(
i, title_to_use = nil
)
if i.is_a? Hash
title("#{title_to_use}:") if title_to_use
e
if i.has_key? 'remote_URL'
indented_display_left_right('URL', 'remote_URL', i)
end
if i.has_key? 'login_name'
indented_display_left_right('login','login_name', i)
end
if i.has_key? 'password'
indented_display_left_right('password','password', i)
add_to_buffer(i['password']) set_the_xorg_buffer
end
if i.has_key? 'email'
indented_display_left_right('email','email', i)
end
if i.has_key? 'wlan_password'
indented_display_left_right('WLAN password','wlan_password', i)
end
if i.has_key? 'eduroam'
indented_display_left_right('Eduroam','eduroam', i)
end
e
end
end
|
49
50
51
52
53
54
|
# File 'lib/roebe/classes/passwords.rb', line 49
def reset
super()
infer_the_namespace
initialize_the_internal_hash
reset_the_internal_dataset
end
|
#reset_the_internal_dataset ⇒ Object
#
reset_the_internal_dataset
#
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
|
# File 'lib/roebe/classes/passwords.rb', line 59
def reset_the_internal_dataset
@internal_hash[:dataset] = nil
@internal_hash[:passwords_file] = nil
@internal_hash[:do_we_want_to_modify_the_xorg_buffer] = true
@internal_hash[:leading_indent] = ''
@internal_hash[:use_this_search_key] = nil
@internal_hash[:additional_data_to_display] = {}
reset_the_internal_xorg_buffer
indent_level_is(2)
end
|
#reset_the_internal_xorg_buffer ⇒ Object
#
reset_the_internal_xorg_buffer
#
180
181
182
183
184
185
|
# File 'lib/roebe/classes/passwords.rb', line 180
def reset_the_internal_xorg_buffer
@internal_hash[:internal_xorg_buffer] = ''.dup end
|
623
624
625
626
627
628
629
630
631
632
633
634
635
636
|
# File 'lib/roebe/classes/passwords.rb', line 623
def run
try_to_require_the_beautiful_url_project
try_to_require_the_xorg_buffer
try_to_assign_the_default_passwords_file_to_the_corresponding_variable
try_to_load_up_the_main_dataset
_ = first_argument?.to_s
if _.empty?
show_help_then_exit
else
set_search_key(first_argument?.to_s) try_to_report_this_key
end
end
|
#set_the_xorg_buffer(i = internal_xorg_buffer?
) ⇒ Object
#
set_the_xorg_buffer
This method call will also reset the buffer.
#
660
661
662
663
664
665
666
667
668
|
# File 'lib/roebe/classes/passwords.rb', line 660
def set_the_xorg_buffer(
i = internal_xorg_buffer?
)
i = i.chomp
unless i.empty?
set_xorg_buffer(i)
reset_the_internal_xorg_buffer
end
end
|
#set_use_this_search_key(i) ⇒ Object
Also known as:
set_search_key
#
set_use_this_search_key
This method will also try to sanitize the given input a little.
#
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/roebe/classes/passwords.rb', line 124
def set_use_this_search_key(i)
i = i.to_s
case i.strip
when /^-?-?Meduni(_|-| )?Wien$/i
i = :meduni_wien
when /^-?-?Uni(_|-| )?Wien$/i,
/^-?-?Wien$/i
i = :univie
when /^-?-?Boku(_|-| )?Wien$/i
i = :BOKU
when /^-?-?Vetmed(_|-| )?Wien$/i
i = :vetmeduni
when /TU(_|-| )?Wien$/i,
/^-?-?TU$/i
i = :tu_wien
when /^-?-?NAWI(_|-| )?Server$/i
i = :nawi
end
@internal_hash[:use_this_search_key] = i.to_s
end
|
#
show_all (show all tag, show tag)
Use this method here to show login information for all my study-related thingies.
Note that the old methods were e. g. show_meduni_wien() or show_uniwien() or show_boku() or show_password_from_the_nawi_server() These method names are no longer in use after the rewrite of this class in February 2023.
#
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
|
# File 'lib/roebe/classes/passwords.rb', line 721
def show_all
indent_level_is(2) e
array_show_these_entries = [
'Meduni Wien',
'Uni Wien',
'Boku Wien',
'Vetmed Wien',
'TU Wien',
'NAWI Server'
]
array_show_these_entries.each {|this_entry|
set_search_key(this_entry)
(this_entry)
try_to_report_this_key
reset_the_second_hash
}
end
|
#show_help ⇒ Object
#
show_help (help tag)
Invocation example:
passwords --help
#
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/roebe/classes/passwords.rb', line 195
def show_help
opne 'These are the available help options: 👍'
e
eparse ' available-keys # show all password entries available meduni'
eparse ' meduni # show password for meduni'
eparse ' uniwien # show password for UniWien'
eparse ' vetmed # show password for VetMed Uni'
eparse ' all or ALL # simply show all passwords'
eparse ' OPEN # open this file here in your editor'
e
e grey('Note that you can use -- for all of the above calls, such as in')
e grey('--open or --all.')
end
|
#show_help_then_exit ⇒ Object
269
270
271
272
|
# File 'lib/roebe/classes/passwords.rb', line 269
def show_help_then_exit
show_help
exit
end
|
262
263
264
|
# File 'lib/roebe/classes/passwords.rb', line 262
def title(i)
e olivedrab(i)
end
|
#try_to_assign_the_default_passwords_file_to_the_corresponding_variable(i = :default) ⇒ Object
#
try_to_assign_the_default_passwords_file_to_the_corresponding_variable
This method will try to use the default passwords file. This will only work on my home system, so we need a way for other users to pass in their own password-file here.
#
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/roebe/classes/passwords.rb', line 232
def try_to_assign_the_default_passwords_file_to_the_corresponding_variable(
i = :default
)
case i
when :default
i = BeautifulUrl.file_passwords if Object.const_defined?(:BeautifulUrl)
end
@internal_hash[:passwords_file] = i
end
|
#try_to_load_up_the_main_dataset(i = file_passwords?
) ⇒ Object
#
try_to_load_up_the_main_dataset
#
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
|
# File 'lib/roebe/classes/passwords.rb', line 498
def try_to_load_up_the_main_dataset(
i = file_passwords?
)
if File.exist? i
begin
@internal_hash[:dataset] = YAML.load_file(i)
rescue ArgumentError => error
opne tomato('There was an error while trying to load '\
'the file `'+sfile(i)+'`.')
e
opne tomato('This error will be shown next:')
e
pp error
exit
end
else
opnn; no_file_exists_at(i)
end
end
|
#try_to_report_this_key(i = search_key?,
, dataset = dataset?
) ⇒ Object
#
try_to_report_this_key (report tag)
This method will try to report the registered data for the given key.
#
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
# File 'lib/roebe/classes/passwords.rb', line 455
def try_to_report_this_key(
i = search_key?,
dataset = dataset?
)
unless i.start_with?('--')
if dataset.has_key?(i)
pointer = dataset[i]
unless @internal_hash[:additional_data_to_display].empty?
pointer.merge!(@internal_hash[:additional_data_to_display])
end
report_this_dataset(pointer, i)
else
opne "#{rev}No key called #{sfancy(i)} was found in the dataset at"
opne " #{sfile(location?)}"
opne rev+'Considering passing '+orange('--help')+
rev+' to show the available help options.'
end
end
end
|
#tu_wien(dataset = dataset?
) ⇒ Object
Also known as:
tu
539
540
541
542
543
|
# File 'lib/roebe/classes/passwords.rb', line 539
def tu_wien(
dataset = dataset?
)
dataset and dataset['tu_wien']
end
|
#univie_unet(dataset = dataset?
) ⇒ Object
Also known as:
univie_dataset?
521
522
523
524
525
|
# File 'lib/roebe/classes/passwords.rb', line 521
def univie_unet(
dataset = dataset?
)
dataset and dataset['univie']
end
|
#use_this_search_key? ⇒ Boolean
Also known as:
search_key?
173
174
175
|
# File 'lib/roebe/classes/passwords.rb', line 173
def use_this_search_key?
@internal_hash[:use_this_search_key]
end
|
#vetmed_uni(dataset = dataset?
) ⇒ Object
548
549
550
551
552
|
# File 'lib/roebe/classes/passwords.rb', line 548
def vetmed_uni(
dataset = dataset?
)
dataset and dataset['vetmeduni']
end
|