Source Code Cross Referenced for AddSystemHandler.java in  » Portal » Open-Portal » com » sun » portal » netfile » servlet » java2 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.netfile.servlet.java2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: AddSystemHandler.java,v 1.34 2006/10/31 12:51:15 ss150821 Exp $
003:         * Copyright 2002 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.netfile.servlet.java2;
014:
015:        /*
016:         * @author  Suresh Yellamaraju
017:         */
018:        import java.net.InetAddress;
019:        import java.net.UnknownHostException;
020:        import java.util.ArrayList;
021:        import java.util.Hashtable;
022:        import java.util.Map;
023:        import java.util.StringTokenizer;
024:        import java.util.logging.Level;
025:        import java.util.logging.Logger;
026:
027:        import com.iplanet.sso.SSOToken;
028:        import com.sun.portal.log.common.PortalLogger;
029:        import com.sun.portal.netfile.shared.NetFileConstants;
030:        import com.sun.portal.netfile.shared.NetFileException;
031:        import com.sun.portal.netfile.transport.NetFileResponse;
032:
033:        public class AddSystemHandler {
034:
035:            private static Logger logger = PortalLogger
036:                    .getLogger(WinFile.class);
037:            String[] pathInfo = null;
038:            String[] wrnt = null;
039:            NetFileLogManager logMgr = null;
040:            NetFileContext nfContext = null;
041:            NetFileHostDenialProcessor nfDenyProc = null;
042:            NetFileResource nfRes = null;
043:            NetFileAttributeExtractor nfAttrs = null;
044:            NetFileResponse nfResp = null;
045:            InetAddress machhost = null;
046:
047:            String type = "";
048:            String machpack = "";
049:            String machinename = "";
050:            String szCharSet = "";
051:            String szDefaultDomain = "";
052:            String szFQHostName = "";
053:            String machdomain = "";
054:            String machinetyp = "";
055:            SSOToken ssoToken = null;
056:            String userName = "";
057:            String password = "";
058:            String errMsg = "";
059:
060:            public AddSystemHandler(String[] platInfo, NetFileLogManager log,
061:                    NetFileContext context, NetFileResource res) {
062:
063:                this .pathInfo = platInfo;
064:                this .logMgr = log;
065:                this .nfContext = context;
066:                this .nfRes = res;
067:            }
068:
069:            public Object addSystem(java.util.List nfReqData)
070:                    throws NetFileException {
071:
072:                Hashtable addSysTable = (Hashtable) nfReqData.get(4);
073:                ssoToken = (SSOToken) nfReqData.get(6);
074:
075:                userName = (String) addSysTable.get("UserID");
076:                password = (String) addSysTable.get("Pwd");
077:                machinename = (String) addSysTable.get("SystemName");
078:                machdomain = (String) addSysTable.get("NTDomName");
079:                machinetyp = (String) addSysTable.get("SysType");
080:                szCharSet = (String) addSysTable.get("CharSet");
081:                szDefaultDomain = (String) addSysTable.get("DefaultDomain");
082:
083:                // logger.info("Add System " + machinename + "\nDomain name is "
084:                // +machdomain +"\nRequest to add system of type " + machinetyp +
085:                // "\nChar Set to be used is " + szCharSet);
086:                Object[] params0 = { machinename, "\nDomain name is ",
087:                        machdomain, "\nRequest to add system of type ",
088:                        machinetyp, "\nChar Set to be used is ", szCharSet };
089:                logger.log(Level.INFO, "PSSRNF_CSPNSJ2004", params0);
090:
091:                nfResp = new NetFileResponse((String) nfReqData.get(0),
092:                        (String) nfReqData.get(1));
093:
094:                /*
095:                 * Determine the IP Address of the given host
096:                 */
097:                try {
098:                    detemineHostInetAddress();
099:                } catch (Exception uhe) {
100:                    errMsg = nfRes.getString("ash.1",
101:                            new Object[] { machinename });
102:                    doLog(nfRes.getString("ashLog.1", new Object[] { errMsg,
103:                            userName }));
104:                    // logger.severe(uhe.getMessage());
105:                    logger.severe("PSSRNF_CSPNSJ2005");
106:                    nfResp.setNetFileResponseObject(errMsg);
107:                    nfResp
108:                            .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
109:                    return nfResp;
110:                }
111:
112:                /*
113:                 * Is the given host a portal server If so, send the exception message
114:                 * to the user
115:                 */
116:                try {
117:                    if (isLocalHost(machhost)) {
118:                        errMsg = nfRes.getString("ash.2");
119:                        doLog(nfRes.getString("ashLog.1", new Object[] {
120:                                errMsg, userName }));
121:                        nfResp.setNetFileResponseObject(errMsg);
122:                        nfResp
123:                                .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
124:                        return nfResp;
125:                    }
126:                } catch (NetFileException nfe) {
127:                    errMsg = nfRes.getString("ash.3");
128:                    doLog(nfRes.getString("ashLog.1", new Object[] { errMsg,
129:                            userName }));
130:                    // logger.severe(nfe.getMessage());
131:                    logger.severe("PSSRNF_CSPNSJ2006");
132:                    nfResp.setNetFileResponseObject(errMsg);
133:                    nfResp
134:                            .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
135:                    return nfResp;
136:                }
137:
138:                /*
139:                 * Is the given host a denied host If so, send the exception message to
140:                 * the user
141:                 */
142:                try {
143:                    Object obj = addSysTable.get("DeniedHosts");
144:                    if (obj != null) {
145:                        ArrayList list = (ArrayList) obj;
146:                        if (isDeniedHost(list)) {
147:                            errMsg = nfRes.getString("ash.4",
148:                                    new Object[] { machinename });
149:                            doLog(nfRes.getString("ashLog.1", new Object[] {
150:                                    errMsg, userName }));
151:                            nfResp.setNetFileResponseObject(errMsg);
152:                            nfResp
153:                                    .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
154:                            return nfResp;
155:                        }
156:                    }
157:                } catch (NetFileException nfe) {
158:                    errMsg = nfRes.getString("ash.5",
159:                            new Object[] { machinename });
160:                    doLog(nfRes.getString("ashLog.1", new Object[] { errMsg,
161:                            userName }));
162:                    // logger.severe(nfe.getMessage());
163:                    logger.severe("PSSRNF_CSPNSJ2007");
164:                    nfResp.setNetFileResponseObject(errMsg);
165:                    nfResp
166:                            .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
167:                    return nfResp;
168:                }
169:
170:                /*
171:                 * Is the given host an allowed host If not, send the exception message
172:                 * to the user
173:                 */
174:                try {
175:                    Object objAllowHosts = addSysTable.get("AllowedHosts");
176:                    Object obj = addSysTable.get("DeniedHosts");
177:                    if ((obj != null) && (objAllowHosts != null)) {
178:                        ArrayList list = (ArrayList) obj;
179:                        ArrayList allowList = (ArrayList) objAllowHosts;
180:                        if (!isAllowedHost(allowList, list, machinename.trim())) {
181:                            // logger.info(machinename + " is not an allowed host ");
182:                            Object[] params4 = { " is not an allowed host " };
183:                            logger
184:                                    .log(Level.INFO, "PSSRNF_CSPNSJ2008",
185:                                            params4);
186:                            errMsg = nfRes.getString("ash.13",
187:                                    new Object[] { machinename });
188:                            doLog(nfRes.getString("ashLog.1", new Object[] {
189:                                    errMsg, userName }));
190:                            nfResp.setNetFileResponseObject(errMsg);
191:                            nfResp
192:                                    .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
193:                            return nfResp;
194:                        }
195:                    }
196:                } catch (NetFileException nfe) {
197:                    if (nfe.getErrorCode() == NetFileException.NETFILE_UNKNOWN_HOST_EXCEPTION) {
198:                        errMsg = nfRes.getString("ash.1",
199:                                new Object[] { machinename });
200:                        nfResp.setNetFileResponseObject(errMsg);
201:                    } else {
202:                        errMsg = nfRes.getString("ash.12",
203:                                new Object[] { machinename });
204:                        nfResp.setNetFileResponseObject(errMsg);
205:                    }
206:                    doLog(nfRes.getString("ashLog.1", new Object[] { errMsg,
207:                            userName }));
208:                    // logger.severe(nfe.getMessage());
209:                    logger.severe("PSSRNF_CSPNSJ2009");
210:                    nfResp
211:                            .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
212:                    return nfResp;
213:                }
214:
215:                /*
216:                 * Is the given host a common host (hence already added) If so, send the
217:                 * exception message to the user
218:                 */
219:                try {
220:                    if (isHostAlreadyAdded((ArrayList) addSysTable
221:                            .get("UserAddedHosts"))) {
222:                        // logger.info(machinename + " has already been added ");
223:                        Object[] params6 = { " has already been added " };
224:                        logger.log(Level.INFO, "PSSRNF_CSPNSJ2010", params6);
225:                        errMsg = nfRes.getString("ash.6",
226:                                new Object[] { machinename });
227:                        doLog(nfRes.getString("ashLog.1", new Object[] {
228:                                errMsg, userName }));
229:                        nfResp.setNetFileResponseObject(errMsg);
230:                        nfResp
231:                                .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
232:                        return nfResp;
233:                    }
234:                } catch (NetFileException nfe) {
235:                    errMsg = nfRes.getString("ash.7",
236:                            new Object[] { machinename });
237:                    doLog(nfRes.getString("ashLog.1", new Object[] { errMsg,
238:                            userName }));
239:                    // logger.severe(nfe.getMessage());
240:                    logger.severe("PSSRNF_CSPNSJ2011");
241:                    nfResp.setNetFileResponseObject(errMsg);
242:                    nfResp
243:                            .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
244:                    return nfResp;
245:                }
246:
247:                /*
248:                 * Now, start determining the host type
249:                 */
250:                CheckPort chkPort = new CheckPort();
251:                try {
252:                    if (machinetyp.equalsIgnoreCase("AUTODETECT")) {
253:                        type = determineHostType(chkPort);
254:                    } else if (machinetyp.equalsIgnoreCase("NFS")) {
255:                        if (isNFSHost(chkPort))
256:                            type = "NFS";
257:                    } else if (machinetyp.equalsIgnoreCase("WIN")) {
258:                        if (isWinHost(chkPort)) {
259:                            type = wrnt[0];
260:                        }
261:                    } else if (machinetyp.equalsIgnoreCase("FTP")) {
262:                        if (isFTPHost(chkPort))
263:                            type = "FTP";
264:                    } else if (machinetyp.equalsIgnoreCase("NETWARE")) {
265:                        if (isNetwareFTPHost(chkPort))
266:                            type = "NETWARE";
267:                    }
268:                } catch (NetFileException nfe) {
269:                    if (nfe.getMessage() != null) {
270:                        if (nfe.getErrorCode() == NetFileException.NETFILE_INVALID_DOMAIN) {
271:                            errMsg = nfRes.getString("ash.8",
272:                                    new Object[] { machdomain });
273:                            doLog(nfRes.getString("ashLog.1", new Object[] {
274:                                    errMsg, userName }));
275:                            nfResp.setNetFileResponseObject(errMsg);
276:                        } else if (nfe.getErrorCode() == NetFileException.NETFILE_SMBCLIENT_NOTFOUND) {
277:                            errMsg = nfRes.getString("ash.11",
278:                                    new Object[] { machinename });
279:                            doLog(nfRes.getString("ashLog.1", new Object[] {
280:                                    errMsg, userName }));
281:                            nfResp.setNetFileResponseObject(errMsg);
282:                        } else if (nfe.getErrorCode() == NetFileException.NETFILE_SERVER_NOTIN_DOMAIN) {
283:                            errMsg = nfRes.getString("ash.14", new Object[] {
284:                                    machinename, machdomain });
285:                            doLog(nfRes.getString("ashLog.1", new Object[] {
286:                                    errMsg, userName }));
287:                            nfResp.setNetFileResponseObject(errMsg);
288:                        } else {
289:                            errMsg = nfRes.getString("ash.9",
290:                                    new Object[] { machinename });
291:                            doLog(nfRes.getString("ashLog.1", new Object[] {
292:                                    errMsg, userName }));
293:                            nfResp.setNetFileResponseObject(errMsg);
294:                        }
295:                    } else {
296:                        errMsg = nfRes.getString("ash.9",
297:                                new Object[] { machinename });
298:                        doLog(nfRes.getString("ashLog.1", new Object[] {
299:                                errMsg, userName }));
300:                        nfResp.setNetFileResponseObject(errMsg);
301:                    }
302:                    // logger.severe(nfe.getMessage());
303:                    logger.severe("PSSRNF_CSPNSJ2012");
304:                    nfResp
305:                            .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
306:                    return nfResp;
307:                } finally {
308:                    chkPort = null;
309:                }
310:
311:                if ((type == null) || (type.trim().length() == 0)) {
312:                    errMsg = nfRes.getString("ash.10",
313:                            new Object[] { machinename });
314:                    doLog(nfRes.getString("ashLog.1", new Object[] { errMsg,
315:                            userName }));
316:                    nfResp.setNetFileResponseObject(errMsg);
317:                    nfResp
318:                            .setNetFileResponseType(NetFileConstants.NF_RESP_FAILURE);
319:                    return nfResp;
320:
321:                } else {
322:                    doLog(nfRes.getString("ashLog.2", new Object[] {
323:                            machinename, type, userName }));
324:                    nfResp.setNetFileResponseObject(type);
325:                    nfResp
326:                            .setNetFileResponseType(NetFileConstants.NF_RESP_SUCCESS);
327:                    return nfResp;
328:                }
329:
330:            }
331:
332:            /*
333:             * Determine the the ip address of the given machine
334:             */
335:            void detemineHostInetAddress() throws java.net.UnknownHostException {
336:                if ((machinename == null) || (machinename.trim().length() == 0))
337:                    throw new java.net.UnknownHostException("null");
338:                try {
339:                    machhost = InetAddress.getByName(machinename);
340:                } catch (UnknownHostException e) {
341:                    try {
342:                        if (nfDenyProc == null) {
343:                            nfDenyProc = new NetFileHostDenialProcessor();
344:                        }
345:                        if (szFQHostName == null || szFQHostName.equals("")) {
346:                            szFQHostName = nfDenyProc.getFQHostName(
347:                                    machinename, szDefaultDomain);
348:                        }
349:                        machhost = InetAddress.getByName(nfDenyProc
350:                                .getFQHostName(machinename, szDefaultDomain));
351:                    } catch (UnknownHostException ue) {
352:                        //                logger.log(Level.SEVERE, "Unknown host", ue);
353:                        logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2013");
354:                        throw ue;
355:                    }
356:                }
357:                machpack = machhost.toString();
358:            }
359:
360:            /*
361:             * Is the given host the same as portal server
362:             * If so, return true, else return false.
363:             * The code below is legacy & needs improvements
364:             */
365:            boolean isLocalHost(InetAddress hostname) throws NetFileException {
366:                Object[] rphost_ip = null;
367:                /*
368:                 * Do not allow access to the local host.
369:                 * This is a perf bottleneck. A process gets created for every request
370:                 * to add a machine. The determination of all the IP addresses of the
371:                 * portal server is infact being done at applet startup time in NetFileServlet,
372:                 * for multi-homed support reasons. The List created there can be used.
373:                 * - Suresh
374:                 */
375:                rphost_ip = getLocalHostNames();
376:
377:                int machip = machpack.indexOf("/", 0);
378:                String newip = machpack.substring(machip + 1);
379:
380:                if ((rphost_ip == null) || (rphost_ip.length < 1))
381:                    throw new NetFileException();
382:
383:                // now see if there's a match
384:                for (int k = 0; k < rphost_ip.length; k++) {
385:                    if (((String) rphost_ip[k]).trim().equals(newip.trim())) {
386:                        return true;
387:                    }
388:                }
389:                return false;
390:            }
391:
392:            boolean isAllowedHost(ArrayList allowedHosts,
393:                    ArrayList deniedHosts, String hostName)
394:                    throws NetFileException {
395:                if (this .nfDenyProc == null)
396:                    this .nfDenyProc = new NetFileHostDenialProcessor();
397:
398:                String szHostName = hostName;
399:                String szFQHostName = nfDenyProc.getFQHostName(szHostName,
400:                        szDefaultDomain);
401:
402:                if (szFQHostName == null)
403:                    throw new NetFileException(
404:                            NetFileException.NETFILE_UNKNOWN_HOST_EXCEPTION, "");
405:                /*
406:                 else
407:                 szHostName = szFQHostName;
408:                 */
409:
410:                InetAddress[] hostAddresses = null;
411:                try {
412:                    hostAddresses = java.net.InetAddress
413:                            .getAllByName(szFQHostName);
414:                } catch (java.net.UnknownHostException uhe1) {
415:                    try {
416:                        szFQHostName = szHostName;
417:                        hostAddresses = java.net.InetAddress
418:                                .getAllByName(szFQHostName);
419:                    } catch (java.net.UnknownHostException uhe) {
420:                        throw new NetFileException(
421:                                NetFileException.NETFILE_UNKNOWN_HOST_EXCEPTION,
422:                                "");
423:                    }
424:                }
425:                try {
426:                    return nfDenyProc.isHostAllowed(allowedHosts, deniedHosts,
427:                            szFQHostName, hostAddresses, true);
428:                } catch (Exception e) {
429:                    //            logger.log(Level.SEVERE, "Exception in determining if " + hostAddresses.toString() + " is allowed", e);
430:                    Object[] params10 = { hostAddresses.toString(),
431:                            " is allowed", e };
432:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2014", params10);
433:                    return false;
434:                }
435:            }
436:
437:            /*
438:             * Obtain the list of denied hosts & verify that host is not denied
439:             */
440:            boolean isDeniedHost(ArrayList aList) throws NetFileException {
441:                if (this .nfDenyProc == null)
442:                    this .nfDenyProc = new NetFileHostDenialProcessor();
443:
444:                InetAddress[] ia_denied_hosts = nfDenyProc
445:                        .getDeniedHostsAddresses(aList);
446:                if ((ia_denied_hosts == null) || (ia_denied_hosts.length < 1))
447:                    return false;
448:
449:                try {
450:                    if (nfDenyProc.isHostDenied(machinename, ia_denied_hosts)) {
451:                        //                logger.info(machinename + " is a denied host ");
452:                        Object[] params11 = { " is a denied host " };
453:                        logger.log(Level.INFO, "PSSRNF_CSPNSJ2015", params11);
454:                        return true;
455:                    }
456:                } catch (Exception e) {
457:                    //            logger.log(Level.SEVERE, "Exception in finding denied host for "+machinename, e);
458:                    Object[] params12 = { machinename, e };
459:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2016", params12);
460:                    throw new NetFileException();
461:                }
462:                return false;
463:            }
464:
465:            /*
466:             * Using the list of user-added hosts, verify if host is added
467:             * This also ensures that if the user tries to add a common host,
468:             * then the host will not be added. Common hosts are expected to be
469:             * part of the host list obtained from the client.
470:             */
471:            boolean isHostAlreadyAdded(ArrayList alist) throws NetFileException {
472:
473:                InetAddress[] ia_names = null;
474:
475:                try {
476:                    if ((alist == null) || (alist.isEmpty()))
477:                        return false;
478:
479:                    ia_names = nfDenyProc.getDeniedHostsAddresses(alist);
480:                    for (int i = 0; i < ia_names.length; i++) {
481:                        if (ia_names[i].equals(machhost))
482:                            return true;
483:                    }
484:                } catch (Exception e) {
485:                    //            logger.log(Level.SEVERE, "Exception in getting verifying if " + machinename + " is an already added host", e);
486:                    Object[] params13 = { machinename,
487:                            " is an already added host", e };
488:                    logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2017", params13);
489:                    throw new NetFileException();
490:                } finally {
491:                    ia_names = null;
492:                }
493:                return false;
494:            }
495:
496:            /*
497:             * Determine host type and return the String of that type
498:             * If the host is of type NT, then a '\n' seperates the
499:             * host-type and the domain name.
500:             */
501:            String determineHostType(CheckPort chkPort) throws NetFileException {
502:                Map[] prefs = nfContext.getPreferences();
503:                nfAttrs = new NetFileAttributeExtractor(prefs[0]);
504:
505:                String hostDetectOrder = nfAttrs.getString(
506:                        NetFileContext.SRAP_NF_HOSTDETECTORDER, "");
507:                StringTokenizer stok = new StringTokenizer(hostDetectOrder);
508:
509:                String hostType = "";
510:                String detectedType = "";
511:                while (stok.hasMoreTokens()) {
512:                    hostType = stok.nextToken();
513:                    detectedType = determineHostType(chkPort, hostType);
514:                    if (!detectedType.equals(""))
515:                        return detectedType;
516:                }
517:                return "";
518:            }
519:
520:            String determineHostType(CheckPort chkPort, String type)
521:                    throws NetFileException {
522:                if (type.equalsIgnoreCase("WIN")) {
523:                    if (isWinHost(chkPort))
524:                        return wrnt[0] + '\n' + wrnt[1];
525:                } else if (type.equalsIgnoreCase("FTP")) {
526:                    if (isFTPHost(chkPort)) {
527:                        if (isNetwareFTPHost(chkPort))
528:                            return "NETWARE";
529:                        else
530:                            return "FTP";
531:                    }
532:                } else if (type.equalsIgnoreCase("NFS")) {
533:                    if (isNFSHost(chkPort))
534:                        return "NFS";
535:                } else if (type.equalsIgnoreCase("NETWARE")) {
536:                    if (isNetwareFTPHost(chkPort))
537:                        return "NETWARE";
538:                }
539:                return "";
540:            }
541:
542:            boolean isWinHost(CheckPort chkPort) throws NetFileException {
543:
544:                int winstat = chkPort.checkTcpPort(machhost.getHostAddress(),
545:                        139);
546:                if (winstat == 1) {
547:                    XFileInterface winFileInterface = null;
548:                    try {
549:                        winFileInterface = XFileFactory.getInstance()
550:                                .newXFileInstance("WIN", szCharSet,
551:                                        this .pathInfo[0],
552:                                        this .nfContext.getUserLocale());
553:                    } catch (NetFileException nfe) {
554:                        //                logger.log(Level.SEVERE, "Error in determining if host is Win type", nfe);
555:                        logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2018");
556:                        if (nfe.getErrorCode() == NetFileException.NETFILE_CLASSNOTFOUND)
557:                            nfe
558:                                    .setErrorCode(NetFileException.NETFILE_SMBCLIENT_NOTFOUND);
559:                        throw nfe;
560:                    }
561:
562:                    try {
563:                        wrnt = winFileInterface.verifyHostType(machdomain,
564:                                machinename, userName, password);
565:                    } catch (NetFileException nfe) {
566:                        throw nfe;
567:                    } catch (Exception e) {
568:                        throw new NetFileException();
569:                    }
570:
571:                    //            logger.info(machinename + " is of type " + wrnt[0]);
572:                    Object[] params15 = { " is of type ", wrnt[0] };
573:                    logger.log(Level.INFO, "PSSRNF_CSPNSJ2019", params15);
574:                    if ((wrnt == null) || (wrnt.length < 1))
575:                        throw new NetFileException();
576:                    else
577:                        return true;
578:                } else if (winstat == -1) {
579:                    throw new NetFileException();
580:                }
581:                return false;
582:            }
583:
584:            boolean isFTPHost(CheckPort chkPort) throws NetFileException {
585:
586:                int ftpstat = chkPort.checkTcpPort(machhost.getHostAddress(),
587:                        21);
588:                if (ftpstat == 1)
589:                    return true;
590:                else if (ftpstat == -1)
591:                    throw new NetFileException();
592:                return false;
593:            }
594:
595:            boolean isNFSHost(CheckPort chkPort) throws NetFileException {
596:                int nfsstat = -1;
597:                if (szFQHostName == null || szFQHostName.equals("")) {
598:                    nfsstat = chkPort.checkTcpPort(machhost.getHostAddress(),
599:                            2049);
600:                } else {
601:                    nfsstat = chkPort.checkTcpPort(szFQHostName, 2049);
602:                }
603:                if (nfsstat == 1)
604:                    return true;
605:                else if (nfsstat == -1)
606:                    throw new NetFileException();
607:                return false;
608:            }
609:
610:            boolean isNetwareFTPHost(CheckPort chkPort) throws NetFileException {
611:
612:                int ftpstat = chkPort.checkTcpPort(machhost.getHostAddress(),
613:                        21);
614:                if (ftpstat == 1) {
615:                    NetWareFile nff = new NetWareFile(szCharSet, nfContext
616:                            .getUserLocale());
617:                    boolean isNetWare = nff.getFTPType(machhost
618:                            .getHostAddress());
619:                    if (isNetWare) {
620:                        return true;
621:                    } else {
622:                        return false;
623:                    }
624:                } else if (ftpstat == -1) {
625:                    return false;
626:                }
627:                return false;
628:            }
629:
630:            /*    Object[] getRPaddrs() {
631:
632:             boolean isWin = (System.getProperty("os.name").toLowerCase().indexOf(
633:             "window") != -1);
634:             boolean isLinux = (System.getProperty("os.name").toLowerCase().indexOf(
635:             "linux") != -1);
636:             // read equivalent attributes for platform.conf and get the server names
637:             // from profile service
638:             ArrayList rpHostIP = new ArrayList();
639:             String configparam = "";
640:
641:             Runtime rt;
642:
643:             try {
644:             rt = Runtime.getRuntime();
645:             int c;
646:             StringBuffer buftxt = new StringBuffer(80);
647:             String[] progarr = new String[2];
648:
649:             if (isWin) {
650:             progarr[0] = "ipconfig";
651:             progarr[1] = "-all";
652:             } else {
653:             progarr[0] = "/sbin/ifconfig";
654:             progarr[1] = "-a";
655:             }
656:
657:             Process shellconn = rt.exec(progarr);
658:             InputStream shellout = shellconn.getInputStream();
659:             while ((c = shellout.read()) > -1) {
660:             char chtxt = ((char) c);
661:             buftxt.append(chtxt);
662:             }
663:             rt = null;
664:             shellout.close();
665:             shellout = null;
666:             shellconn.destroy();
667:             shellconn = null;
668:             configparam = buftxt.toString();
669:             } catch (IOException ex) {
670:             //            logger.log(Level.SEVERE, "FileOption IOException in getrpaddrs: ", ex);
671:             logger.log(Level.SEVERE, "PSSRNF_CSPNSJ2020");
672:             rpHostIP.add("Failed Execution: " + ex);
673:             rt = null;
674:             return rpHostIP.toArray();
675:             }
676:
677:             if (configparam.equals("")) {
678:             //            logger.info("Cannot get local machine hostname.");
679:             logger.info("PSSRNF_CSPNSJ2021");
680:             rpHostIP.add("Cannot get local machine hostname.");
681:             return rpHostIP.toArray();
682:             } else {
683:             StringTokenizer pars = new StringTokenizer(configparam, "\n");
684:             int parscnt = pars.countTokens();
685:             String hostip;
686:             if (isWin) {
687:             int ipaddrindx = 0;
688:             int icolonindx = 0;
689:             for (int j = 0; j < parscnt; j++) {
690:             hostip = pars.nextToken();
691:             ipaddrindx = hostip.indexOf("IP Address", 0);
692:             icolonindx = hostip.indexOf(":", 0);
693:             if ((ipaddrindx >= 0) && (icolonindx >= 0)) {
694:             rpHostIP.add((hostip.substring(icolonindx + 2)).trim());
695:             }
696:             }
697:             rpHostIP.add("127.0.0.1");
698:             } else {
699:             int inetindx = 0;
700:             int inetmaskindx = 0;
701:             for (int j = 0; j < parscnt; j++) {
702:             hostip = pars.nextToken();
703:             if (isLinux) {
704:             inetindx = hostip.indexOf("inet addr:", 0);
705:             inetmaskindx = hostip.indexOf(" ", inetindx + 10);
706:             if ((inetindx >= 0) && (inetmaskindx >= 0)) {
707:             rpHostIP.add(hostip.substring(
708:             inetindx + 10,
709:             inetmaskindx));
710:             }
711:             } else {
712:             inetindx = hostip.indexOf("inet", 0);
713:             inetmaskindx = hostip.indexOf("netmask", 0);
714:             if ((inetindx >= 0) && (inetmaskindx >= 0)) {
715:             rpHostIP.add(hostip.substring(
716:             inetindx + 5,
717:             inetmaskindx));
718:             }
719:             }
720:             }
721:             }
722:             }
723:             return rpHostIP.toArray();
724:             }*/
725:
726:            public static Object[] getLocalHostNames() {
727:                ArrayList hostIP = new ArrayList();
728:                String configparam = "";
729:                try {
730:                    java.util.Enumeration infList = java.net.NetworkInterface
731:                            .getNetworkInterfaces();
732:                    java.util.Enumeration iAddList = null;
733:                    java.net.NetworkInterface nInf = null;
734:                    java.net.InetAddress iAdd = null;
735:
736:                    while (infList.hasMoreElements()) {
737:                        nInf = (java.net.NetworkInterface) infList
738:                                .nextElement();
739:                        iAddList = nInf.getInetAddresses();
740:                        while (iAddList.hasMoreElements()) {
741:                            iAdd = (java.net.InetAddress) iAddList
742:                                    .nextElement();
743:                            hostIP.add(iAdd.getHostAddress());
744:                        }
745:                    }
746:                } catch (Exception e) {
747:                }
748:                return hostIP.toArray();
749:            }
750:
751:            private void doLog(String msg) {
752:                if (this.logMgr == null)
753:                    return;
754:                logMgr.doLog(msg);
755:            }
756:
757:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.