Module: Yast::SquidSquidACLLocalFunctionsInclude

Defined in:
../../src/include/squid/SquidACL_local_functions.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) arpOptions



638
639
640
# File '../../src/include/squid/SquidACL_local_functions.rb', line 638

def arpOptions
  [Convert.to_string(UI.QueryWidget(Id("acl_mac"), :Value))]
end

- (Object) arpVerif



624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File '../../src/include/squid/SquidACL_local_functions.rb', line 624

def arpVerif
  ok = true
  mac = Convert.to_string(UI.QueryWidget(Id("acl_mac"), :Value))
  if Builtins.size(mac) == 0
    ok = false
    # error report
    Report.Error(_("MAC Address must not be empty."))
  elsif !Builtins.regexpmatch(mac, "^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$")
    ok = false
    # error report
    Report.Error(_("Incorrect format of MAC Address."))
  end
  ok
end

- (Object) arpWidgetInit(id_item)

************** ARP ***************************



610
611
612
613
614
615
616
617
618
619
620
621
622
623
# File '../../src/include/squid/SquidACL_local_functions.rb', line 610

def arpWidgetInit(id_item)
  UI.ChangeWidget(Id("acl_mac"), :ValidChars, "1234567890ABCDEFabcdef:")

  if id_item != nil
    acl = Squid.GetACL(id_item)
    UI.ChangeWidget(
      Id("acl_mac"),
      :Value,
      Ops.get(Ops.get_list(acl, "options", []), 0, "")
    )
  end

  nil
end

- (Object) dstOptions



202
203
204
205
206
207
208
209
210
211
212
213
# File '../../src/include/squid/SquidACL_local_functions.rb', line 202

def dstOptions
  data = []
  addr = Convert.to_string(UI.QueryWidget(Id("acl_addr"), :Value))
  mask = Convert.to_string(UI.QueryWidget(Id("acl_mask"), :Value))

  Ops.set(data, 0, addr)
  if Ops.greater_than(Builtins.size(mask), 0) &&
      Ops.greater_than(Builtins.size(addr), 0)
    Ops.set(data, 0, Ops.add(Ops.add(Ops.get(data, 0, ""), "/"), mask))
  end
  deep_copy(data)
end

- (Object) dstVerif



189
190
191
192
193
194
195
196
197
198
199
200
# File '../../src/include/squid/SquidACL_local_functions.rb', line 189

def dstVerif
  ok = true
  addr = Convert.to_string(UI.QueryWidget(Id("acl_addr"), :Value))
  mask = Convert.to_string(UI.QueryWidget(Id("acl_mask"), :Value))

  if !isIPAddr(addr) ||
      Ops.greater_than(Builtins.size(mask), 0) && !isMask(mask)
    ok = false
    Report.Error(_("Invalid values."))
  end
  ok
end

- (Object) dstWidgetInit(id_item)

***************** DST ************************



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File '../../src/include/squid/SquidACL_local_functions.rb', line 171

def dstWidgetInit(id_item)
  widgetInitIPAddr("acl_addr")
  widgetInitMask("acl_mask")

  if id_item != nil
    acl = Squid.GetACL(id_item)
    data = Builtins.splitstring(
      Ops.get(Ops.get_list(acl, "options", []), 0, ""),
      "/"
    )

    UI.ChangeWidget(Id("acl_addr"), :Value, Ops.get(data, 0, ""))
    UI.ChangeWidget(Id("acl_mask"), :Value, Ops.get(data, 1, ""))
  end

  nil
end

- (Object) headerOptions



591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
# File '../../src/include/squid/SquidACL_local_functions.rb', line 591

def headerOptions
  header_name = Convert.to_string(
    UI.QueryWidget(Id("acl_header_name"), :Value)
  )
  regexp = Convert.to_string(UI.QueryWidget(Id("acl_regexp"), :Value))
  ci = Convert.to_boolean(
    UI.QueryWidget(Id("acl_regexp_case_insensitive"), :Value)
  )
  ret = [header_name]

  ret = Builtins.add(ret, "-i") if ci == true
  ret = Builtins.add(ret, regexp)

  deep_copy(ret)
