Module: Yast::NfsServerUiInclude

Defined in:
../../src/include/nfs_server/ui.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) BeginDialog

Opening NFS server dialog

Returns:

  • back,abort, nextor finish



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File '../../src/include/nfs_server/ui.rb', line 291

def BeginDialog
  Wizard.SetScreenShotName("nfs-server-1-start")

  start_nfs_server = NfsServer.start
  domain = Convert.to_string(
    SCR.Read(path(".etc.idmapd_conf.value.General.Domain"))
  )
  if domain == nil
    Popup.Message(
      _(
        "Unable to read the /etc/idmapd.conf file. Setting the default setting for the domain to 'localdomain'."
      )
    )
    domain = "localdomain"
  end

  enable_nfsv4 = NfsServer.enable_nfsv4
  nfs_security = NfsServer.nfs_security

  changed = false

  # firewall widget using CWM
  fw_settings = {
    "services"        => ["service:nfs-kernel-server"], # bnc#446163
    "display_details" => true
  }
  fw_cwm_widget = CWMFirewallInterfaces.CreateOpenFirewallWidget(
    fw_settings
  )

  help_text =
    # Help, part 1 of 2
    _(
      "<P>Here, choose whether to start an NFS server on your computer\nand export some of your directories to others.</P>"
    )

  help_text = Ops.add(
    help_text,
    # Help, part 2 of 2
    _(
      "<P>If you choose <B>Start NFS Server</B>, clicking <B>Next</B> opens\na configuration dialog in which to specify the directories to export.</P>"
    )
  )

  help_text = Ops.add(help_text, Ops.get_string(fw_cwm_widget, "help", ""))

  help_text = Ops.add(
    help_text,
    _(
      "<P>If the server needs to handle NFSv4 clients, check <B>Enable NFSv4</B>\n" +
        "and fill in the NFSv4 domain name you want the ID mapping daemon to use. Leave\n" +
        "it as localdomain or refer to the man page for idmapd and idmapd.conf if you are not sure.</P>\n"
    )
  )

  help_text = Ops.add(
    help_text,
    # FIXME: use %1 as nfs-utils.src.rpm produces nfs-kernel-server.rpm
    _(
      "<P>If the server and client must authenticate using GSS library, check the\n<B>Enable GSS Security</B> box. To use GSS API, you currently need to have Kerberos and gssapi (nfs-utils > 1.0.7) on your system.</P>\n"
    )
  )

  # The end of the definitions

  nfs_contents =
    # frame label
    Frame(
      _("NFS Server"),
      VBox(
        VSpacing(0.2),
        RadioButtonGroup(
          Id(:rbgroup),
          # radio button label
          VBox(
            Left(
              RadioButton(
                Id(:servyes),
                Opt(:notify),
                _("&Start"),
                start_nfs_server
              )
            ),
            #radio button label
            Left(
              RadioButton(
                Id(:servno),
                Opt(:notify),
                _("Do &Not Start"),
                !start_nfs_server
              )
            )
          )
        ),
        VSpacing(0.2)
      )
    )
  fw_contents =
    # frame label
    Frame(
      _("Firewall"),
      VBox(
        VSpacing(0.2),
        Ops.get_term(fw_cwm_widget, "custom_widget", Empty()),
        VSpacing(0.2)
      )
    )

  nfsv4_contents = Frame(
    _("Enable NFSv4"),
    VBox(
      VSpacing(0.2),
      Left(
        CheckBox(
          Id(:enable_nfsv4),
          Opt(:notify),
          _("Enable NFS&v4"),
          enable_nfsv4
        )
      ),
      VSpacing(0.2),
      TextEntry(Id(:domain), _("Enter NFSv4 do&main name:"), domain),
      VSpacing(0.2)
    )
  )


  sec_contents = Left(
    CheckBox(
      Id(:nfs_security),
      Opt(:notify),
      _("Enable &GSS Security"),
      nfs_security
    )
  )


  contents = HVSquash(
    VBox(
      nfs_contents,
      VSpacing(1),
      fw_contents,
      VSpacing(1),
      nfsv4_contents,
      VSpacing(1),
      sec_contents
    )
  )

  # dialog title
  Wizard.SetContents(
    _("NFS Server Configuration"),
    contents,
    help_text,
    true,
    true
  )
  Wizard.DisableBackButton
  Wizard.SetAbortButton(:abort, Label.CancelButton)

  # initialize the widget (set the current value)
  CWMFirewallInterfaces.OpenFirewallInit(fw_cwm_widget, "")

  if enable_nfsv4
    UI.ChangeWidget(Id(:domain), :Enabled, true)
  else
    UI.ChangeWidget(Id(:domain), :Enabled, false)
  end

  event = nil
  ret = nil
  begin
    start_nfs_server = UI.QueryWidget(Id(:rbgroup), :CurrentButton) == :servyes
    if !start_nfs_server
      Wizard.SetNextButton(:next, Label.OKButton)
    else
      Wizard.RestoreNextButton
      Wizard.SetFocusToNextButton
    end

    event = UI.WaitForEvent
    ret = Ops.get(event, "ID")
    if ret == :enable_nfsv4
      enable_nfsv4 = UI.QueryWidget(Id(:enable_nfsv4), :Value) == true
      NfsServer.enable_nfsv4 = enable_nfsv4
      if enable_nfsv4
        UI.ChangeWidget(Id(:domain), :Enabled, true)
      else
        UI.ChangeWidget(Id(:domain), :Enabled, false)
      end
    end

    if ret == :nfs_security
      nfs_security = UI.QueryWidget(Id(:nfs_security), :Value) == true
      NfsServer.nfs_security = nfs_security
    end
    ret = :abort if ret == :cancel

    # handle the events, enable/disable the button, show the popup if button clicked
    CWMFirewallInterfaces.OpenFirewallHandle(fw_cwm_widget, "", event)
    changed = CWMFirewallInterfaces.OpenFirewallModified("") ||
      start_nfs_server != NfsServer.start # "" because method doesn't use parameter at all, nice :(

    ret = :again if ret == :abort && changed && !Popup.ReallyAbort(changed)
  end while ret != :back && ret != :next && ret != :abort

  if ret == :next
    # grab current settings, store them to SuSEFirewall::
    CWMFirewallInterfaces.OpenFirewallStore(fw_cwm_widget, "", event)
    NfsServer.start = start_nfs_server
    NfsServer.domain = Convert.to_string(
      UI.QueryWidget(Id(:domain), :Value)
    )
    return :finish if !start_nfs_server
  end

  Wizard.RestoreBackButton
  Wizard.RestoreScreenShotName
  Convert.to_symbol(ret)
