Class: Yast::FtpServerClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/FtpServer.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) Abort

Returns a confirmation popup dialog whether user wants to really abort.

Returns:

  • (Boolean)

    result of Popup::ReallyAbort(GetModified()



863
864
865
# File '../../src/modules/FtpServer.rb', line 863

def Abort
  Popup.ReallyAbort(GetModified())
end

- (Hash) AutoPackages

zzz Return packages needed to be installed and removed during Autoinstallation to insure module has all needed software installed.

Returns:

  • (Hash)

    with 2 lists.



1188
1189
1190
1191
1192
1193
1194
# File '../../src/modules/FtpServer.rb', line 1188

def AutoPackages
  if @vsftpd_edit
    return { "install" => ["vsftpd"], "remove" => [] }
  else
    return { "install" => ["pure-ftpd"], "remove" => [] }
  end
end

- (Hash) Export

Dump the FtpServer settings to a single map (For use by autoinstallation.)

Returns:

  • (Hash)

    Dumped settings (later acceptable by Import ())



1104
1105
1106
# File '../../src/modules/FtpServer.rb', line 1104

def Export
  deep_copy(@EDIT_SETTINGS)
end

- (Boolean) GetModified

Returns whether the configuration has been modified.

Returns:

  • (Boolean)

    modified



845
846
847
# File '../../src/modules/FtpServer.rb', line 845

def GetModified
  @modified
end

- (Boolean) Import(settings)

Get all FtpServer settings from the first parameter (For use by autoinstallation.)

Parameters:

  • settings (Hash)

    The YCP structure to be imported.

Returns:

  • (Boolean)

    True on success



1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
# File '../../src/modules/FtpServer.rb', line 1027

def Import(settings)
  settings = deep_copy(settings)
  result = true
  Builtins.foreach(@UI_keys) do |key|
    val = Ops.get_string(settings, key)
    Ops.set(@EDIT_SETTINGS, key, val) if val != nil
    if val == nil
      Ops.set(@EDIT_SETTINGS, key, Ops.get(@DEFAULT_CONFIG, key))
    end
  end 

  result
end

- (Boolean) InitDaemon

Set which daemon will be configured (For use by autoinstallation.)

Returns:

  • (Boolean)

    True on success



1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
# File '../../src/modules/FtpServer.rb', line 1045

def InitDaemon
  result = true
  #Checking if ftp daemons are installed
  rad_but = 0
  vsftpd_init_count = 0
  pureftpd_init_count = 0
  ret = nil
  if Package.Installed("vsftpd")
    vsftpd_init_count = Ops.add(vsftpd_init_count, 1)
    @vsftpd_installed = true
  end
  if Package.Installed("pure-ftpd")
    pureftpd_init_count = Ops.add(pureftpd_init_count, 1)
    @pureftpd_installed = true
  end
  if @pureftpd_installed && @vsftpd_installed
    if Service.Enabled("pure-ftpd")
      pureftpd_init_count = Ops.add(pureftpd_init_count, 1)
    end

    if Service.Enabled("vsftpd")
      vsftpd_init_count = Ops.add(vsftpd_init_count, 1)
    end

    #Checking status of ftp daemons

    if Service.Status("vsftpd") == 0
      vsftpd_init_count = Ops.add(vsftpd_init_count, 1)
    end

    if Service.Status("pure-ftpd") == 0
      pureftpd_init_count = Ops.add(pureftpd_init_count, 1)
    end

    if pureftpd_init_count == vsftpd_init_count
      @vsftpd_edit = false
    elsif Ops.less_than(pureftpd_init_count, vsftpd_init_count)
      @vsftpd_edit = false
    else
      @vsftpd_edit = true
    end
  elsif @pureftpd_installed && !@vsftpd_installed
    result = true
    @vsftpd_edit = false
  elsif !@pureftpd_installed && @vsftpd_installed
    result = true
    @vsftpd_edit = true
  else
    result = true
    @vsftpd_edit = false
  end
  result
end

- (Boolean) InitEDIT_SETTINGS

Remap current pure -FtpServer configuration to temporary structure

Returns:

  • (Boolean)

    successfull



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File '../../src/modules/FtpServer.rb', line 454

def InitEDIT_SETTINGS
  Builtins.foreach(@UI_keys) do |key|
    val = ValueUI(key, false)
    Ops.set(@EDIT_SETTINGS, key, val) if val != nil #if (val == nil) Popup::Message(key);;
  end

  Builtins.y2milestone("-------------EDIT_SETTINGS-------------------")
  Builtins.y2milestone(
    "EDIT_SETTINGS configuration has been read: %1",
    @EDIT_SETTINGS
  )
  Builtins.y2milestone("---------------------------------------------")

  true
end

- (Object) main



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
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
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
# File '../../src/modules/FtpServer.rb', line 16

def main
  Yast.import "UI"
  textdomain "ftp-server"

  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Summary"
  Yast.import "Message"
  Yast.import "Popup"
  Yast.import "String"
  Yast.import "Mode"
  Yast.import "Package"
  Yast.import "CommandLine"
  Yast.import "Users"
  Yast.import "SuSEFirewall"
  Yast.import "SuSEFirewallServices"
  Yast.import "PortAliases"

  # Data was modified?
  @modified = false

  # general variable for proposal
  #
  @proposal_valid = false

  # variable signifies if vsftpd is selected and
  # edited via ftp-server (YaST module)
  # global boolean variable
  @vsftpd_edit = false

  # variable signifies if vsftpd is installed and
  #
  # global boolean variable
  @vsftpd_installed = false

  # variable signifies if pure-ftpd is installed and
  #
  # global boolean variable
  @pureftpd_installed = false

  # variable signifies position vsftpd record
  # in structur Inetd::netd_conf
  # -1 init value before calling Inetd::Read()
  #
  # global integer variable
  @vsftpd_xined_id = -1

  # variable signifies if pure-ftpd is installed and
  # in structur Inetd::netd_conf
  # -1 init value before calling Inetd::Read()
  #
  # global integer variable
  @pureftpd_xined_id = -1

  # variable signifies if daemon will be started via xinetd
  #
  # global boolean variable

  @start_xinetd = false

  # variable signifies if daemon is running via xinetd
  #
  # global boolean variable

  @pure_ftp_xinetd_running = false


  # variable signifies if daemon is running via xinetd
  #
  # global boolean variable

  @vsftp_xinetd_running = false

  # variable signifies if daemon will be stoped in xinetd
  #
  # global boolean variable

  @stop_daemon_xinetd = false



  # variable signifies if it is create upload dir
  # only for vsftpd and anonymous connections with allowed upload
  #
  # global boolean variable

  @create_upload_dir = false

  # variable signifies if upload dir has good permissions
  # only for vsftpd and anonymous connections with allowed upload
  #
  # global boolean variable

  @upload_good_permission = false

  # variable signifies if upload dir for anonymous has good permissions
  # it is only for pure-ftpd
  #
  # -1 == home dir is "/"
  #  0 == writting access disallow
  #  1 == writting allowed
  # global integer variable

  @pure_ftp_allowed_permissios_upload = 0

  # variable signifies if user choose change permissions for home dir
  # for anonymous connections with allowed upload
  #
  # global boolean variable

  @change_permissions = false

  # variable signifies home dir for anonymous user
  #
  # global string variable


  @anon_homedir = ""

  # variable signifies uid for anonymous user
  #
  # global integer variable

  @anon_uid = 0

  # variable signifies sleep time during reading settings
  #
  # internal integer variable

  @sl = 500

  # variable includes user info about anonymous user
  #
  # internal map variable
  @userinfo = {}

  # list includes xinetd server_args for pure-ftpd
  #
  # global lis <string> variable

  @pure_ftpd_xinet_conf = []


  # list of keys from map DEFAULT_CONFIG
  #
  # global list <string>

  @UI_keys = [
    "ChrootEnable",
    "VerboseLogging",
    "FtpDirLocal",
    "FtpDirAnon",
    "Umask",
    "UmaskAnon",
    "UmaskLocal",
    "PasMinPort",
    "PasMaxPort",
    "MaxIdleTime",
    "MaxClientsPerIP",
    "MaxClientsNumber",
    "LocalMaxRate",
    "AnonMaxRate",
    "AnonAuthen",
    "AnonReadOnly",
    "AnonCreatDirs",
    "Banner",
    "SSLEnable",
    "TLS",
    "AntiWarez",
    "SSL",
    "StartXinetd",
    "PassiveMode",
    "CertFile",
    "SSLv2",
    "SSLv3",
    "VirtualUser",
    "FTPUser",
    "GuestUser",
    "EnableUpload"
  ]

  # map of deafult values for options in UI
  #
  # global map <string, string >

  @DEFAULT_CONFIG = {
    "ChrootEnable"     => "NO",
    "VerboseLogging"   => "NO",
    "FtpDirLocal"      => "", #if empty doesn't write this options via SCR
    "FtpDirAnon"       => "", #if empty doesn't write this options via SCR
    "Umask"            => "",
    "UmaskAnon"        => "",
    "UmaskLocal"       => "",
    "PasMinPort"       => "40000",
    "PasMaxPort"       => "40500",
    "MaxIdleTime"      => "15",
    "MaxClientsPerIP"  => "3",
    "MaxClientsNumber" => "10",
    "LocalMaxRate"     => "0",
    "AnonMaxRate"      => "0",
    "AnonAuthen"       => "1", # 0 => anonymous only, 1 => authenticated only, 2=> both
    "AnonReadOnly"     => "YES",
    "AnonCreatDirs"    => "NO",
    "Banner"           => _("Welcome message"),
    "SSLEnable"        => "NO",
    "SSLv2"            => "NO", #enable/disable SSL version 2 (vsftpd only)
    "SSLv3"            => "NO", #enable/disable SSL version 3 (vsftpd only)
    "TLS"              => "YES",
    "AntiWarez"        => "YES",
    "SSL"              => "0", #0 - disable SSL, 1-accept SSL, 2 - refuse connection withou SSL (pure-ftpd only)
    "StartXinetd"      => "NO",
    "StartDaemon"      => "0", #0 = start manually, 1 = start when booting, 2 = start via xinetd
    "PassiveMode"      => "YES",
    "CertFile"         => "", #cert file for SSL connections
    "VirtualUser"      => "NO",
    "FTPUser"          => "ftp",
    "GuestUser"        => "",
    "EnableUpload"     => "NO"
  }

  # map <string, string > of pure-ftpd settings
  #
  @PURE_SETTINGS = {}


  # map <string, string > of vsftpd settings
  #
  @VS_SETTINGS = {}

  # map <string, string > of vsftpd settings
  #
  @EDIT_SETTINGS = {}



  Yast.include self, "ftp-server/write_load.rb"




  @ftps = true

  # Write only, used during autoinstallation.
  # Don't run services and SuSEconfig, it's all done at one place.
  @write_only = false

  # Abort function
  # return boolean return true if abort
  @AbortFunction = fun_ref(method(:Modified), "boolean ()")
end

- (Object) Modified

Data was modified?

Returns:

  • true if modified



882
883
884
885
# File '../../src/modules/FtpServer.rb', line 882

def Modified
  Builtins.y2debug("modified=%1", @modified)
  @modified
end

- (String) OptionsSummary

Create unsorted list of options

Returns:

  • (String)

    Returnes string with RichText-formated list



1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
# File '../../src/modules/FtpServer.rb', line 1110

def OptionsSummary
  _S = ""
  option = ""
  #start FTP daemon
  value = Ops.get(@EDIT_SETTINGS, "StartDaemon")
  if value == "0"
    option = "manually"
  elsif value == "1"
    option = "via xinetd"
  else
    option = "via inetd"
  end
  _S = Builtins.sformat("%1<li>Start Deamon: <i>(%2)</i>", _S, option)
  value = Ops.get(@EDIT_SETTINGS, "AnonAuthen")
  if value == "0"
    option = "Anonymous Only"
  elsif value == "1"
    option = "Authenticated Only"
  else
    option = "Both"
  end
  _S = Builtins.sformat("%1<li>Access: <i>(%2)</i>", _S, option)
  # anonymous dir
  if value != "1"
    _S = Builtins.sformat(
      "%1<li>Anonymous Directory: <i>(%2)</i>",
      _S,
      Ops.get(@EDIT_SETTINGS, "FtpDirAnon")
    )
    _S = Builtins.sformat(
      "%1<li>Anonymous Read Only: <i>(%2)</i>",
      _S,
      Ops.get(@EDIT_SETTINGS, "AnonReadOnly")
    )
    _S = Builtins.sformat(
      "%1<li>Anonymous Can Create Directory: <i>(%2)</i>",
      _S,
      Ops.get(@EDIT_SETTINGS, "AnonCreatDirs")
    )
  end
  _S = _("<p><ul><i>FTP daemon is not configured.</i></ul></p>") if _S == ""
  _S
end

- (Object) Overview

Create an overview table with all configured cards

Returns:

  • table items



1179
1180
1181
# File '../../src/modules/FtpServer.rb', line 1179

def Overview
  []
end

- (Boolean) PollAbort

Checks whether an Abort button has been pressed. If so, calls function to confirm the abort call.

Returns:

  • (Boolean)

    true if abort confirmed



871
872
873
874
875
876
# File '../../src/modules/FtpServer.rb', line 871

def PollAbort
  return false if Mode.commandline
  return Abort() if UI.PollInput == :abort

  false
end

- (Object) Read

Read all FtpServer settings

Returns:

  • true on success



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
955
956
957
958
959
960
961
962
# File '../../src/modules/FtpServer.rb', line 891

def Read
  # FtpServer read dialog caption
  caption = _("Initializing FTP Configuration")
  steps = 2

  # Part for commandline - it is necessary choose daemon if both are installed
  if Mode.commandline
    @vsftpd_installed = Package.Installed("vsftpd")
    @pureftpd_installed = Package.Installed("pure-ftpd")

    if @vsftpd_installed && @pureftpd_installed
      if CommandLine.Interactive
        CommandLine.Print(
          String.UnderlinedHeader(_("You have installed both daemons:"), 0)
        )
        CommandLine.Print(_("Choose one of them for configuration."))
        CommandLine.Print(
          _(
            "Do you want to configure vsftpd? Alternatively choose pure-ftpd."
          )
        )
        CommandLine.Print("")
        @vsftpd_edit = true if CommandLine.YesNo
      else
        CommandLine.Error(
          _(
            "You have installed both daemons. Therefore you have to run the configuration in interactive mode."
          )
        )
        return false
      end
    end
    @vsftpd_edit = true if @vsftpd_installed && !@pureftpd_installed

    return false if !@vsftpd_installed && !@pureftpd_installed
  end

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/2
      _("Read settings from the config file"),
      # Progress stage 2/2
      _("Read the previous settings")
    ],
    [
      # Progress stage 1/2
      _("Reading the settings..."),
      Message.Finished
    ],
    ""
  ) #end of Progress::New( caption, " "

  # read settings
  return false if PollAbort()
  Progress.NextStage
  # calling read function for reading settings form config file
  Report.Error(_("Cannot Read Current Settings.")) if !ReadSettings()
  Builtins.sleep(@sl)

  return false if PollAbort()
  # Progress finished
  Progress.NextStage
  Builtins.sleep(@sl)

  return false if PollAbort()
  @modified = false
  true
