Module: Yast::DhcpServerOptionsInclude

Defined in:
../../src/include/dhcp-server/options.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) array_ip_address_pair_widget

Get popup description map for an option type

Returns:

  • popup description map



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
# File '../../src/include/dhcp-server/options.rb', line 850

def array_ip_address_pair_widget
  {
    "widget"            => :custom,
    "custom_widget"     => VBox(
      ReplacePoint(
        Id(:addresses_rp),
        # selection box
        SelectionBox(Id(:addresses), _("A&ddresses"), [])
      ),
      HBox(HStretch(), PushButton(Id(:delete), Label.DeleteButton)),
      # label (in role of help text)
      Left(Label(_("Separate multiple addresses with spaces."))),
      HBox(
        # push button
        TextEntry(Id(:new_addr), _("&Add Address Pair")),
        VBox(Label(""), PushButton(Id(:add), Label.AddButton))
      )
    ),
    "init"              => fun_ref(
      method(:ip_array_init),
      "void (any, string)"
    ),
    "store"             => fun_ref(
      method(:entry_array_store),
      "void (any, string)"
    ),
    "handle"            => fun_ref(
      method(:ip_pair_array_handle),
      "void (any, string, map)"
    ),
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:ip_pair_array_validate),
      "boolean (any, string, map)"
    )
  }
end

- (Object) array_ip_address_widget

Get popup description map for an option type

Returns:

  • popup description map



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
# File '../../src/include/dhcp-server/options.rb', line 774

def array_ip_address_widget
  {
    "widget"            => :custom,
    "custom_widget"     => VBox(
      ReplacePoint(
        Id(:addresses_rp),
        # selection box
        SelectionBox(Id(:addresses), _("A&ddresses"), [])
      ),
      HBox(HStretch(), PushButton(Id(:delete), Label.DeleteButton)),
      HBox(
        # text entry
        TextEntry(Id(:new_addr), _("&New Address")),
        VBox(Label(""), PushButton(Id(:add), Label.AddButton))
      )
    ),
    "init"              => fun_ref(
      method(:ip_array_init),
      "void (any, string)"
    ),
    "store"             => fun_ref(
      method(:entry_array_store),
      "void (any, string)"
    ),
    "handle"            => fun_ref(
      method(:ip_array_handle),
      "void (any, string, map)"
    ),
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:ip_array_validate),
      "boolean (any, string, map)"
    )
  }
end

- (Object) array_uint16_widget

Get popup description map for an option type

Returns:

  • popup description map



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
# File '../../src/include/dhcp-server/options.rb', line 812

def array_uint16_widget
  {
    "widget"            => :custom,
    "custom_widget"     => VBox(
      ReplacePoint(
        Id(:addresses_rp),
        # selection box
        SelectionBox(Id(:addresses), _("&Values"), [])
      ),
      HBox(HStretch(), PushButton(Id(:delete), Label.DeleteButton)),
      HBox(
        # int field
        IntField(Id(:new_entry), _("&New Value"), 0, 65535, 0),
        VBox(Label(""), PushButton(Id(:add), Label.AddButton))
      )
    ),
    "init"              => fun_ref(
      method(:uint16_array_init),
      "void (any, string)"
    ),
    "store"             => fun_ref(
      method(:entry_array_store),
      "void (any, string)"
    ),
    "handle"            => fun_ref(
      method(:uint16_array_handle),
      "void (any, string, map)"
    ),
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:value_array_validate),
      "boolean (any, string, map)"
    )
  }
end

- (Object) commonPopupInit(opt_id, key)

Fallback function to initialize the settings in the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key



264
265
266
267
268
269
270
271
# File '../../src/include/dhcp-server/options.rb', line 264

def commonPopupInit(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = fetchValue(opt_id, key)
  UI.ChangeWidget(Id(key), :Value, value) if value != nil
  UI.SetFocus(Id(key))

  nil
end

- (Object) commonPopupSave(opt_id, key)

Fallback function to save settings from the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key



276
277
278
279
280
281
282
# File '../../src/include/dhcp-server/options.rb', line 276

def commonPopupSave(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = UI.QueryWidget(Id(key), :Value)
  storeValue(opt_id, key, value)

  nil
end

- (String) commonTableEntrySummary(opt_id, key)

Fallback function to display summary text in the table

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key

Returns:

  • (String)

    summary to be written to the table



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File '../../src/include/dhcp-server/options.rb', line 288

def commonTableEntrySummary(opt_id, key)
  opt_id = deep_copy(opt_id)
  return "" if !Ops.is_string?(opt_id)
  index = Builtins.tointeger(
    Builtins.regexpsub(
      Convert.to_string(opt_id),
      "^[a-z]+ ([0-9]+)$",
      "\\1"
    )
  )
  if Builtins.substring(key, 0, 7) == "option "
    return Builtins.sformat(
      "%1",
      Ops.get(@current_entry_options, [index, "value"], "")
    )
  else
    return Builtins.sformat(
      "%1",
      Ops.get(@current_entry_directives, [index, "value"], "")
    )
  end
end

- (Object) entry_array_store(opt_id, key)

Store function of a table entry / popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key



499
500
501
502
503
504
# File '../../src/include/dhcp-server/options.rb', line 499

def entry_array_store(opt_id, key)
  opt_id = deep_copy(opt_id)
  storeValue(opt_id, key, Builtins.mergestring(@entry_list, ", "))

  nil
end

- (Object) fetchValue(opt_id, key)

Fetch value from structures

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key

Returns:

  • (Object)

    the value



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File '../../src/include/dhcp-server/options.rb', line 196

def fetchValue(opt_id, key)
  opt_id = deep_copy(opt_id)
  return nil if opt_id == nil
  index = Builtins.tointeger(
    Builtins.regexpsub(
      Convert.to_string(opt_id),
      "^[a-z]+ ([0-9]+)$",
      "\\1"
    )
  )
  value = ""
  if Builtins.substring(key, 0, 7) == "option "
    value = Ops.get(@current_entry_options, [index, "value"], "")
  else
    value = Ops.get(@current_entry_directives, [index, "value"], "")
  end
  value
end

- (Object) flagInit(opt_id, key)

Initialize the settings in the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key



592
593
594
595
596
597
598
# File '../../src/include/dhcp-server/options.rb', line 592

def flagInit(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = fetchValue(opt_id, key)
  UI.ChangeWidget(Id(key), :Value, value == "__true")

  nil
end

- (Object) flagStore(opt_id, key)

Store function of a table entry / popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key



603
604
605
606
607
608
609
# File '../../src/include/dhcp-server/options.rb', line 603

def flagStore(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = Convert.to_boolean(UI.QueryWidget(Id(key), :Value))
  storeValue(opt_id, key, value ? "__true" : "__false")

  nil
end

- (String) flagSummary(opt_id, key)

Summary function of a table entry / popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key

Returns:

  • (String)

    value to be displayed in the table



615
616
617
618
619
620
621
622
623
624
# File '../../src/include/dhcp-server/options.rb', line 615

def flagSummary(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = fetchValue(opt_id, key)
  if value == "__true"
    # table item, means switched on
    return _("On")
  end
  # table item, means switched off
  _("Off")
end

- (Object) hardwareInit(opt_id, opt_key)

Initialization function of a table entry / popup

Parameters:

  • opt_id (Object)

    any option id

  • opt_key (String)

    string option key



891
892
893
894
895
896
897
898
899
900
# File '../../src/include/dhcp-server/options.rb', line 891

def hardwareInit(opt_id, opt_key)
  opt_id = deep_copy(opt_id)
  value = Convert.to_string(fetchValue(opt_id, opt_key))
  l = Builtins.splitstring(value, " ")
  l = Builtins.filter(l) { |i| i != "" }
  UI.ChangeWidget(Id(:hw), :Value, Ops.get(l, 0, "ethernet"))
  UI.ChangeWidget(Id(:addr), :Value, Ops.get(l, 1, ""))

  nil
end

- (Object) hardwareStore(opt_id, opt_key)

Store function of a table entry / popup

Parameters:

  • opt_id (Object)

    any option id

  • opt_key (String)

    string option key



906
907
908
909
910
911
912
913
914
915
916
917
918
919
# File '../../src/include/dhcp-server/options.rb', line 906

def hardwareStore(opt_id, opt_key)
  opt_id = deep_copy(opt_id)
  storeValue(
    opt_id,
    opt_key,
    Builtins.sformat(
      "%1 %2",
      Convert.to_string(UI.QueryWidget(Id(:hw), :Value)),
      Convert.to_string(UI.QueryWidget(Id(:addr), :Value))
    )
  )

  nil
end

- (Boolean) hardwareValidate(opt_id, key, event)

Validate function of a popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key

  • event (Hash)

    a map event to validate

Returns:

  • (Boolean)

    true if widget settings ok



926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
# File '../../src/include/dhcp-server/options.rb', line 926

def hardwareValidate(opt_id, key, event)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  hosthwaddress = Convert.to_string(UI.QueryWidget(Id(:addr), :Value))

  if !Address.CheckMAC(hosthwaddress)
    Popup.Error(
      Ops.add(
        #error popup
        _("The hardware address is invalid.\n"),
        Address.ValidMAC
      )
    )
    UI.SetFocus(Id(:addr))
    return false
  end

  true
end

- (Object) init_list(opt_id, key, label)

Initialize a selection box

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key

  • label (String)

    string label of the selection box



427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File '../../src/include/dhcp-server/options.rb', line 427

def init_list(opt_id, key, label)
  opt_id = deep_copy(opt_id)
  value = Convert.to_string(fetchValue(opt_id, key))
  value = "" if value == nil
  values = Builtins.splitstring(value, ",")
  values = Builtins.maplist(values) do |v|
    while v != "" && Builtins.substring(v, 0, 1) == " "
      v = Builtins.substring(v, 1)
    end
    while v != "" &&
        Builtins.substring(v, Ops.subtract(Builtins.size(v), 1), 1) == " "
      v = Builtins.substring(v, 0, Ops.subtract(Builtins.size(v), 1))
    end
    v
  end
  @entry_list = Builtins.filter(values) { |v| v != "" }
  redraw_list(opt_id, key, {}, label)

  nil
end

- (Object) initialize_dhcp_server_options(include_target)



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
# File '../../src/include/dhcp-server/options.rb', line 15

def initialize_dhcp_server_options(include_target)
  textdomain "dhcp-server"

  Yast.import "Address"
  Yast.import "DhcpServer"
  Yast.import "IP"
  Yast.import "Label"

  @option_types = {
    "option all-subnets-local"                      => "onoff",
    "option arp-cache-timeout"                      => "uint32",
    "option bootfile-name"                          => "text",
    "option boot-size"                              => "uint16",
    "option broadcast-address"                      => "ip-address",
    "option cookie-servers"                         => "array_ip-address",
    "option default-ip-ttl"                         => "uint8",
    "option default-tcp-ttl"                        => "uint8",
    "option dhcp-client-identifier"                 => "string",
    "option dhcp-max-message-size"                  => "uint16",
    "option domain-name"                            => "text",
    "option domain-name-servers"                    => "array_ip-address",
    "option extensions-path"                        => "text",
    "option finger-server"                          => "array_ip-address",
    "option font-servers"                           => "array_ip-address",
    "option host-name"                              => "quoted_string",
    "option ieee802-3-encapsulation"                => "onoff",
    "option ien116-name-servers"                    => "array_ip-address",
    "option impress-servers"                        => "array_ip-address",
    "option interface-mtu"                          => "uint16",
    "option ip-forwarding"                          => "onoff",
    "option irc-server"                             => "array_ip-address",
    "option log-servers"                            => "array_ip-address",
    "option lpr-servers"                            => "array_ip-address",
    "option mask-supplier"                          => "onoff",
    "option max-dgram-reassembly"                   => "uint16",
    "option merit-dump"                             => "text",
    "option mobile-ip-home-agent"                   => "array_ip-address",
    "option nds-context"                            => "string",
    "option nds-servers"                            => "array_ip-address",
    "option nds-tree-name"                          => "string",
    "option netbios-dd-server"                      => "array_ip-address",
    "option netbios-name-servers"                   => "array_ip-address",
    "option netbios-node-type"                      => "uint8",
    "option netbios-scope"                          => "string",
    "option nis-domain"                             => "text",
    "option nis-servers"                            => "array_ip-address",
    "option nisplus-domain"                         => "text",
    "option nisplus-servers"                        => "array_ip-address",
    "option nntp-server"                            => "array_ip-address",
    "option non-local-source-routing"               => "onoff",
    "option ntp-servers"                            => "array_ip-address",
    "option nwip-domain"                            => "string",
    "option nwip-suboptions"                        => "string",
    "option path-mtu-aging-timeout"                 => "uint32",
    "option path-mtu-plateau-table"                 => "array_uint16",
    "option perform-mask-discovery"                 => "onoff",
    "option policy-filter"                          => "array_ip-address_pair",
    "option pop-server"                             => "array_ip-address",
    "option resource-location-servers"              => "array_ip-address",
    "option root-path"                              => "text",
    "option router-discovery"                       => "onoff",
    "option router-solicitation-address"            => "ip-address",
    "option routers"                                => "array_ip-address",
    "option slp-directory-agent"                    => "slp-discovery-agent",
    "option slp-service-scope"                      => "slp-service-scope",
    "option smtp-server"                            => "array_ip-address",
    "option static-routes"                          => "array_ip-address_pair",
    "option streettalk-directory-assistance-server" => "array_ip-address",
    "option streettalk-server"                      => "array_ip-address",
    "option subnet-mask"                            => "ip-address",
    "option swap-server"                            => "ip-address",
    "option tcp-keepalive-garbage"                  => "onoff",
    "option tcp-keepalive-interval"                 => "uint32",
    "option tftp-server-name"                       => "text",
    "option time-offset"                            => "int32",
    "option time-servers"                           => "array_ip-address",
    "option trailer-encapsulation"                  => "onoff",
    "option uap-servers"                            => "text",
    "option www-server"                             => "array_ip-address",
    "option x-display-manager"                      => "array_ip-address",
    "option fqdn.no-client-update"                  => "onoff",
    "option fqdn.server-update"                     => "onoff",
    "option fqdn.encoded"                           => "onoff",
    "option fqdn.rcode1"                            => "onoff",
    "option fqdn.rcode2"                            => "onoff",
    "option fqdn.fqdn"                              => "text",
    "option nwip.nsq-broadcast"                     => "onoff",
    "option nwip.preferred-dss"                     => "array_ip-address",
    "option nwip.nearest-nwip-server"               => "array_ip-address",
    "option nwip.autoretries"                       => "uint8",
    "option nwip.autoretry-secs"                    => "uint8",
    "option nwip.nwip-1-1"                          => "uint8",
    "option nwip.primary-dss"                       => "ip-address",
    "option vendor-class-identifier"                => "quoted_string",
    "allow"                                         => "adi",
    "deny"                                          => "adi",
    "ignore"                                        => "adi",
    "ldap-dhcp-server-cn"                           => "text",
    # Possible values in the scope:
    # unknown-clients
    # known-clients
    # bootp
    # booting
    # duplicates
    # declines
    # client-updates
    # known-clients
    # unknown-clients
    # members of "class"
    # dynamic bootp clients
    # authenticated clients
    # unauthenticated clients
    # all clients
    #
    # authenticated clients
    # unauthenticated clients
    # all clients
    "always-broadcast"                              => "onoff",
    "always-reply-rfc1048"                          => "onoff",
    "authoritative"                                 => "flag",
    "not authoritative"                             => "flag",
    "boot-unknown-clients"                          => "onoff",
    "ddns-hostname"                                 => "name",
    "ddns-domainname"                               => "name",
    "ddns-rev-domainname"                           => "name",
    "ddns-update-style"                             => "style",
    "ddns-updates"                                  => "onoff",
    "default-lease-time"                            => "time",
    "do-forward-updates"                            => "onoff",
    "dynamic-bootp-lease-cutoff"                    => "date",
    "dynamic-bootp-lease-length"                    => "length",
    "filename"                                      => "text",
    "fixed-address"                                 => "ip-address",
    "get-lease-hostnames"                           => "onoff",
    "hardware"                                      => "hardware",
    "lease-file-name"                               => "name",
    "local-port"                                    => "port",
    "log-facility"                                  => "facility",
    "max-lease-time"                                => "time",
    "min-lease-time"                                => "time",
    "min-secs"                                      => "seconds",
    "next-server"                                   => "server-name",
    "omapi-port"                                    => "port",
    "one-lease-per-client"                          => "onoff",
    "pid-file-name"                                 => "name",
    "ping-check"                                    => "onoff",
    "ping-timeout"                                  => "seconds",
    "ping-timeout"                                  => "seconds",
    "server-identifier"                             => "hostname",
    "server-name"                                   => "name",
    "site-option-space"                             => "name",
    "stash-agent-options"                           => "onoff",
    "update-optimization"                           => "onoff",
    "update-static-leases"                          => "onoff",
    "use-host-decl-names"                           => "onoff",
    "use-lease-addr-for-default-route"              => "onoff",
    "vendor-option-space"                           => "string"
  }

  @widget_types = {
    "uint8"                 => uint8_widget,
    "uint16"                => uint16_widget,
    "uint32"                => uint32_widget,
    "int32"                 => int32_widget,
    "text"                  => text_widget,
    "quoted_string"         => quoted_string_widget,
    "string"                => { "_fill" => "" }, # just to make the map non-empty
    "time"                  => { "_fill" => "" }, # just to make the map non-empty
    "ip-address"            => ip_address_widget,
    "array_ip-address"      => array_ip_address_widget,
    "array_uint16"          => array_uint16_widget,
    "array_ip-address_pair" => array_ip_address_pair_widget
  }
end

- (Object) InitPopups

Initialize popups Create description map and copy it into appropriate variable of the DhcpServer module



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
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
# File '../../src/include/dhcp-server/options.rb', line 1019

def InitPopups
  p = {
    "log-facility" => {
      "popup" => {
        # label -- help text
        "help" => _(
          "If you change this, also update the syslog configuration."
        )
      }
    },
    "hardware"     => {
      "popup" => {
        "widget"            => :custom,
        "custom_widget"     => VBox(
          # combo box
          ComboBox(
            Id(:hw),
            _("&Hardware Type"),
            [
              # combo box entry, networking technology name
              Item(Id("ethernet"), _("Ethernet")),
              # combo box entry, networking technology name
              Item(Id("token-ring"), _("Token Ring"))
            ]
          ),
          # test entry, MAC better not to be translated,
          # translation would decrease the understandability
          TextEntry(Id(:addr), _("&MAC Address"))
        ),
        "init"              => fun_ref(
          method(:hardwareInit),
          "void (any, string)"
        ),
        "store"             => fun_ref(
          method(:hardwareStore),
          "void (any, string)"
        ),
        "validate_type"     => :function,
        "validate_function" => fun_ref(
          method(:hardwareValidate),
          "boolean (any, string, map)"
        )
      }
    },
    "flag"         => {
      "table" => {
        "summary" => fun_ref(method(:flagSummary), "string (any, string)")
      },
      "popup" => {
        "widget" => :checkbox,
        "init"   => fun_ref(method(:flagInit), "void (any, string)"),
        "store"  => fun_ref(method(:flagStore), "void (any, string)")
      }
    },
    "onoff"        => {
      "table" => {
        "summary" => fun_ref(method(:onoffSummary), "string (any, string)")
      },
      "popup" => {
        "widget" => :checkbox,
        "init"   => fun_ref(method(:onoffInit), "void (any, string)"),
        "store"  => fun_ref(method(:onoffStore), "void (any, string)")
      }
    },
    "range"        => {
      "popup" => {
        "widget"            => :custom,
        "custom_widget"     => VBox(
          HBox(
            # text entry
            TextEntry(Id(:lower), _("&Lowest IP Address")),
            # text entry
            TextEntry(Id(:upper), _("&Highest IP Address"))
          ),
          # checkbox
          CheckBox(Id(:bootp), _("Allow Dynamic &BOOTP"))
        ),
        "init"              => fun_ref(
          method(:rangeInit),
          "void (any, string)"
        ),
        "store"             => fun_ref(
          method(:rangeStore),
          "void (any, string)"
        ),
        "validate_type"     => :function,
        "validate_function" => fun_ref(
          method(:rangeValidate),
          "boolean (any, string, map)"
        )
      }
    }
  }

  options = Builtins.mapmap(@option_types) do |k, v|
    widget = Ops.get_map(@widget_types, v, {})
    if widget != {}
      if Ops.get(widget, "validate_type") == nil
        Ops.set(widget, "validate_type", :function)
        Ops.set(
          widget,
          "validate_function",
          fun_ref(method(:validate_value), "boolean (any, string, map)")
        )
      end
      entry = { "popup" => widget }
      next { k => entry }
    end
    next { k => Ops.get_map(p, v, {}) } if Builtins.haskey(p, v)
    { k => {} }
  end

  p = Builtins.union(options, p)

  @popups = deep_copy(p)

  nil
end

- (Object) int32_widget

Get popup description map for an option type

Returns:

  • popup description map



721
722
723
724
725
726
727
# File '../../src/include/dhcp-server/options.rb', line 721

def int32_widget
  {
    "widget"  => :intfield,
    "minimum" => -2147483648, # -2^31
    "maximum" => 2147483647
  } # 2^31-1
end

- (Boolean) ip_address_validate(opt_id, key, event)

Validate function of a popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key

  • event (Hash)

    map representing the event that caused validation

Returns:

  • (Boolean)

    true if widget settings ok



376
377
378
379
380
381
382
383
384
385
386
# File '../../src/include/dhcp-server/options.rb', line 376

def ip_address_validate(opt_id, key, event)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  value = Convert.to_string(UI.QueryWidget(Id(key), :Value))
  if !Address.Check4(value)
    Popup.Message(IP.Valid4)
    UI.SetFocus(Id(key))
    return false
  end
  true
end

- (Object) ip_address_widget

Get popup description map for an option type

Returns:

  • popup description map



762
763
764
765
766
767
768
769
770
# File '../../src/include/dhcp-server/options.rb', line 762

def ip_address_widget
  {
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:ip_address_validate),
      "boolean (any, string, map)"
    )
  }
end

- (Object) ip_array_handle(opt_id, key, event)

Handle the event on the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key

  • event (Hash)

    map event to be handled



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File '../../src/include/dhcp-server/options.rb', line 463

def ip_array_handle(opt_id, key, event)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  if Ops.get(event, "ID") == :add
    new_addr = Convert.to_string(UI.QueryWidget(Id(:new_addr), :Value))
    if !Address.Check(new_addr)
      # popup message
      Popup.Message(_("The entered address is not valid."))
      return nil
    end
    @entry_list = Builtins.add(@entry_list, new_addr)
  end
  redraw_list(opt_id, key, event, _("A&ddresses"))

  nil
end

- (Object) ip_array_init(opt_id, key)

Initialize the settings in the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key



451
452
453
454
455
456
457
# File '../../src/include/dhcp-server/options.rb', line 451

def ip_array_init(opt_id, key)
  opt_id = deep_copy(opt_id)
  # selection box
  init_list(opt_id, key, _("A&ddresses"))

  nil
end

- (Boolean) ip_array_validate(opt_id, key, event)

Validate function of a popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key

  • event (Hash)

    map representing the event that caused validation

Returns:

  • (Boolean)

    true if widget settings ok



485
486
487
488
489
490
491
492
493
494
# File '../../src/include/dhcp-server/options.rb', line 485

def ip_array_validate(opt_id, key, event)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  if Builtins.size(@entry_list) == 0
    # message popup
    Popup.Message(_("At least one address must be specified."))
    return false
  end
  true
end

- (Object) ip_pair_array_handle(opt_id, key, event)

Handle the event on the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key

  • event (Hash)

    map event to be handled



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File '../../src/include/dhcp-server/options.rb', line 553

def ip_pair_array_handle(opt_id, key, event)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  if Ops.get(event, "ID") == :add
    new_addr = Convert.to_string(UI.QueryWidget(Id(:new_addr), :Value))
    l = Builtins.splitstring(new_addr, " ")
    l = Builtins.filter(l) { |s| s != "" }
    if !(Builtins.size(l) == 2 && Address.Check(Ops.get(l, 0, "")) &&
        Address.Check(Ops.get(l, 1, "")))
      # message popup
      Popup.Message(_("The entered addresses are not valid."))
      return nil
    end
    @entry_list = Builtins.add(@entry_list, new_addr)
  end
  redraw_list(opt_id, key, event, _("A&ddresses"))

  nil
end

- (Boolean) ip_pair_array_validate(opt_id, key, event)

Validate function of a popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key

  • event (Hash)

    map representing the event that caused validation

Returns:

  • (Boolean)

    true if widget settings ok



578
579
580
581
582
583
584
585
586
587
# File '../../src/include/dhcp-server/options.rb', line 578

def ip_pair_array_validate(opt_id, key, event)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  if Builtins.size(@entry_list) == 0
    # message popup
    Popup.Message(_("At least one address pair must be specified."))
    return false
  end
  true
end

- (Object) onoffInit(opt_id, key)

Initialize the settings in the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key



629
630
631
632
633
634
635
636
637
638
639
# File '../../src/include/dhcp-server/options.rb', line 629

def onoffInit(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = fetchValue(opt_id, key)
  UI.ChangeWidget(
    Id(key),
    :Value,
    Builtins.tolower(Convert.to_string(value)) == "on"
  )

  nil
end

- (Object) onoffStore(opt_id, key)

Store function of a table entry / popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key



644
645
646
647
648
649
650
# File '../../src/include/dhcp-server/options.rb', line 644

def onoffStore(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = Convert.to_boolean(UI.QueryWidget(Id(key), :Value))
  storeValue(opt_id, key, value ? "on" : "off")

  nil
end

- (String) onoffSummary(opt_id, key)

Summary function of a table entry / popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key

Returns:

  • (String)

    value to be displayed in the table



656
657
658
659
660
661
662
663
664
665
# File '../../src/include/dhcp-server/options.rb', line 656

def onoffSummary(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = fetchValue(opt_id, key)
  if Builtins.tolower(Convert.to_string(value)) == "on"
    # table item, means switched on
    return _("On")
  end
  # table item, means switched off
  _("Off")
end

- (Object) quoted_string_init(opt_id, key)

Initialize the settings in the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File '../../src/include/dhcp-server/options.rb', line 339

def quoted_string_init(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = Convert.to_string(fetchValue(opt_id, key))
  if value != nil
    # removing quotes around
    if Builtins.regexpmatch(value, "^\".*\"$")
      value = Builtins.regexpsub(value, "\"(.*)\"", "\\1")

      # if it was quoted, replacing all >\"< with >"<
      while Builtins.regexpmatch(value, ".*\\\\\".*")
        value = Builtins.regexpsub(value, "(.*)\\\\\"(.*)", "\\1\"\\2")
      end
    end
    UI.ChangeWidget(Id(key), :Value, value)
  end
  UI.SetFocus(Id(key))

  nil
end

- (Boolean) quoted_string_validate(opt_id, key, event)

Validate function of a popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key

  • event (Hash)

    map representing the event that caused validation

Returns:

  • (Boolean)

    true if widget settings ok



672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File '../../src/include/dhcp-server/options.rb', line 672

def quoted_string_validate(opt_id, key, event)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  value = Convert.to_string(UI.QueryWidget(Id(key), :Value))

  if Builtins.regexpmatch(value, "\"")
    value = Builtins.mergestring(Builtins.splitstring(value, "\""), "\\\"")
  end

  UI.ChangeWidget(Id(key), :Value, value)

  # UI::SetFocus (`id (key));
  true
end

- (Object) quoted_string_widget

Get popup description map for an option type

Returns:

  • popup description map



741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
# File '../../src/include/dhcp-server/options.rb', line 741

def quoted_string_widget
  {
    "widget"            => :textentry,
    "init"              => fun_ref(
      method(:quoted_string_init),
      "void (any, string)"
    ),
    "store"             => fun_ref(
      method(:textWidgetStore),
      "void (any, string)"
    ),
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:quoted_string_validate),
      "boolean (any, string, map)"
    )
  }
end

- (Object) rangeInit(opt_id, key)

Initialization function of a table entry / popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key



949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
# File '../../src/include/dhcp-server/options.rb', line 949

def rangeInit(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = Convert.to_string(fetchValue(opt_id, key))
  value = "" if value == nil
  l = Builtins.splitstring(value, " ")
  l = Builtins.filter(l) { |i| i != "" }
  lindex = 0
  if Ops.get(l, 0, "") == "dynamic-bootp"
    lindex = 1
    UI.ChangeWidget(Id(:bootp), :Value, true)
  end
  hindex = Ops.add(lindex, 1)
  UI.ChangeWidget(Id(:lower), :Value, Ops.get(l, lindex, ""))
  UI.ChangeWidget(Id(:upper), :Value, Ops.get(l, hindex, ""))

  nil
end

- (Object) rangeStore(opt_id, key)

Store function of a table entry / popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key



970
971
972
973
974
975
976
977
978
979
980
981
982
983
# File '../../src/include/dhcp-server/options.rb', line 970

def rangeStore(opt_id, key)
  opt_id = deep_copy(opt_id)
  val = Builtins.sformat(
    "%1 %2",
    UI.QueryWidget(Id(:lower), :Value),
    UI.QueryWidget(Id(:upper), :Value)
  )
  if Convert.to_boolean(UI.QueryWidget(Id(:bootp), :Value))
    val = Builtins.sformat("dynamic-bootp %1", val)
  end
  storeValue(opt_id, key, val)

  nil
end

- (Boolean) rangeValidate(opt_id, key, event)

Validate function of a popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key

  • event (Hash)

    a map event to validate

Returns:

  • (Boolean)

    true if widget settings ok



990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
# File '../../src/include/dhcp-server/options.rb', line 990

def rangeValidate(opt_id, key, event)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  lvalue = Convert.to_string(UI.QueryWidget(Id(:lower), :Value))
  if !Address.Check4(lvalue)
    Popup.Message(IP.Valid4)
    UI.SetFocus(Id(:lower))
    return false
  end
  uvalue = Convert.to_string(UI.QueryWidget(Id(:upper), :Value))
  if !Address.Check4(uvalue)
    Popup.Message(IP.Valid4)
    UI.SetFocus(Id(:upper))
    return false
  end
  if Ops.greater_than(IP.ToInteger(lvalue), IP.ToInteger(uvalue))
    # popup message
    Popup.Message(
      _("The lowest address must be lower than the highest one.")
    )
    UI.SetFocus(Id(:lower))
    return false
  end
  true
end

- (Object) redraw_list(opt_id, key, event, label)

Redraw selection box widget

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key

  • event (Hash)

    map event that caused the operation

  • label (String)

    string label of the selection box



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
# File '../../src/include/dhcp-server/options.rb', line 394

def redraw_list(opt_id, key, event, label)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  if Ops.get(event, "ID") == :delete
    del_addr = Convert.to_string(
      UI.QueryWidget(Id(:addresses), :CurrentItem)
    )
    @entry_list = Builtins.filter(@entry_list) { |a| a != del_addr }
  end
  UI.ReplaceWidget(
    :addresses_rp,
    SelectionBox(Id(:addresses), label, @entry_list)
  )
  UI.ChangeWidget(
    Id(:delete),
    :Enabled,
    Ops.greater_than(Builtins.size(@entry_list), 0)
  )
  if Ops.greater_than(Builtins.size(@entry_list), 0)
    UI.ChangeWidget(
      Id(:addresses),
      :CurrentItem,
      Ops.get(@entry_list, 0, "")
    )
  end

  nil
end

- (Object) storeValue(opt_id, key, value)

Store value to structures

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key

  • value (Object)

    any value to store



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
# File '../../src/include/dhcp-server/options.rb', line 219

def storeValue(opt_id, key, value)
  opt_id = deep_copy(opt_id)
  value = deep_copy(value)
  if opt_id == nil
    if Builtins.substring(key, 0, 7) == "option "
      @current_entry_options = Builtins.add(
        @current_entry_options,
        { "key" => Builtins.substring(key, 7), "value" => value }
      )
    else
      @current_entry_directives = Builtins.add(
        @current_entry_directives,
        { "key" => key, "value" => value }
      )
    end
    return
  end
  return if !Ops.is_string?(opt_id)
  index = Builtins.tointeger(
    Builtins.regexpsub(
      Convert.to_string(opt_id),
      "^[a-z]+ ([0-9]+)$",
      "\\1"
    )
  )
  if Builtins.substring(key, 0, 7) == "option "
    Ops.set(
      @current_entry_options,
      [index, "value"],
      Convert.to_string(value)
    )
  else
    Ops.set(
      @current_entry_directives,
      [index, "value"],
      Convert.to_string(value)
    )
  end

  nil
end

- (Object) text_widget

Get popup description map for an option type

Returns:

  • popup description map



731
732
733
734
735
736
737
# File '../../src/include/dhcp-server/options.rb', line 731

def text_widget
  {
    "widget" => :textentry,
    "init"   => fun_ref(method(:textWidgetInit), "void (any, string)"),
    "store"  => fun_ref(method(:textWidgetStore), "void (any, string)")
  }
end

- (Object) textWidgetInit(opt_id, key)

Initialize the settings in the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File '../../src/include/dhcp-server/options.rb', line 314

def textWidgetInit(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = Convert.to_string(fetchValue(opt_id, key))
  if value != nil
    while value != "" && Builtins.substring(value, 0, 1) == "\""
      value = Builtins.substring(value, 1)
    end
    while value != "" &&
        Builtins.substring(value, Ops.subtract(Builtins.size(value), 1)) == "\""
      value = Builtins.substring(
        value,
        0,
        Ops.subtract(Builtins.size(value), 1)
      )
    end
    UI.ChangeWidget(Id(key), :Value, value)
  end
  UI.SetFocus(Id(key))

  nil
end

- (Object) textWidgetStore(opt_id, key)

Summary function of a table entry / popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key



362
363
364
365
366
367
368
369
# File '../../src/include/dhcp-server/options.rb', line 362

def textWidgetStore(opt_id, key)
  opt_id = deep_copy(opt_id)
  value = UI.QueryWidget(Id(key), :Value)
  value = Builtins.sformat("\"%1\"", value)
  storeValue(opt_id, key, value)

  nil
end

- (Object) uint16_array_handle(opt_id, key, event)

Handle the event on the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key

  • event (Hash)

    map event to be handled



521
522
523
524
525
526
527
528
529
530
531
# File '../../src/include/dhcp-server/options.rb', line 521

def uint16_array_handle(opt_id, key, event)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  if Ops.get(event, "ID") == :add
    val = Convert.to_integer(UI.QueryWidget(Id(:new_addr), :Value))
    @entry_list = Builtins.add(@entry_list, Builtins.tostring(val))
  end
  redraw_list(opt_id, key, event, _("&Values"))

  nil
end

- (Object) uint16_array_init(opt_id, key)

Initialize the settings in the popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    string option key



509
510
511
512
513
514
515
# File '../../src/include/dhcp-server/options.rb', line 509

def uint16_array_init(opt_id, key)
  opt_id = deep_copy(opt_id)
  # selection box
  init_list(opt_id, key, _("&Values"))

  nil
end

- (Object) uint16_widget

Get popup description map for an option type

Returns:

  • popup description map



709
710
711
# File '../../src/include/dhcp-server/options.rb', line 709

def uint16_widget
  { "widget" => :intfield, "minimum" => 0, "maximum" => 65535 } # 2^16-1
end

- (Object) uint32_widget

Get popup description map for an option type

Returns:

  • popup description map



715
716
717
# File '../../src/include/dhcp-server/options.rb', line 715

def uint32_widget
  { "widget" => :intfield, "minimum" => 0, "maximum" => 4294967295 } # 2^32-1
end

- (Object) uint8_widget

Get popup description map for an option type

Returns:

  • popup description map



703
704
705
# File '../../src/include/dhcp-server/options.rb', line 703

def uint8_widget
  { "widget" => :intfield, "minimum" => 0, "maximum" => 255 } # 2^8-1
end

- (Object) validate_value(id, key, event)



687
688
689
690
691
692
693
694
695
696
697
698
699
# File '../../src/include/dhcp-server/options.rb', line 687

def validate_value(id, key, event)
  id = deep_copy(id)
  event = deep_copy(event)
  if UI.WidgetExists(Id(key))
    value = UI.QueryWidget(Id(key), :Value)
    if value == ""
      # popup message
      Popup.Message(_("A value must be specified."))
      return false
    end
  end
  true
end

- (Boolean) value_array_validate(opt_id, key, event)

Validate function of a popup

Parameters:

  • opt_id (Object)

    any option id

  • key (String)

    any option key

  • event (Hash)

    map representing the event that caused validation

Returns:

  • (Boolean)

    true if widget settings ok



538
539
540
541
542
543
544
545
546
547
# File '../../src/include/dhcp-server/options.rb', line 538

def value_array_validate(opt_id, key, event)
  opt_id = deep_copy(opt_id)
  event = deep_copy(event)
  if Builtins.size(@entry_list) == 0
    # message popup
    Popup.Message(_("At least one address must be specified."))
    return false
  end
  true
end