001: package com.sun.portal.netlet.client.common;
002:
003: import java.util.Hashtable;
004: import java.util.Enumeration;
005:
006: public class ClientConfig {
007:
008: private static Hashtable parameters = new Hashtable();
009:
010: private static String destProtocol;
011: private static String destHost;
012: private static int destPort;
013:
014: private static boolean doPortWarning = false;
015: private static boolean showPortWarnCheckbox = false;
016: private static boolean doReauth = false;
017: private static boolean JSSEEnabled = false;
018: private static boolean PDCEnabled = false;
019: private static boolean proxyletMode = false;
020:
021: private static boolean proxyMode;
022: private static String proxyHost;
023: private static int proxyPort;
024:
025: private static String proxyAuthUsername;
026: private static String proxyAuthPassword;
027:
028: //Proxy Types
029: public static final int DIRECT = 0; // Direct connection to the Internet
030: public static final int MANUAL = 1; // Manual proxy configuration
031: public static final int AUTO = 2; // Automatic proxy configuration
032: public static final int BROWSER = 3; // 1.4 plugin on Netscaoe 6.2
033:
034: //Connection Type
035: public static final int NORMAL = 0;
036: public static final int FTP = 1;
037: public static final int EXCHANGE = 2;
038:
039: public static void addParams(Hashtable params) {
040: Enumeration enum = params.keys();
041: while (enum.hasMoreElements()) {
042: String key = (String) enum.nextElement();
043: parameters.put(key, params.get(key));
044: }
045: }
046:
047: public static void addParam(String key, String value) {
048: if (key != null && value != null) {
049: parameters.put(key, value);
050: }
051: }
052:
053: public static void init() {
054: //printMap();
055: initParams();
056: }
057:
058: private static void initParams() {
059: getGWNameAndPort();
060: String tmp = null;
061: if ((tmp = getParam("doPortWarning")) != null
062: && tmp.equalsIgnoreCase("true")) {
063: doPortWarning = true;
064: }
065: if ((tmp = getParam("showPortWarnCheckbox")) != null
066: && tmp.equalsIgnoreCase("true")) {
067: showPortWarnCheckbox = true;
068: }
069: if ((tmp = getParam("doReauth")) != null
070: && tmp.equalsIgnoreCase("true")) {
071: doReauth = true;
072: }
073: if ((tmp = getParam("isPDCEnabled")) != null
074: && tmp.equalsIgnoreCase("true")) {
075: PDCEnabled = true;
076: }
077: if ((tmp = getParam("isJSSEEnabled")) != null
078: && tmp.equalsIgnoreCase("true")) {
079: JSSEEnabled = true;
080: }
081: if ((tmp = getParam("proxyletMode")) != null
082: && tmp.equalsIgnoreCase("true")) {
083: proxyletMode = true;
084: }
085: }
086:
087: private static void getGWNameAndPort() {
088: String gwURL = getGWURL();
089: if ((gwURL != null) || !(gwURL.equals(""))) {
090: String tmp = null;
091: destProtocol = gwURL.substring(0, gwURL.indexOf(':'));
092: tmp = gwURL.substring((destProtocol.length() + 3), gwURL
093: .length());
094: tmp = tmp.substring(0, tmp.indexOf('/'));
095: int gwPortIndex = tmp.indexOf(':');
096: if (gwPortIndex == -1) {
097: destHost = tmp;
098: if (destProtocol.equals("http")) {
099: destPort = 80;
100: } else if (destProtocol.equals("https")) {
101: destPort = 443;
102: }
103: } else {
104: destHost = tmp.substring(0, gwPortIndex);
105: try {
106: destPort = Integer.parseInt(tmp.substring(
107: gwPortIndex + 1, tmp.length()));
108: } catch (NumberFormatException n) {
109: System.out
110: .println("Netlet unable to parse gwination port");
111: }
112: }
113: }
114: System.out.println("gateway protocol : " + destProtocol);
115: System.out.println("gateway host : " + destHost);
116: System.out.println("gateway port : " + destPort);
117: }
118:
119: public static String getParam(String name) {
120: return (String) parameters.get(name);
121: }
122:
123: public static void loadProxyDetails(ProxyInfo pi) {
124: proxyHost = pi.getProxySSL();
125: proxyPort = pi.getProxySSLPort();
126: proxyMode = pi.getProxyMode();
127: System.out.println("Client Config proxyHost " + proxyHost);
128: System.out.println("Client Config proxyPort " + proxyPort);
129: System.out.println("Client Config proxyMode " + proxyMode);
130: }
131:
132: public static String getConfigURL() {
133: return getParam("configURL");
134: }
135:
136: public static String getGWURL() {
137: return getParam("gwURL");
138: }
139:
140: public static String getTargetURL() {
141: String targetURL = getParam("targetURL");
142: if (targetURL == null || targetURL.length() <= 0) {
143: String confURL = getConfigURL();
144:
145: targetURL = confURL;
146: if (proxyletMode && confURL.startsWith("/")) {
147: System.out.println("ClientConfig : proxylet running");
148: String codebaseURL = getParam("codebaseURL");
149: if (codebaseURL != null && codebaseURL.length() > 0) {
150: int hostIndex = codebaseURL.indexOf("/");
151: int portIndex = codebaseURL.indexOf("/",
152: hostIndex + 2);
153: targetURL = getGWURL()
154: + codebaseURL.substring(0, portIndex)
155: + confURL;
156: } else {
157: System.err.println("Enable to get codebase url");
158: }
159: } else {
160: targetURL = confURL;
161: }
162: addParam("targetURL", targetURL);
163: }
164: System.out.println("ClientConfig targetURL " + targetURL);
165: return targetURL;
166: }
167:
168: public static String getServerURL() {
169: String serverURL;
170: int doubleSlashIndex = getConfigURL().indexOf("//");
171: serverURL = getConfigURL().substring(0,
172: getConfigURL().indexOf("/", doubleSlashIndex + 2));
173: System.out.println("serverURL " + serverURL);
174: return serverURL;
175: }
176:
177: public static String getDestProtocol() {
178: return destProtocol;
179: }
180:
181: public static String getDestHost() {
182: return destHost;
183: }
184:
185: public static int getDestPort() {
186: return destPort;
187: }
188:
189: public static String getCookieName() {
190: return getParam("cookiename");
191: }
192:
193: public static String getClientBindIP() {
194: return getParam("clientBindIP");
195: }
196:
197: public static String getSessionID() {
198: return getParam("sessionId");
199: }
200:
201: public static void setSessionID(String id) {
202: addParam("sessionId", new String(id));
203: }
204:
205: public static int getNumOfRules() {
206: return Integer.parseInt(getParam("numParms"));
207: }
208:
209: public static boolean doPortWarning() {
210: return doPortWarning;
211: }
212:
213: public static boolean showPortWarnCheckbox() {
214: return showPortWarnCheckbox;
215: }
216:
217: public static boolean doReauth() {
218: return doReauth;
219: }
220:
221: public static boolean isJSSEEnabled() {
222: return JSSEEnabled;
223: }
224:
225: public static boolean isPDCEnabled() {
226: return PDCEnabled;
227: }
228:
229: public static boolean isProxyletMode() {
230: return proxyletMode;
231: }
232:
233: public static boolean isProxyMode() {
234: return proxyMode;
235: }
236:
237: public static String getProxyHost() {
238: return proxyHost;
239: }
240:
241: public static int getProxyPort() {
242: return proxyPort;
243: }
244:
245: /*
246: * util methods called by ProxySConn so that it doesn't have to redo
247: * the proxy auth each time it makes a connection
248: */
249: public static void setProxyAuthUsername(String name) {
250: proxyAuthUsername = name;
251: }
252:
253: public static void setProxyAuthPassword(String name) {
254: proxyAuthPassword = name;
255: }
256:
257: public static String getProxyAuthUsername() {
258: return proxyAuthUsername;
259: }
260:
261: public static String getProxyAuthPassword() {
262: return proxyAuthPassword;
263: }
264:
265: public static boolean getProxyAuth() {
266: return (proxyAuthUsername != null && proxyAuthPassword != null);
267: }
268: }
|