end

- (Object) ReadPermisionUplaod



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
# File '../../src/modules/FtpServer.rb', line 367

def ReadPermisionUplaod
  result = false
  command = ""
  directory = ""
  upload_dir = ""

  directories = Builtins.filter(Builtins.splitstring(@anon_homedir, "/")) do |key|
    key != ""
  end

  Builtins.y2milestone(
    "[ftp-server] (ReadPermisionUplaod) split directories...:  %1 ",
    directories
  )

  if Builtins.size(directories) == 1
    directory = "/"
    upload_dir = Builtins.deletechars(@anon_homedir, "/")
  elsif Ops.greater_than(Builtins.size(directories), 1)
    upload_dir = Ops.get(
      directories,
      Ops.subtract(Builtins.size(directories), 1),
      ""
    )
    #Popup::Message(upload_dir);
    directory = Ops.add(
      "/",
      Builtins.mergestring(
        Builtins.remove(
          directories,
          Ops.subtract(Builtins.size(directories), 1)
        ),
        "/"
      )
    ) 
    #Popup::Message(directory);
  else
    @pure_ftp_allowed_permissios_upload = -1
  end


  if @anon_homedir != "" && @pure_ftp_allowed_permissios_upload != -1
    command = Ops.add(
      Ops.add(Ops.add("ls -l ", directory), " | grep "),
      upload_dir
    )
  end
  if command != ""
    options = Convert.to_map(
      SCR.Execute(path(".target.bash_output"), command)
    )
    Builtins.y2milestone(
      "[ftp-server] (ReadPermisionUplaod) command for checking permissions for upload dir:  %1",
      command
    )
    if Ops.get(options, "exit") == 0
      result = true
    else
      result = false
    end
    if result
      permissions = Builtins.substring(
        Builtins.tostring(Ops.get(options, "stdout")),
        0,
        10
      )
      w = Builtins.filterchars(permissions, "w")
      r = Builtins.filterchars(permissions, "r")
      if Ops.less_than(Builtins.size(w), 3) ||
          Ops.less_than(Builtins.size(r), 3)
        @pure_ftp_allowed_permissios_upload = 0 
        #Popup::Message("good permissions");
      else
        @pure_ftp_allowed_permissios_upload = 1 
        #Popup::Message("wrong permissions");
      end
    end 
    #Popup::Message(tostring(pure_ftp_allowed_permissios_upload));
  end
  result
