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

yast / yast-security / 3656380626

pending completion
3656380626

push

github

Unknown Committer
Unknown Commit Message

14 of 14 new or added lines in 2 files covered. (100.0%)

1367 of 3467 relevant lines covered (39.43%)

5.67 hits per line

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

0.0
/src/include/security/routines.rb
1
# encoding: utf-8
2

3
# ------------------------------------------------------------------------------
4
# Copyright (c) 2006-2012 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/security/routines.ycp
23
# Module:        Security configuration
24
# Summary:        Routines
25
# Authors:        Michal Svec <msvec@suse.cz>
26
#
27
# $Id$
28
#
29
# These functions are used for the user interface creation
30
# and interaction.
31
# <pre>
32
# Usage:
33
#   include "security/ui.ycp";
34
#   map WIDGETS = CallFunction(`your_widgets());
35
# </pre>
36
module Yast
×
37
  module SecurityRoutinesInclude
×
38
    def initialize_security_routines(include_target)
×
39
      Yast.import "UI"
×
40

41
      textdomain "security"
×
42

43
      Yast.import "Popup"
×
44
      Yast.import "Security"
×
45

46
      Yast.include include_target, "security/widgets.rb"
×
47
    end
×
48

49
    # Vertical separator
50
    # @return vertical separator
51
    def VSeparator
×
52
      VSpacing(Opt(:vstretch), 0.1)
×
53
    end
×
54

55
    # Horizontal separator
56
    # @return horizontal separator
57
    def HSeparator
×
58
      HSpacing(Opt(:hstretch), 0.1)
×
59
    end
×
60

61
    # Return a widget from the WIDGETS map created acording to the ID.
62
    # @param [String] _ID security setting identifier
63
    # @return created widget
64
    # @see <a href="widgets.html">widgets.ycp</a>
65
    def settings2widget(_ID)
×
66
      m = Ops.get_map(@WIDGETS, _ID, {})
×
67
      label = Ops.get_string(m, "Label", "")
×
68
      widget = Ops.get_string(m, "Widget", "")
×
69
      value = Ops.get(Security.Settings, _ID, "")
×
70
      minval = Ops.get_integer(m, "MinValue", 0)
×
71
      maxval = Ops.get_integer(m, "MaxValue", 2147483647)
×
72

73
      # "Widget" == "CheckBox"
74
      if widget == "CheckBox"
×
75
        enabled = false
×
76
        enabled = true if value == "yes"
×
77
        chbox = CheckBox(Id(_ID), label, enabled)
×
78
        if Ops.get_string(m, "Notify", "no") == "yes"
×
79
          chbox = CheckBox(Id(_ID), Opt(:notify), label, enabled)
×
80
        end
×
81
        return VBox(Left(chbox), VSeparator())
×
82
      end
×
83

84
      # "Widget" == "TextEntry"
85
      if widget == "TextEntry"
×
86
        return VBox(Left(TextEntry(Id(_ID), label, value)), VSeparator())
×
87
      end
×
88

89
      # "Widget" == "IntField"
90
      if widget == "IntField"
×
91
        intval = Builtins.tointeger(value)
×
92
        intval = 0 if intval == nil
×
93
        return VBox(
×
94
          Left(IntField(Id(_ID), label, minval, maxval, intval)),
×
95
          VSeparator()
×
96
        )
×
97
      end
×
98

99
      # "Widget" == "???"
100
      if widget != "ComboBox"
×
101
        Builtins.y2error("Unknown widget: %1", widget)
×
102
        return VSeparator()
×
103
      end
×
104

105
      # "Widget" == "ComboBox"
106
      li = Ops.get_list(m, "Options", [])
×
107
      combo = []
×
108
      i = 0
×
109
      selected = false
×
110

111
      while Ops.less_than(i, Builtins.size(li))
×
112
        # string|list it
113
        Builtins.y2debug("li=%1 (%2)", li, i)
×
114
        it = Ops.get(li, i)
×
115
        it = "" if it == nil
×
116
        Builtins.y2debug("it=%1", it)
×
117
        id_t = ""
×
118
        id_s = ""
×
119
        if Ops.is_string?(it)
×
120
          id_t = Convert.to_string(it)
×
121
          id_s = Convert.to_string(it)
×
122
        else