end

- (Object) headerVerif



578
579
580
581
582
583
584
585
586
587
588
589
590
# File '../../src/include/squid/SquidACL_local_functions.rb', line 578

def headerVerif
  ok = true
  header_name = Convert.to_string(
    UI.QueryWidget(Id("acl_header_name"), :Value)
  )
  regexp = Convert.to_string(UI.QueryWidget(Id("acl_regexp"), :Value))

  if Builtins.size(header_name) == 0 && Builtins.size(regexp) == 0
    ok = false
    Report.Error(_("Header Name and Regular Expression must not be empty."))
  end
  ok
end

- (Object) headerWidgetInit(id_item)

************** HEADER ************************



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
# File '../../src/include/squid/SquidACL_local_functions.rb', line 552

def headerWidgetInit(id_item)
  if id_item != nil
    acl = Squid.GetACL(id_item)
    UI.ChangeWidget(
      Id("acl_header_name"),
      :Value,
      Ops.get(Ops.get_list(acl, "options", []), 0, "")
    )
    if Ops.get(Ops.get_list(acl, "options", []), 1, "") == "-i"
      UI.ChangeWidget(
        Id("acl_regexp"),
        :Value,
        Ops.get(Ops.get_list(acl, "options", []), 2, "")
      )
      UI.ChangeWidget(Id("acl_regexp_case_insensitive"), :Value, true)
    else
      UI.ChangeWidget(
        Id("acl_regexp"),
        :Value,
        Ops.get(Ops.get_list(acl, "options", []), 1, "")
      )
    end
  end

  nil
end

- (Object) initialize_squid_SquidACL_local_functions(include_target)



30
31
32
33
34
35
36
37
38
39
# File '../../src/include/squid/SquidACL_local_functions.rb', line 30

def initialize_squid_SquidACL_local_functions(include_target)
  Yast.import "UI"

  textdomain "squid"
  Yast.import "Report"

  Yast.import "Squid"

  Yast.include include_target, "squid/helper_functions.rb"
end

- (Object) isCorrectFromTo(from, to)



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File '../../src/include/squid/SquidACL_local_functions.rb', line 68

def isCorrectFromTo(from, to)
  fr = Builtins.tointeger(
    Builtins.regexpsub(
      Builtins.mergestring(Builtins.splitstring(from, ":"), ""),
      "([1-9][0-9]*$)",
      "\\1"
    )
  )
  t = Builtins.tointeger(
    Builtins.regexpsub(
      Builtins.mergestring(Builtins.splitstring(to, ":"), ""),
      "([1-9][0-9]*$)",
      "\\1"
    )
  )

  Ops.less_than(fr, t)
end

- (Object) isHHMMFormat(str)



56
57
58
59
60
61
62
63
64
65
66
67
# File '../../src/include/squid/SquidACL_local_functions.rb', line 56

def isHHMMFormat(str)
  return false if !Builtins.regexpmatch(str, "^[0-9]{1,2}:[0-9]{1,2}$")
  hm = Builtins.splitstring(str, ":")
  tmp = 0

  tmp = Builtins.tointeger(Ops.get(hm, 0, ""))
  return false if Ops.less_than(tmp, 0) || Ops.greater_than(tmp, 23)
  tmp = Builtins.tointeger(Ops.get(hm, 1, ""))
  return false if Ops.less_than(tmp, 0) || Ops.greater_than(tmp, 59)

  true
end

- (Object) isMask(str)



53
54
55
# File '../../src/include/squid/SquidACL_local_functions.rb', line 53

def isMask(str)
  Builtins.regexpmatch(str, "^[0-9]+$") || isIPAddr(str)
end

- (Object) maxconnOptions



545
546
547
# File '../../src/include/squid/SquidACL_local_functions.rb', line 545