end

- (Object) ExportsDialog

Exports dialog itself

Returns:

  • back,abort, `next



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
# File '../../src/include/nfs_server/ui.rb', line 514

def ExportsDialog
  Wizard.SetScreenShotName("nfs-server-2-exports")

  # Help, part 1 of 5
  help_text = _(
    "<P>The upper box contains all the directories to export.\n" +
      "If a directory is selected, the lower box shows the hosts allowed to\n" +
      "mount this directory.</P>\n"
  )

  # Help, part 2 of 5
  help_text = Ops.add(
    help_text,
    _(
      "<P><b>Host Wild Card</b> sets which hosts can access the selected directory.\n" +
        "It can be a single host, groups, wild cards, or\n" +
        "IP networks.</P>\n"
    )
  )

  # #91175
  if @use_star_for_anonymous
    # Help, part 3 of 5, variant for kernel space server
    help_text = Ops.add(
      help_text,
      _(
        "<p>Enter an asterisk (<tt>*</tt>) instead of a name to specify all hosts.</p>"
      )
    )
  else
    # Help, part 3 of 5, variant for user space server
    help_text = Ops.add(
      help_text,
      _("<p>Leave the field empty to specify all hosts.</p>")
    )
  end

  if NfsServer.enable_nfsv4
    # Help, part 4 of 5, caution about fsid=0 in case NFSv4 is enabled.
    help_text = Ops.add(
      help_text,
      _(
        "<p>NFSv4 is enabled. Make sure that only one exported filesystem is marked with the fsid=0 option for a particular client.</p>"
      )
    )

    # bnc#471874, NFS4 is complex and so is our UI :-/
    # but let's fix the help at least
    # Watch out, the space is necessary between br and slash.
    help_text = Ops.add(
      help_text,
      _(
        "<p>In case of multiple exports to a NFSv4 client,\n" +
          "you need to bind the exported paths with no fsid=0 to the one with fsid=0.\n" +
          "To export the server paths <tt>/Eve</tt> and <tt>/Adam</tt> as\n" +
          "<tt>/</tt> and <tt>/husband</tt>, respectively, use<br />\n" +
          "<pre>/Eve         10.0.0.1(fsid=0,crossmnt,ro,...)\n" +
          "/Eve/husband 10.0.0.1(bind=/Adam,ro,...)</pre>\n" +
          "</p>"
      )
    )
  end

  # Help, part 5 of 5
  help_text = Ops.add(
    help_text,
    _("<P>Refer to <tt>man exports</tt> for more information.</P>\n")
  )

  exports = deep_copy(NfsServer.exports)

  contents = VBox()

  contents = Builtins.add(
    contents,
    ReplacePoint(Id(:exportsrep), ExportsSelBox(exports))
  )

  # push button label
  contents = Builtins.add(
    contents,
    HBox(
      PushButton(Id(:mpnewbut), Opt(:key_F3), _("Add &Directory")),
      # push button label
      PushButton(Id(:mpeditbut), Opt(:key_F4), _("&Edit")),
      # push button label
      PushButton(Id(:mpdelbut), Opt(:key_F5), _("De&lete"))
    )
  )
  # push button label
  contents = Builtins.add(
    contents,
    VBox(
      Left(Label(Id(:allowedlab), Opt(:hstretch), "")),
      Table(
        Id(:allowedtab),
        Opt(:notify, :immediate),
        # table header
        Header(
          _("Host Wild Card") + "  ",
          # table header
          _("Options") + "  "
        ),
        []
      )
    )
  )
  # push button label

  contents = Builtins.add(
    contents,
    HBox(
      PushButton(Id(:alwnewbut), _("Add &Host")),
      # push button label
      PushButton(Id(:alweditbut), _("Ed&it")),
      # push button label
      PushButton(Id(:alwdelbut), _("Dele&te"))
    )
  )


  Wizard.SetContentsButtons(
    # dialog title
    _("Directories to Export"),
    contents,
    help_text,
    Label.BackButton,
    Label.FinishButton
  )
  Wizard.SetAbortButton(:abort, Label.CancelButton)

  event = nil
  ret = nil
  simulated = nil # simulated user input
  oldmp = nil
  # preselect an item - convenience, button enabling
  if Ops.greater_than(Builtins.size(exports), 0)
    if NfsServer.enable_nfsv4
      UI.ChangeWidget(
        Id(:exptable),
        :CurrentItem,
        Ops.get_string(exports, [0, "mountpoint"], "")
      )
    else
      UI.ChangeWidget(
        Id(:exportsbox),
        :CurrentItem,
        Ops.get_string(exports, [0, "mountpoint"], "")
      )
    end
  end
  begin
    mountpoint = ""
    if NfsServer.enable_nfsv4
      mountpoint = Convert.to_string(
        UI.QueryWidget(Id(:exptable), :CurrentItem)
      )
    else
      mountpoint = Convert.to_string(
        UI.QueryWidget(Id(:exportsbox), :CurrentItem)
      )
    end

    anymp = mountpoint != nil

    UI.ChangeWidget(Id(:mpeditbut), :Enabled, anymp)
    UI.ChangeWidget(Id(:mpdelbut), :Enabled, anymp)
    UI.ChangeWidget(Id(:alwnewbut), :Enabled, anymp)
    if mountpoint != oldmp
      mountpoint = "" if mountpoint == nil
      UI.ChangeWidget(Id(:allowedlab), :Value, mountpoint)
      oldmp = mountpoint
      allowed = FindAllowed(exports, mountpoint)
      UI.ChangeWidget(
        Id(:allowedtab),
        :Items,
        AllowedTableItems(allowed != nil ? allowed : [])
      )
    end
    anyalw = UI.QueryWidget(Id(:allowedtab), :CurrentItem) != nil
    UI.ChangeWidget(Id(:alweditbut), :Enabled, anyalw)
    UI.ChangeWidget(Id(:alwdelbut), :Enabled, anyalw)

    # Kludge, because a `Table still does not have a shortcut.
    UI.SetFocus(Id(:allowedtab))

    # simulated input,
    # used for `alweditbut afted `mpnewbut
    if simulated == nil
      event = UI.WaitForEvent
      ret = Ops.get(event, "ID")
      ret = :abort if ret == :cancel
    else
      ret = deep_copy(simulated)
      simulated = nil
    end

    if ret == :mpnewbut
      mountpoint2 = GetDirectory(nil, exports)

      if mountpoint2 != nil
        default_allowed = [
          Builtins.sformat(
            "%1(%2)",
            @use_star_for_anonymous ? "*" : "",
            GetDefaultOpts(NfsServer.enable_nfsv4, exports, "*")
          )
        ]
        exports = Builtins.add(
          exports,
          { "mountpoint" => mountpoint2, "allowed" => default_allowed }
        )
        UI.ReplaceWidget(Id(:exportsrep), ExportsSelBox(exports))
        if NfsServer.enable_nfsv4
          UI.ChangeWidget(Id(:exptable), :CurrentItem, mountpoint2)
        else
          UI.ChangeWidget(Id(:exportsbox), :CurrentItem, mountpoint2)
        end
        simulated = :alweditbut
      end
    elsif ret == :mpeditbut
      mp = nil

      if NfsServer.enable_nfsv4
        mp = Convert.to_string(UI.QueryWidget(Id(:exptable), :CurrentItem))
      else
        mp = Convert.to_string(
          UI.QueryWidget(Id(:exportsbox), :CurrentItem)
        )
      end

      if mp != nil
        mountpoint2 = GetDirectory(mp, Builtins.filter(exports) do |ent|
          Ops.get_string(ent, "mountpoint", "") != mp
        end)

        if mountpoint2 != nil
          exports = Builtins.maplist(exports) do |ent|
            tmp = Ops.get_string(ent, "mountpoint", "")
            next Builtins.add(ent, "mountpoint", mountpoint2) if tmp == mp
            deep_copy(ent)
          end

          UI.ReplaceWidget(Id(:exportsrep), ExportsSelBox(exports))

          if NfsServer.enable_nfsv4
            UI.ChangeWidget(Id(:exptable), :CurrentItem, mountpoint2)
          else
            UI.ChangeWidget(Id(:exportsbox), :CurrentItem, mountpoint2)
          end
        end
      end
    elsif ret == :mpdelbut
      mountpoint2 = nil

      if NfsServer.enable_nfsv4
        mountpoint2 = Convert.to_string(
          UI.QueryWidget(Id(:exptable), :CurrentItem)
        )
      else
        mountpoint2 = Convert.to_string(
          UI.QueryWidget(Id(:exportsbox), :CurrentItem)
        )
      end

      exports = Builtins.filter(exports) do |entry|
        Ops.get_string(entry, "mountpoint", "") != mountpoint2
      end if mountpoint2 != nil

      UI.ReplaceWidget(Id(:exportsrep), ExportsSelBox(exports))
      if Ops.greater_than(Builtins.size(exports), 0)
        if NfsServer.enable_nfsv4
          UI.ChangeWidget(
            Id(:exptable),
            :CurrentItem,
            Ops.get_string(exports, [0, "mountpoint"], "")
          )
        else
          UI.ChangeWidget(
            Id(:exportsbox),
            :CurrentItem,
            Ops.get_string(exports, [0, "mountpoint"], "")
          )
        end
      end
    elsif ret == :alwnewbut
      mountpoint2 = nil

      if NfsServer.enable_nfsv4
        mountpoint2 = Convert.to_string(
          UI.QueryWidget(Id(:exptable), :CurrentItem)
        )
      else
        mountpoint2 = Convert.to_string(
          UI.QueryWidget(Id(:exportsbox), :CurrentItem)
        )
      end

      if mountpoint2 != nil
        allowed = FindAllowed(exports, mountpoint2)

        hostopt = GetAllowedHosts(
          exports,
          mountpoint2,
          nil,
          nil,
          allowed,
          false
        )
        if hostopt != nil
          allowed = Builtins.add(
            allowed,
            Ops.add(
              Ops.add(
                Ops.add(Ops.get(hostopt, 0, ""), "("),
                Ops.get(hostopt, 1, "")
              ),
              ")"
            )
          )
          exports = ReplaceInExports(exports, mountpoint2, allowed)

          UI.ChangeWidget(
            Id(:allowedtab),
            :Items,
            AllowedTableItems(allowed)
          )
          if NfsServer.enable_nfsv4
            UI.ReplaceWidget(Id(:exportsrep), ExportsSelBox(exports))
            UI.ChangeWidget(Id(:exptable), :CurrentItem, mountpoint2)
          end
        end
      end
    elsif ret == :alweditbut
      mountpoint2 = nil

      if NfsServer.enable_nfsv4
        mountpoint2 = Convert.to_string(
          UI.QueryWidget(Id(:exptable), :CurrentItem)
        )
      else
        mountpoint2 = Convert.to_string(
          UI.QueryWidget(Id(:exportsbox), :CurrentItem)
        )
      end

      if mountpoint2 != nil
        allowed = FindAllowed(exports, mountpoint2)
        hosts = ""
        opts = ""
        if allowed != nil
          alw_no = Convert.to_integer(
            UI.QueryWidget(Id(:allowedtab), :CurrentItem)
          )
          if alw_no != nil
            ho = AllowedToHostsOpts(Ops.get(allowed, alw_no, ""))
            hosts = Ops.get(ho, 0, "")
            opts = Ops.get(ho, 1, "")
          end
          allowed = Builtins.remove(allowed, alw_no)
        end
        hostopt = GetAllowedHosts(
          exports,
          mountpoint2,
          hosts,
          opts,
          allowed,
          true
        )
        if hostopt != nil
          allowed = Builtins.add(
            allowed,
            Ops.add(
              Ops.add(
                Ops.add(Ops.get(hostopt, 0, ""), "("),
                Ops.get(hostopt, 1, "")
              ),
              ")"
            )
          )
          exports = ReplaceInExports(exports, mountpoint2, allowed)

          UI.ChangeWidget(
            Id(:allowedtab),
            :Items,
            AllowedTableItems(allowed)
          )
          if NfsServer.enable_nfsv4
            UI.ReplaceWidget(Id(:exportsrep), ExportsSelBox(exports))
            UI.ChangeWidget(Id(:exptable), :CurrentItem, mountpoint2)
          end
        end
      end
    elsif ret == :alwdelbut
      mountpoint2 = nil

      if NfsServer.enable_nfsv4
        mountpoint2 = Convert.to_string(
          UI.QueryWidget(Id(:exptable), :CurrentItem)
        )
      else
        mountpoint2 = Convert.to_string(
          UI.QueryWidget(Id(:exportsbox), :CurrentItem)
        )
      end

      if mountpoint2 != nil
        allowed = FindAllowed(exports, mountpoint2)
        alwno = Convert.to_integer(
          UI.QueryWidget(Id(:allowedtab), :CurrentItem)
        )
        if allowed != nil && alwno != nil
          allowed = Builtins.remove(allowed, alwno)
          exports = Builtins.maplist(exports) do |entry|
            if Ops.get_string(entry, "mountpoint", "") == mountpoint2
              entry = Builtins.add(entry, "allowed", allowed)
            end
            deep_copy(entry)
          end

          UI.ChangeWidget(
            Id(:allowedtab),
            :Items,
            AllowedTableItems(allowed)
          )
          if NfsServer.enable_nfsv4
            UI.ReplaceWidget(Id(:exportsrep), ExportsSelBox(exports))
            UI.ChangeWidget(Id(:exptable), :CurrentItem, mountpoint2)
          end
        end
      end
    elsif ret == :abort && !Popup.ReallyAbort(true)
      ret = :again
    end
  end while ret != :back && ret != :next && ret != :abort

  NfsServer.exports = deep_copy(exports) if ret == :next

  Wizard.RestoreScreenShotName
  Convert.to_symbol(ret)
