diff --git a/common/src/java/com/zimbra/common/localconfig/LC.java b/common/src/java/com/zimbra/common/localconfig/LC.java index 3dfd0fe9a96..755ce765f75 100644 --- a/common/src/java/com/zimbra/common/localconfig/LC.java +++ b/common/src/java/com/zimbra/common/localconfig/LC.java @@ -1527,7 +1527,9 @@ public enum PUBLIC_SHARE_VISIBILITY { samePrimaryDomain, all, none }; public static final KnownKey zimbra_strict_unclosed_comment_tag = KnownKey.newKey(true); public static final KnownKey zimbra_skip_tags_with_unclosed_cdata = KnownKey.newKey("style"); - + //ZCS-11191 : Allow to enable/disable SRS feature + public static final KnownKey zimbra_srs_enabled = KnownKey.newKey(false); + static { // Automatically set the key name with the variable name. for (Field field : LC.class.getFields()) { diff --git a/store/src/java/com/zimbra/cs/service/admin/ModifyServer.java b/store/src/java/com/zimbra/cs/service/admin/ModifyServer.java index 18dabf4801b..b9b7786efac 100644 --- a/store/src/java/com/zimbra/cs/service/admin/ModifyServer.java +++ b/store/src/java/com/zimbra/cs/service/admin/ModifyServer.java @@ -21,7 +21,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -37,7 +36,6 @@ import com.zimbra.cs.account.AccountServiceException; import com.zimbra.cs.account.Provisioning; import com.zimbra.cs.account.Server; -import com.zimbra.cs.account.ZAttrServer; import com.zimbra.cs.account.accesscontrol.AdminRight; import com.zimbra.cs.account.accesscontrol.Rights.Admin; import com.zimbra.soap.ZimbraSoapContext; @@ -87,107 +85,104 @@ public void docRights(List relatedRights, List notes) { notes.add(String.format(AdminRightCheckPoint.Notes.MODIFY_ENTRY, Admin.R_modifyServer.getName(), "server")); } - + + /** + * Enable/disable postsrs service + * @param server to check what services are available + * @param attrs existing map to populate services + * @return nothing + */ public void startOrStopPostSRSd(Server server, Map attrs) throws ServiceException { - - ZimbraLog.mailbox.info("=============================="); - - List command = new ArrayList<>(); - List response = new ArrayList<>(); - List attrsUI = new ArrayList<>(); - List attrsLDAP = new ArrayList<>(); - boolean UIWantsToEnablePostsrs = false; - boolean isPostsrsEnabledInLDAP = false; - final String POSTSRSD_EXE = LC.zimbra_home.value() + "/common/sbin/postsrsd"; - final String POSTSRSD_SECRET = "/opt/zimbra/common/etc/postsrsd.secret"; - - try { - - if(!attrs.isEmpty()) { - Collections.addAll(attrsUI, (String[]) attrs.get("zimbraServiceEnabled")); - ZimbraLog.mailbox.info("attrsUI: " + attrsUI); - UIWantsToEnablePostsrs = attrsUI.contains("postsrs"); - } - - if(!server.getAttrs().isEmpty()) { - Collections.addAll(attrsLDAP, server.getServiceEnabled()); - ZimbraLog.mailbox.info("attrsLDAP: " + attrsLDAP); - isPostsrsEnabledInLDAP = attrsLDAP.contains("postsrs"); - } - - if(UIWantsToEnablePostsrs && !isPostsrsEnabledInLDAP) { - command = Stream.of(POSTSRSD_EXE, "-s", POSTSRSD_SECRET, "-d", "mydomain", "-D").collect(Collectors.toList()); - response = executeLinuxCommand(command); - ZimbraLog.mailbox.info(response); - ZimbraLog.mailbox.info("postsrsd has been enabled"); - } - else if(UIWantsToEnablePostsrs && isPostsrsEnabledInLDAP) { - ZimbraLog.mailbox.info("postsrsd is already enabled"); - } - else if(!UIWantsToEnablePostsrs && isPostsrsEnabledInLDAP) { - // There is no command to disable SRS so far. The only way is killing the process. - command = Stream.of("pgrep", "-f", "postsrsd").collect(Collectors.toList()); - response = executeLinuxCommand(command); - ZimbraLog.mailbox.info("response: " + response); - if(response.isEmpty()) { - ZimbraLog.mailbox.info("postsrsd is already disabled"); - } - else { - String postSrsdPID = response.get(0); - command.clear(); - response.clear(); - command = Stream.of("kill", "-9", postSrsdPID).collect(Collectors.toList()); - response = executeLinuxCommand(command); - ZimbraLog.mailbox.info("response: " + response); - ZimbraLog.mailbox.info("postsrsd has been disabled"); - } - } - else if(!UIWantsToEnablePostsrs && !isPostsrsEnabledInLDAP) { - ZimbraLog.mailbox.info("postsrsd is already disabled"); - } - - } catch (IOException e) { - ZimbraLog.mailbox.warn(e); - } catch (InterruptedException e) { - ZimbraLog.mailbox.warn(e); - } - - - ZimbraLog.mailbox.info("=============================="); - + + List command = new ArrayList<>(); + List response = new ArrayList<>(); + List attrsUI = new ArrayList<>(); + List attrsLDAP = new ArrayList<>(); + boolean UIWantsToEnablePostsrs = false; + boolean isPostsrsEnabledInLDAP = false; + final String POSTSRSD_SECRET = "/opt/zimbra/common/etc/postsrsd.secret"; + final String POSTSRSD_EXE = LC.zimbra_home.value() + "/common/sbin/postsrsd"; + + try { + if (!attrs.isEmpty()) { + Collections.addAll(attrsUI, (String[]) attrs.get(Provisioning.A_zimbraServiceEnabled)); + ZimbraLog.mailbox.info("attrsUI: " + attrsUI); + UIWantsToEnablePostsrs = attrsUI.contains("postsrs"); + } + + if (!server.getAttrs().isEmpty()) { + Collections.addAll(attrsLDAP, server.getServiceEnabled()); + ZimbraLog.mailbox.info("attrsLDAP: " + attrsLDAP); + isPostsrsEnabledInLDAP = attrsLDAP.contains("postsrs"); + } + + if (UIWantsToEnablePostsrs && !isPostsrsEnabledInLDAP) { + command = Stream.of(POSTSRSD_EXE, "-s", POSTSRSD_SECRET, "-d", server.getName(), "-D") + .collect(Collectors.toList()); + response = executeLinuxCommand(command); + ZimbraLog.mailbox.info(response); + ZimbraLog.mailbox.info("postsrsd has been enabled"); + } else if (UIWantsToEnablePostsrs && isPostsrsEnabledInLDAP) { + ZimbraLog.mailbox.info("postsrsd is already enabled"); + } else if (!UIWantsToEnablePostsrs && isPostsrsEnabledInLDAP) { + // There is no command to disable SRS so far. The only way is killing the + // process. + command = Stream.of("pgrep", "-f", "postsrsd").collect(Collectors.toList()); + response = executeLinuxCommand(command); + ZimbraLog.mailbox.info("response: " + response); + if (response.isEmpty()) { + ZimbraLog.mailbox.info("postsrsd is already disabled"); + } else { + String postSrsdPID = response.get(0); + command.clear(); + response.clear(); + command = Stream.of("kill", "-9", postSrsdPID).collect(Collectors.toList()); + response = executeLinuxCommand(command); + ZimbraLog.mailbox.info("response: " + response); + ZimbraLog.mailbox.info("postsrsd has been disabled"); + } + } else if (!UIWantsToEnablePostsrs && !isPostsrsEnabledInLDAP) { + ZimbraLog.mailbox.info("postsrsd is already disabled"); + } + } catch (IOException e) { + ZimbraLog.mailbox.warn(e); + } catch (InterruptedException e) { + ZimbraLog.mailbox.warn(e); + } } - + + /** + * Execute linux command + * @param command to be executed + * @return list of string + */ public List executeLinuxCommand(List command) throws IOException, InterruptedException { - InputStream is = null; - ProcessBuilder pb = null; - Process ps = null; - List lines = new ArrayList<>(); - - ZimbraLog.mailbox.info("command: " + command); - - // Executing the linux command - pb = new ProcessBuilder(command); - ps = pb.start(); - int exitValue = ps.waitFor(); - ZimbraLog.mailbox.info("command executed"); - // Getting executed command response as List - if(exitValue == 0) { - is = ps.getInputStream(); - } - else { - is = ps.getErrorStream(); - } - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - String line; - while((line = br.readLine()) != null) { - lines.add(line); - } - ps.destroy(); - - return lines; - - } - -} + InputStream is = null; + ProcessBuilder pb = null; + Process ps = null; + List lines = new ArrayList<>(); + + ZimbraLog.mailbox.info("command: " + command); + // Executing the linux command + pb = new ProcessBuilder(command); + ps = pb.start(); + int exitValue = ps.waitFor(); + ZimbraLog.mailbox.info("command executed"); + // Getting executed command response as List + if (exitValue == 0) { + is = ps.getInputStream(); + } else { + is = ps.getErrorStream(); + } + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + String line; + while ((line = br.readLine()) != null) { + lines.add(line); + } + ps.destroy(); + + return lines; + } +} \ No newline at end of file