Class: Roebe::Wlan

Inherits:
Base show all
Defined in:
lib/roebe/classes/wlan/wlan.rb

Constant Summary collapse

DEFAULT_VALUE_FOR_RUN_ALREADY =
#

DEFAULT_VALUE_FOR_RUN_ALREADY

#
true
FILE =
#

FILE

#
'$RSRC/roebe/lib/roebe/classes/wlan/wlan.rb'
FILE_WPA_SUPPLICANT_CONF =
#

FILE_WPA_SUPPLICANT_CONF

#
'/etc/wpa_supplicant.conf'
FILE_NAME_FOR_THE_WIRELESS_INTERFACE =
#

FILE_NAME_FOR_THE_WIRELESS_INTERFACE

#
"#{::Roebe.project_yaml_directory?}/name_for_the_wireless_interface.yml"
PASSPHRASE1 =
#

PASSPHRASE1

This constant exists just for automatically simplifying connecting to a local WLAN without much fuzz. It is also completely irrelevant whether other people know this phrase, hence why it is hardcoded here; on the plus side, it allows us to autogenerate the .conf file that wpa_passphrase requires.

#
'e8a2e276a261fef46a721ea8379a5685ca36869f625df2e172d007c97e308ff4'
HOME_ESSID =
#

HOME_ESSID

Adjust accordingly to the ESSID that you want to use.

#
'UPC'\
'1371700'

Constants inherited from Base

Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE

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

Methods included from Base::CommandlineArguments

#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(commandline_arguments = ARGV, run_already = DEFAULT_VALUE_FOR_RUN_ALREADY) ⇒ Wlan

#

initialize

#


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/roebe/classes/wlan/wlan.rb', line 93

def initialize(
    commandline_arguments = ARGV,
    run_already           = DEFAULT_VALUE_FOR_RUN_ALREADY
  )
  reset
  @run_already = run_already # ← Must come quite early, even before setting the commandline-arguments.
  if commandline_arguments.is_a?(Array) and
    (commandline_arguments.size > 0) and
    (commandline_arguments.first == :do_not_run_yet)
    @run_already = false
  elsif commandline_arguments.is_a? Symbol
    case commandline_arguments
    # ===================================================================== #
    # === :do_not_run_yet
    # ===================================================================== #
    when :do_not_run_yet,
         :do_not_run
      @run_already = false
    end
  end
  set_commandline_arguments(
    commandline_arguments
  )
  case @run_already
  # ======================================================================= #
  # === :do_not_run_yet
  # ======================================================================= #
  when :do_not_run_yet,
       :do_not_run
    @run_already = false
  end
  run if @run_already
end

Instance Method Details

#autofix_rfkill_problemObject

#

autofix_rfkill_problem

This method can be used to solve RF-kill related problems.

#


253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/roebe/classes/wlan/wlan.rb', line 253

def autofix_rfkill_problem
  array_unblock_these_devices = %w( # Denote which devices ought to be blocked.
    0
    2
    3
  )
  e
  e '(1) First, we will issue '+gold('rfkill list all')+' to see '\
    'all blocked devices:'
  e
  run_rfkill_list_all_command
  e
  e '(2) Next, we will unblock the main device at '+
    slateblue('0')+' and '+slateblue('3')+'. (Hardcoded entries for now.)'
  e
  array_unblock_these_devices.each {|this_device|
    esystem "rfkill unblock #{this_device}"
  }
  e
  e 'If everything worked then the status should have changed.'
  e
  e "3) Let's verify this:"
  e
  run_rfkill_list_all_command
  e
end

#autogenerate_configuration_file_for_the_wpa_passphraseObject

#

autogenerate_configuration_file_for_the_wpa_passphrase

This method will autogenerate the file that I will use on my laptop setup (at home).

#


317
318
319
320
321
322
323
324
325
326
# File 'lib/roebe/classes/wlan/wlan.rb', line 317

def autogenerate_configuration_file_for_the_wpa_passphrase
  what = 'network={
ssid="UPC1371700"
# psk="'+default_password?+'"
psk=e8a2e276a261fef46a721ea8379a5685ca36869f625df2e172d007c97e308ff4
}'
  into = FILE_WPA_SUPPLICANT_CONF
  opne 'Now writing into the file at `'+sfile(into)+'`.'
  write_what_into(what, into)
end

#automatically_start_the_wlan_device_on_my_laptopObject

#

automatically_start_the_wlan_device_on_my_laptop

This method is specifically for my home-setup, e. g. my main laptop.

#


943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
# File 'lib/roebe/classes/wlan/wlan.rb', line 943

def automatically_start_the_wlan_device_on_my_laptop
  cliner
  e
  e 'This entry-point for wlan is primarily optimized for my own laptop.'
  e
  e 'This script will next attempt to systematically perform all steps'
  e 'necessary in order to get the WLAN device to work.'
  e
  e '1) First, we will try to determine the locally available ESSIDs.'
  e
  this_file = save_essid_where?
  if File.exist? this_file
    e 'We will make use of the file at `'+sfile(this_file)+'`.'
    e
    e 'The content of this file is:'
    e
    e sfancy('  '+File.read(this_file))
    e
  end
  e
  e '2) Using a hardcoded value for ESSID next ('+sfancy(HOME_ESSID)+')'
  e
  # ======================================================================= #
  # Since we use this hardcoded approach, we will NOT store this
  # ESSID value.
  # ======================================================================= #
  set_default_essid_for_the_laptop
  e 'The ESSID is now: '+sfancy(query_essid_value)
  e
  if is_on_roebe?
    e "#{rev}Also autogenerating the configuration file that "\
      "wpa_passphrase requires."
    autogenerate_configuration_file_for_the_wpa_passphrase
  end
  e
  e 'Next setting ip link set wlan(device_number) up:'
  e
  ip_link_set_wlan_up
  e
  startup_wlan
  e
  cliner
