use of com.zimbra.cs.rmgmt.RemoteResult in project zm-mailbox by Zimbra.
the class GetServerNIFs method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext lc = getZimbraSoapContext(context);
String ipAddressType = request.getAttribute(AdminConstants.A_TYPE, null);
boolean ipV4 = false, ipV6 = false;
if (StringUtil.equalIgnoreCase(ipAddressType, IPV6)) {
ipV6 = true;
} else if (StringUtil.equalIgnoreCase(ipAddressType, "both")) {
ipV4 = true;
ipV6 = true;
} else {
// ipv4 is the default type
ipV4 = true;
}
Element serverEl = request.getElement(AdminConstants.E_SERVER);
String method = serverEl.getAttribute(AdminConstants.A_BY);
String serverName = serverEl.getText();
Provisioning prov = Provisioning.getInstance();
Server server = prov.get(Key.ServerBy.fromString(method), serverName);
if (server == null) {
throw ServiceException.INVALID_REQUEST("Cannot find server record for the host: " + serverName, null);
}
RemoteManager rmgr = RemoteManager.getRemoteManager(server);
RemoteResult rr = rmgr.execute(RemoteCommands.ZM_SERVER_IPS);
BufferedReader in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(rr.getMStdout())));
String line;
Element response = lc.createElement(AdminConstants.GET_SERVER_NIFS_RESPONSE);
try {
while ((line = in.readLine()) != null) {
Matcher IPmatcher = ADDR_PATTERN.matcher(line);
Matcher maskMatcher = MASK_PATTERN.matcher(line);
if (IPmatcher.find() && maskMatcher.find()) {
String ipAddress = IPmatcher.group(VALUE_GROUP).toLowerCase();
InetAddress addressType = InetAddress.getByName(ipAddress);
if (addressType instanceof Inet6Address && !ipV6) {
continue;
} else if (addressType instanceof Inet4Address && !ipV4) {
continue;
}
String type = (addressType instanceof Inet4Address) ? IPV4 : IPV6;
Element elNIF = response.addElement(AdminConstants.E_NI);
elNIF.addElement(AdminConstants.E_A).addAttribute(AdminConstants.A_N, IPmatcher.group(KEY_GROUP).toLowerCase()).addAttribute(AdminConstants.A_TYPE, type).setText(ipAddress);
elNIF.addElement(AdminConstants.E_A).addAttribute(AdminConstants.A_N, maskMatcher.group(KEY_GROUP).toLowerCase()).setText(maskMatcher.group(VALUE_GROUP));
}
}
} catch (IOException e) {
throw ServiceException.FAILURE("exception occurred handling CLI command", e);
}
return response;
}
use of com.zimbra.cs.rmgmt.RemoteResult in project zm-mailbox by Zimbra.
the class CollectConfigFiles method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
//check the auth token
AuthToken authToken = getAdminAuthTokenFromCookie(req, resp);
if (authToken == null) {
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
if (!authToken.isAdmin()) {
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
//take the host name
Provisioning prov = Provisioning.getInstance();
String hostName = req.getParameter(P_HOST);
Server server = prov.get(Key.ServerBy.name, hostName);
if (server == null) {
throw ServiceException.INVALID_REQUEST("server with name " + hostName + " could not be found", null);
}
//call RemoteManager
RemoteManager rmgr = RemoteManager.getRemoteManager(server);
RemoteResult rr = rmgr.execute(RemoteCommands.COLLECT_CONFIG_FILES);
//stream the data
resp.setContentType(DOWNLOAD_CONTENT_TYPE);
ContentDisposition cd = new ContentDisposition(Part.INLINE).setParameter("filename", hostName + ".conf.tgz");
resp.addHeader("Content-Disposition", cd.toString());
ByteUtil.copy(new ByteArrayInputStream(rr.getMStdout()), true, resp.getOutputStream(), false);
} catch (ServiceException e) {
returnError(resp, e);
return;
}
}
use of com.zimbra.cs.rmgmt.RemoteResult in project zm-mailbox by Zimbra.
the class GetMailQueueInfo method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Element serverElem = request.getElement(AdminConstants.E_SERVER);
String serverName = serverElem.getAttribute(AdminConstants.A_NAME);
Server server = prov.get(Key.ServerBy.name, serverName);
if (server == null) {
throw ServiceException.INVALID_REQUEST("server with name " + serverName + " could not be found", null);
}
checkRight(zsc, context, server, Admin.R_manageMailQueue);
RemoteManager rmgr = RemoteManager.getRemoteManager(server);
RemoteResult rr = rmgr.execute(RemoteCommands.ZMQSTAT_ALL);
Map<String, String> queueInfo;
try {
queueInfo = RemoteResultParser.parseSingleMap(rr);
} catch (IOException ioe) {
throw ServiceException.FAILURE("exception occurred handling command", ioe);
}
if (queueInfo == null) {
throw ServiceException.FAILURE("server " + serverName + " returned no result", null);
}
Element response = zsc.createElement(AdminConstants.GET_MAIL_QUEUE_INFO_RESPONSE);
serverElem = response.addElement(AdminConstants.E_SERVER);
serverElem.addAttribute(AdminConstants.A_NAME, serverName);
for (String k : queueInfo.keySet()) {
Element queue = serverElem.addElement(AdminConstants.E_QUEUE);
queue.addAttribute(AdminConstants.A_NAME, k);
queue.addAttribute(AdminConstants.A_N, queueInfo.get(k));
}
return response;
}
use of com.zimbra.cs.rmgmt.RemoteResult in project zm-mailbox by Zimbra.
the class CollectLDAPConfigZimbra method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
//check the auth token
AuthToken authToken = getAdminAuthTokenFromCookie(req, resp);
if (authToken == null) {
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
if (!authToken.isAdmin()) {
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
//find the LDAP master
Provisioning prov = Provisioning.getInstance();
String ldapHost = LC.ldap_host.value();
if (ldapHost == null) {
throw ServiceException.INVALID_REQUEST("Cannot find value for ldap_host in local config", null);
}
Server server = prov.get(Key.ServerBy.name, ldapHost);
if (server == null) {
throw ServiceException.INVALID_REQUEST("Cannot find server record for LDAP master host: " + ldapHost, null);
}
//call RemoteManager
RemoteManager rmgr = RemoteManager.getRemoteManager(server);
RemoteResult rr = rmgr.execute(RemoteCommands.COLLECT_LDAP_ZIMBRA);
//stream the data
resp.setContentType(DOWNLOAD_CONTENT_TYPE);
ContentDisposition cd = new ContentDisposition(Part.INLINE).setParameter("filename", ldapHost + ".ldif.gz");
resp.addHeader("Content-Disposition", cd.toString());
ByteUtil.copy(new ByteArrayInputStream(rr.getMStdout()), true, resp.getOutputStream(), false);
} catch (ServiceException e) {
returnError(resp, e);
return;
}
}
Aggregations