Source Code Cross Referenced for AddSystemProcessor.java in  » Portal » Open-Portal » com » sun » portal » netfile » servlet » java1 » 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.java1 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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