end

- (Object) ReadPUREFTPDSettings

Read current pure-ftpd configuration

@return [Boolean] successfull



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File '../../src/modules/FtpServer.rb', line 270

def ReadPUREFTPDSettings
  Builtins.foreach(SCR.Dir(path(".pure-ftpd"))) do |key|
    val = Convert.to_string(SCR.Read(Builtins.add(path(".pure-ftpd"), key)))
    #string val = (string) select((list <string>) SCR::Read(add(.pure-ftpd, key)), 0, "");
    Ops.set(@PURE_SETTINGS, key, val) if val != nil
  end

  Builtins.y2milestone("-------------PURE_SETTINGS-------------------")
  Builtins.y2milestone(
    "pure-ftpd configuration has been read: %1",
    @PURE_SETTINGS
  )
  Builtins.y2milestone("---------------------------------------------")


  true
end

- (Boolean) ReadSettings

Read current configuration

Returns:

  • (Boolean)

    successfull



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
511
512
513
514
515
516
517
518
519
520
521
522
523
# File '../../src/modules/FtpServer.rb', line 476

def ReadSettings
  result = false
  if @vsftpd_edit
    result = ReadVSFTPDSettings()
  else
    result = ReadPUREFTPDSettings()
  end
  result = InitEDIT_SETTINGS() if result

  #read info about anonymous user "ftp"
  Users.SetGUI(false)
  if Users.Read == "" && Ops.get(@EDIT_SETTINGS, "VirtualUser") == "NO"
    if @vsftpd_edit && Ops.get(@EDIT_SETTINGS, "GuestUser") != "" &&
        Ops.get(@EDIT_SETTINGS, "FtpDirLocal") == ""
      #Popup::Message("if ((vsftpd_edit) && (EDIT_SETTINGS");
      Users.SelectUserByName(Ops.get(@EDIT_SETTINGS, "GuestUser"))
      @userinfo = Users.GetCurrentUser
      guest_home_dir = Ops.get_string(@userinfo, "homeDirectory")
      if guest_home_dir != "" && guest_home_dir != nil &&
          Ops.get(@EDIT_SETTINGS, "FtpDirLocal") == ""
        Ops.set(@EDIT_SETTINGS, "FtpDirLocal", guest_home_dir)
      end
    end
    Users.SelectUserByName(Ops.get(@EDIT_SETTINGS, "FTPUser"))
    @userinfo = Users.GetCurrentUser
    @anon_homedir = Ops.get_string(@userinfo, "homeDirectory")
    @anon_uid = Ops.get_integer(@userinfo, "uidNumber")
    #y2milestone("-------------User info-------------------");
    #y2milestone("Users :CurrentUser %1", userinfo);
    #y2milestone("---------------------------------------------");
    if @anon_homedir != "" && @anon_homedir != nil
      if Ops.get(@EDIT_SETTINGS, "FtpDirAnon") == ""
        Ops.set(@EDIT_SETTINGS, "FtpDirAnon", @anon_homedir)
      elsif Ops.get(@EDIT_SETTINGS, "FtpDirAnon") != nil
        @anon_homedir = Ops.get(@EDIT_SETTINGS, "FtpDirAnon")
      end
    end
  end
  #read firewall settings
  progress_orig = Progress.set(false)
  SuSEFirewall.Read
  Progress.set(progress_orig)
  #read existing upload directory for vsftpd
  result = ReadVSFTPDUpload() if @vsftpd_edit

  result = ReadPermisionUplaod()
  result