def maxconnOptions
  [Builtins.tostring(UI.QueryWidget(Id("acl_connections"), :Value))]
end

- (Object) maxconnVerif



542
543
544
# File '../../src/include/squid/SquidACL_local_functions.rb', line 542

def maxconnVerif
  true
end

- (Object) maxconnWidgetInit(id_item)

************** MAXCONN ***********************



529
530
531
532
533
534
535
536
537
538
539
540
541
# File '../../src/include/squid/SquidACL_local_functions.rb', line 529

def maxconnWidgetInit(id_item)
  if id_item != nil
    acl = Squid.GetACL(id_item)

    UI.ChangeWidget(
      Id("acl_connections"),
      :Value,
      Builtins.tointeger(Ops.get(Ops.get_list(acl, "options", []), 0, ""))
    )
  end

  nil
end

- (Object) methodOptions



522
523
524
# File '../../src/include/squid/SquidACL_local_functions.rb', line 522

def methodOptions
  [Convert.to_string(UI.QueryWidget(Id("acl_method"), :Value))]
end

- (Object) methodVerif



519
520
521
# File '../../src/include/squid/SquidACL_local_functions.rb', line 519

def methodVerif
  true
end

- (Object) methodWidgetInit(id_item)

************** METHOD ************************



506
507
508
509
510
511
512
513
514
515
516
517
518
# File '../../src/include/squid/SquidACL_local_functions.rb', line 506

def methodWidgetInit(id_item)
  if id_item != nil
    acl = Squid.GetACL(id_item)

    UI.ChangeWidget(
      Id("acl_method"),
      :Value,
      Ops.get(Ops.get_list(acl, "options", []), 0, "")
    )
  end

  nil
end

- (Object) myportVerif



457
458
459
460
461
462
463
464
465
466
# File '../../src/include/squid/SquidACL_local_functions.rb', line 457

def myportVerif
  ok = true
  port = Convert.to_string(UI.QueryWidget(Id("acl_port"), :Value))

  if !Builtins.regexpmatch(port, "^[0-9]+$")
    ok = false
    Report.Error(_("Invalid value."))
  end
  ok
end

- (Object) myportWidgetInit(id_item)

************* MYPORT *************************



442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# File '../../src/include/squid/SquidACL_local_functions.rb', line 442

def myportWidgetInit(id_item)
  UI.ChangeWidget(Id("acl_port"), :ValidChars, "1234567890")

  if id_item != nil
    acl = Squid.GetACL(id_item)

    UI.ChangeWidget(
      Id("acl_port"),
      :Value,
      Ops.get(Ops.get_list(acl, "options", []), 0, "")
    )
  end

  nil
end

- (Object) portOptions



435
436
437
# File '../../src/include/squid/SquidACL_local_functions.rb', line 435

def portOptions
  [Convert.to_string(UI.QueryWidget(Id("acl_port"), :Value))]
end

- (Object) portVerif



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File '../../src/include/squid/SquidACL_local_functions.rb', line 416

def portVerif
  ok = true
  port = Convert.to_string(UI.QueryWidget(Id("acl_port"), :Value))

  if !Builtins.regexpmatch(port, "^[0-9]+(-[0-9]+){0,1}$")
    ok = false
  else
    ports = Builtins.splitstring(port, "-")
    if Builtins.size(ports) == 2 &&
        Ops.greater_than(
          Builtins.tointeger(Ops.get(ports, 0, "")),
          Builtins.tointeger(Ops.get(ports, 1, ""))
        )
      ok = false
    end
  end
  Report.Error(_("Invalid value.")) if !ok
  ok
end

- (Object) portWidgetInit(id_item)

*************** PORT *************************



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File '../../src/include/squid/SquidACL_local_functions.rb', line 401