×
123
          it_list = Convert.convert(it, :from => "any", :to => "list <string>")
×
124

125
          id_t = Ops.get(it_list, 0, "")
×
126
          id_s = Ops.get(it_list, 1, "")
×
127
        end
×
128
        if value == id_t
×
129
          combo = Builtins.add(combo, Item(Id(id_t), id_s, true))
×
130
          selected = true
×
131
        else
×
132
          combo = Builtins.add(combo, Item(Id(id_t), id_s))
×
133
        end
×
134
        i = Ops.add(i, 1)
×
135
      end
×
136
      if !selected && Ops.get_string(m, "Editable", "no") == "yes"
×
137
        combo = Builtins.add(combo, Item(Id(value), value, true))
×
138
      end
×
139

140
      combobox = nil
×
141
      opt_t = nil
×
142
      opt_t = Opt(:editable) if Ops.get_string(m, "Editable", "no") == "yes"
×
143
      if Ops.get_string(m, "Notify", "no") == "yes"
×
144
        opt_t = opt_t == nil ? Opt(:notify) : Builtins.add(opt_t, :notify)
×
145
      end
×
146
      if opt_t != nil
×
147
        combobox = ComboBox(Id(_ID), opt_t, label, combo)
×
148
      else
×
149
        combobox = ComboBox(Id(_ID), label, combo)
×
150
      end
×
151

152
      VBox(Left(combobox), VSeparator())
×
153
    end
×
154

155
    # Query the widget with `id(ID) for its `Value
156
    # @param [String] _ID security setting identifier
157
    def widget2settings(_ID)
×
158
      ret = UI.QueryWidget(Id(_ID), :Value)
×
159
      new = ""
×
160
      if Ops.is_boolean?(ret)
×
161
        if ret == true
×
162
          new = "yes"
×
163
        else
×
164
          new = "no"
×
165
        end
×
166
      elsif Ops.is_integer?(ret)
×
167
        new = Builtins.sformat("%1", ret)
×
168
      elsif Ops.is_string?(ret)
×
169
        new = Convert.to_string(ret)
×
170
      else
×
171
        Builtins.y2error("Unknown widget type: %1", ret)
×
172
        new = nil
×
173
      end
×
174

175
      if new != nil && Ops.get(Security.Settings, _ID, "") != new
×
176
        Builtins.y2milestone(
×
177
          "Setting modified (%1): %2 -> %3)",
×
178
          _ID,
×
179
          Ops.get(Security.Settings, _ID, ""),
×
180
          new
×
181
        )
×
182
        Ops.set(Security.Settings, _ID, new)
×
183
        Security.modified = true
×
184
      end
×
185

186
      nil
×
187
    end
×
188

189
    # Frame with spacings
190
    # @param [Float] f1 horizontal spacing
191
    # @param [Float] f2 vertical spacing
192
    # @param [String] _S frame label
193
    # @param [Yast::Term] _T frame contents
194
    # @return frame with contents
195
    def XFrame(f1, f2, _S, _T)
×
196
      f1 = deep_copy(f1)
×
197
      f2 = deep_copy(f2)
×
198
      _T = deep_copy(_T)
×
199
      Frame(
×
200
        _S,
×
201
        HBox(HSpacing(f1), VBox(VSpacing(f2), _T, VSpacing(f2)), HSpacing(f1))
×
202
      )
×
203
    end
×
204

205
    # Check if minimum is less than maximum in the widget
206
    # @param [String] minID ID os the minimum widget
207
    # @param [String] maxID ID os the maximum widget
208
    # @return true or false
209
    def checkMinMax(minID, maxID)
×
210
      min = UI.QueryWidget(Id(minID), :Value)
×
211
      max = UI.QueryWidget(Id(maxID), :Value)
×
212
      if Ops.is_integer?(min) || Ops.is_float?(min)
×
213
        if Ops.is_integer?(max) || Ops.is_float?(max)
×
214
          return true if Ops.less_or_equal(min, max)
×
215
        end
×
216
      end
×
217
      false
×
218
    end
×
219

220
    # If modified, ask for confirmation
221
    # @return true if abort is confirmed
222
    def ReallyAbort
×
223
      !Security.Modified || Popup.ReallyAbort(true)
×
224
    end
×
225
  end
×
226
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

© 2025 Coveralls, Inc