/
cmdline.rb
1332 lines (1266 loc) · 42.3 KB
/
cmdline.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
# Copyright 2004, Novell, Inc. All rights reserved.
#
# File: dns-server/cmdline.ycp
# Package: DNS Server Configuration
# Summary: Command Line for YaST2 DNS Server
# Authors: Lukas Ocilka <locilka@suse.cz>
#
# $Id$
module Yast
module DnsServerCmdlineInclude
def initialize_dns_server_cmdline(include_target)
textdomain "dns-server"
Yast.import "CommandLine"
Yast.import "String"
Yast.import "DnsServer"
Yast.import "DnsServerAPI"
@cmdline = {
"id" => "dns-server",
# TRANSLATORS: commandline general name of the module in help
"help" => _(
"DNS server configuration"
),
"initialize" => fun_ref(DnsServer.method(:Read), "boolean ()"),
"finish" => fun_ref(DnsServer.method(:Write), "boolean ()"),
"actions" => {
"startup" => {
"handler" => fun_ref(method(:DNSHandlerStartup), "boolean (map)"),
"help" => _("Start-up settings"),
"example" => ["startup show", "startup atboot; startup manual"]
},
"forwarders" => {
"handler" => fun_ref(method(:DNSHandlerForwarders), "boolean (map)"),
# TRANSLATORS: commandline short help for command
"help" => _(
"DNS forwarders"
),
"example" => [
"forwarders show",
"forwarders add ip=125.11.235.1",
"forwarders remove ip=44.82.1.12"
]
},
"logging" => {
"handler" => fun_ref(method(:DNSHandlerLogging), "boolean (map)"),
# TRANSLATORS: commandline short help for command
"help" => _(
"Logging settings"
),
"example" => [
"logging show",
"logging set updates=no transfers=yes",
"logging destination=syslog",
"logging destination=file maxsize=0 file=/var/log/named.log maxversions=0"
]
},
"zones" => {
"handler" => fun_ref(method(:DNSHandlerZones), "boolean (map)"),
# TRANSLATORS: commandline short help for command
"help" => _(
"DNS zones"
),
"example" => [
"zones show",
"zones add name=example.org zonetype=primary",
"zones add name=example.com zonetype=secondary primaryserver=192.168.0.1",
"zones add name=example.com zonetype=forward forwarders=192.168.0.1,192.168.0.2",
"zones remove name=example.org",
"zones set name=example.com primaryserver=192.168.10.1",
"zones set name=example.com forwarders=192.168.0.3"
]
},
"acls" => {
"handler" => fun_ref(method(:DNSHandlerACLs), "boolean (map)"),
# TRANSLATORS: commandline short help for command
"help" => _(
"Access control lists"
),
"examples" => ["acls show"]
},
"transport" => {
"handler" => fun_ref(method(:DNSHandlerTransport), "boolean (map)"),
# TRANSLATORS: commandline short help for command
"help" => _(
"Zone transport rules"
),
"examples" => [
"transport show",
"transport show zone=example.com",
"transport zone=master.com enable=localnets"
]
},
"nameserver" => {
"handler" => fun_ref(
method(:DNSHandlerNameServers),
"boolean (map)"
),
# TRANSLATORS: commandline short help for command, base cmdline command
"help" => _(
"Zone name servers"
),
"example" => [
"nameserver show",
"nameserver show zone=example.com",
"nameserver add zone=example.com ns=ns1",
"nameserver add zone=example.com ns=ns2.example.com.",
"nameserver remove zone=example.com ns=ns2"
]
},
"mailserver" => {
"handler" => fun_ref(
method(:DNSHandlerMailServers),
"boolean (map)"
),
# TRANSLATORS: commandline short help for command, base cmdline command
"help" => _(
"Zone mail servers"
),
"example" => [
"mailserver show",
"mailserver show zone=example.org",
"mailserver add zone=example.org mx=mx1 priority=100",
"mailserver add zone=example.org mx=mx2.example.com. priority=99",
"mailserver remove zone=example.org mx=mx2.example.com. priority=99"
]
},
"soa" => {
"handler" => fun_ref(method(:DNSHandlerSOA), "boolean (map)"),
# TRANSLATORS: commandline short help for command, base cmdline command
"help" => _(
"Start of authority (SOA)"
),
"example" => [
"soa show zone=example.org",
"soa set zone=example.org serial=2006081623 ttl=2D3H20S",
"soa set zone=example.org serial=2006081624 expiry=1W retry=180"
]
},
"dnsrecord" => {
"handler" => fun_ref(
method(:DNSHandlerResourceRecords),
"boolean (map)"
),
# TRANSLATORS: commandline short help for command, base cmdline command
"help" => _(
"Zone resource records, such as A, CNAME, NS, MX, or PTR"
),
"example" => [
"dnsrecord show",
"dnsrecord show zone=example.org",
"dnsrecord show zone=example.org type=A",
"dnsrecord add zone=example.org query=office.example.org. type=NS value=ns3",
"dnsrecord add zone=example.org query=ns3 type=CNAME value=server3.anywhere.net.",
"dnsrecord remove zone=example.org query=office type=A value=192.168.32.1"
]
},
"host" => {
"handler" => fun_ref(
method(:DNSHandlerHostRecords),
"boolean (map)"
),
# TRANSLATORS: commandline short help for command, base cmdline command, A is record type
"help" => _(
"Handles A and corresponding PTR record at once"
),
"example" => [
"host show",
"host show zone=example.org",
"host add zone=master.com hostname=examplehost.example.org. ip=192.168.0.201",
"host remove zone=master.com hostname=examplehost ip=192.168.0.201"
]
}
},
"options" => {
"show" => {
# TRANSLATORS: commandline short help for command
"help" => _(
"Show current settings"
)
},
"atboot" => {
# TRANSLATORS: commandline short help for command
"help" => _(
"Start DNS server in the boot process"
)
},
"manual" => {
# TRANSLATORS: commandline short help for command
"help" => _(
"Start DNS server manually"
)
},
"add" => {
# TRANSLATORS: commandline short help for command
"help" => _(
"Add a new record"
)
},
"remove" => {
# TRANSLATORS: commandline short help for command
"help" => _(
"Remove a record"
)
},
"ip" => {
"type" => "ip4",
# TRANSLATORS: commandline short help for command
"help" => _(
"IPv4 address"
)
},
"destination" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Logging destination (syslog|file)"
)
},
"set" => {
# TRANSLATORS: commandline short help for command
"help" => _(
"Set option"
)
},
"file" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Filename for logging (full path)"
)
},
"maxsize" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Maximum log size [0-9]+(KMG)*"
)
},
"maxversions" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Maximum number of versions for rotation, '0' means no rotation"
)
},
"name" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Zone name"
)
},
"zonetype" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Zone type, primary or secondary"
)
},
"masterserver" => {
"type" => "ip4",
# TRANSLATORS: commandline short help for command
# TRANSLATORS: obsolete option, primaryserver should be used instead
"help" => _(
"DNS zone master server"
)
},
"primaryserver" => {
"type" => "ip4",
# TRANSLATORS: commandline short help for command
"help" => _(
"DNS zone primary server"
)
},
"zone" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Zone name"
)
},
"enable" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Enable option"
)
},
"disable" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Disable option"
)
},
"ns" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Name server (in fully qualified format finished with a dot or relative name)"
)
},
"mx" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Mail server (in fully qualified format finished with a dot or relative name)"
)
},
"priority" => {
"type" => "integer",
# TRANSLATORS: commandline short help for command
"help" => _(
"Mail server priority (number from 0 to 65535)"
)
},
"serial" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Serial number of zone update"
)
},
"ttl" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"General time to live of records in zone"
)
},
"refresh" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"An interval before the zone records should be refreshed"
)
},
"retry" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Interval between retries of failed refresh"
)
},
"expiry" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Interval after which zone records are no longer authoritative"
)
},
"minimum" => {
"type" => "string",
# TRANSLATORS: commandline short help for command, TTL is DNS-Specific (Time to Live), shouldn't be translated
"help" => _(
"Minimum TTL that should be exported with records in this zone"
)
},
"type" => {
"type" => "string",
# TRANSLATORS: commandline short help for command, Types are DNS-Specific, cannot be translated
"help" => _(
"DNS resource record type, such as A, CNAME, NS, MX, or PTR"
)
},
"query" => {
"type" => "string",
# TRANSLATORS: commandline short help for command, DNS query is a question for value when we have a /key/ and type, ('A' record for 'example.org'? -> 192.0.34.166)
"help" => _(
"DNS query, such as example.org for A record"
)
},
"value" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"DNS resource record value, such as 192.0.34.166 for example.org's A record"
)
},
"hostname" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Hostname for the DNS record"
)
},
"queries" => {
"type" => "string",
# TRANSLATORS: commandline short help for command, %1 are possible untranlatable parameters "(yes|no)"
"help" => Builtins.sformat(
_("Log named queries %1"),
"(yes|no)"
)
},
"updates" => {
"type" => "string",
# TRANSLATORS: commandline short help for command, %1 are possible untranlatable parameters "(yes|no)"
"help" => Builtins.sformat(
_("Log zone updates %1"),
"(yes|no)"
)
},
"transfers" => {
"type" => "string",
# TRANSLATORS: commandline short help for command, %1 are possible untranlatable parameters "(yes|no)"
"help" => Builtins.sformat(
_("Log zone transfers %1"),
"(yes|no)"
)
},
"forwarders" => {
"type" => "string",
# TRANSLATORS: commandline short help for command
"help" => _(
"Comma-separated list of zone forwarders"
)
}
},
"mappings" => {
"startup" => ["show", "atboot", "manual"],
"forwarders" => ["show", "add", "remove", "ip"],
"logging" => [
"show",
"destination",
"set",
"file",
"maxsize",
"maxversions",
"queries",
"transfers",
"updates"
],
"zones" => [
"show",
"add",
"remove",
"set",
"name",
"masterserver",
"primaryserver",
"zonetype",
"forwarders"
],
"acls" => ["show"],
"transport" => ["show", "enable", "disable", "zone"],
"nameserver" => ["show", "add", "remove", "ns", "zone"],
"mailserver" => ["show", "add", "remove", "mx", "zone", "priority"],
"soa" => [
"show",
"set",
"zone",
"serial",
"ttl",
"refresh",
"retry",
"expiry",
"minimum"
],
"dnsrecord" => [
"show",
"add",
"remove",
"zone",
"query",
"type",
"value"
],
"host" => ["show", "add", "remove", "zone", "hostname", "ip"]
}
}
Builtins.y2milestone("----------------------------------------")
Builtins.y2milestone(
Builtins.sformat("Starting CommandLine with parameters %1", WFM.Args)
)
CommandLine.Run(@cmdline)
Builtins.y2milestone("----------------------------------------")
# EOF
end
# Wizard Screen function formats and prints unifyied commandline screen
def ScreenWizard(header, content)
CommandLine.Print("")
CommandLine.Print(String.UnderlinedHeader(header, 0))
CommandLine.Print("")
if content != ""
CommandLine.Print(content)
CommandLine.Print("")
end
nil
end
# Function prints commandline error about missing parameter
def Missing(missing_parameter)
CommandLine.Error(
Builtins.sformat(
# TRANSLATORS: command line error message, %1 is a missing required parameter
_("Parameter %1 is required."),
missing_parameter
)
)
nil
end
# Function prints commandline error about unknown value for option
def UnknownValue(cmdline_parameter)
CommandLine.Error(
Builtins.sformat(
# TRANSLATORS: command line error message, %1 is a parameter name
_("Unknown value for parameter %1."),
cmdline_parameter
)
)
nil
end
# Function for handling commandline 'startup'
def DNSHandlerStartup(options)
options = deep_copy(options)
# both cannot be together
if Ops.get(options, "atboot") != nil && Ops.get(options, "manual") != nil
# TRANSLATORS: commandline section header
ScreenWizard(_("Start-Up Settings:"), "")
# TRANSLATORS: commandline error message
CommandLine.Error(_("Only one parameter is allowed."))
# start at boot
elsif Ops.get(options, "atboot") != nil
ScreenWizard(
# TRANSLATORS: commandline section header
_("Start-Up Settings:"),
# TRANSLATORS: commandline progress information
_("Enabling DNS server in the boot process...")
)
DnsServer.SetStartService(true)
return true
# start manually
elsif Ops.get(options, "manual") != nil
ScreenWizard(
# TRANSLATORS: commandline section header
_("Start-Up Settings:"),
# TRANSLATORS: commandline progress information
_("Removing DNS server from the boot process...")
)
DnsServer.SetStartService(false)
return true
# show current state
elsif Ops.get(options, "show") != nil
content = ""
if DnsServer.GetStartService
# TRANSLATORS: commandline DNS service status information
content = _("DNS server is enabled in the boot process.")
else
# TRANSLATORS: commandline DNS service status information
content = _("DNS server needs manual starting.")
end
# TRANSLATORS: commandline section header
ScreenWizard(_("Start-Up Settings:"), content)
return false
end
false
end
# Function for handling commandline 'forwarders'
def DNSHandlerForwarders(options)
options = deep_copy(options)
# show current settings
if Ops.get(options, "show") != nil
table_items = []
Builtins.foreach(DnsServerAPI.GetForwarders) do |ip|
table_items = Builtins.add(table_items, [ip])
end
ScreenWizard(
# TRANSLATORS: commandline section header,
_("Forwarding:"),
# TRANSLATORS: commandline table header item
String.TextTable([_("Forwarder IP")], table_items, {})
)
return false
elsif Ops.get(options, "add") != nil && Ops.get(options, "remove") != nil
# TRANSLATORS: commandline error message
CommandLine.Error(_("Only one action parameter is allowed."))
return false
elsif Ops.get(options, "add") != nil
ip = Ops.get_string(options, "ip", "")
if ip == ""
Missing("ip")
return false
end
return DnsServerAPI.AddForwarder(ip)
elsif Ops.get(options, "remove") != nil
ip = Ops.get_string(options, "ip", "")
if ip == ""
Missing("ip")
return false
end
return DnsServerAPI.RemoveForwarder(ip)
end
false
end
def SetLogTo(settings)
settings = deep_copy(settings)
# $[
# "type" : "file",
# "file" : options["file"]:"",
# "maxsize" : options["maxsize"]:"0",
# "maxversions" : options["maxversions"]:"0"
# ]
if Ops.get(settings, "type") == "syslog"
DnsServerAPI.SetLoggingChannel({ "destination" => "syslog" })
elsif Ops.get(settings, "type") == "file"
DnsServerAPI.SetLoggingChannel(
{
"destination" => "file",
"filename" => Ops.get(settings, "file", ""),
"size" => Ops.get(settings, "maxsize", ""),
"versions" => Ops.get(settings, "maxversions", "")
}
)
else
# unknown logging
Builtins.y2error("Unknown logging type '%1'", Ops.get(settings, "type"))
return
end
nil
end
# Function returns map $[ queries : (yes|no), updates : (yes|no), transfers : (yes|no) ]
def GetLoggingAdditionals
categories = DnsServerAPI.GetLoggingCategories
addlog = { "queries" => "no", "xfer-in" => "no", "xfer-out" => "no" }
Builtins.foreach(categories) do |category|
Ops.set(addlog, category, "yes")
end
deep_copy(addlog)
end
def DNSHandlerLoggingShow
table_items = []
logging_channel = DnsServerAPI.GetLoggingChannel
if Ops.get(logging_channel, "destination", "syslog") == "syslog"
table_items = Builtins.add(
table_items,
[
# TRANSLATORS: commandline table item
_("Logging destination"),
# TRANSLATORS: commandline table item
_("System log")
]
)
elsif Ops.get(logging_channel, "destination", "file") == "file"
table_items = Builtins.add(
table_items,
[
# TRANSLATORS: commandline table item
_("Logging destination"),
# TRANSLATORS: commandline table item
_("File")
]
)
table_items = Builtins.add(
table_items,
[
# TRANSLATORS: commandline table item
_("Filename"),
Ops.get(logging_channel, "filename", "")
]
)
table_items = Builtins.add(
table_items,
[
# TRANSLATORS: commandline table item
_("Maximum size"),
Ops.get(logging_channel, "size", "")
]
)
table_items = Builtins.add(
table_items,
[
# TRANSLATORS: commandline table item
_("Maximum versions"),
Ops.get(logging_channel, "versions", "")
]
)
end
logadds = GetLoggingAdditionals()
# $[ "queries" : "no", "updates" : "no", "transfers" : "no" ]
tabadds_items = []
tabadds_items = Builtins.add(
tabadds_items,
[
# TRANSLATORS: commandline table item, do not translate named
_("Log named queries"),
Ops.get(logadds, "queries", "")
]
)
tabadds_items = Builtins.add(
tabadds_items,
[
# TRANSLATORS: commandline table item
_("Log zone updates"),
Ops.get(logadds, "xfer-in", "")
]
)
tabadds_items = Builtins.add(
tabadds_items,
[
# TRANSLATORS: commandline table item
_("Log zone transfers"),
Ops.get(logadds, "xfer-out", "")
]
)
ScreenWizard(
# TRANSLATORS: commandline section header
_("Logging Settings:"),
Ops.add(
Ops.add(
String.TextTable(
[
# TRANSLATORS: commandline table header item
_("Setting"),
# TRANSLATORS: commandline table header item
_("Value")
],
table_items,
{}
),
"\n\n"
),
String.TextTable(
[
# TRANSLATORS: commandline table header item
_("Logging Rule"),
# TRANSLATORS: commandline table header item
_("Value")
],
tabadds_items,
{}
)
)
)
nil
end
# Function for handling logging settings
def DNSHandlerLogging(options)
options = deep_copy(options)
# show current settings
if Ops.get(options, "show") != nil
DNSHandlerLoggingShow()
elsif Ops.get(options, "destination") != nil
# logging to syslog
if Ops.get(options, "destination") == "syslog"
return DnsServerAPI.SetLoggingChannel({ "destination" => "syslog" })
# logging to file
elsif Ops.get(options, "destination") == "file"
return DnsServerAPI.SetLoggingChannel(
{
"destination" => "file",
"filename" => Ops.get_string(options, "file", ""),
"size" => Ops.get_string(options, "maxsize", ""),
"versions" => Ops.get_string(options, "maxversions", "")
}
)
# unknown value
else
UnknownValue("destination")
return false
end
elsif Ops.get(options, "set") != nil
category_mapping = {
"queries" => "queries",
"updates" => "xfer-in",
"transfers" => "xfer-out"
}
current_categories = DnsServerAPI.GetLoggingCategories
Builtins.foreach(["queries", "updates", "transfers"]) do |category|
if Ops.get(options, category) != nil
enable = Builtins.tolower(Ops.get_string(options, category)) == "yes"
if enable
Builtins.y2milestone("Enabling %1", category)
current_categories = Builtins.toset(
Builtins.add(
current_categories,
Ops.get(category_mapping, category, "")
)
)
else
Builtins.y2milestone("Disabling %1", category)
current_categories = Builtins.filter(current_categories) do |current|
Ops.get(category_mapping, category, "") != current
end
end
end
end
return DnsServerAPI.SetLoggingCategories(current_categories)
end
false
end
def DNSHandlerZonesShow
table_items = []
Builtins.foreach(DnsServerAPI.GetZones) do |zone_name, zone|
masterservers = []
forwarders = []
if ["slave", "secondary"].include?(zone)
masterservers = DnsServerAPI.GetZoneMasterServers(zone_name)
elsif Ops.get(zone, "type") == "forward"
forwarders = DnsServerAPI.GetZoneForwarders(zone_name)
end
table_items = Builtins.add(
table_items,
[
zone_name,
Ops.get(zone, "type"),
Builtins.mergestring(masterservers, ", "),
Builtins.mergestring(forwarders, ", ")
]
)
end
ScreenWizard(
# TRANSLATORS: commandline section header,
_("DNS Zones:"),
# TRANSLATORS: commandline table header item
String.TextTable(
[
# TRANSLATORS: commandline table header item
_("Name"),
# TRANSLATORS: commandline table header item
_("Type"),
# TRANSLATORS: commandline table header item
_("Master Server"),
# TRANSLATORS: commandline table header item
_("Forwarders")
],
table_items,
{}
)
)
false
end
# Function for handling DNS zones in general
def DNSHandlerZones(options)
options = deep_copy(options)
Builtins.y2milestone("Options: %1", options)
# Show current settings
primaryserver = options["masterserver"] || options["primaryserver"]
if Ops.get(options, "show") != nil
return DNSHandlerZonesShow()
# Both Add and Remove defined => Error!
elsif Ops.get(options, "add") != nil && Ops.get(options, "remove") != nil
CommandLine.Error(_("Only one action parameter is allowed."))
return false
# Adding zone
elsif Ops.get(options, "add") != nil
if DnsServerAPI.AddZone(
Ops.get_string(options, "name"),
Ops.get_string(options, "zonetype"),
{ "masterserver" => primaryserver }
)
if Ops.get_string(options, "zonetype") == "forward"
return DnsServerAPI.SetZoneForwarders(
Ops.get_string(options, "name"),
Builtins.splitstring(
Ops.get_string(options, "forwarders", ""),
","
)
)
else
return true
end
else
Builtins.y2error("Cannot add new zone %1", options)
return false
end
# Removing zone
elsif Ops.get(options, "remove") != nil
return DnsServerAPI.RemoveZone(Ops.get_string(options, "name"))
# Changing settings
elsif Ops.get(options, "set") != nil
# Zone MasterServers
if primaryserver != nil
return DnsServerAPI.SetZoneMasterServers(
Ops.get_string(options, "name"),
[primaryserver]
)
# Zone Forwarders
elsif Ops.get(options, "forwarders") != nil
return DnsServerAPI.SetZoneForwarders(
Ops.get_string(options, "name"),
Builtins.splitstring(Ops.get_string(options, "forwarders", ""), ",")
)
end
end
false
end
def DNSHandlerACLsShow
table_items = []
Builtins.foreach(DnsServerAPI.GetACLs) do |name, acl_values|
table_items = Builtins.add(
table_items,
[
name,
Ops.get(acl_values, "default", "no") == "yes" ?
# TRANSLATORS: table item - ACL type
_("Predefined") :
# TRANSLATORS: table item - ACL type
_("Custom"),
Ops.get(acl_values, "value", "")
]
)
end
ScreenWizard(
# TRANSLATORS: commandline section header
_("ACLs:"),
# TRANSLATORS: commandline table header item
String.TextTable(
[
# TRANSLATORS: commandline table header item
_("Name"),
# TRANSLATORS: commandline table header item
_("Type"),
# TRANSLATORS: commandline table header item
_("Value")
],
table_items,
{}
)
)
false
end
def DNSHandlerACLs(options)
options = deep_copy(options)
if Ops.get(options, "show") != nil
DNSHandlerACLsShow()
return false
end
false
end
def DNSHandlerTransportShow(only_for_zone)
table_items = []
Builtins.foreach(DnsServerAPI.GetZones) do |zone_name, zone|
# skipping all zones which arent requested
next if only_for_zone != nil && only_for_zone != zone_name
Builtins.foreach(DnsServerAPI.GetZoneTransportACLs(zone_name)) do |acl|
table_items = Builtins.add(table_items, [zone_name, acl])
end
end
ScreenWizard(
# TRANSLATORS: commandline section header
_("Zone Transport:"),
# TRANSLATORS: commandline table header item
String.TextTable(
[
# TRANSLATORS: commandline table header item
_("Zone"),
# TRANSLATORS: commandline table header item
_("Enabled ACL")
],
table_items,
{}
)
)
true
end