end

#available_essid_devices?Boolean Also known as: array_discovered_essid_devices?

#

available_essid_devices?

#

Returns:

  • (Boolean)


244
245
246
# File 'lib/roebe/classes/wlan/wlan.rb', line 244

def available_essid_devices?
  @internal_hash[:array_discovered_essid_devices]
end

#connect_to_wlanObject

#

connect_to_wlan

#


1086
1087
1088
# File 'lib/roebe/classes/wlan/wlan.rb', line 1086

def connect_to_wlan
  esystem 'iw dev '+name_of_the_wlan_device?+' connect -w SSID'
end

#consider_reading_the_essid_entry_from_a_file(use_this_file_path = save_essid_where? ) ⇒ Object

#

consider_reading_the_essid_entry_from_a_file

#


189
190
191
192
193
194
195
196
197
198
199
# File 'lib/roebe/classes/wlan/wlan.rb', line 189

def consider_reading_the_essid_entry_from_a_file(
    use_this_file_path = save_essid_where?
  )
  if File.exist? use_this_file_path
    this_essid = YAML.load_file(use_this_file_path)
    set_essid(
      this_essid,
      :do_not_save_again # Do not save it again.
    )
  end
end

#consider_restoring_essid(be_verbose = be_verbose? ) ⇒ Object

#

consider_restoring_essid

This method will, essentially, load from the main ESSID file again.

#


796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
# File 'lib/roebe/classes/wlan/wlan.rb', line 796

def consider_restoring_essid(
    be_verbose = be_verbose?
  )
  case be_verbose
  when :be_verbose
    be_verbose = true
  end
  this_file = save_essid_where?
  if File.exist? this_file
    this_essid = YAML.load_file(this_file)
    if be_verbose
      opne "Loading essid from #{sfile(this_file)} "\
           "(#{orange(this_essid.to_s)})"
    end
    set_essid(
      this_essid,
      :do_not_save_again # Do not save it again.
    )
  end
end

#determine_the_available_essid_devices(run_this_command = 'iwlist scan | grep ESSID', result = nil) ⇒ Object Also known as: scan_for_available_essids

#

determine_the_available_essid_devices

#


401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/roebe/classes/wlan/wlan.rb', line 401

def determine_the_available_essid_devices(
    run_this_command = 'iwlist scan | grep ESSID',
    result           = nil
  )
  if result.nil?
    result = `#{run_this_command}`
  end
  @internal_hash[:array_discovered_essid_devices] = result.split("\n").select {|line|
    line.include? 'ESSID:'
  }.map {|entry|
    entry.sub(/ESSID:/,'').delete(':"').lstrip
  }.reject {|inner_entry| inner_entry.to_s.empty? }
end

#do_connect_to_the_main_wlan_device_automaticallyObject

#

do_connect_to_the_main_wlan_device_automatically

#


1093
1094
1095
1096
1097
1098
1099
# File 'lib/roebe/classes/wlan/wlan.rb', line 1093

def do_connect_to_the_main_wlan_device_automatically
  opne 'Trying to set up the WLAN connection automatically.'
  ip_link_set_wlan_up
  invoke_default_wpa_passphrase
  run_background_wpa_supplicant_command
  start_dhclient
end

#do_smart_startup_sequenceObject

#

do_smart_startup_sequence

To invoke this method from the commandline, try:

wlan --smart
#


854
855
856
857
858
859
860
861
862
863
# File 'lib/roebe/classes/wlan/wlan.rb', line 854

def do_smart_startup_sequence
  e 'This method will do a "smart" startup sequence, meaning that it'
  e 'will attempt to fully bring up the (main) wlan interface, using'
  e 'the pre-determined ESSID and wlan-device name.'
  e
  e "First, we will feedback some information. The #{gold('ESSID')} is:"
  report_essid
  e 'Next we will set the essid; then we perform ifconfig up.'
  startup_wlan
end

#essid?Boolean Also known as: main_essid?, query_essid_value

#

essid?

#

Returns:

  • (Boolean)


236
237
238
# File 'lib/roebe/classes/wlan/wlan.rb', line 236

def essid?
  @internal_hash[:use_this_essid].to_s.chomp
end

#feedback_the_essid_we_will_useObject

#

feedback_the_essid_we_will_use

#


1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
# File 'lib/roebe/classes/wlan/wlan.rb', line 1154

def feedback_the_essid_we_will_use
  if essid?.empty?
    opne 'We have not yet designated a proper ESSID.'
    opne 'If you wish to set one, you may wish to do something like this:'
    e
    efancy '  wlan set_essid BLABLABLA'
    if is_on_roebe?
      verbose_show_the_default_essid
    end
    e
  else
    opne 'The ESSID we will use is:'
    e
    report_raw_essid
    e
  end
end

#help_about_wpaObject

#

help_about_wpa

