Module: Yast::SecurityRoutinesInclude

Defined in:
../../src/include/security/routines.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) checkMinMax(minID, maxID)

Check if minimum is less than maximum in the widget

Parameters:

  • minID (String)

    ID os the minimum widget

  • maxID (String)

    ID os the maximum widget

Returns:

  • true or false



209
210
211
212
213
214
215
216
217
218
# File '../../src/include/security/routines.rb', line 209

def checkMinMax(minID, maxID)
  min = UI.QueryWidget(Id(minID), :Value)
  max = UI.QueryWidget(Id(maxID), :Value)
  if Ops.is_integer?(min) || Ops.is_float?(min)
    if Ops.is_integer?(max) || Ops.is_float?(max)
      return true if Ops.less_or_equal(min, max)
    end
  end
  false
end

- (Object) HSeparator

Horizontal separator

Returns:

  • horizontal separator



57
58
59
# File '../../src/include/security/routines.rb', line 57

def HSeparator
  HSpacing(Opt(:hstretch), 0.1)
end

- (Object) initialize_security_routines(include_target)



38
39
40
41
42
43
44
45
46
47
# File '../../src/include/security/routines.rb', line 38

def initialize_security_routines(include_target)
  Yast.import "UI"

  textdomain "security"

  Yast.import "Popup"
  Yast.import "Security"

  Yast.include include_target, "security/widgets.rb"
end

- (Object) ReallyAbort

If modified, ask for confirmation

Returns:

  • true if abort is confirmed



222
223
224
# File '../../src/include/security/routines.rb', line 222

def ReallyAbort
  !Security.Modified || Popup.ReallyAbort(true)
end

- (Object) settings2widget(_ID)

Return a widget from the WIDGETS map created acording to the ID.

Parameters:

  • ID (String)

    security setting identifier

Returns:

  • created widget

See Also:

  • href="widgets.html">widgets.ycp


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
# File '../../src/include/security/routines.rb', line 65

def settings2widget(_ID)
  m = Ops.get_map(@WIDGETS, _ID, {})
  label = Ops.get_string(m, "Label", "")
  widget = Ops.get_string(m, "Widget", "")
  value = Ops.get(Security.Settings, _ID, "")
  minval = Ops.get_integer(m, "MinValue", 0)
  maxval = Ops.get_integer(m, "MaxValue", 2147483647)

  # "Widget" == "CheckBox"
  if widget == "CheckBox"
    enabled = false
    enabled = true if value == "yes"
    chbox = CheckBox(Id(_ID), label, enabled)
    if Ops.get_string(m, "Notify", "no") == "yes"
      chbox = CheckBox(Id(_ID), Opt(:notify), label, enabled)
    end
    return VBox(Left(chbox), VSeparator())
  end

  # "Widget" == "TextEntry"
  if widget == "TextEntry"
    return VBox(Left(TextEntry(Id(_ID), label, value)), VSeparator())
  end

  # "Widget" == "IntField"
  if widget == "IntField"
    intval = Builtins.tointeger(value)
    intval = 0 if intval == nil
    return VBox(
      Left(IntField(Id(_ID), label, minval, maxval, intval)),
      VSeparator()
    )
  end

  # "Widget" == "???"
  if widget != "ComboBox"
    Builtins.y2error("Unknown widget: %1", widget)
    return VSeparator()
  end

  # "Widget" == "ComboBox"
  li = Ops.get_list(m, "Options", [])
  combo = []
  i = 0
  selected = false

  while Ops.less_than(i, Builtins.size(li))
    # string|list it
    Builtins.y2debug("li=%1 (%2)", li, i)
    it = Ops.get(li, i)
    it = "" if it == nil
    Builtins.y2debug("it=%1", it)
    id_t = ""
    id_s = ""
    if Ops.is_string?(it)
      id_t = Convert.to_string(it)
      id_s = Convert.to_string(it)
    else
      it_list = Convert.convert(it, :from => "any", :to => "list <string>")

      id_t = Ops.get(it_list, 0, "")
      id_s = Ops.get(it_list, 1, "")
    end
    if value == id_t
      combo = Builtins.add(combo, Item(Id(id_t), id_s, true))
      selected = true
    else
      combo = Builtins.add(combo, Item(Id(id_t), id_s))
    end
    i = Ops.add(i, 1)
  end
  if !selected && Ops.get_string(m, "Editable", "no") == "yes"
    combo = Builtins.add(combo, Item(Id(value), value, true))
  end

  combobox = nil
  opt_t = nil
  opt_t = Opt(:editable) if Ops.get_string(m, "Editable", "no") == "yes"
  if Ops.get_string(m, "Notify", "no") == "yes"
    opt_t = opt_t == nil ? Opt(:notify) : Builtins.add(opt_t, :notify)
  end
  if opt_t != nil
    combobox = ComboBox(Id(_ID), opt_t, label, combo)
  else
    combobox = ComboBox(Id(_ID), label, combo)
  end

  VBox(Left(combobox), VSeparator())
end

- (Object) VSeparator

Vertical separator

Returns:

  • vertical separator



51
52
53
# File '../../src/include/security/routines.rb', line 51

def VSeparator
  VSpacing(Opt(:vstretch), 0.1)
end

- (Object) widget2settings(_ID)

Query the widget with id(ID) for itsValue

Parameters:

  • ID (String)

    security setting identifier



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
# File '../../src/include/security/routines.rb', line 157

def widget2settings(_ID)
  ret = UI.QueryWidget(Id(_ID), :Value)
  new = ""
  if Ops.is_boolean?(ret)
    if ret == true
      new = "yes"
    else
      new = "no"
    end
  elsif Ops.is_integer?(ret)
    new = Builtins.sformat("%1", ret)
  elsif Ops.is_string?(ret)
    new = Convert.to_string(ret)
  else
    Builtins.y2error("Unknown widget type: %1", ret)
    new = nil
  end

  if new != nil && Ops.get(Security.Settings, _ID, "") != new
    Builtins.y2milestone(
      "Setting modified (%1): %2 -> %3)",
      _ID,
      Ops.get(Security.Settings, _ID, ""),
      new
    )
    Ops.set(Security.Settings, _ID, new)
    Security.modified = true
  end

  nil
end

- (Object) XFrame(f1, f2, _S, _T)

Frame with spacings

Parameters:

  • f1 (Float)

    horizontal spacing

  • f2 (Float)

    vertical spacing

  • S (String)

    frame label

  • T (Yast::Term)

    frame contents

Returns:

  • frame with contents



195
196
197
198
199
200
201
202
203
# File '../../src/include/security/routines.rb', line 195

def XFrame(f1, f2, _S, _T)
  f1 = deep_copy(f1)
  f2 = deep_copy(f2)
  _T = deep_copy(_T)
  Frame(
    _S,
    HBox(HSpacing(f1), VBox(VSpacing(f2), _T, VSpacing(f2)), HSpacing(f1))
  )
end