def portWidgetInit(id_item)
  UI.ChangeWidget(Id("acl_port"), :ValidChars, "1234567890-")

  if id_item != nil
    acl = Squid.GetACL(id_item)

    UI.ChangeWidget(
      Id("acl_port"),
      :Value,
      Ops.get(Ops.get_list(acl, "options", []), 0, "")
    )
  end

  nil
end

- (Object) protoOptions



499
500
501
# File '../../src/include/squid/SquidACL_local_functions.rb', line 499

def protoOptions
  [Convert.to_string(UI.QueryWidget(Id("acl_proto"), :Value))]
end

- (Object) protoVerif



490
491
492
493
494
495
496
497
498
# File '../../src/include/squid/SquidACL_local_functions.rb', line 490

def protoVerif
  ok = true
  protocol = Convert.to_string(UI.QueryWidget(Id("acl_proto"), :Value))

  if Builtins.size(protocol) == 0
    Report.Error(_("Protocol must not be empty."))
  end
  ok
end

- (Object) protoWidgetInit(id_item)

************** PROTO *************************



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File '../../src/include/squid/SquidACL_local_functions.rb', line 471

def protoWidgetInit(id_item)
  UI.ChangeWidget(
    Id("acl_proto"),
    :ValidChars,
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
  )

  if id_item != nil
    acl = Squid.GetACL(id_item)

    UI.ChangeWidget(
      Id("acl_proto"),
      :Value,
      Ops.get(Ops.get_list(acl, "options", []), 0, "")
    )
  end

  nil
end

- (Object) regexp(name, frame_title, help)

Returns map describing acl which has type of regular expression.



325
326
327
328
329
330
331
332
333
334
# File '../../src/include/squid/SquidACL_local_functions.rb', line 325

def regexp(name, frame_title, help)
  {
    "name"         => name,
    "widget"       => regexpWidget(frame_title),
    "widget_init"  => fun_ref(method(:regexpWidgetInit), "void (integer)"),
    "verification" => fun_ref(method(:regexpVerif), "boolean ()"),
    "options"      => fun_ref(method(:regexpOptions), "list <string> ()"),
    "help"         => help
  }
end

- (Object) regexpOptions

Universal options function for regular expression.



310
311
312
313
314
315
316
317
318
319
320
321
322
# File '../../src/include/squid/SquidACL_local_functions.rb', line 310

def regexpOptions
  ret = []
  if Convert.to_boolean(
      UI.QueryWidget(Id("acl_regexp_case_insensitive"), :Value)
    )
    Ops.set(ret, 0, "-i")
  end
  ret = Builtins.add(
    ret,
    Convert.to_string(UI.QueryWidget(Id("acl_regexp"), :Value))
  )
  deep_copy(ret)
end

- (Object) regexpVerif

Universal verification function for regular expression.



299
300
301
302
303
304
305
306
307
308
# File '../../src/include/squid/SquidACL_local_functions.rb', line 299

def regexpVerif
  ok = true
  regexp = Convert.to_string(UI.QueryWidget(Id("acl_regexp"), :Value))

  if Builtins.size(regexp) == 0
    ok = false
    Report.Error(_("Regular Expression must not be empty."))
  end
  ok
end

- (Object) regexpWidget(frame_title)

*************** REGEXP *********************** Returns universal widget for setting a regular expression.



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File '../../src/include/squid/SquidACL_local_functions.rb', line 260

def regexpWidget(frame_title)
  Frame(
    frame_title,
    VBox(
      TextEntry(Id("acl_regexp"), _("Regular Expression"), ""),
      Left(
        CheckBox(
          Id("acl_regexp_case_insensitive"),
          _("Case Insensitive"),
          false
        )
      )
    )
  )
end

- (Object) regexpWidgetInit(id_item)

Universal widget_init for regular expression.



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File '../../src/include/squid/SquidACL_local_functions.rb', line 277