Invoke this method via:

wlan --wpa
#


911
912
913
914
915
916
917
918
919
920
# File 'lib/roebe/classes/wlan/wlan.rb', line 911

def help_about_wpa
  opne 'Try to issue the following command if you have problems '\
       'with WPA-based networks:'
  e
  opne sfancy('  wlan --wpa')
  e
  opne "The file #{sfile('/etc/wpa_supplicant.conf')} often "\
       "contains useful information."
  e
end

#home_essid?Boolean

#

home_essid?

#

Returns:

  • (Boolean)


182
183
184
# File 'lib/roebe/classes/wlan/wlan.rb', line 182

def home_essid?
  @internal_hash[:home_essid]
end

#interactive_queryObject

#

interactive_query

This method can be used to query the user for relevant input, in order to properly set up the WLAN connection at hand.

#


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
162
163
164
165
166
167
168
169
170
# File 'lib/roebe/classes/wlan/wlan.rb', line 133

def interactive_query
  e 'The following functionality can be used to interactively determine '
  e 'the relevant parameters for your WLAN connection.'
  e
  e 'First we will show the available ESSIDs:'
  e
  show_available_essids
  e
  e 'The available ESSID devices are:'
  e
  determine_the_available_essid_devices
  e
  pp array_discovered_essid_devices?
  e
  scan_for_wlans
  e
  report_name_of_the_wlan_device
  e
  show_to_the_user_how_to_use_the_wpa_passphrase_command
  e
  e 'The name of the WLAN device is: '+sfancy(name_of_the_wlan_device?)
  e
  e 'Now, input the ESSID to use (default: '+steelblue(HOME_ESSID)+'):'
  e '(You can use :default as input for the default-password.)'
  user_input = $stdin.gets.chomp
  @internal_hash[:home_essid] = user_input
  case user_input
  when ':default'
    user_input = default_password?
  end
  e "This password (#{steelblue(user_input)}) will be "\
    "stored into the file #{sfile(SAVE_ESSID_HERE)}."
  write_what_into(@internal_hash[:home_essid], SAVE_ESSID_HERE)
  e
  e 'Next running the dhclient command:'
  br
  run_proper_dhclient_command
end

#invoke_default_wpa_passphrase(use_this_password = password? ) ⇒ Object

#

invoke_default_wpa_passphrase

This method will make use of the default password to be stored into the wpa-supplicant config file.

To invoke this method from the commandline, try:

wlan --invoke-default-wpa-passphrase
#


998
999
1000
1001
1002
1003
1004
# File 'lib/roebe/classes/wlan/wlan.rb', line 998

def invoke_default_wpa_passphrase(
    use_this_password = password?
  )
  _ = '  wpa_passphrase '+return_main_essid+' '+
      use_this_password+' >> '+FILE_WPA_SUPPLICANT_CONF
  esystem _.lstrip, :do_colourize
end
#
#


925
926
927
928
929
# File 'lib/roebe/classes/wlan/wlan.rb', line 925

def ip_link_set_wlan_up(
    this_interface = name_of_the_wlan_device?
  )
  esystem "ip link set #{this_interface} up", :do_colourize
end

#load_and_return_main_essid(this_file = save_essid_where? ) ⇒ Object Also known as: return_main_essid

#

load_and_return_main_essid

#


1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
# File 'lib/roebe/classes/wlan/wlan.rb', line 1191

def load_and_return_main_essid(
    this_file = save_essid_where?
  )
  if File.exist? this_file
    YAML.load_file(this_file)
  else
    opne 'No file exists at '+sfile(this_file)+'.'
    ''
  end
end
#

menu (menu tag)

#


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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
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
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
# File 'lib/roebe/classes/wlan/wlan.rb', line 419

