16 |
brianR |
1 |
/*
|
|
|
2 |
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
46 |
brianR |
17 |
package net.brutex.xservices.ws.impl;
|
16 |
brianR |
18 |
|
54 |
brianR |
19 |
import java.util.Enumeration;
|
|
|
20 |
import java.util.Properties;
|
78 |
brianR |
21 |
import java.util.UUID;
|
54 |
brianR |
22 |
|
16 |
brianR |
23 |
import javax.jws.WebService;
|
18 |
brianR |
24 |
import net.brutex.xservices.types.HostConnection;
|
78 |
brianR |
25 |
import net.brutex.xservices.types.HostinfoType;
|
22 |
brianR |
26 |
import net.brutex.xservices.types.MailMimeType;
|
16 |
brianR |
27 |
import net.brutex.xservices.types.ReturnCode;
|
83 |
brianR |
28 |
import net.brutex.xservices.types.ant.FileSetResource;
|
46 |
brianR |
29 |
import net.brutex.xservices.util.BrutexNamespaces;
|
17 |
brianR |
30 |
import net.brutex.xservices.util.RunTask;
|
46 |
brianR |
31 |
import net.brutex.xservices.ws.MiscService;
|
|
|
32 |
|
23 |
brianR |
33 |
import org.apache.cxf.annotations.WSDLDocumentation;
|
|
|
34 |
import org.apache.cxf.annotations.WSDLDocumentationCollection;
|
17 |
brianR |
35 |
import org.apache.tools.ant.taskdefs.HostInfo;
|
20 |
brianR |
36 |
import org.apache.tools.ant.taskdefs.Sleep;
|
18 |
brianR |
37 |
import org.apache.tools.ant.taskdefs.email.EmailTask;
|
16 |
brianR |
38 |
|
|
|
39 |
/**
|
46 |
brianR |
40 |
*
|
16 |
brianR |
41 |
* @author Brian Rosenberger, bru@brutex.de
|
|
|
42 |
*/
|
78 |
brianR |
43 |
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.MiscService", serviceName = "MiscService")
|
16 |
brianR |
44 |
public class MiscServiceImpl implements MiscService {
|
|
|
45 |
|
78 |
brianR |
46 |
public HostinfoType getHostinfo(String hostname) {
|
|
|
47 |
HostInfo info = new HostInfo();
|
|
|
48 |
info.setTaskName("HostInfo");
|
|
|
49 |
RunTask runner = new RunTask(info);
|
|
|
50 |
info.setHost(hostname);
|
|
|
51 |
// info.setPrefix(prefix);
|
|
|
52 |
ReturnCode ret = runner.postTask();
|
|
|
53 |
HostinfoType infotype = new HostinfoType(
|
|
|
54 |
ret.getProperty("NAME"),
|
|
|
55 |
ret.getProperty("DOMAIN"),
|
|
|
56 |
ret.getProperty("ADDR4"),
|
|
|
57 |
ret.getProperty("ADDR6"));
|
|
|
58 |
return infotype;
|
46 |
brianR |
59 |
}
|
78 |
brianR |
60 |
|
54 |
brianR |
61 |
public ReturnCode getInfo() {
|
|
|
62 |
ReturnCode r = new ReturnCode();
|
|
|
63 |
r.returnCode = 0;
|
|
|
64 |
// Get all system properties
|
|
|
65 |
Properties props = System.getProperties();
|
16 |
brianR |
66 |
|
54 |
brianR |
67 |
// Enumerate all system properties
|
78 |
brianR |
68 |
@SuppressWarnings("unchecked")
|
54 |
brianR |
69 |
Enumeration<String> e = (Enumeration<String>) props.propertyNames();
|
78 |
brianR |
70 |
for (; e.hasMoreElements();) {
|
|
|
71 |
// Get property name
|
|
|
72 |
String propName = (String) e.nextElement();
|
54 |
brianR |
73 |
|
78 |
brianR |
74 |
// Get property value
|
|
|
75 |
String propValue = (String) props.get(propName);
|
|
|
76 |
r.stdOut = r.stdOut + propName + ": " + propValue + "\n";
|
54 |
brianR |
77 |
}
|
|
|
78 |
|
|
|
79 |
return r;
|
|
|
80 |
}
|
|
|
81 |
|
46 |
brianR |
82 |
public ReturnCode sendMailSimple(HostConnection mailhost, String from,
|
|
|
83 |
String tolist, String subject, String message) {
|
|
|
84 |
return sendMail(from, from, tolist, "", "", subject, message,
|
|
|
85 |
"text/plain", null, mailhost.hostname, mailhost.port,
|
|
|
86 |
mailhost.user, mailhost.password, "utf-8", false, false);
|
|
|
87 |
}
|
18 |
brianR |
88 |
|
46 |
brianR |
89 |
public ReturnCode sendMailSimpleWithAttachment(HostConnection mailhost,
|
|
|
90 |
String from, String tolist, String subject, String message,
|
|
|
91 |
FileSetResource res) {
|
|
|
92 |
return sendMail(from, from, tolist, "", "", subject, message,
|
|
|
93 |
"text/plain", res, mailhost.hostname, mailhost.port,
|
|
|
94 |
mailhost.user, mailhost.password, "utf-8", false, false);
|
|
|
95 |
}
|
21 |
brianR |
96 |
|
46 |
brianR |
97 |
public ReturnCode sendMail(HostConnection mailhost, String from,
|
|
|
98 |
String tolist, String cclist, String bcclist, String subject,
|
|
|
99 |
MailMimeType mimetype, String charset, String message,
|
|
|
100 |
FileSetResource res, boolean ssl, boolean tls) {
|
|
|
101 |
return sendMail(from, from, tolist, cclist, bcclist, subject, message,
|
|
|
102 |
mimetype.value(), res, mailhost.hostname, mailhost.port,
|
|
|
103 |
mailhost.user, mailhost.password, charset, tls, ssl);
|
|
|
104 |
}
|
21 |
brianR |
105 |
|
46 |
brianR |
106 |
public ReturnCode sleep(int minutes, int seconds) {
|
|
|
107 |
return sleep(0, minutes, seconds, 0);
|
|
|
108 |
}
|
21 |
brianR |
109 |
|
78 |
brianR |
110 |
public String generateUUID() {
|
|
|
111 |
return UUID.randomUUID().toString();
|
46 |
brianR |
112 |
}
|
22 |
brianR |
113 |
|
46 |
brianR |
114 |
private ReturnCode sendMail(String from, String replyto, String tolist,
|
|
|
115 |
String cclist, String bcclist, String subject, String message,
|
|
|
116 |
String messagemimetype, FileSetResource attachments,
|
|
|
117 |
String mailhost, int mailport, String user, String password,
|
|
|
118 |
String charset, boolean tls, boolean ssl) {
|
|
|
119 |
EmailTask mail = new EmailTask();
|
|
|
120 |
mail.setTaskName("Mail");
|
|
|
121 |
RunTask runner = new RunTask(mail);
|
|
|
122 |
mail.setFrom(from);
|
|
|
123 |
mail.setReplyTo(replyto);
|
|
|
124 |
mail.setToList(tolist);
|
|
|
125 |
mail.setCcList(cclist);
|
|
|
126 |
mail.setBccList(bcclist);
|
|
|
127 |
mail.setSubject(subject);
|
|
|
128 |
mail.setMessage(message);
|
|
|
129 |
mail.setMessageMimeType(messagemimetype);
|
|
|
130 |
if (attachments != null) {
|
54 |
brianR |
131 |
mail.addFileset(attachments.getAntResource(mail.getProject()));
|
46 |
brianR |
132 |
}
|
|
|
133 |
mail.setMailhost(mailhost);
|
|
|
134 |
mail.setMailport(mailport);
|
|
|
135 |
mail.setUser(user);
|
|
|
136 |
mail.setPassword(password);
|
|
|
137 |
mail.setCharset(charset);
|
|
|
138 |
mail.setSSL(ssl);
|
|
|
139 |
mail.setEnableStartTLS(tls);
|
|
|
140 |
return runner.postTask();
|
|
|
141 |
}
|
22 |
brianR |
142 |
|
46 |
brianR |
143 |
private ReturnCode sleep(int hours, int minutes, int seconds,
|
|
|
144 |
int milliseconds) {
|
|
|
145 |
Sleep sleep = new Sleep();
|
|
|
146 |
sleep.setTaskName("Sleep");
|
|
|
147 |
RunTask runner = new RunTask(sleep);
|
|
|
148 |
sleep.setHours(hours);
|
|
|
149 |
sleep.setMinutes(minutes);
|
|
|
150 |
sleep.setSeconds(seconds);
|
|
|
151 |
sleep.setMilliseconds(milliseconds);
|
|
|
152 |
return runner.postTask();
|
|
|
153 |
}
|
16 |
brianR |
154 |
}
|