end

- (Object) ReadVSFTPDSettings

Read current vsftpd configuration

@return [Boolean] successfull



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File '../../src/modules/FtpServer.rb', line 292

def ReadVSFTPDSettings
  Builtins.foreach(SCR.Dir(path(".vsftpd"))) do |key|
    val = Convert.to_string(SCR.Read(Builtins.add(path(".vsftpd"), key)))
    #string val = (string) select((list <string>) SCR::Read(add(.pure-ftpd, key)), 0, "");
    Ops.set(@VS_SETTINGS, key, val) if val != nil
  end
  Builtins.y2milestone("-------------VS_SETTINGS-------------------")
  Builtins.y2milestone(
    "VSFTPD configuration has been read: %1",
    @VS_SETTINGS
  )
  Builtins.y2milestone("---------------------------------------------")


  true
end

- (Object) ReadVSFTPDUpload



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
# File '../../src/modules/FtpServer.rb', line 316

def ReadVSFTPDUpload
  result = false
  command = ""
  if @anon_homedir != ""
    command = Ops.add(Ops.add("ls -l ", @anon_homedir), " | grep upload")
  end
  if command != ""
    options = Convert.to_map(
      SCR.Execute(path(".target.bash_output"), command)
    )
    Builtins.y2milestone(
      "[ftp-server] (ReadVSFTPDUpload) command for existing upload dir:  %1  output: %2",
      command,
      options
    )
    if Ops.get(options, "exit") == 0
      result = true
    else
      result = false
    end
    if result
      #Popup::Message("Work ReadVSFTPDUpload");
      @create_upload_dir = true
      permissions = Builtins.substring(
        Builtins.tostring(Ops.get(options, "stdout")),
        0,
        10
      )
      w = Builtins.filterchars(permissions, "w")
      r = Builtins.filterchars(permissions, "r")
      if Ops.less_than(Builtins.size(w), 3) ||
          Ops.less_than(Builtins.size(r), 3)
        @upload_good_permission = false 
        #Popup::Message("good permissions");
      else
        @upload_good_permission = true 
        #Popup::Message("wrong permissions");
      end
    end
  end

  result
