Class: Yast::FtpServerClass

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

Overview

Configure both vsftpd and pure-ftpd in a single class.

For the configuration we have 3 vocabularies, mapped by Yast::FtpServerWriteLoadInclude#ValueUI.

  • pure-ftpd uses CamelCase keys

  • vsftpd uses snake_case keys

  • yast uses CamelCase keys which are almost(!!1!) the same as for pure-ftpd.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (string) anon_homedir

Returns:

  • (string)


1148
# File '../../src/modules/FtpServer.rb', line 1148

publish_variable :anon_homedir, "string"

- (integer) anon_uid

Returns:

  • (integer)


1149
# File '../../src/modules/FtpServer.rb', line 1149

publish_variable :anon_uid, "integer"

- (boolean) change_permissions

Returns:

  • (boolean)


1147
# File '../../src/modules/FtpServer.rb', line 1147

publish_variable :change_permissions, "boolean"

- (boolean) create_upload_dir

Returns:

  • (boolean)


1144
# File '../../src/modules/FtpServer.rb', line 1144

publish_variable :create_upload_dir, "boolean"

- (Hash<String,String>) DEFAULT_CONFIG

Defaults for #EDIT_SETTINGS in case the value is not found in the system settings.

Returns:

  • (Hash<String,String>)


1163
# File '../../src/modules/FtpServer.rb', line 1163

publish :variable => :DEFAULT_CONFIG, :type => "map <string, string>"

- (Hash<String,String>) EDIT_SETTINGS

Uses CamelCase with similar but not the same keys as #PURE_SETTINGS. ValueUI maps it to #PURE_SETTINGS and #VS_SETTINGS.

Returns:

  • (Hash<String,String>)


1182
# File '../../src/modules/FtpServer.rb', line 1182

publish :variable => :EDIT_SETTINGS, :type => "map <string, string>"

- (boolean) ftps

Returns:

  • (boolean)


1188
# File '../../src/modules/FtpServer.rb', line 1188

publish_variable :ftps, "boolean"

- (boolean) modified

Returns:

  • (boolean)


1133
# File '../../src/modules/FtpServer.rb', line 1133

publish_variable :modified, "boolean"

- (boolean) proposal_valid

Returns:

  • (boolean)


1134
# File '../../src/modules/FtpServer.rb', line 1134

publish_variable :proposal_valid, "boolean"

- (integer) pure_ftp_allowed_permissios_upload

Returns:

  • (integer)


1146
# File '../../src/modules/FtpServer.rb', line 1146

publish_variable :pure_ftp_allowed_permissios_upload, "integer"

- (boolean) pure_ftp_xinetd_running

Returns:

  • (boolean)


1141
# File '../../src/modules/FtpServer.rb', line 1141

publish_variable :pure_ftp_xinetd_running, "boolean"

- (list <string>) pure_ftpd_xinet_conf

Returns:

  • (list <string>)


1150
# File '../../src/modules/FtpServer.rb', line 1150

publish_variable :pure_ftpd_xinet_conf, "list <string>"

- (Hash<String,String>) PURE_SETTINGS

Uses CamelCase, ValueUI maps it to #EDIT_SETTINGS and #DEFAULT_CONFIG.

Returns:

  • (Hash<String,String>)


1169
# File '../../src/modules/FtpServer.rb', line 1169

publish :variable => :PURE_SETTINGS, :type => "map <string, string>"

- (boolean) pureftpd_installed

Returns:

  • (boolean)


1137
# File '../../src/modules/FtpServer.rb', line 1137

publish_variable :pureftpd_installed, "boolean"

- (integer) pureftpd_xined_id

Returns:

  • (integer)


1139
# File '../../src/modules/FtpServer.rb', line 1139

publish_variable :pureftpd_xined_id, "integer"

- (boolean) start_xinetd

Returns:

  • (boolean)


1140
# File '../../src/modules/FtpServer.rb', line 1140

publish_variable :start_xinetd, "boolean"

- (boolean) stop_daemon_xinetd

Returns:

  • (boolean)


1143
# File '../../src/modules/FtpServer.rb', line 1143

publish_variable :stop_daemon_xinetd, "boolean"

- (Array<String>) UI_keys (readonly)

A list of setting keys yast cares about, in the #EDIT_SETTINGS vocabulary. It should be made a constant.

Returns:

  • (Array<String>)


1157
# File '../../src/modules/FtpServer.rb', line 1157

publish :variable => :UI_keys, :type => "list <string>"

- (boolean) upload_good_permission

Returns:

  • (boolean)


1145
# File '../../src/modules/FtpServer.rb', line 1145

publish_variable :upload_good_permission, "boolean"

- (Hash<String,String>) VS_SETTINGS

Uses snake_case, ValueUI maps it to #EDIT_SETTINGS and #DEFAULT_CONFIG.

Returns:

  • (Hash<String,String>)


1175
# File '../../src/modules/FtpServer.rb', line 1175

publish :variable => :VS_SETTINGS, :type => "map <string, string>"

- (boolean) vsftp_xinetd_running

Returns:

  • (boolean)


1142
# File '../../src/modules/FtpServer.rb', line 1142

publish_variable :vsftp_xinetd_running, "boolean"

- (boolean) vsftpd_edit

Returns:

  • (boolean)


1135
# File '../../src/modules/FtpServer.rb', line 1135

publish_variable :vsftpd_edit, "boolean"

