741 |
10 Oct 06 |
olle |
1 |
/* |
1652 |
22 May 07 |
gregory |
$Id$ |
741 |
10 Oct 06 |
olle |
3 |
|
1916 |
31 Aug 07 |
jari |
Copyright (C) 2006 Olle Mansson |
1916 |
31 Aug 07 |
jari |
Copyright (C) 2007 Gregory Vincic |
741 |
10 Oct 06 |
olle |
6 |
|
1652 |
22 May 07 |
gregory |
This file is part of Proteios. |
1652 |
22 May 07 |
gregory |
Available at http://www.proteios.org/ |
741 |
10 Oct 06 |
olle |
9 |
|
1652 |
22 May 07 |
gregory |
Proteios is free software; you can redistribute it and/or modify it |
1652 |
22 May 07 |
gregory |
under the terms of the GNU General Public License as published by |
1652 |
22 May 07 |
gregory |
the Free Software Foundation; either version 2 of the License, or |
1652 |
22 May 07 |
gregory |
(at your option) any later version. |
741 |
10 Oct 06 |
olle |
14 |
|
1652 |
22 May 07 |
gregory |
Proteios is distributed in the hope that it will be useful, but |
1652 |
22 May 07 |
gregory |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1652 |
22 May 07 |
gregory |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1652 |
22 May 07 |
gregory |
General Public License for more details. |
741 |
10 Oct 06 |
olle |
19 |
|
1652 |
22 May 07 |
gregory |
You should have received a copy of the GNU General Public License |
1652 |
22 May 07 |
gregory |
along with this program; if not, write to the Free Software |
1652 |
22 May 07 |
gregory |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
1652 |
22 May 07 |
gregory |
02111-1307, USA. |
1652 |
22 May 07 |
gregory |
24 |
*/ |
741 |
10 Oct 06 |
olle |
25 |
|
741 |
10 Oct 06 |
olle |
// Xerver Free Web Server |
741 |
10 Oct 06 |
olle |
// Copyright (C) 2002-2005 Omid Rouhani |
741 |
10 Oct 06 |
olle |
28 |
// |
741 |
10 Oct 06 |
olle |
29 |
// |
741 |
10 Oct 06 |
olle |
// This program is free software; you can redistribute it and/or |
741 |
10 Oct 06 |
olle |
// modify it under the terms of the GNU General Public License |
741 |
10 Oct 06 |
olle |
// as published by the Free Software Foundation; either version 2 |
741 |
10 Oct 06 |
olle |
// of the License, or (at your option) any later version. |
741 |
10 Oct 06 |
olle |
34 |
// |
741 |
10 Oct 06 |
olle |
// This program is distributed in the hope that it will be useful, |
741 |
10 Oct 06 |
olle |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
741 |
10 Oct 06 |
olle |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
741 |
10 Oct 06 |
olle |
// GNU General Public License for more details. |
741 |
10 Oct 06 |
olle |
39 |
// |
741 |
10 Oct 06 |
olle |
// You should have received a copy of the GNU General Public License |
741 |
10 Oct 06 |
olle |
// along with this program; if not, write to the Free Software |
741 |
10 Oct 06 |
olle |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
741 |
10 Oct 06 |
olle |
43 |
// |
741 |
10 Oct 06 |
olle |
44 |
// |
741 |
10 Oct 06 |
olle |
45 |
// ############################################################# |
741 |
10 Oct 06 |
olle |
// ## YOU CAN CONTACT THE AUTHOR (OMID ROUHANI) AT: ## |
741 |
10 Oct 06 |
olle |
// ## HTTP://WWW.JAVASCRIPT.NU/XERVER/ ## |
741 |
10 Oct 06 |
olle |
48 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## IF YOUR SOFTWARE IS NOT RELEASED UNDER THE ## |
741 |
10 Oct 06 |
olle |
// ## GNU GENERAL PUBLIC LICENSE (GPL), ## |
741 |
10 Oct 06 |
olle |
// ## PLEASE DO NOT COPY ANYTHING FROM THIS SOURCE CODE!!! ## |
741 |
10 Oct 06 |
olle |
52 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## FOR FULL LICENSE, PLEASE READ "XERVER LICENSE". ## |
741 |
10 Oct 06 |
olle |
54 |
// ############################################################# |
741 |
10 Oct 06 |
olle |
55 |
|
1652 |
22 May 07 |
gregory |
56 |
package se.lu.thep.coreftpd.ftp_server; |
741 |
10 Oct 06 |
olle |
57 |
|
790 |
23 Oct 06 |
olle |
58 |
import org.proteios.core.PropertiesFileHandler; |
741 |
10 Oct 06 |
olle |
59 |
|
741 |
10 Oct 06 |
olle |
60 |
/** |
1652 |
22 May 07 |
gregory |
61 |
* |
1652 |
22 May 07 |
gregory |
* <B>About this class:</B> <BR> |
741 |
10 Oct 06 |
olle |
* This represents the settings for Xerver FTP server (read from "FTP.cfg"). |
741 |
10 Oct 06 |
olle |
* <BR> |
741 |
10 Oct 06 |
olle |
* You can't write to the settings file with this class, only read the settings. |
1652 |
22 May 07 |
gregory |
66 |
* |
741 |
10 Oct 06 |
olle |
* @author <a href="http://www.JavaScript.nu/xerver/" TARGET="_top">Omid Rouhani</a> |
741 |
10 Oct 06 |
olle |
* @version 1.0 |
741 |
10 Oct 06 |
olle |
69 |
*/ |
741 |
10 Oct 06 |
olle |
70 |
|
1652 |
22 May 07 |
gregory |
71 |
final public class FTPSettings { |
1652 |
22 May 07 |
gregory |
72 |
private final static String s_initFile = FTPServerController.s_initFile; |
741 |
10 Oct 06 |
olle |
73 |
|
741 |
10 Oct 06 |
olle |
74 |
public static int i_portNr; |
1652 |
22 May 07 |
gregory |
75 |
|
741 |
10 Oct 06 |
olle |
76 |
public static int i_howToShowAlias; |
1652 |
22 May 07 |
gregory |
77 |
|
741 |
10 Oct 06 |
olle |
78 |
public static boolean b_guestAccountExists; |
1652 |
22 May 07 |
gregory |
79 |
|
741 |
10 Oct 06 |
olle |
80 |
public static int i_maxTimeToIdle; |
1652 |
22 May 07 |
gregory |
81 |
|
741 |
10 Oct 06 |
olle |
82 |
public static int i_maxNumberOfNOOP; |
1652 |
22 May 07 |
gregory |
83 |
|
741 |
10 Oct 06 |
olle |
84 |
public static int i_dataPortNr; |
741 |
10 Oct 06 |
olle |
85 |
|
2703 |
16 May 08 |
olle |
86 |
public static int [] ai_portRange = null; |
2703 |
16 May 08 |
olle |
87 |
|
790 |
23 Oct 06 |
olle |
88 |
/** |
790 |
23 Oct 06 |
olle |
* Logger used. Used to log specific events. |
790 |
23 Oct 06 |
olle |
90 |
*/ |
790 |
23 Oct 06 |
olle |
91 |
private static final org.apache.log4j.Logger log = org.apache.log4j.LogManager |
1652 |
22 May 07 |
gregory |
92 |
.getLogger("se.lu.thep.coreftpd.ftp_server"); |
741 |
10 Oct 06 |
olle |
93 |
|
1652 |
22 May 07 |
gregory |
94 |
public FTPSettings() throws Exception { |
741 |
10 Oct 06 |
olle |
95 |
updateData(); |
741 |
10 Oct 06 |
olle |
96 |
} |
741 |
10 Oct 06 |
olle |
97 |
|
1652 |
22 May 07 |
gregory |
98 |
public void updateData() throws Exception { |
790 |
23 Oct 06 |
olle |
// *** Debug Info |
1652 |
22 May 07 |
gregory |
100 |
log.info("FTPSettings::updateData(): Start - s_initFile = \"" |
1652 |
22 May 07 |
gregory |
101 |
+ s_initFile + "\""); |
790 |
23 Oct 06 |
olle |
102 |
/* |
790 |
23 Oct 06 |
olle |
* Open FTP configuration file |
790 |
23 Oct 06 |
olle |
104 |
*/ |
790 |
23 Oct 06 |
olle |
105 |
PropertiesFileHandler pfh = new PropertiesFileHandler(s_initFile); |
790 |
23 Oct 06 |
olle |
// *** Debug Info |
1652 |
22 May 07 |
gregory |
107 |
log.info("FTPSettings::updateData(): pfh.getProperty(\"PORT_NR\") = \"" |
1652 |
22 May 07 |
gregory |
108 |
+ pfh.getProperty("PORT_NR") + "\""); |
1652 |
22 May 07 |
gregory |
109 |
log |
1652 |
22 May 07 |
gregory |
110 |
.info("FTPSettings::updateData(): pfh.getProperty(\"SHOW_ALIAS\") = \"" |
1652 |
22 May 07 |
gregory |
111 |
+ pfh.getProperty("SHOW_ALIAS") + "\""); |
1652 |
22 May 07 |
gregory |
112 |
log |
1652 |
22 May 07 |
gregory |
113 |
.info("FTPSettings::updateData(): pfh.getProperty(\"MAX_IDLE_TIME\") = \"" |
1652 |
22 May 07 |
gregory |
114 |
+ pfh.getProperty("MAX_IDLE_TIME") + "\""); |
1652 |
22 May 07 |
gregory |
115 |
log |
1652 |
22 May 07 |
gregory |
116 |
.info("FTPSettings::updateData(): pfh.getProperty(\"MAX_NOOP_ALLOWED\") = \"" |
1652 |
22 May 07 |
gregory |
117 |
+ pfh.getProperty("MAX_NOOP_ALLOWED") + "\""); |
1652 |
22 May 07 |
gregory |
118 |
log |
1652 |
22 May 07 |
gregory |
119 |
.info("FTPSettings::updateData(): pfh.getProperty(\"DATA_PORT_NR\") = \"" |
1652 |
22 May 07 |
gregory |
120 |
+ pfh.getProperty("DATA_PORT_NR") + "\""); |
1652 |
22 May 07 |
gregory |
121 |
log |
2703 |
16 May 08 |
olle |
122 |
.info("FTPSettings::updateData(): pfh.getProperty(\"PASSIVE_PORT_RANGE\") = \"" |
2703 |
16 May 08 |
olle |
123 |
+ pfh.getProperty("PASSIVE_PORT_RANGE") + "\""); |
2703 |
16 May 08 |
olle |
124 |
log |
1652 |
22 May 07 |
gregory |
125 |
.info("FTPSettings::updateData(): pfh.getProperty(\"GUEST_ACCOUNT\") = \"" |
1652 |
22 May 07 |
gregory |
126 |
+ pfh.getProperty("GUEST_ACCOUNT") + "\""); |
790 |
23 Oct 06 |
olle |
127 |
setValue("PORT_NR", pfh.getProperty("PORT_NR")); |
790 |
23 Oct 06 |
olle |
128 |
setValue("SHOW_ALIAS", pfh.getProperty("SHOW_ALIAS")); |
790 |
23 Oct 06 |
olle |
129 |
setValue("MAX_IDLE_TIME", pfh.getProperty("MAX_IDLE_TIME")); |
790 |
23 Oct 06 |
olle |
130 |
setValue("MAX_NOOP_ALLOWED", pfh.getProperty("MAX_NOOP_ALLOWED")); |
790 |
23 Oct 06 |
olle |
131 |
setValue("DATA_PORT_NR", pfh.getProperty("DATA_PORT_NR")); |
2703 |
16 May 08 |
olle |
132 |
setValue("PASSIVE_PORT_RANGE", pfh.getProperty("PASSIVE_PORT_RANGE")); |
790 |
23 Oct 06 |
olle |
133 |
setValue("GUEST_ACCOUNT", pfh.getProperty("GUEST_ACCOUNT")); |
790 |
23 Oct 06 |
olle |
134 |
/* |
1652 |
22 May 07 |
gregory |
* BufferedReader br_userFile = new BufferedReader(new |
1652 |
22 May 07 |
gregory |
* FileReader(s_initFile)); |
1652 |
22 May 07 |
gregory |
137 |
* |
1652 |
22 May 07 |
gregory |
* String tmpLine; while ((tmpLine=br_userFile.readLine())!=null) { |
1652 |
22 May 07 |
gregory |
* tmpLine.trim(); if (tmpLine.length()>0) { if (tmpLine.charAt(0)!=';') { |
1652 |
22 May 07 |
gregory |
* String varName, varValue; int indexOfValue=tmpLine.indexOf("="); |
1652 |
22 May 07 |
gregory |
* varName=tmpLine.substring(0,indexOfValue); |
1652 |
22 May 07 |
gregory |
* varValue=tmpLine.substring(indexOfValue+1); |
1652 |
22 May 07 |
gregory |
143 |
* |
1652 |
22 May 07 |
gregory |
* setValue(varName,varValue); } } } |
1652 |
22 May 07 |
gregory |
145 |
* |
1652 |
22 May 07 |
gregory |
* br_userFile.close(); |
1652 |
22 May 07 |
gregory |
147 |
*/ |
741 |
10 Oct 06 |
olle |
148 |
} |
741 |
10 Oct 06 |
olle |
149 |
|
1652 |
22 May 07 |
gregory |
150 |
private void setValue(String varName, String varValue) { |
1652 |
22 May 07 |
gregory |
// System.out.println(varName+" "+varValue); |
741 |
10 Oct 06 |
olle |
152 |
if (varName.equalsIgnoreCase("PORT_NR")) |
1652 |
22 May 07 |
gregory |
153 |
i_portNr = Integer.parseInt(varValue); |
741 |
10 Oct 06 |
olle |
154 |
else if (varName.equalsIgnoreCase("SHOW_ALIAS")) |
1652 |
22 May 07 |
gregory |
155 |
i_howToShowAlias = Integer.parseInt(varValue); |
741 |
10 Oct 06 |
olle |
156 |
else if (varName.equalsIgnoreCase("MAX_IDLE_TIME")) |
1652 |
22 May 07 |
gregory |
157 |
i_maxTimeToIdle = 1000 * Integer.parseInt(varValue); |
741 |
10 Oct 06 |
olle |
158 |
else if (varName.equalsIgnoreCase("MAX_NOOP_ALLOWED")) |
1652 |
22 May 07 |
gregory |
159 |
i_maxNumberOfNOOP = Integer.parseInt(varValue); |
741 |
10 Oct 06 |
olle |
160 |
else if (varName.equalsIgnoreCase("DATA_PORT_NR")) |
1652 |
22 May 07 |
gregory |
161 |
i_dataPortNr = Integer.parseInt(varValue); |
2703 |
16 May 08 |
olle |
162 |
else if (varName.equalsIgnoreCase("PASSIVE_PORT_RANGE")) |
2703 |
16 May 08 |
olle |
163 |
{ |
2703 |
16 May 08 |
olle |
164 |
int i_firstComma = varValue.indexOf(","); |
2703 |
16 May 08 |
olle |
165 |
if (i_firstComma != -1) |
2703 |
16 May 08 |
olle |
166 |
{ |
2703 |
16 May 08 |
olle |
167 |
ai_portRange = new int[2]; |
2703 |
16 May 08 |
olle |
168 |
ai_portRange[0] = Integer.parseInt(varValue.substring(0,i_firstComma)); |
2703 |
16 May 08 |
olle |
169 |
ai_portRange[1] = Integer.parseInt(varValue.substring(i_firstComma+1)); |
2703 |
16 May 08 |
olle |
170 |
} |
2703 |
16 May 08 |
olle |
171 |
} |
2703 |
16 May 08 |
olle |
172 |
else if (varName.equalsIgnoreCase("GUEST_ACCOUNT")) |
2703 |
16 May 08 |
olle |
173 |
{ |
1652 |
22 May 07 |
gregory |
174 |
int i_guestAccountExists = Integer.parseInt(varValue); |
1652 |
22 May 07 |
gregory |
175 |
if (i_guestAccountExists == 0) |
1652 |
22 May 07 |
gregory |
176 |
b_guestAccountExists = false; |
741 |
10 Oct 06 |
olle |
177 |
else |
1652 |
22 May 07 |
gregory |
178 |
b_guestAccountExists = true; |
741 |
10 Oct 06 |
olle |
179 |
} |
741 |
10 Oct 06 |
olle |
180 |
} |
741 |
10 Oct 06 |
olle |
181 |
} |