end

- (Object) SetModified(set_modified)

Function set modified variable.

Parameters:

  • boolean

    modified



852
853
854
855
856
# File '../../src/modules/FtpServer.rb', line 852

def SetModified(set_modified)
  @modified = set_modified

  nil
end

- (Object) Summary

Create a textual summary and a list of unconfigured cards

Returns:

  • summary of the current configuration



1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
# File '../../src/modules/FtpServer.rb', line 1158

def Summary
  _S = ""
  if Builtins.size(@EDIT_SETTINGS) == 0
    # Translators: Summary head, if nothing configured
    _S = Summary.AddHeader(_S, _("FTP daemon"))
    _S = Summary.AddLine(_S, Summary.NotConfigured)
  else
    # Translators: Summary head, if something configured
    head = Builtins.sformat(
      _("FTP daemon %1"),
      @vsftpd_edit ? "vsftpd" : "pure-ftpd"
    )
    _S = Summary.AddHeader(_S, head)
    _S = Summary.AddHeader(_S, _("These options will be configured"))
    _S = Builtins.sformat("%1<ul>%2</ul></p>", _S, OptionsSummary())
  end
  _S
end

- (String) ValueUIEdit(key)

read value from PURE_EDIT_SETTINGS

Parameters:

  • key (String)

    for edit map (ID of option)