def menu(
    i = commandline_arguments?
  )
  if i.is_a? Array
    i = i.join(' ').strip
  end
  case i # case tag
  # ======================================================================= #
  # === wlan --run-dhclient
  # ======================================================================= #
  when /^-?-?run(_|-)?dhclient$/i
    run_proper_dhclient_command
    exit
  # ======================================================================= #
  # === wlan --main-file?
  # ======================================================================= #
  when /^-?-?main(_|-)?file\??$/i
    e SAVE_ESSID_HERE
    exit
  # ======================================================================= #
  # === wlan --essid
  # ======================================================================= #
  when /^-?-?essid\??$/, # wlan --essid?
       /^essid\??$/,
       /ESSID/ # This also includes essid?
    if i.include? '?' # Trigger this via: wlan --essid?
      consider_restoring_essid if essid?.empty?
      feedback_the_essid_we_will_use
    else
      show_available_essids
    end
    exit
  # ======================================================================= #
  # === wlan rfkill?
  # ======================================================================= #
  when /^-?-?rfkill\??$/i,
       /^-?-?rfkill(_|-)?status\??$/i
    verbose_run_rfkill_list_all_command
    exit
  # ======================================================================= #
  # === wlan run_background_wpa_supplicant_command
  #
  # This entry point essentially runs the "wpa_supplicant -B -D wext -i"
  # command.
  # ======================================================================= #
  when /^-?-?run(_|-)?background(_|-)?wpa(_|-)?supplicant(_|-)?command$/i,
       /^-?-?background$/i,
       /^-?-?bg$/i,
       /^-?-?wpa(_|-)?startup$/i,
       /^5$/
    run_background_wpa_supplicant_command
    exit
  # ======================================================================= #
  # === wlan 1
  # ======================================================================= #
  when /^1$/
    show_available_wlan_devices
    exit
  # ======================================================================= #
  # === wlan --set_default_essid_for_the_laptop
  # ======================================================================= #
  when /^-?-?set(_|-)?default(_|-)?essid(_|-)?for(_|-)?the(_|-)?laptop$/i,
       /^-?-?default(_|-)?essid(_|-)?for(_|-)?the(_|-)?laptop$/i
    e
    e 'Setting the default ESSID for the laptop next.'
    e
    set_default_essid_for_the_laptop(:also_save_it)
    exit
  # ======================================================================= #
  # === wlan --show_available_essids
  # ======================================================================= #
  when /^-?-?show(-|_| )?available(-|_| )?essids$/i,
       /^-?-?show(-|_| )?essids$/i,
       /^-?-?show(-|_| )?available\??$/i
    show_available_essids
  # ======================================================================= #
  # === wlan --smart-start
  #
  # This entry point will do a "smart" startup sequence, primarily
  # optimized for my laptop.
  # ======================================================================= #
  when /^-?-?smart(_|-)?start$/i,
       /^-?-?do(_|-)?smart(_|-)?startup(_|-)?sequence$/i,
       /^-?-?smart$/i,
       /^-?-?steps\??$/i
    do_smart_startup_sequence
    exit
  # ======================================================================= #
  # === wlan --autogenerate
  #
  # This entry point will autogenerate the configuration file that
  # is specific for the wpa_passphrase command. This is tailored to
  # my own use case, so it will probably be utterly useless for
  # other people.
  # ======================================================================= #
  when /^-?-?autogenerate(_|-)?configuration(_|-)?file(_|-)?for(_|-)?the(_|-)?wpa(_|-)?passphrase$/i,
       /^-?-?autogenerate$/i,
       /^4$/
    autogenerate_configuration_file_for_the_wpa_passphrase
    exit
  # ======================================================================= #
  # === wlan --ip_link_set_wlan_up
  # ======================================================================= #
  when /^-?-?ip(_|-)?link(_|-)?set(_|-)?wlan(_|-)?up$/i,
       /^3$/
    ip_link_set_wlan_up
    exit
  # ======================================================================= #
  # === wlan UPC
  # ======================================================================= #
  when /^UPC(.+)$/
    set_essid(i) { :be_verbose }
    exit
  # ======================================================================= #
  # === wlan --connected?
  #
  # Query whether we are wlan-connected or not (yes/no boolean).
  # ======================================================================= #
  when /^-?-?connected\??$/i,
       /^-?-?are(_|-)?we(_|-)?connected\??$/i
    query_whether_we_are_wlan_connected
    exit
  # ======================================================================= #
  # === wlan --password
  # ======================================================================= #
  when /^-?-?password$/i,
       /^-?-?passwords$/i,
       /^-?-?wpa(_|-)?passwords$/i,
       /^-?-?pass\??$/i,
       /^-?-?passphrase$/i # === wlan --passphrase
    show_to_the_user_how_to_use_the_wpa_passphrase_command
    exit
  # ======================================================================= #
  # === wlan --show-available-essids-then-debug
  # ======================================================================= #
  when /^-?-?show(-|_| )?available(-|_| )?essids(-|_| )?then(-|_| )?debug$/i,
       /^-?-?available\??$/i,
       /^-?-?available(-|_| )?essids\??$/i,
       /^-?-?top$/i
    show_available_essids
    show_debug_information
    exit
  # ======================================================================= #
  # === wlan --wlan-set-device=wlan0
  # ======================================================================= #
  when /^-?-?wlan(-|_| )?set(-|_| )?device=(.+)$/i,
       /^-?-?set(-|_| )?wlan(-|_| )?device=(.+)$/i,
       /^-?-?set(-|_| )?device=(.+)$/i
    _ = $2.to_s.dup
    _ = $3.to_s.dup if $3
    set_main_wlan_device(_)
    exit
  # ======================================================================= #
  # === wlan --set
  #
  # This entry point allows us to set to a specific ESSID.
  #
  # Invocation examples:
  #
  #   wlan --set
  #   wlan --set UPC1371700
  #
  # ======================================================================= #
  when /^-?-?set(-|_| )?essid(.+)?/i, # $2
       /^-?-?set(-|_| )?ssid(.+)?/i,  # $2
       /^-?-?ESSID(.+)?/i             # $1
    _ = nil
    _ = $1.to_s.dup if $1
    _ = $2.to_s.dup if $2
    set_essid(_)
    exit
  # ======================================================================= #
  # === wlan --debug?
  #
  # Show some debug-information.
  # ======================================================================= #
  when /^-?-?debug\??$/i
    show_debug_information
  # ======================================================================= #
  # === wlan --help
  # ======================================================================= #
  when /^he/,
       /^-?-?help/,
       /^HELP$/
    show_help(:then_exit)
  # ======================================================================= #
  # === wlan --default
  # ======================================================================= #
  when /^-?-?default$/
    _ 'iwconfig wlan0'
    exit
  # ======================================================================= #
  # === wlan --open
  # ======================================================================= #
  when /^-?-?open$/i
    open_this_file_here_in_editor
    exit
  # ======================================================================= #
  # === wlan --configure
  # ======================================================================= #
  when /^-?-?configure$/
    e 'iwconfig '+wlan_device_name?+' essid NETWORK_ID key WIRELESS_KEY'
  # ======================================================================= #
  # === wlan --laptop
  # ======================================================================= #
  when /^-?-?laptop$/i
    automatically_start_the_wlan_device_on_my_laptop
  # ======================================================================= #
  # === wlan --use-passphrase
  #
  # The passphrase follows this usage-scheme:
  #
  #   wpa_passphrase <ssid> [passphrase]
  #
  # ======================================================================= #
  when /^-?-?use(_|-)?passphrase$/i,
       /^-?-?do(_|-)?use(_|-)?passphrase$/i,
       /^-?-?invoke(_|-)?default(_|-)?wpa(_|-)?passphrase$/i,
       /^-?-?wpa(_|-)?passphrase$/i, # === wlan wpa-passphrase
       /^-?-?pass$/i,
       /^-?-?wpa$/i,
       /^-?-?wpasupplicant$/i
    invoke_default_wpa_passphrase
    exit
  # ======================================================================= #
  # === wlan --up
  # ======================================================================= #
  when /^-?-?up$/i,
       /^-?-?startup(_|-)?wlan$/i,
       /^-?-?wlan(_|-)?up$/i
    startup_wlan # up tag
    exit
  # ======================================================================= #
  # === wlan --interactive
  # ======================================================================= #
  when /^-?-?interactive$/i # === wlan --interactive
    interactive_query
    exit
  # ======================================================================= #
  # === wlan --home-essid?
  #
  # This entry point will show the ESSID in use.
  # ======================================================================= #
  when /^-?-?home(_|-)?essid\??$/i,
       /^-?-?essid\?$/i,  # === wlan --essid?
       /^-?-?hessid\??$/i # === wlan --hessid
    show_home_essid
    exit
  # ======================================================================= #
  # === wlan autofix_rfkill_problem
  # ======================================================================= #
  when /^-?-?autofix(_|-)?rfkill(_|-)?problem$/i,
       /^-?-?autofix$/i, # === wlan --autofix
       /^-?-?unblock$/i # === wlan --unblock
    autofix_rfkill_problem
    exit
  # ======================================================================= #
  # === wlan --scan
  # ======================================================================= #
  when /^-?-?scan$/ # scan tag
    scan_for_wlans
    scan_for_available_essids
    scan_for_accesspoints
    exit
  # ======================================================================= #
  # === wlan --connect
  # ======================================================================= #
  when /^-?-?connect$/
    connect_to_wlan
  # ======================================================================= #
  # === wlan --access
  # ======================================================================= #
  when /^-?-?access$/
    scan_for_accesspoints
    exit
  # ======================================================================= #
  # === wlan --scan-for-wlans
  #
  # An alias to this is:
  #
  #   wlan --scan-for-essid
  #
  # ======================================================================= #
  when /^-?-?scan(-|_| )?for(-|_| )?wlans$/,
       /^-?-?scan(-|_| )?for(-|_| )?essid$/
    scan_for_wlans
    exit
  # ======================================================================= #
  # === wlan --automatic
  # ======================================================================= #
  when /^-?-?automatic$/i,
       /^-?-?startup$/i
    do_connect_to_the_main_wlan_device_automatically
    exit
  # ======================================================================= #
  # === wlan dhclient
  # ======================================================================= #
  when /^-?-?dhclient$/i,
       /^-?-?dhc$/i,
       /^6$/
    run_dhclient_command
    exit
  # ======================================================================= #
  # === wlan --name?
  #
  # This entry point will feedback the main wlan-device in use.
  #
  # Invocation examples:
  #
  #   wlan --name?
  #   wlan --device-name?
  #   wlan --device?
  #
  # ======================================================================= #
  when /^-?-?name?/i,
       /^-?-?device(-|_)?name?$/i,
       /^-?-?device\?$/i
    report_name_of_the_wlan_device
    exit
  else
    # else handle special cases:
    case i
    # ======================================================================= #
    # === Operation not possible due to RF-kill
    # ======================================================================= #
    when /Operation not possible due to RF-kill$/i
      autofix_rfkill_problem
    end
  end
