Search in sources :

Example 1 with RemoteManager

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;
}
Also used : RemoteResult(com.zimbra.cs.rmgmt.RemoteResult) Inet4Address(java.net.Inet4Address) Server(com.zimbra.cs.account.Server) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) RemoteManager(com.zimbra.cs.rmgmt.RemoteManager) Element(com.zimbra.common.soap.Element) Inet6Address(java.net.Inet6Address) IOException(java.io.IOException) Provisioning(com.zimbra.cs.account.Provisioning) ByteArrayInputStream(java.io.ByteArrayInputStream) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) BufferedReader(java.io.BufferedReader) InetAddress(java.net.InetAddress)

Example 2 with RemoteManager

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;
}
Also used : Server(com.zimbra.cs.account.Server) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) RemoteManager(com.zimbra.cs.rmgmt.RemoteManager) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 3 with RemoteManager

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;
}
Also used : RemoteMailQueue(com.zimbra.cs.rmgmt.RemoteMailQueue) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) RemoteManager(com.zimbra.cs.rmgmt.RemoteManager) QueueAttr(com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr) ZMountpoint(com.zimbra.client.ZMountpoint)

Example 4 with RemoteManager

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;
    }
}
Also used : RemoteResult(com.zimbra.cs.rmgmt.RemoteResult) Server(com.zimbra.cs.account.Server) ContentDisposition(com.zimbra.common.mime.ContentDisposition) ServiceException(com.zimbra.common.service.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteManager(com.zimbra.cs.rmgmt.RemoteManager) AuthToken(com.zimbra.cs.account.AuthToken) Provisioning(com.zimbra.cs.account.Provisioning)

Example 5 with RemoteManager

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;
    }
}
Also used : RemoteResult(com.zimbra.cs.rmgmt.RemoteResult) Server(com.zimbra.cs.account.Server) ContentDisposition(com.zimbra.common.mime.ContentDisposition) ServiceException(com.zimbra.common.service.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteManager(com.zimbra.cs.rmgmt.RemoteManager) AuthToken(com.zimbra.cs.account.AuthToken) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

RemoteManager (com.zimbra.cs.rmgmt.RemoteManager)6 Provisioning (com.zimbra.cs.account.Provisioning)5 Server (com.zimbra.cs.account.Server)5 RemoteResult (com.zimbra.cs.rmgmt.RemoteResult)4 ServiceException (com.zimbra.common.service.ServiceException)3 Element (com.zimbra.common.soap.Element)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ContentDisposition (com.zimbra.common.mime.ContentDisposition)2 AuthToken (com.zimbra.cs.account.AuthToken)2 IOException (java.io.IOException)2 ZMountpoint (com.zimbra.client.ZMountpoint)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 RemoteMailQueue (com.zimbra.cs.rmgmt.RemoteMailQueue)1 QueueAttr (com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Inet4Address (java.net.Inet4Address)1 Inet6Address (java.net.Inet6Address)1 InetAddress (java.net.InetAddress)1