Returns:

  • (String)

    value of key from edit map



827
828
829
# File '../../src/modules/FtpServer.rb', line 827

def ValueUIEdit(key)
  Ops.get(@EDIT_SETTINGS, key)
end

- (Object) Write

Write all FtpServer settings

Returns:

  • true on success



966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
# File '../../src/modules/FtpServer.rb', line 966

def Write
  # FtpServer read dialog caption
  caption = _("Saving FTP Configuration")
  steps = 3

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/2
      _("Write the settings to the config file"),
      # Progress stage 2/2
      _("Write the settings for starting daemon")
    ],
    [
      # Progress step 1/1
      _("Writing the settings..."),
      Message.Finished
    ],
    ""
  ) #end of Progress::New(caption, " "

  # write settings
  return false if PollAbort()
  Progress.NextStage
  # write options to the config file
  Report.Error(_("Cannot write settings!")) if !WriteSettings()
  Builtins.sleep(@sl)

  return false if PollAbort()
  Progress.NextStage
  # write settings for starting daemon
  Report.Error(_("Cannot write settings for xinetd!")) if !WriteXinetd()
  Builtins.sleep(@sl)

  return false if PollAbort()
  Progress.NextStage
  # write settings for starting daemon
  if !WriteUpload()
    Report.Error(
      _("Cannot create upload directory for anonymous connections.")
    )
  end
  Builtins.sleep(@sl)


  return false if PollAbort()
  # Progress finished
  Progress.NextStage
  Builtins.sleep(@sl)

  return false if PollAbort()
  true
end

- (Boolean) WriteFirewallSettings

Write firewall configuration

Returns:

  • (Boolean)

    successfull



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
# File '../../src/modules/FtpServer.rb', line 595

def WriteFirewallSettings
  port_range = ""
  active_port = ""

  if SuSEFirewall.IsStarted
    if Ops.get(@EDIT_SETTINGS, "PassiveMode") == "YES"
      port_range = Ops.add(
        Ops.add(Ops.get(@EDIT_SETTINGS, "PasMinPort"), ":"),
        Ops.get(@EDIT_SETTINGS, "PasMaxPort")
      )
    else
      active_port = PortAliases.IsKnownPortName("ftp-data") ? "ftp-data" : "20"
    end

    suse_config = {
      "tcp_ports" => [
        PortAliases.IsKnownPortName("ftp") ? "ftp" : "21",
        active_port != "" ? active_port : port_range
      ]
    }

    if @vsftpd_edit
      return SuSEFirewallServices.SetNeededPortsAndProtocols(
        "service:vsftpd",
        suse_config
      )
    else
      return SuSEFirewallServices.SetNeededPortsAndProtocols(
        "service:pure-ftpd",
        suse_config
      )
    end
  else
    return true
  end