end

#name_of_the_wlan_device?(file_path = FILE_NAME_FOR_THE_WIRELESS_INTERFACE) ⇒ Boolean Also known as: wlan_device_name?, main_wlan_device?

#

name_of_the_wlan_device?

#

Returns:

  • (Boolean)


829
830
831
832
833
# File 'lib/roebe/classes/wlan/wlan.rb', line 829

def name_of_the_wlan_device?(
    file_path = FILE_NAME_FOR_THE_WIRELESS_INTERFACE
  )
  YAML.load_file(file_path)
end

#open_this_file_here_in_editorObject

#

open_this_file_here_in_editor (open tag)

#


899
900
901
# File 'lib/roebe/classes/wlan/wlan.rb', line 899

def open_this_file_here_in_editor
  esystem "bluefish #{FILE} &"
end

#password?Boolean Also known as: default_password?

#

password?

#

Returns:

  • (Boolean)


753
754
755
# File 'lib/roebe/classes/wlan/wlan.rb', line 753

def password?
  '1aaaaaaaaa'
end

#query_whether_we_are_wlan_connectedObject

#

query_whether_we_are_wlan_connected

#


348
349
350
351
352
353
# File 'lib/roebe/classes/wlan/wlan.rb', line 348

def query_whether_we_are_wlan_connected
  cmd_to_use = 'iw wlan0 link'
  e sfancy(cmd_to_use)
  result = `#{cmd_to_use}`
  e result
