1 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
|
|
package uk.ac.ukc.iscream.filter.plugins; |
3 |
|
|
|
4 |
|
|
//---IMPORTS--- |
5 |
|
|
import uk.ac.ukc.iscream.filter.PluginServiceCheck; |
6 |
|
|
import java.net.*; |
7 |
|
|
import java.io.*; |
8 |
|
|
|
9 |
|
|
/** |
10 |
|
|
* A quick FTP service checker. |
11 |
|
|
* |
12 |
|
|
* @author $Author$ |
13 |
|
|
* @version $Id$ |
14 |
|
|
*/ |
15 |
|
|
public class FTP__ServiceCheck implements PluginServiceCheck { |
16 |
|
|
|
17 |
|
|
//---FINAL ATTRIBUTES--- |
18 |
|
|
|
19 |
|
|
/** |
20 |
|
|
* The current CVS revision of this class |
21 |
|
|
*/ |
22 |
|
|
public final String REVISION = "$Revision: 1.3 $"; |
23 |
|
|
|
24 |
|
|
public final String DESC = "Checks that an FTP server is alive."; |
25 |
|
|
|
26 |
|
|
//---STATIC METHODS--- |
27 |
|
|
|
28 |
|
|
//---CONSTRUCTORS--- |
29 |
|
|
|
30 |
|
|
//---PUBLIC METHODS--- |
31 |
|
|
|
32 |
|
|
/** |
33 |
|
|
* Performs the service check on a given host. |
34 |
|
|
* |
35 |
|
|
* @param hostname the host to check |
36 |
|
|
* @return XML data representing the result of the test |
37 |
|
|
*/ |
38 |
|
|
public String runServiceCheck(String hostname){ |
39 |
|
|
String status = ""; |
40 |
|
|
String message = ""; |
41 |
|
|
try { |
42 |
|
|
Socket socket = new Socket(hostname, 21); |
43 |
|
|
BufferedReader socketIn = new BufferedReader(new InputStreamReader(socket.getInputStream())); |
44 |
|
|
String response = socketIn.readLine(); |
45 |
|
|
if(response.startsWith("220")) { |
46 |
|
|
status = "0"; |
47 |
|
|
message = "Good Header received: "+response; |
48 |
|
|
} |
49 |
|
|
else { |
50 |
|
|
status = "1"; |
51 |
|
|
message = "Bad Header received: "+response; |
52 |
|
|
} |
53 |
|
|
socketIn.close(); |
54 |
|
|
socket.close(); |
55 |
|
|
} catch (Exception e) { |
56 |
|
|
status = "0"; |
57 |
|
|
message = "Service check failed to establish connection to host: " + e.getMessage(); |
58 |
|
|
} |
59 |
|
|
// send the results back |
60 |
|
|
return "<FTP status=\"" + status + "\" message=\"" + message + "\"></FTP>"; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
/** |
64 |
|
|
* return the String representation of what the filter does |
65 |
|
|
*/ |
66 |
|
|
public String getDescription(){ |
67 |
|
|
return DESC; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
//---PRIVATE METHODS--- |
71 |
|
|
|
72 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
73 |
|
|
|
74 |
|
|
//---ATTRIBUTES--- |
75 |
|
|
|
76 |
|
|
//---STATIC ATTRIBUTES--- |
77 |
|
|
|
78 |
|
|
} |