001: //httpRemoteProxyConfig.java
002: //-----------------------
003: //part of the AnomicHTTPD caching proxy
004: //(C) by Michael Peter Christen; mc@anomic.de
005: //first published on http://www.anomic.de
006: //Frankfurt, Germany, 2004
007: //
008: //this file was contributed by Martin Thelian
009: //$LastChangedDate$
010: //$LastChangedBy$
011: //$LastChangedRevision$
012: //
013: //This program is free software; you can redistribute it and/or modify
014: //it under the terms of the GNU General Public License as published by
015: //the Free Software Foundation; either version 2 of the License, or
016: //(at your option) any later version.
017: //
018: //This program is distributed in the hope that it will be useful,
019: //but WITHOUT ANY WARRANTY; without even the implied warranty of
020: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
021: //GNU General Public License for more details.
022: //
023: //You should have received a copy of the GNU General Public License
024: //along with this program; if not, write to the Free Software
025: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
026: //
027: //Using this software in any meaning (reading, learning, copying, compiling,
028: //running) means that you agree that the Author(s) is (are) not responsible
029: //for cost, loss of data or any harm that may be caused directly or indirectly
030: //by usage of this softare or this documentation. The usage of this software
031: //is on your own risk. The installation and usage (starting/running) of this
032: //software may allow other people or application to access your computer and
033: //any attached devices and is highly dependent on the configuration of the
034: //software which must be done by the user of the software; the author(s) is
035: //(are) also not responsible for proper configuration and usage of the
036: //software, even if provoked by documentation provided together with
037: //the software.
038: //
039: //Any changes to this file according to the GPL as documented in the file
040: //gpl.txt aside this file in the shipment you received can be done to the
041: //lines that follows this copyright notice here, but changes must not be
042: //done inside the copyright notive above. A re-distribution must contain
043: //the intact and unchanged copyright notice.
044: //Contributions and changes to the program code must be marked as such.
045:
046: //You must compile this file with
047: //javac -classpath .:../Classes Settings_p.java
048: //if the shell's current path is HTROOT
049:
050: package de.anomic.http;
051:
052: import java.util.HashSet;
053:
054: import de.anomic.plasma.plasmaSwitchboard;
055:
056: public final class httpRemoteProxyConfig {
057:
058: /*
059: * Remote Proxy configuration
060: */
061: private boolean remoteProxyUse;
062: private boolean remoteProxyUse4Yacy;
063: private boolean remoteProxyUse4SSL;
064:
065: private String remoteProxyHost;
066: private int remoteProxyPort;
067: private String remoteProxyUser;
068: private String remoteProxyPwd;
069:
070: private String remoteProxyNoProxy = "";
071: private String[] remoteProxyNoProxyPatterns = null;
072:
073: public final HashSet<String> remoteProxyAllowProxySet = new HashSet<String>();
074: public final HashSet<String> remoteProxyDisallowProxySet = new HashSet<String>();
075:
076: public boolean useProxy() {
077: return this .remoteProxyUse;
078: }
079:
080: public boolean useProxy4Yacy() {
081: return this .remoteProxyUse4Yacy;
082: }
083:
084: public boolean useProxy4SSL() {
085: return this .remoteProxyUse4SSL;
086: }
087:
088: public String getProxyHost() {
089: return this .remoteProxyHost;
090: }
091:
092: public int getProxyPort() {
093: return this .remoteProxyPort;
094: }
095:
096: public String getProxyUser() {
097: return this .remoteProxyUser;
098: }
099:
100: public String getProxyPwd() {
101: return this .remoteProxyPwd;
102: }
103:
104: public String getProxyNoProxy() {
105: return this .remoteProxyNoProxy;
106: }
107:
108: public String[] getProxyNoProxyPatterns() {
109: return this .remoteProxyNoProxyPatterns;
110: }
111:
112: public String toString() {
113: StringBuffer toStrBuf = new StringBuffer();
114:
115: toStrBuf.append("Status: ").append(
116: this .remoteProxyUse ? "ON" : "OFF").append(" | ")
117: .append("Host: ");
118: if ((this .remoteProxyUser != null)
119: && (this .remoteProxyUser.length() > 0)) {
120: toStrBuf.append(this .remoteProxyUser).append("@");
121: }
122: toStrBuf.append(
123: (this .remoteProxyHost == null) ? "unknown"
124: : this .remoteProxyHost).append(":").append(
125: this .remoteProxyPort).append(" | ").append(
126: "Usage: HTTP");
127: if (this .remoteProxyUse4Yacy)
128: toStrBuf.append(" YACY");
129: if (this .remoteProxyUse4SSL)
130: toStrBuf.append(" SSL");
131: toStrBuf.append(" | ").append("No Proxy for: ").append(
132: this .remoteProxyNoProxy);
133:
134: return new String(toStrBuf);
135: }
136:
137: public static httpRemoteProxyConfig init(String proxyHostName,
138: int proxyHostPort) {
139: httpRemoteProxyConfig newConfig = new httpRemoteProxyConfig();
140:
141: newConfig.remoteProxyUse = true;
142: newConfig.remoteProxyUse4SSL = true;
143: newConfig.remoteProxyUse4Yacy = true;
144: newConfig.remoteProxyPort = proxyHostPort;
145: newConfig.remoteProxyHost = proxyHostName;
146: if ((newConfig.remoteProxyHost == null)
147: || (newConfig.remoteProxyHost.length() == 0)) {
148: newConfig.remoteProxyUse = false;
149: }
150:
151: return newConfig;
152: }
153:
154: public static httpRemoteProxyConfig init(plasmaSwitchboard sb) {
155: httpRemoteProxyConfig newConfig = new httpRemoteProxyConfig();
156:
157: // determining if remote proxy usage is enabled
158: newConfig.remoteProxyUse = sb.getConfig("remoteProxyUse",
159: "false").equalsIgnoreCase("true");
160:
161: // determining if remote proxy should be used for yacy -> yacy communication
162: newConfig.remoteProxyUse4Yacy = sb.getConfig(
163: "remoteProxyUse4Yacy", "true").equalsIgnoreCase("true");
164:
165: // determining if remote proxy should be used for ssl connections
166: newConfig.remoteProxyUse4SSL = sb.getConfig(
167: "remoteProxyUse4SSL", "true").equalsIgnoreCase("true");
168:
169: // reading the proxy host name
170: newConfig.remoteProxyHost = sb.getConfig("remoteProxyHost", "")
171: .trim();
172: if ((newConfig.remoteProxyHost == null)
173: || (newConfig.remoteProxyHost.length() == 0)) {
174: newConfig.remoteProxyUse = false;
175: }
176:
177: // reading the proxy host port
178: try {
179: newConfig.remoteProxyPort = Integer.parseInt(sb.getConfig(
180: "remoteProxyPort", "3128"));
181: } catch (NumberFormatException e) {
182: newConfig.remoteProxyPort = 3128;
183: }
184:
185: newConfig.remoteProxyUser = sb.getConfig("remoteProxyUser", "")
186: .trim();
187: newConfig.remoteProxyPwd = sb.getConfig("remoteProxyPwd", "")
188: .trim();
189:
190: // determining addresses for which the remote proxy should not be used
191: newConfig.remoteProxyNoProxy = sb.getConfig(
192: "remoteProxyNoProxy", "").trim();
193: newConfig.remoteProxyNoProxyPatterns = newConfig.remoteProxyNoProxy
194: .split(",");
195:
196: return newConfig;
197: }
198: }
|