def regexpWidgetInit(id_item)
  if id_item != nil
    acl = Squid.GetACL(id_item)

    if Ops.get(Ops.get_list(acl, "options", []), 0, "") == "-i"
      UI.ChangeWidget(Id("acl_regexp_case_insensitive"), :Value, true)
      Ops.set(
        acl,
        "options",
        Builtins.remove(Ops.get_list(acl, "options", []), 0)
      )
    end
    UI.ChangeWidget(
      Id("acl_regexp"),
      :Value,
      Ops.get(Ops.get_list(acl, "options", []), 0, "")
    )
  end

  nil
end

- (Object) splitToChars(str)



41
42
43
44
45
46
47
48
49
50
51
# File '../../src/include/squid/SquidACL_local_functions.rb', line 41

def splitToChars(str)
  len = Builtins.size(str)
  i = 0
  ret = []
  while Ops.less_than(i, len)
    ret = Builtins.add(ret, Builtins.substring(str, i, 1))
    i = Ops.add(i, 1)
  end

  deep_copy(ret)
end

- (Object) srcdomainOptions



248
249
250
# File '../../src/include/squid/SquidACL_local_functions.rb', line 248

def srcdomainOptions
  [Convert.to_string(UI.QueryWidget(Id("acl_domain"), :Value))]
end

- (Object) srcdomainVerif



237
238
239
240
241
242
243
244
245
246
247
# File '../../src/include/squid/SquidACL_local_functions.rb', line 237

def srcdomainVerif
  ok = true

  if Builtins.size(
      Convert.to_string(UI.QueryWidget(Id("acl_domain"), :Value))
    ) == 0
    ok = false
    Report.Error(_("Domain Name must not be empty."))
  end
  ok
end

- (Object) srcdomainWidgetInit(id_item)

*************** SRCDOMAIN ********************



223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File '../../src/include/squid/SquidACL_local_functions.rb', line 223

def srcdomainWidgetInit(id_item)
  widgetInitDomainName("acl_domain")

  if id_item != nil
    acl = Squid.GetACL(id_item)
    UI.ChangeWidget(
      Id("acl_domain"),
      :Value,
      Ops.get(Ops.get_list(acl, "options", []), 0, "")
    )
  end

  nil
end

- (Object) srcOptions



155
156
157
158
159
160
161
162
163
164
165
166
# File '../../src/include/squid/SquidACL_local_functions.rb', line 155

def srcOptions
  data = []
  addr = Convert.to_string(UI.QueryWidget(Id("acl_addr"), :Value))
  mask = Convert.to_string(UI.QueryWidget(Id("acl_mask"), :Value))

  Ops.set(data, 0, addr)
  if Ops.greater_than(Builtins.size(mask), 0) &&
      Ops.greater_than(Builtins.size(addr), 0)
    Ops.set(data, 0, Ops.add(Ops.add(Ops.get(data, 0, ""), "/"), mask))
  end
  deep_copy(data)
end

- (Object) srcVerif



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File '../../src/include/squid/SquidACL_local_functions.rb', line 139

def srcVerif
  ok = true
  addr = Convert.to_string(UI.QueryWidget(Id("acl_addr"), :Value))
  mask = Convert.to_string(UI.QueryWidget(Id("acl_mask"), :Value))
  tmp = Builtins.splitstring(addr, "-")

  if Builtins.size(addr) == 0 ||
      !isIPAddr(addr) && !isIPAddr(Ops.get(tmp, 0, "")) &&
        !isIPAddr(Ops.get(tmp, 1, "")) ||
      Ops.greater_than(Builtins.size(mask), 0) && !isMask(mask)
    ok = false
    Report.Error(_("Invalid values."))
  end
  ok
end

- (Object) srcWidgetInit(id_item)

***************** SRC ************************



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File '../../src/include/squid/SquidACL_local_functions.rb', line 121

def srcWidgetInit(id_item)
  UI.ChangeWidget(Id("acl_addr"), :ValidChars, "1234567890.-")
  widgetInitMask("acl_mask")

  if id_item != nil
    acl = Squid.GetACL(id_item)
    data = Builtins.splitstring(
      Ops.get(Ops.get_list(acl, "options", []), 0, ""),
      "/"
    )

    UI.ChangeWidget(Id("acl_addr"), :Value, Ops.get(data, 0, ""))
    UI.ChangeWidget(Id("acl_mask"), :Value, Ops.get(data, 1, ""))
  end

  nil