end

#report_name_of_the_wlan_deviceObject

#

report_name_of_the_wlan_device

#


374
375
376
377
378
379
# File 'lib/roebe/classes/wlan/wlan.rb', line 374

def report_name_of_the_wlan_device
  e 'The name of the main wlan-device is:'
  e
  e sfile("  #{name_of_the_wlan_device?}")
  e
end

#report_raw_essidObject Also known as: report_essid, report_the_raw_essid

#

report_raw_essid

#


760
761
762
# File 'lib/roebe/classes/wlan/wlan.rb', line 760

def report_raw_essid
  e "  #{sfancy(essid?)}" # ← Show it on a new line on its own.
end

#resetObject

#

reset (reset tag)

#


204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/roebe/classes/wlan/wlan.rb', line 204

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  set_be_verbose
  # ======================================================================= #
  # === :array_discovered_essid_devices
  # ======================================================================= #
  @internal_hash[:array_discovered_essid_devices] = []
  # ======================================================================= #
  # === :home_essid
  # ======================================================================= #
  @internal_hash[:home_essid] = nil
  # ======================================================================= #
  # === :use_this_essid
  # ======================================================================= #
  @internal_hash[:use_this_essid] = nil # Which ESSID to use.
  # ======================================================================= #
  # === :array_discovered_essid_devices
  #
  # The following Array keeps track of the the found ESSID devices in
  # the local environment.
  # ======================================================================= #
  @internal_hash[:array_discovered_essid_devices] = []
  consider_reading_the_essid_entry_from_a_file
end

#runObject

#

run (run tag)

#


1291
1292
1293
1294
1295
1296
1297
1298
# File 'lib/roebe/classes/wlan/wlan.rb', line 1291

def run
  menu
  consider_restoring_essid(:be_verbose)
  show_intro_message
  run_various_commands
  scan_for_wlans
  help_about_wpa
end

#run_already?Boolean

#

run_already?

#

Returns:

  • (Boolean)


175
176
177
# File 'lib/roebe/classes/wlan/wlan.rb', line 175

def run_already?
  @run_already
end

#run_background_wpa_supplicant_command(name_of_the_wlan_device = name_of_the_wlan_device? ) ⇒ Object Also known as: run_wpa_command

#

run_background_wpa_supplicant_command

This method will run the actual wpa_supplicant command.

#


889
890
891
892
893
894
# File 'lib/roebe/classes/wlan/wlan.rb', line 889

def run_background_wpa_supplicant_command(
    name_of_the_wlan_device = name_of_the_wlan_device?
  )
  _ = 'wpa_supplicant -B -D wext -i '+name_of_the_wlan_device+' -c /etc/wpa_supplicant.conf'
  esystem _, :do_colourize
end

#run_proper_dhclient_command(i = name_of_the_wlan_device? ) ⇒ Object Also known as: obtain_ip, run_dhclient_command, start_dhclient

#

run_proper_dhclient_command

This method will essentially just wrap around bin/dhclient.

#


1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
# File 'lib/roebe/classes/wlan/wlan.rb', line 1275

def run_proper_dhclient_command(
    i = name_of_the_wlan_device?
  )
  _ = "dhclient -v #{i}"
  _result = esystem(_, :do_colourize)
  if _result.nil? or (_result == false)
    opne "The `#{steelblue('dhclient')}` binary "\
         "does not appear to be available locally."
  end
end

#run_rfkill_list_all_commandObject

#

run_rfkill_list_all_command

This method will simply invoke “rfkill list all”.

#


822
823
824
# File 'lib/roebe/classes/wlan/wlan.rb', line 822

def run_rfkill_list_all_command
  esystem 'rfkill list all'
end

#run_various_commandsObject

#

run_various_commands

#


868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
# File 'lib/roebe/classes/wlan/wlan.rb', line 868

def run_various_commands
  array = %w(
    dhclient
    ifconfig
    iwlist
    iwconfig
    wpa_supplicant
  )
  opne 'The various commands can be found here:'+N+N
  array.each {|command|
    e command
    result = `which #{command} 2>&1`
    efancy '  '+result.chomp
  }
end

#save_essid(be_verbose = be_verbose? ) ⇒ Object

#

save_essid (store tag)

This method will save the ESSID value into a file.

#


333
334
335
336
337
338
339
340
341
342
343
# File 'lib/roebe/classes/wlan/wlan.rb', line 333

def save_essid(
    be_verbose = be_verbose?
  )
  what = YAML.dump(essid?)
  where = save_essid_where?
  mkdir(File.dirname(where))
  if be_verbose
    opne "Next saving #{sfancy(essid?)} into `#{sfile(where)}`."
  end
  save_what_into(what, where)
end

#save_essid_where?Boolean

#

save_essid_where?

#

Returns:

  • (Boolean)


1184
1185
1186
# File 'lib/roebe/classes/wlan/wlan.rb', line 1184

def save_essid_where?
  SAVE_ESSID_HERE
end

#scan_for_accesspointsObject Also known as: show_available_wlan_devices

#

scan_for_accesspoints

#