end

- (Boolean) WritePUREFTPDSettings

Write pure-ftpd configuration to config file

Returns:

  • (Boolean)

    successfull



529
530
531
532
533
534
535
536
537
538
# File '../../src/modules/FtpServer.rb', line 529

def WritePUREFTPDSettings
  Builtins.foreach(@PURE_SETTINGS) do |option_key, option_val|
    SCR.Write(Builtins.add(path(".pure-ftpd"), option_key), option_val)
  end
  # This is very important
  # it flushes the cache, and stores the configuration on the disk
  SCR.Write(path(".pure-ftpd"), nil)

  true
end

- (Boolean) WriteSettings

Write current configuration

Returns:

  • (Boolean)

    successfull



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
# File '../../src/modules/FtpServer.rb', line 650

def WriteSettings
  result = false
  result = WriteToSETTINGS()
  if @vsftpd_edit
    result = WriteVSFTPDSettings() if result
  else
    result = WritePUREFTPDSettings() if result
    # write homedirectory for anonymous user (ftp)
    # fto user will be change only for pure-ftpd
    # vsftpd change option anon_root
    if Ops.get(@EDIT_SETTINGS, "VirtualUser") == "NO" && !@vsftpd_edit
      if result
        if Ops.get(@EDIT_SETTINGS, "FtpDirAnon") != @anon_homedir &&
            @anon_homedir != "" &&
            @anon_homedir != nil
          error = Users.EditUser(
            { "homeDirectory" => Ops.get(@EDIT_SETTINGS, "FtpDirAnon") }
          )
          if error != nil && error != ""
            result = false
            Popup.Error(error)
          end
          if result
            if Users.CommitUser
              Users.SetGUI(false)
              error = Users.Write
              if error != nil && error != ""
                Popup.Error(error)
                result = false
              end
            end
          end #end of if (Users::CommitUser ()) {
        end #end of if ((EDIT_SETTINGS["FtpDirAnon"]:nil != anon_homedir) &&
      end #end of if (result) {
    end #end of if (EDIT_SETTINGS["VirtualUser"]:nil == "NO") {
  end # end of } else {

  result = WriteFirewallSettings() if result
  if result
    # write configuration to the firewall
    progress_orig = Progress.set(false)
    result = SuSEFirewall.Write
    Progress.set(progress_orig)
  end
  result
end

- (Boolean) WriteToEditMap(key, value)

Write value from UI to temporary structure

Parameters:

  • key (String)

    of EDIT_SETTINGS map

  • value (String)

    of “key” EDIT_SETTINGS map

Returns:

  • (Boolean)

    successfull



639
640
641
642
# File '../../src/modules/FtpServer.rb', line 639

def WriteToEditMap(key, value)
  Ops.set(@EDIT_SETTINGS, key, value)
  true
end

- (Boolean) WriteToSETTINGS

Remap UI pure-ftpd or vsftpd configuration to write structure for SCR

Returns:

  • (Boolean)

    successfull



562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File '../../src/modules/FtpServer.rb', line 562

def WriteToSETTINGS
  Builtins.foreach(@UI_keys) { |key| ValueUI(key, true) }

  Builtins.y2milestone("-------------PURE_SETTINGS-------------------")
  Builtins.y2milestone(
    "pure-ftpd writing configuration : %1",
    @PURE_SETTINGS
  )
  Builtins.y2milestone("---------------------------------------------")

  Builtins.y2milestone("-------------VS_SETTINGS-------------------")
  Builtins.y2milestone("Vsftpd writing configuration : %1", @VS_SETTINGS)
  Builtins.y2milestone("---------------------------------------------")
  true
end

- (Boolean) WriteUpload

Ask for creation upload directory It is necessary if user want to allow uploading for anonymous

Returns:

  • (Boolean)

    result of function (true/false)



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
# File '../../src/modules/FtpServer.rb', line 711