- (boolean) vsftpd_installed

Returns:

  • (boolean)


1136
# File '../../src/modules/FtpServer.rb', line 1136

publish_variable :vsftpd_installed, "boolean"

- (integer) vsftpd_xined_id

Returns:

  • (integer)


1138
# File '../../src/modules/FtpServer.rb', line 1138

publish_variable :vsftpd_xined_id, "integer"

- (boolean) write_only

Returns:

  • (boolean)


1189
# File '../../src/modules/FtpServer.rb', line 1189

publish_variable :write_only, "boolean"

Class Method Details

+ (Object) publish_variable(name, type)

This helper allows YARD to extract DSL-defined attributes. Unfortunately YARD has problems with the Capitalized ones, so those must be done manually.



1123
1124
1125
# File '../../src/modules/FtpServer.rb', line 1123

def self.publish_variable(name, type)
  publish :variable => name, :type => type
end

Instance Method Details

- (Boolean) Abort

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

Returns:

  • (Boolean)

    result of Popup::ReallyAbort(GetModified()



790
791
792
# File '../../src/modules/FtpServer.rb', line 790

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.



1109
1110
1111
1112
1113
1114
1115
# File '../../src/modules/FtpServer.rb', line 1109

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 ())



1033
1034
1035
# File '../../src/modules/FtpServer.rb', line 1033

def Export
  deep_copy(@EDIT_SETTINGS)
end

- (Boolean) GetModified

Returns whether the configuration has been modified.

Returns:

  • (Boolean)

    modified



774
775
776
# File '../../src/modules/FtpServer.rb', line 774

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



950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
# File '../../src/modules/FtpServer.rb', line 950

def Import(settings)
  settings = deep_copy(settings)
  # Evaluate the kind of ftpserver at first via xinetd....
  # (bnc#892701)
  IdFTPXinetd()
  # ...and check/initialize the correct ftpserver which will
  # be used for configuration.
  # (bnc#907354)
  InitDaemon()

  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



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
1022
1023
1024
1025
1026
1027
1028
# File '../../src/modules/FtpServer.rb', line 976

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



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File '../../src/modules/FtpServer.rb', line 413

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

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

  true
end

- (Object) main



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

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 = []

  @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"
  ]

  @DEFAULT_CONFIG = {
    "ChrootEnable"     => "NO",
    "VerboseLogging"   => "NO",  # Default value for pure-ftpd.
    "log_ftp_protocol" => "YES", # Default value for vsftp (bnc#888287). 
    "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"
  }

  @PURE_SETTINGS = {}
  @VS_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
end

- (Object) Modified

Data was modified?

Returns:

  • true if modified



807
808
809
810
# File '../../src/modules/FtpServer.rb', line 807

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

- (String) OptionsSummary

Create unsorted list of options

Returns:

  • (String)

    Returnes string with RichText-formated list



1039
1040
1041
1042
1043
1044
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
# File '../../src/modules/FtpServer.rb', line 1039

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

- (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



798
799
800
801
802
803
# File '../../src/modules/FtpServer.rb', line 798

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



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

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

Read pure-fptd configuration checking permissions for upload

@return [Boolean] successfull



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

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),
      ""
    )
    directory = Ops.add(
      "/",
      Builtins.mergestring(
        Builtins.remove(
          directories,
          Ops.subtract(Builtins.size(directories), 1)
        ),
        "/"
      )
    ) 
  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 
      else
        @pure_ftp_allowed_permissios_upload = 1 
      end
    end 
  end
  result
end

- (Object) ReadPUREFTPDSettings

Read current pure-ftpd configuration

@return [Boolean] successfull



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File '../../src/modules/FtpServer.rb', line 247

def ReadPUREFTPDSettings
  Builtins.foreach(SCR.Dir(path(".pure-ftpd"))) do |key|
    val = Convert.to_string(SCR.Read(Builtins.add(path(".pure-ftpd"), key)))
    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



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

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



266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File '../../src/modules/FtpServer.rb', line 266

def ReadVSFTPDSettings
  Builtins.foreach(SCR.Dir(path(".vsftpd"))) do |key|
    val = Convert.to_string(SCR.Read(Builtins.add(path(".vsftpd"), key)))
    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

Read vsftpd configuration existing upload file and permissions

@return [Boolean] successfull



286
287
288
289
290
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
# File '../../src/modules/FtpServer.rb', line 286

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
      @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 
      else
        @upload_good_permission = true 
      end
    end
  end

  result
end

- (Object) SetModified(set_modified)

Function set #modified variable.

Parameters:

  • set_modified (Boolean)


781
782
783
784
785
# File '../../src/modules/FtpServer.rb', line 781

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



1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File '../../src/modules/FtpServer.rb', line 1085

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



767
768
769
# File '../../src/modules/FtpServer.rb', line 767

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

- (Object) Write

Write all FtpServer settings

Returns:

  • true on success



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

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



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

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



488
489
490
491
492
493
494
495
496
497
# File '../../src/modules/FtpServer.rb', line 488

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



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

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



581
582
583
584
# File '../../src/modules/FtpServer.rb', line 581

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



519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File '../../src/modules/FtpServer.rb', line 519

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)



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

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 
  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



503
504
505
506
507
508
509
510
511
512
# File '../../src/modules/FtpServer.rb', line 503

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)



642
643
644
645
646
647
648
# File '../../src/modules/FtpServer.rb', line 642

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