end

- (newhosts, newopts) GetAllowedHosts(exports, expath, hosts, opts, allowed, fromedit)

Ask user for an entry for the allowed hosts list.

Parameters:

  • exports (Array<Hash>)

    the current UI version of the exports list

  • expath (String)

    the exported filesystem for which this is done

  • hosts (String)

    hosts default value

  • opts (String)

    options default value

  • allowed (Array<String>)

    current list, to check for duplicates

Returns:

  • (newhosts, newopts)

    or nil if cancelled. Options without parentheses.



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File '../../src/include/nfs_server/ui.rb', line 166

def GetAllowedHosts(exports, expath, hosts, opts, allowed, fromedit)
  exports = deep_copy(exports)
  allowed = deep_copy(allowed)
  Wizard.SetScreenShotName("nfs-server-2b-hosts")
  error = nil
  event = nil
  hostchanged = false
  optchanged = false

  hosts = "" if hosts == nil
  opts = "" if opts == nil
  allowed = [] if allowed == nil
  allowed_names = Builtins.maplist(allowed) do |str|
    brpos = Builtins.findfirstof(str, "(")
    str = Builtins.substring(str, 0, brpos) if str != nil
    str
  end

  UI.OpenDialog(
    Opt(:decorated),
    HBox(
      HSpacing(1),
      VBox(
        VSpacing(0.2),
        # make at least the default options fit
        HSpacing(30),
        # text entry label
        TextEntry(Id(:hostsent), Opt(:notify), _("&Host Wild Card"), hosts),
        # text entry label
        TextEntry(Id(:optsent), Opt(:notify), _("O&ptions"), opts),
        VSpacing(0.2),
        # ok pushbutton: confirm the dialog
        ButtonBox(
          PushButton(Id(:ok), Opt(:default, :key_F10), Label.OKButton),
          PushButton(Id(:cancel), Opt(:key_F9), Label.CancelButton)
        ),
        VSpacing(0.2)
      ),
      HSpacing(1)
    )
  )

  UI.SetFocus(Id(:hostsent))
  ret = nil
  begin
    event = UI.WaitForEvent
    ret = Ops.get(event, "ID")

    if ret == :hostsent
      hosts = Convert.to_string(UI.QueryWidget(Id(:hostsent), :Value))
      UI.ChangeWidget(Id(:hostsent), :Value, hosts)
      hostchanged = true if !hostchanged
      next
    end

    hosts = Convert.to_string(UI.QueryWidget(Id(:hostsent), :Value))
    if @use_star_for_anonymous && hosts == ""
      hosts = "*"
      UI.ChangeWidget(Id(:hostsent), :Value, hosts)
    elsif !@use_star_for_anonymous && hosts == "*" # #91175
      hosts = ""
      UI.ChangeWidget(Id(:hostsent), :Value, hosts)
    end

    if ret == :optsent
      # check to see if user has changed options entry in the dialogue
      # thrown due to a "Add Hosts" (as opposed to editing existing ones).
      # If yes, suggest the user with a suitable default option set.
      if hostchanged && !fromedit
        if !optchanged
          hosts = Convert.to_string(UI.QueryWidget(Id(:hostsent), :Value))
          opts = GetDefaultOpts(NfsServer.enable_nfsv4, exports, hosts)
          UI.ChangeWidget(Id(:optsent), :Value, opts)
          optchanged = true
        end
      end
    end

    if ret == :ok && (!CheckNoSpaces(hosts) || !CheckExportOptions(opts))
      ret = nil
    end
    if ret == :ok && !NfsServer.enable_nfsv4
      if Builtins.issubstring(opts, "fsid=0")
        Popup.Message(
          _(
            "'fsid=0' is not a valid option unless \nNFSv4 is enabled (previous page).\n"
          )
        )
        ret = nil
      end
    end

    if ret == :ok && NfsServer.enable_nfsv4
      error = CheckUniqueRootForClient(exports, expath, hosts, opts)
      if error != nil
        Popup.Message(error)
        ret = nil
      end
    end

    if ret == :ok && Builtins.contains(allowed_names, hosts)
      # error popup message
      Popup.Message(_("Options for this wild card\nare already set."))
      ret = nil
    end
  end while ret != :ok && ret != :cancel

  opts = Convert.to_string(UI.QueryWidget(Id(:optsent), :Value))
  UI.CloseDialog

  if opts == ""
    opts = GetDefaultOpts(NfsServer.enable_nfsv4, exports, hosts)
  end

  opts = Builtins.deletechars(opts, " ()")

  Wizard.RestoreScreenShotName

  return [hosts, opts] if ret == :ok
  nil