934
935
936
# File 'lib/roebe/classes/wlan/wlan.rb', line 934

def scan_for_accesspoints
  esystem "iw dev #{name_of_the_wlan_device?} scan | grep SSID"
end

#scan_for_wlansObject

#

scan_for_wlans (scan tag)

All this does, basically, is to run:

iwlist wlan0 scan

From the commandline, this can be invoked via:

roebe --scan-for-wlans
#


1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
# File 'lib/roebe/classes/wlan/wlan.rb', line 1113

def scan_for_wlans
  e
  opne "Next, we will scan for nearby #{slateblue('WLANs')}.#{N}"
  e
  cmd = "iwlist #{main_wlan_device?} scan"
  e "  #{sfancy(cmd.chomp)}"
  e
  result = `#{cmd}`
  unless result.empty?
    opne result.chomp
  end
  if result.include? 'ESSID' 
    opnn; efancy 'Look for ESSID entries above. (from the command: '+
          simp(cmd)+sfancy(')')
    opne 'ESSID [NETWORK_NAME]'
    opne 'Where NETWORK_NAME is the name of an available '\
         'wireless network.'
  end
  opne "iwconfig wlan0 essid NETWORK_NAME key WIRELESS_KEY#{N}#{N}"
  e 'Where '+yel('NETWORK_NAME')+' is the name of the network you want to connect'
  e 'to and WIRELESS_KEY is the security key for that network.'
  e
  e 'NOTE:'
  e
  e 'The iwconfig command defaults to HEX values for wireless keys.'
  e
  e 'If you need to use ASCII then you have to prepend the "s" prefix to'
  e 'your key like so:'
  e
  e sfancy("  iwconfig wlan0 essid NETWORK_NAME key s:WIRELESS_KEY#{N}#{N}")
  e
  e 'With your connection made, you now have to get an IP address for '
  e 'your machine using the dhclient command like:'
  e
  e sfancy('  dhclient wlan0')
  e
end

#set_default_essid_for_the_laptop(i = :do_not_save_this_value) ⇒ Object

#

set_default_essid_for_the_laptop

#


1175
1176
1177
1178
1179
# File 'lib/roebe/classes/wlan/wlan.rb', line 1175

def set_default_essid_for_the_laptop(
    i = :do_not_save_this_value
  )
  set_essid(HOME_ESSID, i)
end

#set_essid(i = nil, save_new_essid = true) ⇒ Object

#

set_essid (essid tag)

To invoke this method, do:

wlan set_essid BLABLABLA

The second argument tells us whether we will save this new essid file or whether we won’t.

#


1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
# File 'lib/roebe/classes/wlan/wlan.rb', line 1212

def set_essid(
    i              = nil,
    save_new_essid = true
  )
  i = i.to_s.dup if i.nil?
  # ======================================================================= #
  # Next do a little bit of sanitizing:
  # ======================================================================= #
  if i.include? '-device='
    i.sub!(/-device=/,'')
  end
  set_be_quiet if save_new_essid == :be_silent
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :be_verbose
    # ===================================================================== #
    when :be_verbose
      set_be_verbose
    end
  end
  i.delete!('=') if i.include? '='
  case save_new_essid
  # ======================================================================= #
  # === :do_not_save_this_value
  # ======================================================================= #
  when :do_not_save_this_value,
       :do_not_save_again
    save_new_essid = false
  when :also_save_it
    save_new_essid = true
  end
  if save_new_essid.to_s.include? 'do_not'
    save_new_essid = false
  end
  if i.include? ' '
    i.strip!
    if i.include? ' '
      # =================================================================== #
      # We simply split the input if it still has any ' ' character.
      # =================================================================== #
      i = i.split(' ')[1]
    end
  end
  i = i.chomp.strip
  @internal_hash[:use_this_essid] = i
  save_essid if save_new_essid
end

#set_main_wlan_device(i) ⇒ Object

#

set_main_wlan_device

#


839
840
841
842
843
844
# File 'lib/roebe/classes/wlan/wlan.rb', line 839

def set_main_wlan_device(i)
  e "Setting to the new wlan-device name `#{sfancy(i)}`."
  what = i
  into = FILE_NAME_FOR_THE_WIRELESS_INTERFACE
  write_what_into(what, into)
end

#show_available_essidsObject

#

show_available_essids

Show the available essids in the surrounding.

#


386
387
388
389
390
391
392
393
394
395
396
# File 'lib/roebe/classes/wlan/wlan.rb', line 386

def show_available_essids
  opne 'We will next show all available ESSIDs:'
  e
  run_this_command = 'iwlist scan | grep ESSID'
  result = `#{run_this_command}`
  e sfancy(run_this_command)
  determine_the_available_essid_devices(
    run_this_command, result
  )
  e
end

#show_debug_informationObject

#

show_debug_information (debug tag)

#


304
305
306
307
308
309
# File 'lib/roebe/classes/wlan/wlan.rb', line 304

def show_debug_information
  e '@internal_hash[:array_discovered_essid_devices]:'
  e
  pp array_discovered_essid_devices?
  e
end

#show_help(optional_shall_we_exit = false) ⇒ Object

#

show_help (help tag)

To invoke this method from the commandline, do:

wlan --help
#


1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
# File 'lib/roebe/classes/wlan/wlan.rb', line 1014

