/
widgets.rb
1849 lines (1705 loc) · 59.4 KB
/
widgets.rb
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
# encoding: utf-8
# File: clients/ntp-client.ycp
# Package: Configuration of ntp-client
# Summary: Main file
# Authors: Jiri Srain <jsrain@suse.cz>
#
# $Id$
#
# Main file for ntp-client configuration. Uses all other files.
module Yast
module NtpClientWidgetsInclude
def initialize_ntp_client_widgets(include_target)
textdomain "ntp-client"
Yast.import "Confirm"
Yast.import "Popup"
Yast.import "Label"
Yast.import "LogView"
Yast.import "SLPAPI"
Yast.import "NetworkInterfaces"
Yast.import "NetworkService"
Yast.import "NtpClient"
Yast.import "CWMFirewallInterfaces"
Yast.import "Report"
Yast.import "Hostname"
Yast.import "IP"
Yast.import "Progress"
Yast.include include_target, "ntp-client/helps.rb"
Yast.include include_target, "ntp-client/dialogs.rb"
# selected type of peer
@peer_type_selected = nil
# List of NTP servers already found
@found_servers_cache = nil
# The 'Current Record' when NTP is being initialized, see bug 177575
@selected_record_during_init = {}
# if there was some server defined before pool_ntp_org was selected
@ntp_server_before_random_servers = ""
@last_country = nil
end
# Save the configuration and restart NTP deamon
def SilentWrite
orig_progress = Progress.set(false)
ret = NtpClient.Write
Progress.set(orig_progress)
ret
end
# Show popup with NTP daemon's log
def showLogPopup
LogView.Display(
{
"file" => "/var/log/ntp",
"save" => true,
"actions" => [
# menubutton entry, try to keep short
[
_("Restart NTP Daemon"),
fun_ref(method(:restartNtpDaemon), "void ()")
],
# menubutton entry, try to keep short
[
_("Save Settings and Restart NTP Daemon"),
fun_ref(method(:SilentWrite), "boolean ()")
]
]
}
)
nil
end
# Handle function of the widget
# @param [String] id string widget id
# @param [Hash] event map event that caused storing process
# @return [Symbol] always nil
def ntpEnabledOrDisabled(id, event)
event = deep_copy(event)
ev_id = Ops.get(event, "ID")
if ev_id == "boot" || ev_id == "never" || ev_id == "sync"
enabled = UI.QueryWidget(Id("start"), :CurrentButton) != "never"
UI.ChangeWidget(Id(id), :Enabled, enabled)
end
nil
end
# Handle function of the widget
# @param [String] id string widget id
# @param [Hash] event map event that caused storing process
# @return [Symbol] always nil
def timeSyncOrNo(id, event)
event = deep_copy(event)
ev_id = Ops.get(event, "ID")
if ev_id == "boot" || ev_id == "never" || ev_id == "sync"
enabled = UI.QueryWidget(Id("start"), :CurrentButton) == "sync"
UI.ChangeWidget(Id(id), :Enabled, enabled)
end
nil
end
# Initialize the widget
# @param [String] id any widget id
def intervalInit(id)
UI.ChangeWidget(Id("interval"), :Value, NtpClient.sync_interval)
enabled = UI.QueryWidget(Id("start"), :CurrentButton) == "sync"
UI.ChangeWidget(Id("interval"), :Enabled, enabled)
nil
end
# Store settings of the widget
# @param [String] id any widget id
# @param [Hash] event map event that caused storing process
def intervalStore(id, event)
event = deep_copy(event)
NtpClient.sync_interval = Convert.to_integer(
UI.QueryWidget(Id("interval"), :Value)
)
nil
end
# Initialize the widget
# @param [String] id any widget id
def startInit(id)
if NtpClient.synchronize_time
UI.ChangeWidget(Id("start"), :CurrentButton, "sync")
elsif NtpClient.run_service
UI.ChangeWidget(Id("start"), :CurrentButton, "boot")
else
UI.ChangeWidget(Id("start"), :CurrentButton, "never")
end
nil
end
# Store settings of the widget
# @param [String] id any widget id
# @param [Hash] event map event that caused storing process
def startStore(id, event)
event = deep_copy(event)
NtpClient.run_service = UI.QueryWidget(Id("start"), :CurrentButton) == "boot"
NtpClient.synchronize_time = UI.QueryWidget(Id("start"), :CurrentButton) == "sync"
nil
end
# Handle function of the widget
# @param [String] id string widget id
# @param [Hash] event map event that caused storing process
# @return [Object] always nil
def startHandle(id, event)
event = deep_copy(event)
start = UI.QueryWidget(Id("start"), :CurrentButton) == "boot"
#All these network devices are possibly started on boot || managed by NM
#hence do not display the message
d1 = NetworkInterfaces.Locate("STARTMODE", "onboot")
d2 = NetworkInterfaces.Locate("STARTMODE", "auto")
d3 = NetworkInterfaces.Locate("STARTMODE", "nfsroot")
d4 = NetworkInterfaces.Locate("STARTMODE", "managed")
devices = Convert.convert(
Builtins.union(Builtins.union(d1, d2), Builtins.union(d3, d4)),
:from => "list",
:to => "list <string>"
)
devices = Builtins.filter(devices) { |d| d != "lo" }
#Do not display this warning if we use NetworkManager (#299666)
if start && !NetworkService.is_network_manager && Builtins.size(devices) == 0 &&
Ops.get_string(event, "EventReason", "") != "" &&
!# continue-cancel popup
Popup.ContinueCancel(
_(
"Warning!\n" +
"\n" +
"If you do not have a permanent Internet connection,\n" +
"starting the NTP daemon can take a very long time and \n" +
"the daemon might not run properly."
)
)
UI.ChangeWidget(Id("start"), :CurrentButton, "never")
end
if start != NtpClient.run_service
Builtins.y2milestone(
"set modified from %1 to true 1",
NtpClient.modified
)
NtpClient.modified = true
end
if start
CWMFirewallInterfaces.EnableOpenFirewallWidget
else
CWMFirewallInterfaces.DisableOpenFirewallWidget
end
if CWMFirewallInterfaces.OpenFirewallModified("firewall")
NtpClient.change_firewall = true
end
nil
end
# Checks the current simple configuration filled in UI.
# Selected option RandomPoolServers returns true;
# Selected valid server address also returns true;
#
# @return [Boolean] whether the configuration is correct
def CheckCurrentSimpleConfiguration(check_the_server)
# if the option "random_servers" is selected, do not check the server name
if UI.WidgetExists(Id("use_random_servers")) &&
Convert.to_boolean(UI.QueryWidget(Id("use_random_servers"), :Value))
return true
end
server_1 = Convert.to_string(UI.QueryWidget(Id("server_address"), :Value))
if !check_the_server && server_1 == ""
Builtins.y2milestone("Not checking an empty server...")
return true
end
server_2 = server_1
if Builtins.regexpmatch(server_2, "(.*).$")
server_2 = Builtins.regexpsub(server_2, "(.*).$", "\\1")
end
if !Hostname.Check(server_1) && !Hostname.CheckFQ(server_1) &&
!IP.Check(server_1) &&
!Hostname.Check(server_2) && !Hostname.CheckFQ(server_2)
# TRANSLATORS: Popup error message
Report.Error(
Builtins.sformat(
_(
"NTP server '%1' is not a valid hostname,\nfully qualified hostname, IPv4 address, or IPv6 address."
),
server_1
)
)
return false
end
true
end
# Check the current confifuration and returns whether some server address is defined
def ServerAddressIsInConfiguration
ret = false
rss = NtpClient.IsRandomServersServiceEnabled
Builtins.foreach(NtpClient.ntp_records) do |one_record|
# checking for server
if Ops.get(one_record, "type") == "server"
# RandomServersService is disabled
if !rss
ret = true
raise Break
# RandomServersService is enabled, don't take servers from RSS
elsif !Builtins.contains(
NtpClient.random_pool_servers,
Ops.get_string(one_record, "address", "")
)
ret = true
raise Break
end
end
end
ret
end
# Handle function of the widget
# @param [String] key any widget id
# @param [Hash] event map event that caused storing process
# @return [Symbol] always `complex
def complexButtonHandle(key, event)
event = deep_copy(event)
if Ops.get(event, "ID") == "complex_button"
# true - check and report the missing server value
# false - the opposite
handle_the_server = Convert.to_string(
UI.QueryWidget(Id("server_address"), :Value)
) != ""
conf_check = CheckCurrentSimpleConfiguration(handle_the_server)
Builtins.y2milestone(
"Checking the current simple configuration returned: %1",
conf_check
)
Ops.set(
NtpClient.selected_record,
"address",
UI.QueryWidget(Id("server_address"), :Value)
)
# disabled in case of PoolNTPorg feature
# and in case of missing server value
if Convert.to_boolean(UI.QueryWidget(Id("server_address"), :Enabled)) &&
Ops.get(NtpClient.selected_record, "address") != nil &&
Ops.get_string(NtpClient.selected_record, "address", "") != ""
# Save the server_address only when changed
# do not re-add it (with defaut values) - bug 177575
if Ops.get_string(@selected_record_during_init, "address", "") ==
Ops.get_string(NtpClient.selected_record, "address", "")
Builtins.y2milestone(
"The currently selected server is the same as when starting the module..."
)
else
Ops.set(NtpClient.selected_record, "type", "server")
Builtins.y2milestone(
"Storing the current address record: %1",
NtpClient.selected_record
)
NtpClient.storeSyncRecord
end
# deleting the current record if current server address is empty
elsif Ops.get_string(NtpClient.selected_record, "address", "") == ""
# delete only the server record if there is some current server record
if ServerAddressIsInConfiguration()
NtpClient.selected_record = nil
NtpClient.storeSyncRecord
end
end
Builtins.y2milestone("Switching to advanced configuration...")
return :complex
end
ntpEnabledOrDisabled(key, event)
nil
end
# Handle function of the widget
# @param [String] key string widget id
# @param [Hash] event map event that caused storing process
# @return [Symbol] always `complex
def fudgeButtonHandle(key, event)
event = deep_copy(event)
:fudge
end
# Initialize the widget
# @param [String] id any widget id
def chrootInit(id)
UI.ChangeWidget(Id(id), :Value, NtpClient.run_chroot)
nil
end
# Store settings of the widget
# @param [String] id any widget id
# @param [Hash] event map event that caused storing process
def chrootStore(id, event)
event = deep_copy(event)
tmp = NtpClient.run_chroot
NtpClient.run_chroot = Convert.to_boolean(UI.QueryWidget(Id(id), :Value))
if tmp != NtpClient.run_chroot
Builtins.y2milestone(
"set modified from %1 to true 2",
NtpClient.modified
)
NtpClient.modified = true
end
nil
end
def secureInit(id)
Builtins.y2milestone("Restrict %1", NtpClient.restrict_map)
if NtpClient.PolicyIsNonstatic
UI.ChangeWidget(Id("secure"), :Enabled, false)
else
UI.ChangeWidget(Id("secure"), :Value, NtpClient.restrict_map != {})
end
nil
end
def secureStore(id, event)
event = deep_copy(event)
restrict = Convert.to_boolean(UI.QueryWidget(Id(id), :Value))
if restrict
servers = NtpClient.GetUsedNtpServers
if NtpClient.restrict_map == {}
Ops.set(
NtpClient.restrict_map,
"default",
{ "mask" => "", "comment" => "", "options" => "ignore" }
)
Ops.set(
NtpClient.restrict_map,
"127.0.0.1",
{ "mask" => "", "comment" => "", "options" => "" }
)
Builtins.foreach(servers) do |s|
Ops.set(
NtpClient.restrict_map,
s,
{
"mask" => "",
"comment" => "",
"options" => "nomodify notrap noquery"
}
)
end
end
else
NtpClient.restrict_map = {}
end
nil
end
# Initialize the widget
# @param [String] id any widget id
def PolicyInit(id)
if NtpClient.PolicyIsNomodify
UI.ChangeWidget(Id("policy_combo"), :Value, Id(:nomodify))
UI.ChangeWidget(Id("custom_policy"), :Value, "")
UI.ChangeWidget(Id("custom_policy"), :Enabled, false)
elsif NtpClient.PolicyIsAuto
UI.ChangeWidget(Id("policy_combo"), :Value, Id(:auto))
UI.ChangeWidget(Id("custom_policy"), :Value, "")
UI.ChangeWidget(Id("custom_policy"), :Enabled, false)
else
UI.ChangeWidget(Id("policy_combo"), :Value, Id(:custom))
UI.ChangeWidget(Id("custom_policy"), :Value, NtpClient.ntp_policy)
UI.ChangeWidget(Id("custom_policy"), :Enabled, true)
end
nil
end
# Store settings of the widget
# @param [String] id any widget id
# @param [Hash] event map event that caused storing process
def PolicyStore(id, event)
event = deep_copy(event)
tmp = NtpClient.ntp_policy
if UI.QueryWidget(Id("policy_combo"), :Value) == :nomodify
NtpClient.ntp_policy = ""
elsif UI.QueryWidget(Id("policy_combo"), :Value) == :auto
NtpClient.ntp_policy = "auto"
else
NtpClient.ntp_policy = Convert.to_string(
UI.QueryWidget(Id("custom_policy"), :Value)
)
end
if tmp != NtpClient.ntp_policy
Builtins.y2milestone("set modified to true 3")
NtpClient.modified = true
end
nil
end
def RandomServersInit(id)
ntpEnabledOrDisabled(id, {})
return nil if id != "use_random_servers"
Builtins.y2milestone("Initializing random servers")
rnd_servers = NtpClient.IsRandomServersServiceEnabled
if rnd_servers
# Random servers function is enabled
UI.ChangeWidget(Id("use_random_servers"), :Value, true)
UI.ChangeWidget(Id("server_address"), :Enabled, false)
UI.ChangeWidget(Id(:select_server), :Enabled, false)
UI.ChangeWidget(Id("server_address"), :Value, "")
else
# Random servers function is disabled
UI.ChangeWidget(Id("use_random_servers"), :Value, false)
if NtpClient.run_service || NtpClient.synchronize_time
UI.ChangeWidget(Id("server_address"), :Enabled, true)
UI.ChangeWidget(Id(:select_server), :Enabled, true)
else
UI.ChangeWidget(Id("server_address"), :Enabled, false)
UI.ChangeWidget(Id(:select_server), :Enabled, false)
end
end
nil
end
def RandomServersStore(id, event)
event = deep_copy(event)
return nil if id != "use_random_servers"
if Convert.to_boolean(UI.QueryWidget(Id("use_random_servers"), :Value))
NtpClient.ActivateRandomPoolServersFunction
else
NtpClient.DeActivateRandomPoolServersFunction
end
nil
end
# Function handles the "use_random_servers" checkbox
def RandomServersHandle(id, event)
event = deep_copy(event)
ntpEnabledOrDisabled(id, event)
# do not handle anything when called by pressing the checkbox
return nil if id != "use_random_servers"
return nil if Ops.get_string(event, "EventReason", "") != "ValueChanged"
if Ops.get_string(event, "WidgetID", "") != "use_random_servers"
return nil
end
Builtins.y2milestone("Handling random_servers")
use_random_servers = Convert.to_boolean(
UI.QueryWidget(Id("use_random_servers"), :Value)
)
# If random servers are selected, user is not allowed to enter his/her own NTP server
if use_random_servers
Builtins.y2milestone("Activating random servers")
@ntp_server_before_random_servers = Convert.to_string(
UI.QueryWidget(Id("server_address"), :Value)
)
# if there is already some server defined
if @ntp_server_before_random_servers != ""
if !Popup.ContinueCancel(
_(
"Enabling Random Servers from pool.ntp.org would\n" +
"replace the current NTP server.\n" +
"\n" +
"Really replace the current NTP server?"
)
)
# user has cancelled the operation, return it back
UI.ChangeWidget(Id("use_random_servers"), :Value, false)
return nil
end
end
UI.ChangeWidget(Id("server_address"), :Enabled, false)
UI.ChangeWidget(Id(:select_server), :Enabled, false)
UI.ChangeWidget(Id("server_address"), :Value, "")
else
Builtins.y2milestone("Deactivating random servers")
UI.ChangeWidget(Id("server_address"), :Enabled, true)
UI.ChangeWidget(Id(:select_server), :Enabled, true)
UI.ChangeWidget(
Id("server_address"),
:Value,
@ntp_server_before_random_servers
)
end
nil
end
# Redraw the overview table
def overviewRedraw
types = {
# table cell, NTP relationship type
"server" => _("Server"),
# table cell, NTP relationship type
"peer" => _("Peer"),
# table cell, NTP relationship type
"broadcast" => _(
"Outgoing Broadcast"
),
# table cell, NTP relationship type
"broadcastclient" => _(
"Incoming Broadcast"
)
}
items = Builtins.maplist(NtpClient.getSyncRecords) do |i|
type = Ops.get_string(i, "type", "")
address = Ops.get_string(i, "address", "")
index = Ops.get_integer(i, "index", -1)
if type == "__clock"
clock_type = getClockType(address)
unit_number = getClockUnitNumber(address)
device = Ops.get_string(i, "device", "")
if device == ""
# table cell, %1 is integer 0-3
device = Builtins.sformat(_("Unit Number: %1"), unit_number)
end
device = "" if clock_type == 1 && unit_number == 0
clock_name = Ops.get(@clock_types, [clock_type, "name"], "")
if clock_name == ""
# table cell, NTP relationship type
clock_name = _("Local Radio Clock")
end
next Item(Id(index), clock_name, device)
end
Item(Id(index), Ops.get_string(types, type, ""), address)
end
UI.ChangeWidget(Id(:overview), :Items, items)
UI.SetFocus(Id(:overview))
nil
end
# Handle events on the widget
# @param [String] id any widget id
# @param [Hash] event map event that caused storing process
# @return [Object] event to pass to WS or nil
def overviewHandle(id, event)
event = deep_copy(event)
# ntpEnabledOrDisabled (id, event);
if Ops.get(event, "ID") == :display_log
showLogPopup
return nil
end
ev_id = Ops.get(event, "ID")
if ev_id == "boot" || ev_id == "never" || ev_id == "sync" ||
ev_id == "policy_combo"
pol = Convert.to_symbol(UI.QueryWidget(Id("policy_combo"), :Value))
enabled = UI.QueryWidget(Id("start"), :CurrentButton) != "never"
# UI::ChangeWidget (`id (`advanced), `Enabled, enabled);
enabled = enabled && pol != :nomodify
UI.ChangeWidget(Id(:add), :Enabled, enabled)
UI.ChangeWidget(Id(:edit), :Enabled, enabled)
UI.ChangeWidget(Id(:delete), :Enabled, enabled)
UI.ChangeWidget(Id(:overview), :Enabled, enabled)
if enabled && pol == :custom
UI.ChangeWidget(Id("custom_policy"), :Enabled, true)
UI.ChangeWidget(Id("custom_policy"), :Value, NtpClient.ntp_policy)
else
UI.ChangeWidget(Id("custom_policy"), :Enabled, false)
UI.ChangeWidget(Id("custom_policy"), :Value, "")
end
Builtins.y2milestone(
"set modified from %1 to true 4.1 id %2 map %3",
NtpClient.modified,
id,
event
)
NtpClient.modified = true
return nil
end
types = {
"server" => :server,
"peer" => :peer,
"__clock" => :clock,
"broadcast" => :bcast,
"broadcastclient" => :bcastclient
}
if Ops.get(event, "ID") == :add
NtpClient.selectSyncRecord(-1)
@peer_type_selected = nil
Builtins.y2milestone(
"set modified from %1 to true 4.2 id %2 map %3",
NtpClient.modified,
id,
event
)
NtpClient.modified = true
return :add
elsif Ops.get(event, "ID") == :edit || Ops.get(event, "ID") == :overview
NtpClient.selectSyncRecord(
Convert.to_integer(UI.QueryWidget(Id(:overview), :CurrentItem))
)
type = Ops.get_string(NtpClient.selected_record, "type", "")
Builtins.y2milestone(
"set modified from %1 to true 4.3 id %2 map %3",
NtpClient.modified,
id,
event
)
NtpClient.modified = true
return Ops.get(types, type)
elsif Ops.get(event, "ID") == :delete
# yes-no popup
if Confirm.DeleteSelected
NtpClient.deleteSyncRecord(
Convert.to_integer(UI.QueryWidget(Id(:overview), :CurrentItem))
)
overviewRedraw
@sync_record_modified = true
Builtins.y2milestone(
"set modified from %1 to true 4.4 id %2 map %3",
NtpClient.modified,
id,
event
)
NtpClient.modified = true
end
end
nil
end
# Initialize the widget
# @param [String] id any widget id
def overviewInit(id)
tmp = NtpClient.modified
overviewRedraw
overviewHandle(id, { "ID" => "boot" })
NtpClient.modified = tmp
nil
end
# Initialize the widget
# @param [String] id any widget id
def addressInit(id)
#remember selected_record_during_init only when the module is started
##230240
if @selected_record_during_init == {}
@selected_record_during_init = deep_copy(NtpClient.selected_record)
end
ad = NtpClient.ad_controller
if ad != ""
UI.ChangeWidget(Id(id), :Value, ad)
else
UI.ChangeWidget(
Id(id),
:Value,
Ops.get_string(NtpClient.selected_record, "address", "")
)
end
UI.SetFocus(Id(id))
nil
end
# Store settings of the widget
# @param [String] id any widget id
# @param [Hash] event map event that caused storing process
def addressStore(id, event)
event = deep_copy(event)
# Don't store anything in case of switching to the advanced configuration
return if Ops.get(event, "ID") == :complex
Ops.set(
NtpClient.selected_record,
"address",
UI.QueryWidget(Id(id), :Value)
)
if NtpClient.simple_dialog
# Save the server_address only when changed
# do not re-add it (with defaut values) - bug 177575
if Ops.get_string(@selected_record_during_init, "address", "") ==
Ops.get_string(NtpClient.selected_record, "address", "")
Builtins.y2milestone(
"The currently selected server is the same as when starting the module..."
)
else
Builtins.y2milestone(
"Storing the server address in simple configuration"
)
Ops.set(NtpClient.selected_record, "type", "server")
end
end
nil
end
# Handle events on the widget
# @param [String] id string widget id
# @param [Hash] event map event that caused storing process
# @return [Boolean] is successful
def serverAddressValidate(id, event)
event = deep_copy(event)
# NTP Client is disabled, do not check the server name
if Ops.get(event, "ID") == :next && UI.WidgetExists(Id("start")) &&
Convert.to_string(UI.QueryWidget(Id("start"), :CurrentButton)) == "never"
return true
end
# do not check the server IP/Host when changing dialog to "Select"
# or when switching to the advanced configuration
if Ops.get(event, "ID") == :select_local ||
Ops.get(event, "ID") == :select_public ||
Ops.get(event, "ID") == :complex
return true
end
CheckCurrentSimpleConfiguration(true)
end
# Handle events on the widget
# @param [String] id string widget id
# @param [Hash] event map event that caused storing process
# @return [Symbol] event to pass to WS or nil
def serverAddressHandle(id, event)
event = deep_copy(event)
ev_id = Ops.get(event, "ID")
server = Convert.to_string(UI.QueryWidget(Id(id), :Value))
if ev_id == "boot" || ev_id == "never"
enabled = UI.QueryWidget(Id("start"), :CurrentButton) != "never"
# checkbox selected - random servers feature
if UI.QueryWidget(Id("use_random_servers"), :Value) == true
UI.ChangeWidget(Id(id), :Enabled, false)
UI.ChangeWidget(Id(:select_server), :Enabled, false)
else
UI.ChangeWidget(Id(id), :Enabled, enabled)
UI.ChangeWidget(Id(:select_server), :Enabled, enabled)
end
UI.ChangeWidget(Id(:test_server), :Enabled, enabled)
return nil
end
if ev_id == :test_server
if UI.WidgetExists(Id("use_random_servers")) &&
Convert.to_boolean(UI.QueryWidget(Id("use_random_servers"), :Value))
NtpClient.TestNtpServer(
Ops.get(
NtpClient.random_pool_servers,
Builtins.random(4),
"0.pool.ntp.org"
),
:result_popup
)
else
if serverAddressValidate("server_address", {})
NtpClient.TestNtpServer(server, :result_popup)
end
end
elsif ev_id == :select_local
return :select_local
elsif ev_id == :select_public
return :select_public
end
nil
end
# Initialize the widget
# @param [String] id any widget id
def optionsInit(id)
# bnc#438704, add a recommended option
UI.ChangeWidget(
Id("options"),
:Value,
Ops.get_string(NtpClient.selected_record, "options", "iburst")
)
nil
end
# Store settings of the widget
# @param [String] id any widget id
# @param [Hash] event map event that caused storing process
def optionsStore(id, event)
event = deep_copy(event)
Ops.set(
NtpClient.selected_record,
"options",
UI.QueryWidget(Id("options"), :Value)
)
nil
end
def restrictOptionsInit(id)
address = Ops.get_string(NtpClient.selected_record, "address", "")
if NtpClient.restrict_map == {} || NtpClient.PolicyIsNonstatic
UI.ChangeWidget(Id("ac_options"), :Enabled, false)
else
if Builtins.haskey(NtpClient.restrict_map, address)
UI.ChangeWidget(
Id("ac_options"),
:Value,
Ops.get_string(NtpClient.restrict_map, [address, "options"], "")
)
else
UI.ChangeWidget(Id("ac_options"), :Value, "notrap nomodify noquery")
end
end
nil
end
def restrictOptionsStore(id, event)
event = deep_copy(event)
address = Ops.get_string(NtpClient.selected_record, "address", "")
opts = Convert.to_string(UI.QueryWidget(Id("ac_options"), :Value))
return if address == ""
if NtpClient.PolicyIsNonstatic
NtpClient.restrict_map = {}
return
end
if Builtins.haskey(NtpClient.restrict_map, address)
Ops.set(NtpClient.restrict_map, [address, "options"], opts)
else
Ops.set(
NtpClient.restrict_map,
address,
{ "comment" => "", "mask" => "", "options" => opts }
)
end
nil
end
# Initialize the widget
# @param [String] id any widget id
def peerTypesInit(id)
if @peer_type_selected != nil
UI.ChangeWidget(Id("peer_types"), :CurrentButton, @peer_type_selected)
else
UI.ChangeWidget(Id("peer_types"), :CurrentButton, "server")
end
nil
end
# Handle events on the widget
# @param [String] id any widget id
# @param [Hash] event map event that caused storing process
# @return [Symbol] event to pass to WS or nil
def peerTypesHandle(id, event)
event = deep_copy(event)
@peer_type_selected = Convert.to_string(
UI.QueryWidget(Id("peer_types"), :CurrentButton)
)
types = {
"server" => :server,
"peer" => :peer,
"__clock" => :clock,
"broadcast" => :bcast,
"broadcastclient" => :bcastclient
}
if Ops.get(event, "ID") == :next
Ops.set(NtpClient.selected_record, "type", @peer_type_selected)
return Ops.get(types, @peer_type_selected)
end
nil
end
# Initialize the widget
# @param [String] id string widget id
def createSymlinkInit(id)
UI.ChangeWidget(
Id(id),
:Value,
Ops.get_boolean(NtpClient.selected_record, "create_symlink", false)
)
nil
end
# Handle function of the widget
# @param [String] id string widget id
# @param [Hash] event map event that caused storing process
# @return [Symbol] always nil
def createSymlinkHandle(id, event)
event = deep_copy(event)
active = Convert.to_boolean(UI.QueryWidget(Id("create_symlink"), :Value))
current = 0
if id == "clock_type"
current = Builtins.tointeger(
Convert.to_string(UI.QueryWidget(Id(id), :Value))
)
active = active && Ops.get(@clock_types, [current, "device"], "") == ""
end
UI.ChangeWidget(Id("device"), :Enabled, active)
UI.ChangeWidget(Id("browse"), :Enabled, active)
nil
end
# Store settings of the widget
# @param [String] id string widget id
# @param [Hash] event map event that caused storing process
def createSymlinkStore(id, event)
event = deep_copy(event)
Ops.set(
NtpClient.selected_record,
"create_symlink",
Convert.to_boolean(UI.QueryWidget(Id(id), :Value))
)
nil
end
# Handle function of the widget
# @param [String] id string widget id
# @param [Hash] event map event that caused storing process
# @return [Symbol] always nil
def clockTypeHandle(id, event)
event = deep_copy(event)
current = Builtins.tointeger(
Convert.to_string(UI.QueryWidget(Id(id), :Value))
)
hw_avail = Ops.get(@clock_types, [current, "device"], "") != ""
UI.ChangeWidget(Id("create_symlink"), :Enabled, hw_avail)
createSymlinkHandle(id, event)
end
# Initialize the widget
# @param [String] id string widget id
def clockTypeInit(id)
UI.ChangeWidget(