end

- (Object) GetDirectory(mountpoint, exports)

Ask user for a directory to export. Allow browsing.

Parameters:

  • mountpoint (String)

    default value

  • exports (Array<Hash>)

    exports list to check for duplicates

Returns:

  • a path to export or nil if cancelled



52
53
54
55
56
57
58
59
60
61
62
63
64
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
154
155
156
# File '../../src/include/nfs_server/ui.rb', line 52

def GetDirectory(mountpoint, exports)
  exports = deep_copy(exports)
  Wizard.SetScreenShotName("nfs-server-2a-dir")

  mountpoint = "" if mountpoint == nil

  UI.OpenDialog(
    Opt(:decorated),
    HBox(
      HSpacing(1),
      VBox(
        VSpacing(0.2),
        HBox(
          TextEntry(
            Id(:mpent),
            # text entry label
            _("&Directory to Export"),
            mountpoint
          ),
          HSpacing(1),
          VBox(
            # button label
            Bottom(PushButton(Id(:browse), Opt(:key_F6), _("&Browse...")))
          )
        ),
        VSpacing(0.2),
        ButtonBox(
          PushButton(Id(:ok), Opt(:default, :key_F10), Label.OKButton),
          PushButton(Id(:cancel), Opt(:key_F9), Label.CancelButton)
        ),
        VSpacing(0.2)
      ),
      HSpacing(1)
    )
  )
  UI.SetFocus(Id(:mpent))

  ret = nil
  begin
    ret = UI.UserInput
    mountpoint = Convert.to_string(UI.QueryWidget(Id(:mpent), :Value))

    if ret == :ok
      if mountpoint == nil || mountpoint == ""
        Popup.Message(
          _("Enter a non-empty export path. For example, /exports.")
        )
        ret = nil
      else
        allowed = FindAllowed(exports, mountpoint)
        if allowed != nil
          # error popup message
          Popup.Message(
            _("The exports table already contains this directory.")
          )
          ret = nil
        elsif !@spaces_allowed &&
            Builtins.findfirstof(mountpoint, " \t") != nil
          Popup.Message(
            Builtins.sformat(
              # message popup; %1, %2 are package names
              _(
                "The user mode NFS server (%1) cannot export directories\n" +
                  "with spaces in their names.\n" +
                  "Use the kernel-based server (%2) to do that."
              ),
              "nfs-server",
              "nfs-kernel-server"
            )
          )
          ret = nil
        elsif Ops.less_than(SCR.Read(path(".target.size"), mountpoint), 0) &&
            !Mode.config
          # the dir does not exist
          ret = Popup.YesNo(_("The directory does not exist. Create it?")) ? :ok : nil
        end
      end
    elsif ret == :browse
      dir = Convert.to_string(UI.QueryWidget(Id(:mpent), :Value))
      dir = "/" if Builtins.size(dir) == 0

      # title in the file selection dialog
      dir = UI.AskForExistingDirectory(
        dir,
        _("Select the Directory to Export")
      )

      if Ops.greater_than(Builtins.size(dir), 0)
        len = Builtins.size(dir)
        # remove the trailing "/"
        if dir != "/" &&
            Builtins.substring(dir, Ops.subtract(len, 1), 1) == "/"
          dir = Builtins.substring(dir, 0, Ops.subtract(len, 1))
        end
        UI.ChangeWidget(Id(:mpent), :Value, dir)
      end
    end
  end while ret != :ok && ret != :cancel

  UI.CloseDialog
  Wizard.RestoreScreenShotName

  return mountpoint if ret == :ok
  nil