end

- (Object) timeOptions



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File '../../src/include/squid/SquidACL_local_functions.rb', line 379

def timeOptions
  days = Builtins.mergestring(
    Convert.convert(
      UI.QueryWidget(Id("acl_days"), :SelectedItems),
      :from => "any",
      :to   => "list <string>"
    ),
    ""
  )
  times = Builtins.mergestring(
    [
      Convert.to_string(UI.QueryWidget(Id("acl_from"), :Value)),
      Convert.to_string(UI.QueryWidget(Id("acl_to"), :Value))
    ],
    "-"
  )
  [days, times]
end

- (Object) timeVerif



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File '../../src/include/squid/SquidACL_local_functions.rb', line 359

def timeVerif
  ok = true
  from = Convert.to_string(UI.QueryWidget(Id("acl_from"), :Value))
  to = Convert.to_string(UI.QueryWidget(Id("acl_to"), :Value))
  selected_items = Builtins.size(
    Convert.to_list(UI.QueryWidget(Id("acl_days"), :SelectedItems))
  )

  if selected_items == 0
    ok = false
    Report.Error(_("You must select at least one day."))
  elsif !isHHMMFormat(from) || !isHHMMFormat(to)
    ok = false
    Report.Error(_("Time is not set in correct format."))
  elsif !isCorrectFromTo(from, to)
    ok = false
    Report.Error(_("From must be less than To.")) #TODO: better error message
  end
  ok
end

- (Object) timeWidgetInit(id_item)

*************** TIME *************************



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File '../../src/include/squid/SquidACL_local_functions.rb', line 340

def timeWidgetInit(id_item)
  widgetInitHHMM("acl_from")
  widgetInitHHMM("acl_to")

  if id_item != nil
    acl = Squid.GetACL(id_item)
    days = splitToChars(Ops.get(Ops.get_list(acl, "options", []), 0, ""))
    times = Builtins.splitstring(
      Ops.get(Ops.get_list(acl, "options", []), 1, ""),
      "-"
    )

    UI.ChangeWidget(Id("acl_days"), :SelectedItems, days)
    UI.ChangeWidget(Id("acl_from"), :Value, Ops.get(times, 0, ""))
    UI.ChangeWidget(Id("acl_to"), :Value, Ops.get(times, 1, ""))
  end

  nil
end

- (Object) widgetInitDomainName(id)



101
102
103
104
105
106
107
108
109
110
# File '../../src/include/squid/SquidACL_local_functions.rb', line 101

def widgetInitDomainName(id)
  id = deep_copy(id)
  UI.ChangeWidget(
    Id(id),
    :ValidChars,
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."
  )

  nil
end

- (Object) widgetInitHHMM(id)



111
112
113
114
115
116
117
# File '../../src/include/squid/SquidACL_local_functions.rb', line 111

def widgetInitHHMM(id)
  id = deep_copy(id)
  UI.ChangeWidget(Id(id), :ValidChars, "1234567890:")
  UI.ChangeWidget(Id(id), :InputMaxLength, 5)

  nil
end

- (Object) widgetInitIPAddr(id)



89
90
91
92
93
94
# File '../../src/include/squid/SquidACL_local_functions.rb', line 89

def widgetInitIPAddr(id)
  id = deep_copy(id)
  UI.ChangeWidget(Id(id), :ValidChars, "1234567890.")

  nil
end

- (Object) widgetInitMask(id)



95
96
97
98
99
100
# File '../../src/include/squid/SquidACL_local_functions.rb', line 95

def widgetInitMask(id)
  id = deep_copy(id)
  UI.ChangeWidget(Id(id), :ValidChars, "1234567890.")

  nil
end