• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-squid / 10845679279

13 Sep 2024 08:23AM UTC coverage: 37.03%. Remained the same
10845679279

push

github

lslezak
Adapt files for the SLE-15-SP7 branch

748 of 2020 relevant lines covered (37.03%)

3.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

34.29
/src/include/squid/helper_functions.rb
1
# encoding: utf-8
2

3
# ------------------------------------------------------------------------------
4
# Copyright (c) 2006 Novell, Inc. All Rights Reserved.
5
#
6
#
7
# This program is free software; you can redistribute it and/or modify it under
8
# the terms of version 2 of the GNU General Public License as published by the
9
# Free Software Foundation.
10
#
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along with
16
# this program; if not, contact Novell, Inc.
17
#
18
# To contact Novell about this file by physical or electronic mail, you may find
19
# current contact information at www.novell.com.
20
# ------------------------------------------------------------------------------
21

22
# File:        include/squid/helper_functions.ycp
23
# Package:        Configuration of squid
24
# Summary:        Helper functions for various situations.
25
# Authors:        Daniel Fiser <dfiser@suse.cz>
26
#
27
# $Id: dialogs.ycp 27914 2006-02-13 14:32:08Z locilka $
28
module Yast
1✔
29
  module SquidHelperFunctionsInclude
1✔
30
    def initialize_squid_helper_functions(_include_target)
1✔
31
      textdomain "squid"
6✔
32

33
      Yast.import "FileUtils"
6✔
34
    end
35

36
    # Returns a widget with setting of units
37
    def sizeUnitWidget(id)
1✔
38
      ComboBox(Id(id), _("&Units"), [Item("KB"), Item("MB")])
×
39
    end
40

41
    # Returns multiple which equals to given parameter.
42
    def unitToMultiple(unit)
1✔
43
      return 1024 if unit == "KB"
×
44
      return 1024 * 1024 if unit == "MB"
×
45

46
      nil
47
    end
48

49
    # Returns a widget with setting of units
50
    def timeUnitWidget(id)
1✔
51
      ComboBox(
×
52
        Id(id),
53
        " ",
54
        [
55
          Item(Id("seconds"), _("seconds")),
56
          Item(Id("minutes"), _("minutes")),
57
          Item(Id("hours"), _("hours")),
58
          Item(Id("days"), _("days"))
59
        ]
60
      )
61
    end
62

63
    def isCorrectPathnameOfLogFile(str)
1✔
64
      ok = Builtins.regexpmatch(str, "^/([^/]+/)*[^/]+$")
×
65
      if ok
×
66
        dir = Builtins.regexptokenize(str, "^(.+)/[^/]+$")
×
67
        ok = false if !FileUtils.IsDirectory(Ops.get(dir, 0, "/"))
×
68
      end
69
      ok
×
70
    end
71

72
    def isIPAddr(str)
1✔
73
      ok = true
×
74
      l = Builtins.regexptokenize(
×
75
        str,
76
        "^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)$"
77
      )
78

79
      if Builtins.size(l) != 4
×
80
        ok = false
×
81
      else
82
        i = 0
×
83
        Builtins.foreach(l) do |value|
×
84
          i = Builtins.tointeger(value)
×
85
          if Ops.less_than(i, 0) || Ops.greater_than(i, 255)
×
86
            ok = false
×
87
            raise Break
×
88
          end
89
        end
90
      end
91

92
      ok
×
93
    end
94

95
    def isHostName(str)
1✔
96
      # max 22 chars length
97
      # see http://www.no-ip.com/support/faq/EN/dynamic_ddns/what_is_a_valid_hostname.html
98
      Builtins.regexpmatch(str, "^[a-zA-Z0-9][a-zA-Z0-9-]{0,21}$")
×
99
    end
100

101
    def isCorrectHost(host)
1✔
102
      return false if !isIPAddr(host) && !isHostName(host)
×
103
      true
×
104
    end
105
  end
106
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc