Search in sources :

Example 1 with RemoteResult

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;
}
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 RemoteResult

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;
    }
}
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 3 with RemoteResult

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

Example 4 with RemoteResult

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;
    }
}
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

Provisioning (com.zimbra.cs.account.Provisioning)4 Server (com.zimbra.cs.account.Server)4 RemoteManager (com.zimbra.cs.rmgmt.RemoteManager)4 RemoteResult (com.zimbra.cs.rmgmt.RemoteResult)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ContentDisposition (com.zimbra.common.mime.ContentDisposition)2 ServiceException (com.zimbra.common.service.ServiceException)2 Element (com.zimbra.common.soap.Element)2 AuthToken (com.zimbra.cs.account.AuthToken)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 IOException (java.io.IOException)2 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 Matcher (java.util.regex.Matcher)1