• 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

11.27
/src/include/squid/popup_dialogs.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/popup_dialogs.ycp
23
# Package:        Configuration of squid
24
# Summary:        Popup dialogs definitions
25
# Authors:        Daniel Fiser <dfiser@suse.cz>
26
#
27
# $Id$
28
module Yast
1✔
29
  module SquidPopupDialogsInclude
1✔
30
    def initialize_squid_popup_dialogs(include_target)
1✔
31
      Yast.import "UI"
5✔
32

33
      textdomain "squid"
5✔
34
      Yast.import "Label"
5✔
35
      Yast.import "SquidACL"
5✔
36

37
      Yast.include include_target, "squid/inits.rb"
5✔
38
      Yast.include include_target, "squid/store_del.rb"
5✔
39
      Yast.include include_target, "squid/helper_functions.rb"
5✔
40
    end
41

42
    # ****************  HTTP PORT  *******************
43
    # returns true if something added/edited otherwise false
44
    def AddEditHttpPortDialog(id_item)
1✔
45
      ui = nil
×
46
      ret = false
×
47
      label = id_item.nil? ? _("Add New HTTP Port") : _("Edit Current HTTP Port")
×
48
      contents = VBox(
×
49
        Label(label),
50
        VSpacing(0.5),
51
        TextEntry(Id("host"), _("Host"), ""),
52
        TextEntry(Id("port"), _("Port"), ""),
53
        Left(CheckBox(Id("transparent"), _("Transparent"), false)),
54
        VSpacing(),
55
        VStretch(),
56
        ButtonBox(
57
          PushButton(Id(:ok), Label.OKButton),
58
          PushButton(Id(:cancel), Label.CancelButton)
59
        )
60
      )
61

62
      UI.OpenDialog(Opt(:decorated), contents)
×
63
      UI.ChangeWidget(Id("port"), :ValidChars, "1234567890")
×
64
      UI.ChangeWidget(Id("host"), :InputMaxLength, 22)
×
65

66
      InitAddEditHttpPortDialog(id_item)
×
67

68
      loop do
×
69
        ui = UI.UserInput
×
70

71
        if ui == :abort || ui == :cancel
×
72
          ret = false
×
73
          break
×
74
        elsif ui == :ok
×
75
          if StoreDataFromAddEditHttpPortDialog(id_item)
×
76
            ret = true
×
77
            break
×
78
          end
79
        end
80
      end
81

82
      UI.CloseDialog
×
83
      ret
×
84
    end
85
    # ****************  HTTP PORT END  ***************
86

87
    # ****************  CACHE  ***********************
88
    def AddEditRefreshPatternDialog(id_item)
1✔
89
      ret = false
×
90
      ui = nil
×
91
      label = id_item.nil? ? _("Add New Refresh Pattern") : _("Edit Current refresh Pattern")
×
92
      tmp = nil
×
93

94
      contents = VBox(
×
95
        Label(label),
96
        VSpacing(0.5),
97
        VSquash(
98
          HBox(
99
            TextEntry(Id("regexp"), _("Regular Expression"), ""),
100
            Bottom(
101
              CheckBox(Id("regexp_case_insensitive"), _("Case Insensitive"))
102
            )
103
          )
104
        ),
105
        IntField(Id("min"), Opt(:notify), _("Min (in minutes)"), 0, 99999, 0),
106
        IntField(Id("percent"), _("Percent"), 0, 99999, 0),
107
        IntField(Id("max"), Opt(:notify), _("Max (in minutes)"), 0, 99999, 0),
108
        VSpacing(),
109
        VStretch(),
110
        ButtonBox(
111
          PushButton(Id(:ok), Label.OKButton),
112
          PushButton(Id(:cancel), Label.CancelButton)
113
        )
114
      )
115

116
      UI.OpenDialog(Opt(:decorated), contents)
×
117

118
      InitAddEditRefreshPatternDialog(id_item)
×
119

120
      loop do
×
121
        ui = UI.UserInput
×
122

123
        if ui == :cancel || ui == :abort
×
124
          ret = false
×
125
          break
×
126
        elsif ui == :ok
×
127
          if StoreDataFromAddEditRefreshPatternDialog(id_item)
×
128
            ret = true
×
129
            break
×
130
          end
131
        elsif ui == "min"