def WriteUpload
  result = true
  command = ""
  upload = ""
  options = {}
  authentication = Builtins.tointeger(Ops.get(@EDIT_SETTINGS, "AnonAuthen"))
  if @vsftpd_edit && authentication != 1 && @create_upload_dir && @upload_good_permission
    write_enable = Ops.get(@EDIT_SETTINGS, "EnableUpload") == "YES" ? true : false
    anon_upload = Ops.get(@EDIT_SETTINGS, "AnonReadOnly") == "NO" ? true : false
    anon_create_dirs = Ops.get(@EDIT_SETTINGS, "AnonCreatDirs") == "YES" ? true : false
    if write_enable && (anon_upload || anon_create_dirs)
      if Builtins.substring(
          @anon_homedir,
          Ops.subtract(Builtins.size(@anon_homedir), 1)
        ) == "/"
        upload = "upload"
      else
        upload = "/upload"
      end
    end
    command = "dir=`ls "
    command = Ops.add(command, @anon_homedir)
    command = Ops.add(
      command,
      " | grep upload`; if [ -z $dir ]; then mkdir "
    )
    command = Ops.add(
      Ops.add(Ops.add(command, @anon_homedir), upload),
      "; chown "
    )

    if Ops.get(@EDIT_SETTINGS, "GuestUser") != ""
      command = Ops.add(
        Ops.add(Ops.add(command, Ops.get(@EDIT_SETTINGS, "GuestUser")), ":"),
        Ops.get(@EDIT_SETTINGS, "GuestUser")
      )
    elsif Ops.get(@EDIT_SETTINGS, "FTPUser") != ""
      command = Ops.add(
        Ops.add(Ops.add(command, Ops.get(@EDIT_SETTINGS, "FTPUser")), ":"),
        Ops.get(@EDIT_SETTINGS, "FTPUser")
      )
    end

    command = Ops.add(
      Ops.add(Ops.add(Ops.add(command, " "), @anon_homedir), upload),
      "; chmod 766 "
    )
    command = Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(Ops.add(command, @anon_homedir), upload),
            "; else chmod 766 "
          ),
          @anon_homedir
        ),
        upload
      ),
      "; fi"
    )
    # "dir=`ls /srv/ftp/ | grep upload`; if [ -z $dir ]; then echo $dir; mkdir /srv/ftp/upload;
    #  chown ftp:ftp /srv/ftp/upload/; chmod 755 /srv/ftp/upload; else chmod 766 /srv/ftp/upload/; fi"
    Builtins.y2milestone(
      "[ftp-server] (WriteUpload) bash command for creating upload dir : %1",
      command
    )
    options = Convert.to_map(
      SCR.Execute(path(".target.bash_output"), command)
    )
    if Ops.get(options, "exit") == 0
      result = true
    else
      result = false
    end 

    #Popup::Message(command);
  else
    result = true
  end
  #restart/reaload daemons...
  if @vsftpd_edit
    if Service.Status("vsftpd") == 0
      options = Convert.to_map(
        SCR.Execute(path(".target.bash_output"), "rcvsftpd restart")
      )
    end
  else
    if Service.Status("pure-ftpd") == 0
      options = Convert.to_map(
        SCR.Execute(path(".target.bash_output"), "rcpure-ftpd restart")
      )
    end
  end

  #update permissions for home directory if upload is enabled...
  if @pure_ftp_allowed_permissios_upload != -1 && @change_permissions
    if @vsftpd_edit
      command = Ops.add("chmod 755 ", @anon_homedir)
      options = Convert.to_map(
        SCR.Execute(path(".target.bash_output"), command)
      )
    else
      command = Ops.add("chmod 777 ", @anon_homedir)
      options = Convert.to_map(
        SCR.Execute(path(".target.bash_output"), command)
      )
    end
  end

  result
end

- (Boolean) WriteVSFTPDSettings

Write vsftpd configuration to config file

Returns:

  • (Boolean)

    successfull



544
545
546
547
548
549
550
551
552
553
# File '../../src/modules/FtpServer.rb', line 544

def WriteVSFTPDSettings
  Builtins.foreach(@VS_SETTINGS) do |option_key, option_val|
    SCR.Write(Builtins.add(path(".vsftpd"), option_key), option_val)
  end
  # This is very important
  # it flushes the cache, and stores the configuration on the disk
  SCR.Write(path(".vsftpd"), nil)

  true
end

- (Boolean) WriteXinetd

Write current configuration

Returns:

  • (Boolean)

    result of function (true/false)



700
701
702
703
704
705
706
# File '../../src/modules/FtpServer.rb', line 700

def WriteXinetd
  result = false
  if @vsftpd_xined_id != -1
    result = WriteStartViaXinetd(@start_xinetd, false)
  end
  result
end