-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrb_wiz_lib.rb
More file actions
executable file
·1275 lines (1044 loc) · 38.5 KB
/
Copy pathrb_wiz_lib.rb
File metadata and controls
executable file
·1275 lines (1044 loc) · 38.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
90
91
92
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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
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
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
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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
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
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env ruby
require 'mrdialog'
require 'net/ip'
require 'system/getifaddrs'
require 'socket'
require 'netaddr'
require 'uri'
require File.join(ENV['RBDIR'].nil? ? '/usr/lib/redborder' : ENV['RBDIR'],'lib/rb_config_utils.rb')
class WizConf
# Read propierties from sysfs for a network devices
def netdev_property(devname)
netdev = {}
IO.popen("udevadm info -q property -p /sys/class/net/#{devname} 2>/dev/null").each do |line|
unless line.match(/^(?<key>[^=]*)=(?<value>.*)$/).nil?
netdev[line.match(/^(?<key>[^=]*)=(?<value>.*)$/)[:key]] = line.match(/^(?<key>[^=]*)=(?<value>.*)$/)[:value]
end
end
if File.exist?"/sys/class/net/#{devname}/address"
f = File.new("/sys/class/net/#{devname}/address",'r')
netdev["MAC"] = f.gets.chomp
f.close
end
if File.exist?"/sys/class/net/#{devname}/operstate"
f = File.new("/sys/class/net/#{devname}/operstate",'r')
netdev["STATUS"] = f.gets.chomp
f.close
end
netdev
end
end
# Class to create a Network configuration box
class NetConf < WizConf
attr_accessor :conf, :confdev, :cancel, :management_iface, :sync_interface
def initialize()
@cancel = false
@returning_from_cancel = false
@conf = []
@confdev = {}
@devmode = { "dhcp" => "Dynamic", "static" => "Static" }
@devmodereverse = { "Dynamic" => "dhcp", "Static" => "static" }
@management_iface = nil
@sync_interface = nil
end
def doit(network_interfaces)
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Management Interface Selection"
loop do
self.management_iface = dialog.radiolist("Please select an interface to use as the management interface:", network_interfaces, 0, 0, 4)
return cancel_wizard unless management_iface
selected_interface = network_interfaces.find { |iface| iface[0] == management_iface }
if selected_interface[1].include?("IP: ")
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Skip Network Configuration"
if dialog.yesno("The interface '#{selected_interface[0]}' already has an IP. Do you want to skip network configuration?", 6, 60)
return
end
end
configure_interface(management_iface, network_interfaces)
break if !@returning_from_cancel
@returning_from_cancel = false
end
end
def doitsync(network_interfaces)
return if network_interfaces.empty?
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Synchronism Interface Selection"
loop do
self.sync_interface = dialog.radiolist("Please select an interface to use as the synchronism interface:", network_interfaces, 0, 0, 4)
return cancel_wizard unless sync_interface
selected_interface = network_interfaces.find { |iface| iface[0] == sync_interface }
if selected_interface[1].include?("IP: ")
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Skip Network Configuration"
if dialog.yesno("The interface '#{selected_interface[0]}' already has an IP. Do you want to skip network configuration?", 6, 60)
return
end
end
configure_sync_interface(sync_interface)
break if !@returning_from_cancel
@returning_from_cancel = false
end
end
def get_network_interfaces
network_interfaces = []
radiolist_data = Struct.new(:tag, :item, :select)
first_interface = true
# loop over list of net devices
listnetdev = Dir.entries("/sys/class/net/").select {|f| !File.directory? f}
listnetdev.each do |netdev|
# loopback and devices with no pci nor mac are not welcome!
next if netdev == "lo"
netdevprop = netdev_property(netdev)
next unless (netdevprop["ID_BUS"] == "pci" and !netdevprop["MAC"].nil?)
# Fetch network scripts to get IP information
ip = get_ip_for_interface(netdev)
get_network_scripts(netdev)
data = radiolist_data.new
data.tag = netdev
data.item = "MAC: " + netdevprop["MAC"] + ", Vendor: " + netdevprop["ID_MODEL_FROM_DATABASE"]
data.item += ", IP: #{ip}" unless ip.nil? # Add IP if available
data.select = first_interface ? true : false
first_interface = false if first_interface
network_interfaces.push(data.to_a)
end
return network_interfaces
end
# Helper method to extract the IPv4 address from the network script
def get_ip_for_interface(netdev)
if File.exist?("/etc/sysconfig/network-scripts/ifcfg-#{netdev}")
config_file = File.read("/etc/sysconfig/network-scripts/ifcfg-#{netdev}")
if config_file.match(/^IPADDR=/)
return config_file.match(/^IPADDR=(?<ip>.*)$/)[:ip]
end
end
return nil # Return nil if no IP found
end
def configure_interface(interface, network_interfaces)
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Interface Configuration"
if network_interfaces.length == 1 || dialog.yesno("\nWould you like to assign a static IP to this interface?\n\nIf you choose not to, the interface will default to DHCP for automatic IP configuration.\n", 0, 0)
dev = DevConf.new(interface, self)
dev.conf = @confdev[interface] if @confdev[interface]
dev.doit
if dev.conf.empty?
get_network_scripts(interface)
@returning_from_cancel = true
return
else
@confdev[interface] = {
"mode" => "static",
"ip" => dev.conf['IP:'],
"netmask" => dev.conf['Netmask:'],
"gateway" => dev.conf['Gateway:'].to_s.empty? ? "" : dev.conf['Gateway:']
}
end
else
@confdev[interface] = {"mode" => "dhcp"}
end
end
def configure_sync_interface(interface)
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Synchronism Interface Configuration"
if dialog.yesno("\nWould you like to assign a static IP to this interface?\n\nIf you choose not to, the interface will default to DHCP for automatic IP configuration.\n", 0, 0)
dev = DevConf.new(interface, self)
dev.conf = @confdev[interface] if @confdev[interface]
dev.doit
@confdev[interface] = {
"mode" => "static",
"ip" => dev.conf['IP:'],
"netmask" => dev.conf['Netmask:'],
"gateway" => dev.conf['Gateway:'].to_s.empty? ? "" : dev.conf['Gateway:']
} unless dev.conf.empty?
if dev.conf.empty?
get_network_scripts(interface)
@returning_from_cancel = true
return
end
else
@confdev[interface] = {
"mode" => "dhcp",
"ip" => get_ip_of_interface(interface),
"netmask" => get_netmask_of_interface(interface)
}
if @confdev[interface]["ip"].nil? && @confdev[interface]["netmask"].nil?
get_network_scripts(interface)
@returning_from_cancel = true
return
end
end
end
def get_ip_of_interface(interface_name)
Socket.getifaddrs.each do |ifaddr|
if ifaddr.name == interface_name && ifaddr.addr&.ipv4?
return ifaddr.addr.ip_address # Extract and return the IP as a string
end
end
nil
end
def get_netmask_of_interface(interface_name)
Socket.getifaddrs.each do |ifaddr|
if ifaddr.name == interface_name && ifaddr.addr&.ipv4?
return ifaddr.netmask.ip_address # Extract and return the netmask as a string
end
end
nil
end
def get_network_scripts(netdev)
if File.exist?("/etc/sysconfig/network-scripts/ifcfg-#{netdev}")
config_file = File.read("/etc/sysconfig/network-scripts/ifcfg-#{netdev}")
if config_file.match(/^IPADDR=/)
ip = config_file.match(/^IPADDR=(?<ip>.*)$/)&.[](:ip)
netmask = config_file.match(/^NETMASK=(?<netmask>.*)$/)&.[](:netmask) || "255.255.255.0"
gateway = config_file.match(/^GATEWAY=(?<gateway>.*)$/)&.[](:gateway) || ""
@confdev[netdev] = {
"mode" => "static",
"ip" => ip,
"netmask" => netmask,
"gateway" => gateway
}
else
@confdev[netdev] = {"mode" => "dhcp"}
end
else
@confdev[netdev] = {"mode" => "dhcp"}
end
end
end
class DevConf < WizConf
attr_accessor :device_name, :conf, :cancel
def initialize(x, parent)
@cancel = false
@device_name = x
@conf = {}
@parent = parent
end
def doit
dialog = MRDialog.new
dialog.clear = true
text = <<EOF
You are about to configure the network device #{@device_name}, which has the following properties:
EOF
netdevprop = netdev_property(@device_name)
text += " \n"
text += "MAC: #{netdevprop["MAC"]}\n"
text += "DRIVER: #{netdevprop["ID_NET_DRIVER"]}\n" unless netdevprop["ID_NET_DRIVER"].nil?
text += "PCI PATH: #{netdevprop["ID_PATH"]}\n" unless netdevprop["ID_PATH"].nil?
text += "VENDOR: #{netdevprop["ID_VENDOR_FROM_DATABASE"]}\n" unless netdevprop["ID_VENDOR_FROM_DATABASE"].nil?
text += "MODEL: #{netdevprop["ID_MODEL_FROM_DATABASE"]}\n" unless netdevprop["ID_MODEL_FROM_DATABASE"].nil?
text += "STATUS: #{netdevprop["STATUS"]}\n" unless netdevprop["STATUS"].nil?
text += " \n"
@conf['IP:'] = Config_utils.get_ipv4_network(@device_name)[:ip] if @conf['IP:'].nil?
@conf['Netmask:'] = Config_utils.get_ipv4_network(@device_name)[:netmask] if @conf['Netmask:'].nil?
@conf['Gateway:'] = Config_utils.get_ipv4_network(@device_name)[:gateway] if @conf['Gateway:'].nil?
flen = 20
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen)
loop do
items = []
label = "IP:"
data = form_data.new
data.label = label
data.ly = 1
data.lx = 1
data.item = @conf[label]
data.iy = 1
data.ix = 10
data.flen = flen
data.ilen = 0
items.push(data.to_a)
label = "Netmask:"
data = form_data.new
data.label = label
data.ly = 2
data.lx = 1
data.item = @conf[label]
data.iy = 2
data.ix = 10
data.flen = flen
data.ilen = 0
items.push(data.to_a)
label = "Gateway:"
data = form_data.new
data.label = label
data.ly = 3
data.lx = 1
data.item = @conf[label]
data.iy = 3
data.ix = 10
data.flen = flen
data.ilen = 0
items.push(data.to_a)
dialog.title = "Network configuration for #{@device_name}"
@conf = dialog.form(text, items, 20, 60, 0)
# need to check result
if @conf.empty?
# Cancel was pressed
break
else
# ok pressed
@conf['Mode:'] = "Static"
if Config_utils.check_ipv4({:ip => @conf['IP:']}) and Config_utils.check_ipv4({:netmask => @conf['Netmask:']})
# seems to be ok
unless @conf['Gateway:'] == "" || Config_utils.check_ipv4({:ip => @conf['Gateway:']})
next
end
else
# error detected
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Network Configuration Error"
text = <<EOF
An error has been detected in the network configuration.
Please review the IP, Netmask, and Gateway address settings.
EOF
dialog.msgbox(text, 10, 41)
next
end
break
end
end
end
end
class MemcachedConf < WizConf
attr_accessor :conf, :cancel
def initialize()
@cancel = false
@conf = {}
end
def doit
memcached_config = {
"cfg_address"=>"",
"cfg_port"=>11211
}
loop do
dialog = MRDialog.new
dialog.clear = true
text = <<EOF
Please configure the Memcached service.
Memcached is a distributed memory object caching system that stores key-value pairs in memory.
It is used to speed up dynamic database-driven websites by caching data and objects in memory
to reduce the number of times an external data source must be read.
EOF
items = []
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen, :attr)
label = "Memcached domain:"
data = form_data.new
data.label = label
data.ly = 1
data.lx = 1
data.item = memcached_config[label]
data.iy = 1
data.ix = 20
data.flen = 30
data.ilen = 0
data.attr = 0
items.push(data.to_a)
label = "Memcached port:"
data = form_data.new
data.label = label
data.ly = 2
data.lx = 1
data.item = memcached_config[label]
data.iy = 2
data.ix = 20
data.flen = 30
data.ilen = 0
data.attr = 0
items.push(data.to_a)
dialog.title = "Memcached Configuration"
memcached_config = dialog.mixedform(text, items, 20, 60, 0)
if memcached_config.empty?
@cancel = true
break
else
break
end
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Memcached Configuration Error"
text = <<EOF
An error has been detected in the Memcached configuration.
Please review the settings and ensure that the host and port are valid.
EOF
dialog.msgbox(text, 12, 60)
end
@conf['cfg_address'] = memcached_config['Memcached domain:']
@conf['cfg_port'] = memcached_config['Memcached port:']
end
end
class HostConf < WizConf
attr_accessor :conf, :cancel
def initialize()
@cancel = false
@conf = {}
end
def doit
host = {}
@conf["Hostname:"] = ""
@conf["Domain name:"] = ""
fullhostname = `hostnamectl --static`.chomp
unless fullhostname.match(/^(?<hostname>[^.]+)(\.(?<domain>.*))?$/).nil?
@conf["Hostname:"] = fullhostname.match(/^(?<hostname>[^.]+)(\.(?<domain>.*))?$/)[:hostname]
@conf["Domain name:"] = fullhostname.match(/^(?<hostname>[^.]+)(\.(?<domain>.*))?$/)[:domain]
end
if @conf["Hostname:"] == "rbmanager" or @conf["Hostname:"] == "localhost" or @conf["Hostname:"] = ""
@conf["Hostname:"] = "rb-#{rand(36**10).to_s(36)}"
@conf["Domain name:"] = "redborder.cluster"
end
loop do
dialog = MRDialog.new
dialog.clear = true
dialog.insecure = true
text = <<EOF
Please enter the hostname and domain name for the device.
The hostname can include only ASCII letters ('a' to 'z', case-insensitive), digits ('0' to '9'), and hyphens ('-'). According to RFC1123, hostname labels can begin with a letter or digit but cannot start or end with a hyphen.
Additionally, each label in the hostname and domain name must be between 1 and 63 characters, and the entire hostname must not exceed 253 ASCII characters.
For guidance on choosing an appropriate hostname, please refer to RFC1178.
EOF
items = []
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen, :attr)
items = []
label = "Hostname:"
data = form_data.new
data.label = label
data.ly = 1
data.lx = 1
data.item = @conf[label]
data.iy = 1
data.ix = 14
data.flen = 63
data.ilen = 0
data.attr = 0
items.push(data.to_a)
label = "Domain name:"
data = form_data.new
data.label = label
data.ly = 2
data.lx = 1
data.item = @conf[label]
data.iy = 2
data.ix = 14
data.flen = 253
data.ilen = 0
data.attr = 0
items.push(data.to_a)
dialog.title = "Hostname and Domain Name Configuration"
host = dialog.mixedform(text, items, 20, 80, 0)
if host.empty?
# Cancel button pushed
@cancel = true
break
else
if Config_utils.check_hostname(host["Hostname:"]) and Config_utils.check_domain(host["Domain name:"])
# need to confirm lenght
if host["Hostname:"].length < 64 and (host["Hostname:"].length + host["Domain name:"].length) < 254
break
end
end
end
# error, do another loop
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Hostname or Domain Name Configuration Error"
text = <<EOF
An error has been detected in the hostname or domain name configuration.
Please review the character set and length to ensure they meet the required standards.
EOF
dialog.msgbox(text, 0, 0)
end
@conf[:hostname] = host["Hostname:"]
@conf[:domainname] = host["Domain name:"]
end
end
class DNSConf < WizConf
attr_accessor :conf, :cancel
def initialize()
@cancel = false
@conf = []
end
def doit
dns = {}
count=1
@conf.each do |x|
dns["DNS#{count}:"] = x
count+=1
end
loop do
dialog = MRDialog.new
dialog.clear = true
dialog.insecure = true
text = <<EOF
Please, set DNS servers.
You can set up to 3 DNS servers, but only one is mandatory. Set DNS values in order, first, second (optional) and then third (optional).
Please, insert each value fo IPv4 address in dot notation.
EOF
items = []
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen, :attr)
items = []
label = "DNS1:"
data = form_data.new
data.label = label
data.ly = 1
data.lx = 1
data.item = dns[label]
data.iy = 1
data.ix = 8
data.flen = 16
data.ilen = 0
data.attr = 0
items.push(data.to_a)
label = "DNS2:"
data = form_data.new
data.label = label
data.ly = 2
data.lx = 1
data.item = dns[label]
data.iy = 2
data.ix = 8
data.flen = 16
data.ilen = 0
data.attr = 0
items.push(data.to_a)
label = "DNS3:"
data = form_data.new
data.label = label
data.ly = 3
data.lx = 1
data.item = dns[label]
data.iy = 3
data.ix = 8
data.flen = 16
data.ilen = 0
data.attr = 0
items.push(data.to_a)
dialog.title = "DNS Configuration"
dns = dialog.mixedform(text, items, 20, 60, 0)
if dns.empty?
# Cancel button pushed
@cancel = true
break
else
if Config_utils.check_ipv4({:ip=>dns["DNS1:"]})
unless dns["DNS2:"].empty?
if Config_utils.check_ipv4({:ip=>dns["DNS2:"]})
unless dns["DNS3:"].empty?
if Config_utils.check_ipv4({:ip=>dns["DNS3:"]})
break
end
else
break
end
end
else
break
end
end
end
# error, do another loop
dialog = MRDialog.new
dialog.clear = true
dialog.title = "DNS Configuration Error"
text = <<EOF
An error has been detected in the DNS or search configuration.
Please review the DNS settings and ensure that only IPv4 addresses in dot notation are used.
EOF
dialog.msgbox(text, 12, 60)
end
unless dns.empty?
@conf << dns["DNS1:"]
unless dns["DNS2:"].empty?
@conf << dns["DNS2:"]
unless dns["DNS3:"].empty?
@conf << dns["DNS3:"]
end
end
end
end
end
class SerfSyncDevConf < WizConf
attr_accessor :conf, :cancel, :networks
def initialize()
@cancel = false
@returning_from_cancel = false
@conf = ""
@networks = {}
end
def doit(sync_interface)
dialog = MRDialog.new
dialog.clear = true
text = <<EOF
Please configure the synchronism network.
Select one of the device networks to designate as the synchronism network. This network is essential for connecting nodes and building the cluster. It also facilitates communication between internal services.
In some cases, the synchronism network may not have a default gateway and could be isolated from other networks.
EOF
network_interfaces = []
radiolist_data = Struct.new(:tag, :item, :select)
select = true
networks.each do |k,v|
data = radiolist_data.new
data.tag = k
data.item = v
data.select = select
if k == sync_interface
data.select = true
select = false
else
data.select = false
end
network_interfaces.push(data.to_a)
end
network_interfaces.push(radiolist_data.new("Manual", "Manually set a sync network", false).to_a)
dialog.title = "Synchronism Network configuration"
loop do
sync_interface = dialog.radiolist("Please select a network to use as the synchronism network:",
network_interfaces, 10, 80, 0)
return cancel_wizard unless sync_interface
sync_network = network_interfaces.find { |ni| ni[0] == sync_interface }[1]
self.conf = configure_interface(sync_network)
break unless @returning_from_cancel
@returning_from_cancel = false
end
end
def configure_interface(sync_network)
synchronism_network_config = SerfSyncConf.new(sync_network)
synchronism_network_config.doit()
cancel_wizard if synchronism_network_config.cancel
if synchronism_network_config.conf.empty?
@returning_from_cancel = true
return
else
return synchronism_network_config.conf
end
end
end
class SerfSyncConf < WizConf
attr_accessor :conf, :cancel
def initialize(sync_network)
@cancel = false
@returning_from_cancel = false
@conf = {}
@sync_network = sync_network
end
def doit
if Config_utils.check_ipv4(@sync_network)
sync_netaddr = NetAddr::CIDRv4.create(@sync_network)
return self.conf = "#{sync_netaddr.network}#{sync_netaddr.netmask}"
end
sync = {}
loop do
dialog = MRDialog.new
dialog.clear = true
dialog.insecure = true
text = <<EOF
Please configure the synchronism network.
You need to provide the synchronism network in two formats:
IPv4 CIDR format (e.g., 192.168.1.0/24)
IPv4 mask format (e.g., 192.168.1.0/255.255.255.0)
This network is essential for connecting nodes and building the cluster, as it enables communication between internal services.
In some cases, this network may not have a default gateway and could be isolated from other networks.
EOF
items = []
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen, :attr)
items = []
label = "Sync Network:"
data = form_data.new
data.label = label
data.ly = 1
data.lx = 1
data.item = sync[label]
data.iy = 1
data.ix = 15
data.flen = 31
data.ilen = 0
data.attr = 0
items.push(data.to_a)
dialog.title = "Sync Network Configuration"
sync = dialog.mixedform(text, items, 24, 80, 0)
if dialog.exit_code == dialog.dialog_ok
if Config_utils.check_ipv4(sync["Sync Network:"])
# it is ok
break
else
# error
end
else
# Cancel button pushed
@returning_from_cancel = true
break
end
# error, do another loop
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Sync Network Configuration Error"
text = <<EOF
An error has been detected in the Sync Network configuration.
Please review the settings and ensure that the IPv4 address is in dot notation, followed by either the mask length or the netmask. For example: 192.168.100.0/24.
EOF
dialog.msgbox(text, 15, 41)
end
begin
sync_netaddr = NetAddr::CIDRv4.create(sync["Sync Network:"])
self.conf = "#{sync_netaddr.network}#{sync_netaddr.netmask}"
rescue
end
end
end
class SerfMcastConf < WizConf
attr_accessor :conf, :cancel
def initialize()
@cancel = false
@conf = ""
end
def doit
dialog = MRDialog.new
dialog.clear = true
text = <<EOF
Please select the configuration type:
- Multicast: Configures the Serf agent to operate in Multicast mode. In this mode, Serf automatically discovers the cluster using a multicast address and the domain name as the cluster domain.
- Unicast: Configures the Serf agent to operate in Unicast mode. In this mode, Serf attempts to join an existing cluster by scanning via ARP over the Synchronism network.
In both modes, the Synchronism network is used to identify and bind to the appropriate network device.
EOF
items = []
radiolist_data = Struct.new(:tag, :item, :select)
data = radiolist_data.new
data.tag = "Multicast"
data.item = "Multicast over a cluster domain"
data.select = true # default
items.push(data.to_a)
data = radiolist_data.new
data.tag = "Unicast"
data.item = "Unicast over the synchronism network"
data.select = false # default
items.push(data.to_a)
dialog.title = "Communication Cluster Mode"
selected_item = dialog.radiolist(text, items, 22, 80, 0)
if dialog.exit_code == dialog.dialog_ok
@conf = ( selected_item == "Multicast" ? true : false )
else
@cancel = true
end
end
end
class SerfCryptConf < WizConf
attr_accessor :conf, :cancel
def initialize()
@cancel = false
@conf = ""
end
def doit
result = {}
loop do
dialog = MRDialog.new
dialog.clear = true
dialog.insecure = true
dialog.title = "Serf Encryption Key"
text = <<EOF
Please provide a password to encrypt Serf network traffic.
This password will prevent unauthorized nodes from connecting to the cluster. You may use any printable characters, with a length of 6 to 20 characters.
EOF
flen = 20
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen)
items = []
label = "Password:"
data = form_data.new
data.label = label
data.ly = 1
data.lx = 1
data.item = ""
data.iy = 1
data.ix = 15
data.flen = flen
data.ilen = 0
items.push(data.to_a)
label = "Enter again:"
data = form_data.new
data.label = label
data.ly = 2
data.lx = 1
data.item = ""
data.iy = 2
data.ix = 15
data.flen = flen
data.ilen = 0
items.push(data.to_a)
result = dialog.passwordform(text, items, 16, 60, 0)
if dialog.exit_code == dialog.dialog_ok
if result["Password:"] == result["Enter again:"]
if result["Password:"].length < 6 or result["Password:"].length > 20
# error, incorrect length
else
# it is ok
break
end
else
# error, password does not match
end
else
@cancel = true
break
end
# error, do another loop
dialog = MRDialog.new
dialog.clear = true
dialog.title = "Serf Encryption Key Error"
text = <<EOF
An error has been detected in the Serf encryption key.
Please ensure the key is between 6 and 20 characters long, and that both fields match.
EOF
dialog.msgbox(text, 12, 60)
end
@conf = Config_utils.get_encrypt_key(result["Password:"])
end
end
class ModeConf < WizConf
attr_accessor :conf, :cancel
def initialize()
@cancel = false
@conf = ""
end
def doit
modelist = [
{"name"=>"custom", "description"=>"Minimum set of services to join into a cluster"},
{"name"=>"core", "description"=>"Basic set of services to create a cluster"},
{"name"=>"full", "description"=>"All services running to perform a full cluster experience"}
] # default values
if File.exist?("#{ENV['RBDIR']}/mode-list.yml")
modelist = YAML.load_file("#{ENV['RBDIR']}/mode-list.yml")
end
dialog = MRDialog.new
dialog.clear = true
text = <<EOF
Please select the mode of operation for the manager node.
- If this is the first installation of a Redborder manager and you plan to create a cluster with multiple nodes, select 'core' mode.
- For additional nodes in the cluster, choose 'custom' mode.
- If this is a standalone manager installation, select 'full' mode.