end

- (Object) initialize_nfs_server_ui(include_target)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File '../../src/include/nfs_server/ui.rb', line 23

def initialize_nfs_server_ui(include_target)
  Yast.import "UI"

  textdomain "nfs_server"

  Yast.import "CWMFirewallInterfaces"
  Yast.import "Label"
  Yast.import "Mode"
  Yast.import "NfsServer"
  Yast.import "Popup"
  Yast.import "Sequencer"
  Yast.import "Wizard"
  Yast.include include_target, "nfs_server/routines.rb"

  # The kernel-based server can handle spaces in paths,
  # the user-mode server cannot.
  @spaces_allowed = false

  # The kernel based server complains about an empty host specification
  # and wants us to use "*". But the user mode server would match it
  # only with an unqualified name. We must not use "*" there
  # to mean an anonymous client.
  @use_star_for_anonymous = false
end

- (Object) NfsServerAutoSequence

Whole configuration of NfsServer but without reading and writing. For use with autoinstallation.

Returns:

  • sequence result



960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
# File '../../src/include/nfs_server/ui.rb', line 960

def NfsServerAutoSequence
  _Aliases = { "begin" => lambda { BeginDialog() }, "exports" => lambda do
    ExportsDialog()
  end }

  _Sequence = {
    "ws_start" => "begin",
    "begin"    => { :next => "exports", :finish => :next, :abort => :abort },
    "exports"  => { :next => :next, :abort => :abort }
  }

  Wizard.CreateDialog
  Wizard.SetDesktopTitleAndIcon("nfs_server")

  ret = Sequencer.Run(_Aliases, _Sequence)
  UI.CloseDialog
  ret
end