Search in sources :

Example 71 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext 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 72 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetDistributionListMembership method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    GetDistributionListMembershipRequest req = JaxbUtil.elementToJaxb(request);
    int limit = (req.getLimit() == null) ? 0 : req.getLimit();
    if (limit < 0) {
        throw ServiceException.INVALID_REQUEST("limit" + limit + " is negative", null);
    }
    int offset = (req.getOffset() == null) ? 0 : req.getOffset();
    if (offset < 0) {
        throw ServiceException.INVALID_REQUEST("offset" + offset + " is negative", null);
    }
    DistributionListSelector dlSel = req.getDl();
    DistributionListBy dlBy = dlSel.getBy().toKeyDistributionListBy();
    String dlKey = dlSel.getKey();
    DistributionList distributionList = prov.get(dlBy, dlKey);
    defendAgainstGroupHarvesting(distributionList, dlBy, dlKey, zsc, Admin.R_getDistributionListMembership, /* shouldn't be used */
    Admin.R_getDistributionListMembership);
    HashMap<String, String> via = new HashMap<String, String>();
    List<DistributionList> lists = prov.getDistributionLists(distributionList, false, via);
    Element response = zsc.createElement(AdminConstants.GET_DISTRIBUTION_LIST_MEMBERSHIP_RESPONSE);
    for (DistributionList dl : lists) {
        Element dlEl = response.addNonUniqueElement(AdminConstants.E_DL);
        dlEl.addAttribute(AdminConstants.A_NAME, dl.getName());
        dlEl.addAttribute(AdminConstants.A_ID, dl.getId());
        String viaDl = via.get(dl.getName());
        if (viaDl != null)
            dlEl.addAttribute(AdminConstants.A_VIA, viaDl);
    }
    return response;
}
Also used : GetDistributionListMembershipRequest(com.zimbra.soap.admin.message.GetDistributionListMembershipRequest) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DistributionListBy(com.zimbra.common.account.Key.DistributionListBy) Element(com.zimbra.common.soap.Element) DistributionListSelector(com.zimbra.soap.admin.type.DistributionListSelector) Provisioning(com.zimbra.cs.account.Provisioning) DistributionList(com.zimbra.cs.account.DistributionList)

Example 73 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetIndexStats method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Element mreq = request.getElement(AdminConstants.E_MAILBOX);
    String accountId = mreq.getAttribute(AdminConstants.A_ACCOUNTID);
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.id, accountId, zsc.getAuthToken());
    if (account == null) {
        throw AccountServiceException.NO_SUCH_ACCOUNT(accountId);
    }
    if (account.isCalendarResource()) {
        // need a CalendarResource instance for RightChecker
        CalendarResource resource = prov.get(Key.CalendarResourceBy.id, account.getId());
        checkCalendarResourceRight(zsc, resource, Admin.R_reindexCalendarResourceMailbox);
    } else {
        checkAccountRight(zsc, account, Admin.R_reindexMailbox);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
    if (mbox == null) {
        throw ServiceException.FAILURE("mailbox not found for account " + accountId, null);
    }
    Element response = zsc.createElement(AdminConstants.GET_INDEX_STATS_RESPONSE);
    IndexStats stats = mbox.index.getIndexStats();
    Element statsElem = response.addElement(AdminConstants.E_STATS);
    statsElem.addAttribute(AdminConstants.A_MAX_DOCS, stats.getMaxDocs());
    statsElem.addAttribute(AdminConstants.A_DELETED_DOCS, stats.getNumDeletedDocs());
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) IndexStats(com.zimbra.cs.mailbox.MailboxIndex.IndexStats) CalendarResource(com.zimbra.cs.account.CalendarResource) Provisioning(com.zimbra.cs.account.Provisioning)

Example 74 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetLicenseInfo method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext lc = getZimbraSoapContext(context);
    String expirationDate = LC.get(TRIAL_EXPIRATION_DATE_KEY);
    LicenseExpirationInfo expirationInfo = new LicenseExpirationInfo(expirationDate);
    GetLicenseInfoResponse resp = new GetLicenseInfoResponse(expirationInfo);
    return lc.jaxbToElement(resp);
}
Also used : LicenseExpirationInfo(com.zimbra.soap.admin.type.LicenseExpirationInfo) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GetLicenseInfoResponse(com.zimbra.soap.admin.message.GetLicenseInfoResponse)

