use of com.zimbra.cs.rmgmt.RemoteManager 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.RemoteManager in project zm-mailbox by Zimbra.
the class MailQueueFlush 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);
rmgr.execute(RemoteCommands.FLUSHQUEUE);
Element response = zsc.createElement(AdminConstants.MAIL_QUEUE_FLUSH_RESPONSE);
return response;
}
use of com.zimbra.cs.rmgmt.RemoteManager in project zm-mailbox by Zimbra.
the class TestUtil method postfixFlushDeferredMailQueue.
/**
* @return true if likely to have had things delayed in the deferred queue
*/
private static boolean postfixFlushDeferredMailQueue(Server server, long waitMillis) {
long start = System.currentTimeMillis();
try {
if (null == server) {
server = Provisioning.getInstance().getLocalServer();
}
RemoteMailQueue rmq = RemoteMailQueue.getRemoteMailQueue(server, "deferred", true);
boolean stillScanning = rmq.waitForScan(waitMillis);
if (stillScanning) {
ZimbraLog.test.info("postfixFlushDeferredMailQueue - taking too long to scan queue.");
return true;
}
RemoteMailQueue.SearchResult sr = rmq.search(null, 0, Integer.MAX_VALUE);
if (sr.qitems.size() == 0) {
ZimbraLog.test.info("postfixFlushDeferredMailQueue - deferred queue was empty.");
return false;
}
String[] ids = new String[sr.qitems.size()];
int i = 0;
StringBuilder qinfo = new StringBuilder();
for (Map<QueueAttr, String> qitem : sr.qitems) {
qinfo.append("\nDEFERRED_POSTFIX_QUEUE_ENTRY:");
ids[i++] = qitem.get(QueueAttr.id);
for (QueueAttr qattr : QueueAttr.values()) {
String val = qitem.get(qattr);
if (!Strings.isNullOrEmpty(val)) {
qinfo.append(" ").append(qattr.name()).append("=").append(val);
}
}
}
ZimbraLog.test.info("postfixFlushDeferredMailQueue - deferred queue:%s", qinfo);
rmq.action(server, RemoteMailQueue.QueueAction.requeue, ids);
ZimbraLog.test.info("postfixFlushDeferredMailQueue done requeue");
// requeueing isn't enough on its own to get things moving
RemoteManager rmgr = RemoteManager.getRemoteManager(server);
rmgr.execute(RemoteCommands.FLUSHQUEUE);
ZimbraLog.test.info("postfixFlushDeferredMailQueue finished [%s]", ZimbraLog.elapsedTime(start, System.currentTimeMillis()));
} catch (ServiceException e) {
ZimbraLog.test.error("postfixFlushDeferredMailQueue - Problem getting 'deferred' mail queue", e);
}
return true;
}
use of com.zimbra.cs.rmgmt.RemoteManager 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.RemoteManager 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