def show_help(
    optional_shall_we_exit = false
  )
  case optional_shall_we_exit
  when :then_exit
    optional_shall_we_exit = true
  end
  opnn { :no_trailing }
  e
  e
  e "These are the #{slateblue('documented help options')}:"
  e
  ecomment '    wlan '+mediumorchid('up')+'                     '\
           '# start wlan; bring up the wlan interface' # up tag
  ecomment '    wlan '+mediumorchid('set_essid')+'              '\
           '# set the essid'
  ecomment '    wlan '+mediumorchid('background')+'             '\
           '# start the wpa_supplicant command in the background'
  ecomment '    wlan '+mediumorchid('set-device')+'             '\
           '# set to a specific wlan device such as "wlan0"'
  ecomment '    wlan '+mediumorchid('device?')+'                '\
           '# query which device is presently in use'
  ecomment '    wlan '+mediumorchid('essid?')+'                 '\
           '# feedback the main ESSID in use'
  ecomment '    wlan '+mediumorchid('interactive?')+'           '\
           '# use the class interactively'
  ecomment '    wlan '+mediumorchid('name?')+'                  '\
           '# show the name of the main '\
           'wlan-interface, such as "wlan2"'
  ecomment '    wlan '+mediumorchid('dhclient')+'               '\
           '# start up dhclient to the main wlan-interface'
  ecomment '                                # (this is similar to dhcpcd)'
  ecomment '    wlan '+mediumorchid('scan')+'                   '\
           '# scan for access points'
  ecomment '    wlan '+mediumorchid('connected?')+'             '\
           '# determine whether we are connected to the '\
           'wlan (yes/no possibility)'
  ecomment '    wlan '+mediumorchid('automatic')+'              '\
           '# try to bring up the wlan interface automatically'
  ecomment '    wlan '+mediumorchid('autofix_rfkill_problem')+' '\
           '# autofix rf-kill related issues'
  ecomment '    wlan '+mediumorchid('autogenerate')+'           '\
           '# autogenerate the .conf file '\
           'required by wpa_passphrase (for my home system)'
  ecomment '    wlan '+mediumorchid('smart')+'                  '\
           '# do a smart (semi-automatic) '\
           'startup for the main wlan device'
  ecomment '    wlan '+mediumorchid('connect')+'                '\
           '# connect to an access points'
  ecomment '    wlan '+mediumorchid('laptop')+'                 '\
           '# connect my home laptop at once'
  ecomment '    wlan '+mediumorchid('main-file?')+'             '\
           '# show in which file the main ESSID is stored'
  e
  e "Note that all entries support a leading #{steelblue('--')}"\
    ", such as in #{orange('wlan --essid?')}"
  e "or in #{orange('wlan --scan')}."
  e
  exit if optional_shall_we_exit
end

#show_home_essidObject

#

show_home_essid

#


780
781
782
# File 'lib/roebe/classes/wlan/wlan.rb', line 780

def show_home_essid
  efancy(main_essid?)
end

#show_intro_messageObject

#

show_intro_message

#


1078
1079
1080
1081
# File 'lib/roebe/classes/wlan/wlan.rb', line 1078

def show_intro_message
  opne "We will #{slateblue('scan')} for available "\
       "wlan-associated data next.#{N}#{N}"
end

#show_to_the_user_how_to_use_the_wpa_passphrase_commandObject Also known as: show_passphrase

#

show_to_the_user_how_to_use_the_wpa_passphrase_command

To show this on the commandline do:

wlan --password
#


363
364
365
366
367
368
369
# File 'lib/roebe/classes/wlan/wlan.rb', line 363

def show_to_the_user_how_to_use_the_wpa_passphrase_command
  opne 'The way how to store a '+slateblue('passphrase')+' is by doing this:'
  e
  e simp('  wpa_passphrase SSID PASSPHRASE >> /etc/wpa_supplicant.conf')
  e simp('  wpa_passphrase '+return_main_essid+' '+default_password?+' >> /etc/wpa_supplicant.conf')
  e
end

#startup_wlan(this_interface = name_of_the_wlan_device? ) ⇒ Object

#

startup_wlan

For this method to work properly, the ESSID must have been stored PRIOR to calling it.

To invoke this from the commandline, do:

roebe --startup-wlan
#


291
292
293
294
295
296
297
298
299
# File 'lib/roebe/classes/wlan/wlan.rb', line 291

def startup_wlan(
    this_interface = name_of_the_wlan_device?
  )
  ip_link_set_wlan_up(this_interface)
  esystem 'iwconfig '+this_interface+' essid '+essid?
  esystem 'ifconfig '+this_interface+' up'
  run_background_wpa_supplicant_command
  obtain_ip
end

#verbose_run_rfkill_list_all_commandObject

#

verbose_run_rfkill_list_all_command

#


768
769
770
771
772
773
774
775
# File 'lib/roebe/classes/wlan/wlan.rb', line 768

def verbose_run_rfkill_list_all_command
  e 'Issuing this command next:'
  e
  e sfancy('  rfkill list all')
  e
  run_rfkill_list_all_command
  e
end

#verbose_show_the_default_essidObject

#

verbose_show_the_default_essid

#


1265
1266
1267
1268
# File 'lib/roebe/classes/wlan/wlan.rb', line 1265

def verbose_show_the_default_essid
  opne 'The default ESSID is: '+
       steelblue(HOME_ESSID)
end