Example 75 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetLoggerStats method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    // this command can only execute on the monitor host, so proxy if necessary
    Provisioning prov = Provisioning.getInstance();
    String monitorHost = prov.getConfig().getAttr(Provisioning.A_zimbraLogHostname);
    if (monitorHost == null || monitorHost.trim().equals(""))
        throw ServiceException.FAILURE("zimbraLogHostname is not configured", null);
    Server monitorServer = prov.get(Key.ServerBy.name, monitorHost);
    checkRight(zsc, context, monitorServer, Admin.R_getServerStats);
    if (monitorServer == null)
        throw ServiceException.FAILURE("could not find zimbraLogHostname server: " + monitorServer, null);
    if (!prov.getLocalServer().getId().equalsIgnoreCase(monitorServer.getId()))
        return proxyRequest(request, context, monitorServer);
    Element response = zsc.createElement(AdminConstants.GET_LOGGER_STATS_RESPONSE);
    boolean loggerEnabled = false;
    Server local = prov.getLocalServer();
    String[] services = local.getMultiAttr(Provisioning.A_zimbraServiceEnabled);
    if (services != null) {
        for (int i = 0; i < services.length && !loggerEnabled; i++) {
            loggerEnabled = "logger".equals(services[i]);
        }
    }
    if (loggerEnabled) {
        Element host = request.getOptionalElement(AdminConstants.E_HOSTNAME);
        Element stats = request.getOptionalElement(AdminConstants.E_STATS);
        Element start = request.getOptionalElement(AdminConstants.E_START_TIME);
        Element end = request.getOptionalElement(AdminConstants.E_END_TIME);
        Element values = null;
        HashSet<String> counters = null;
        if (stats != null) {
            values = stats.getOptionalElement(AdminConstants.E_VALUES);
            if (values != null) {
                List<Element> counterList = values.listElements(AdminConstants.E_STAT);
                if (counterList.size() > 0)
                    counters = new HashSet<String>(counterList.size());
                for (Element e : counterList) {
                    counters.add(e.getAttribute(AdminConstants.A_NAME));
                }
            }
        }
        if (host == null && stats == null) {
            // list hosts
            fetchHostnames(response);
        } else if (host != null && stats == null) {
            // list groups for host
            fetchGroupNames(response, host.getAttribute(AdminConstants.A_HOSTNAME));
        } else if (stats != null && host == null) {
            String limitStr = stats.getAttribute(AdminConstants.A_LIMIT, null);
            boolean limit = limitStr != null && !"no".equalsIgnoreCase(limitStr) && !"false".equalsIgnoreCase(limitStr) && !"0".equalsIgnoreCase(limitStr);
            // fetch stats for all hosts
            String startTime = null;
            String endTime = null;
            if (start != null || end != null) {
                if (start == null || end == null)
                    throw ServiceException.FAILURE("both start and end must be specified", null);
                startTime = start.getAttribute(AdminConstants.A_TIME);
                endTime = end.getAttribute(AdminConstants.A_TIME);
                fetchColumnData(response, counters, stats.getAttribute(AdminConstants.A_NAME), startTime, endTime, limit);
            } else {
                fetchColumnData(response, counters, stats.getAttribute(AdminConstants.A_NAME), limit);
            }
        } else if (stats != null && host != null) {
            String statsText = stats.getText();
            if (statsText != null && statsText.trim().length() > 0) {
                // list counters
                fetchColumnNames(response, host.getAttribute(AdminConstants.A_HOSTNAME), stats.getAttribute(AdminConstants.A_NAME));
            } else {
                String limitStr = stats.getAttribute(AdminConstants.A_LIMIT, null);
                boolean limit = limitStr != null && !"no".equalsIgnoreCase(limitStr) && !"false".equalsIgnoreCase(limitStr) && !"0".equalsIgnoreCase(limitStr);
                // fetch stats for host
                String startTime = null;
                String endTime = null;
                if (start != null || end != null) {
                    if (start == null || end == null)
                        throw ServiceException.FAILURE("both start and end must be specified", null);
                    startTime = start.getAttribute(AdminConstants.A_TIME);
                    endTime = end.getAttribute(AdminConstants.A_TIME);
                    fetchColumnData(response, counters, host.getAttribute(AdminConstants.A_HOSTNAME), stats.getAttribute(AdminConstants.A_NAME), startTime, endTime, limit);
                } else {
                    fetchColumnData(response, counters, host.getAttribute(AdminConstants.A_HOSTNAME), stats.getAttribute(AdminConstants.A_NAME), limit);
                }
            }
        } else {
            throw ServiceException.FAILURE("Unknown query combination", null);
        }
    } else {
        response.addElement(AdminConstants.E_NOTE).setText("Logger is not enabled");
    }
    return response;
}
Also used : Server(com.zimbra.cs.account.Server) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) HashSet(java.util.HashSet)

Aggregations

ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)382 Element (com.zimbra.common.soap.Element)315 Provisioning (com.zimbra.cs.account.Provisioning)162 Account (com.zimbra.cs.account.Account)158 Mailbox (com.zimbra.cs.mailbox.Mailbox)106 OperationContext (com.zimbra.cs.mailbox.OperationContext)82 ItemId (com.zimbra.cs.service.util.ItemId)58 Server (com.zimbra.cs.account.Server)47 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)44 ServiceException (com.zimbra.common.service.ServiceException)40 HashMap (java.util.HashMap)37 Domain (com.zimbra.cs.account.Domain)32 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)23 IOException (java.io.IOException)20 Group (com.zimbra.cs.account.Group)17 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)17 Message (com.zimbra.cs.mailbox.Message)17 MimeMessage (javax.mail.internet.MimeMessage)16 Map (java.util.Map)15