×
132
          if Ops.greater_than(
×
133
            Convert.to_integer(tmp),
134
            Convert.to_integer(UI.QueryWidget(Id("max"), :Value))
135
          )
136
            UI.ChangeWidget(Id("max"), :Value, tmp)
×
137
          end
138
        elsif ui == "max"
×
139
          tmp = UI.QueryWidget(Id("max"), :Value)
×
140
          if Ops.greater_than(
×
141
            Convert.to_integer(UI.QueryWidget(Id("min"), :Value)),
142
            Convert.to_integer(tmp)
143
          )
144
            UI.ChangeWidget(Id("min"), :Value, tmp)
×
145
          end
146
        end
147
      end
148

149
      UI.CloseDialog
×
150
      ret
×
151
    end
152
    # ****************  CACHE END  *******************
153

154
    # ****************  ACCESS CONTROL  **************
155
    def addItemToAddEditHttpAccessDialog(acl_not, item)
1✔
156
      items = []
×
157

158
      i = 0
×
159
      Builtins.foreach(
160
        Convert.convert(
161
          UI.QueryWidget(Id("acls"), :Items),
162
          from: "any",
163
          to:   "list <term>"
164
        )
165
      ) do |value|
×
166
        items = Builtins.add(
×
167
          items,
168
          Item(
169
            Id(i),
170
            Ops.get_string(value, 1, ""),
171
            Ops.get_string(value, 2, "")
172
          )
173
        )
174
        i = Ops.add(i, 1)
×
175
      end
176
      items = Builtins.add(items, Item(Id(i), acl_not == true ? "not" : "", item))
×
177
      UI.ChangeWidget(Id("acls"), :Items, items)
×
178

179
      nil
180
    end
181

182
    def delItemFromAddEditHttpAccessDialog(id_item)
1✔
183
      items = []
×
184

185
      i = 0
×
186
      Builtins.foreach(
187
        Convert.convert(
188
          UI.QueryWidget(Id("acls"), :Items),
189
          from: "any",
190
          to:   "list <term>"
191
        )
192
      ) do |value|
×
193
        if Ops.get(value, 0) != Id(id_item)
×
194
          items = Builtins.add(
×
195
            items,
196
            Item(
197
              Id(i),
198
              Ops.get_string(value, 1, ""),
199
              Ops.get_string(value, 2, "")
200
            )
201
          )
202
          i = Ops.add(i, 1)
×
203
        end
204
      end
205
      UI.ChangeWidget(Id("acls"), :Items, items)
×
206
      if Ops.greater_or_equal(id_item, Builtins.size(items))
×
207
        id_item = Ops.subtract(id_item, 1)
×
208
      end
209
      id_item
×
210
    end
211

212
    def AddEditHttpAccessDialog(id_item)
1✔
213
      ret = false
×
214
      ui = nil
×
215
      acl = ""
×
216
      acl_not = false
×
217
      tmp_term = nil
×
218
      id_acl = 0
×
219
      label = id_item.nil? ? _("Add New HTTP Access") : _("Edit HTTP Access")
×
220
      contents = VBox(
×
221
        Label(label),
222
        VSpacing(0.5),
223
        ComboBox(
224
          Id("allow_deny"),
225
          _("Allow/Deny"),
226
          [Item(Id("allow"), _("Allow")), Item(Id("deny"), _("Deny"))]
227
        ),
228
        # `VSpacing(),
229
        MinSize(
230
          25,
231
          7,
232
          Table(Id("acls"), Opt(:notify), Header("   ", _("ACL")), [])
233
        ),
234
        Left(
235
          HBox(
236
            PushButton(Id(:del), Label.DeleteButton),
237
            PushButton(Id(:opposite), _("O&pposite"))
238
          )
239
        ),
240
        VSpacing(0.5),
241
        MinWidth(
242
          25,
243
          Frame(
244
            _("Add ACL"),
245
            VSquash(
246
              HBox(
247
                Bottom(CheckBox(Id("acl_not"), _("not"))),
248
                MinWidth(15, ComboBox(Id("acl"), "ACL", [])),
249
                Bottom(PushButton(Id(:add), Label.AddButton))
250
              )
251
            )
252
          )
253
        ),
254
        VStretch(),
255
        ButtonBox(
256
          PushButton(Id(:ok), Label.OKButton),
257
          PushButton(Id(:cancel), Label.CancelButton)
258
        )
259
      )
260

261
      UI.OpenDialog(contents)
×
262

263
      InitAddEditHttpAccessDialog(id_item)
×
264

265
      loop do
×
266
        ui = UI.UserInput
×
267

268
        if ui == :cancel || ui == :abort
×
269
          ret = false
×
270
          break
×
271
        elsif ui == :ok
×
272
          if StoreDataFromAddEditHttpAccessDialog(id_item)
×
273
            ret = true
×
274
            break
×
275
          end
276
        elsif ui == :add
×
277
          acl = Convert.to_string(UI.QueryWidget(Id("acl"), :Value))
×
278
          acl_not = Convert.to_boolean(UI.QueryWidget(Id("acl_not"), :Value))
×
279
          if Ops.greater_than(Builtins.size(acl), 0)
×
280
            addItemToAddEditHttpAccessDialog(acl_not, acl)
×
281
            InitAddEditHttpAccessDialog(nil)
×
282
          end
283
        elsif ui == :del
×
284
          id_acl = delItemFromAddEditHttpAccessDialog(
×
285
            Convert.to_integer(UI.QueryWidget(Id("acls"), :CurrentItem))
286
          )
287
          InitAddEditHttpAccessDialog(nil)
×
288
          UI.ChangeWidget(Id("acls"), :CurrentItem, id_acl)
×
289
        elsif ui == :opposite || ui == "acls"
×
290
          id_acl = Convert.to_integer(UI.QueryWidget(Id("acls"), :CurrentItem))
×
291
          tmp_term = Convert.to_term(
×
292
            UI.QueryWidget(Id("acls"), term(:Item, id_acl))
293
          )
294

295
          if Ops.get_string(tmp_term, 1, "") == "not"
×
296
            UI.ChangeWidget(Id("acls"), term(:Item, id_acl, 0), "")
×
297
          else
298
            UI.ChangeWidget(Id("acls"), term(:Item, id_acl, 0), "not")
×
299
          end
300
        end
301
      end
302

303
      UI.CloseDialog
×
304

305
      ret
×
306
    end
307

308
    def AddEditACLDialog(id_item)
1✔
309
      ret = false
×
310
      ui = nil
×
311
      orig_type = ""
×
312
      type = ""
×
313
      label = id_item.nil? ? _("Add New ACL Group") : _("Edit ACL Group")
×
314
      contents = HBox(
×
315
        HWeight(30, RichText(Id("help_text"), "")),
316
        HWeight(
317
          70,
318
          VBox(
319
            Label(label),
320
            VSpacing(0.5),
321
            TextEntry(Id("name"), _("Name"), ""),
322
            Left(
323
              ComboBox(
324
                Id("type"),
325
                Opt(:notify),
326
                _("Type"),
327
                SquidACL.GetTypesToComboBox
328
              )
329
            ),
330
            ReplacePoint(Id(:replace_point), Empty()),
331
            VStretch(),
332
            ButtonBox(
333
              PushButton(Id(:ok), Label.OKButton),
334
              PushButton(Id(:cancel), Label.CancelButton)
335
            )
336
          )
337
        )
338
      )
339

340
      UI.OpenDialog(contents)
×
341

342
      InitAddEditACLDialog(id_item)
×
343

344
      orig_type = Convert.to_string(UI.QueryWidget(Id("type"), :Value))
×
345
      SquidACL.Replace(:replace_point, orig_type)
×
346
      SquidACL.InitWidget(orig_type, id_item, "help_text")
×
347

348
      loop do
×
349
        ui = UI.UserInput
×
350

351
        if ui == :cancel || ui == :abort
×
352
          ret = false
×
353
          break
×
354
        elsif ui == :ok
×
355
          if StoreDataFromAddEditACLDialog(id_item)
×
356
            ret = true
×
357
            break
×
358
          end
359
        elsif ui == "type"
×
360
          type = Convert.to_string(UI.QueryWidget(Id("type"), :Value))
×
361
          SquidACL.Replace(:replace_point, type)
×
362
          if type == orig_type
×
363
            SquidACL.InitWidget(type, id_item, "help_text")
×
364
          else
365
            SquidACL.InitWidget(type, nil, "help_text")
×
366
          end
367
        end
368
      end
369

370
      UI.CloseDialog
×
371

372
      ret
×
373
    end
374
  end
375
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