java/code/src/com/redhat/rhn/frontend/action/systems/SystemRemoteCommandAction.java |
326 ++++++++++
java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml |
17
java/code/webapp/WEB-INF/nav/system_detail.xml |
6
java/code/webapp/WEB-INF/pages/systems/system-remote-command.jsp |
60 +
java/code/webapp/WEB-INF/struts-config.xml |
10
5 files changed, 415 insertions(+), 4 deletions(-)
New commits:
commit 0cea563c3fd5a0cf2c78a8798d615c5041b557b0
Author: Bo Maryniuk <bo(a)suse.de>
Date: Fri Aug 23 13:29:33 2013 +0200
Perl to JSP port: Single system Remote Command
diff --git
a/java/code/src/com/redhat/rhn/frontend/action/systems/SystemRemoteCommandAction.java
b/java/code/src/com/redhat/rhn/frontend/action/systems/SystemRemoteCommandAction.java
new file mode 100644
index 0000000..2f9915f
--- /dev/null
+++ b/java/code/src/com/redhat/rhn/frontend/action/systems/SystemRemoteCommandAction.java
@@ -0,0 +1,326 @@
+/**
+ * Copyright (c) 2013 SUSE
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ *
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+
+package com.redhat.rhn.frontend.action.systems;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.action.DynaActionForm;
+
+import com.redhat.rhn.common.localization.LocalizationService;
+import com.redhat.rhn.common.util.DatePicker;
+import com.redhat.rhn.common.util.StringUtil;
+import com.redhat.rhn.common.util.StringUtil.ScriptCheckResult;
+import com.redhat.rhn.domain.action.script.ScriptRunAction;
+import com.redhat.rhn.domain.server.Server;
+import com.redhat.rhn.domain.user.User;
+import com.redhat.rhn.frontend.struts.RequestContext;
+import com.redhat.rhn.frontend.struts.RhnAction;
+import com.redhat.rhn.frontend.struts.RhnHelper;
+import com.redhat.rhn.manager.action.ActionManager;
+import com.redhat.rhn.manager.system.SystemManager;
+
+/**
+ * Action for the single system remote command scheduling.
+ *
+ * @author Bo Maryniuk <bo(a)suse.de>
+ */
+public class SystemRemoteCommandAction extends RhnAction {
+ /**
+ * Class to retention form data.
+ */
+ public static final class FormData {
+ public static final String UID = "uid";
+ public static final String GID = "gid";
+ public static final String SCRIPT = "script_body";
+ public static final String LABEL = "lbl";
+ public static final String TIMEOUT = "timeout";
+ public static final Long DEFAULT_TIMEOUT = 600L;
+
+ public static final String[] MANDATORY_FIELDS = {
+ FormData.UID,
+ FormData.GID,
+ FormData.SCRIPT,
+ };
+
+ private String uid;
+ private String gid;
+ private String scriptBody;
+ private String label;
+ private Long timeout;
+
+ /**
+ * Default constructor.
+ */
+ public FormData() {
+ this.uid = "root";
+ this.gid = "root";
+ this.timeout = FormData.DEFAULT_TIMEOUT;
+ this.label = "";
+ this.scriptBody = "#!/bin/sh\n# Add your shell script below\n";
+ }
+
+ /**
+ * Get UID
+ * @return the uid
+ */
+ public String getUid() {
+ return uid;
+ }
+
+ /**
+ * Set UID
+ * @param userid the uid to set
+ * @return Form data object.
+ */
+ public FormData setUid(String userid) {
+ this.uid = userid;
+ return this;
+ }
+
+ /**
+ * Get GID
+ * @return the gid
+ */
+ public String getGid() {
+ return gid;
+ }
+
+ /**
+ * Set GID
+ * @param groupid the gid to set
+ * @return Form data object.
+ */
+ public FormData setGid(String groupid) {
+ this.gid = groupid;
+ return this;
+ }
+
+ /**
+ * Get script content.
+ * @return the scriptBody
+ */
+ public String getScriptBody() {
+ return scriptBody;
+ }
+
+ /**
+ * Set script content.
+ * @param script the content of the script to set
+ * @return Form data object.
+ */
+ public FormData setScriptBody(String script) {
+ this.scriptBody = script;
+ return this;
+ }
+
+ /**
+ * Get label
+ * @return the label
+ */
+ public String getLabel() {
+ return label;
+ }
+
+ /**
+ * Set label
+ * @param commandLabel the label to set
+ * @return Form data object.
+ */
+ public FormData setLabel(String commandLabel) {
+ this.label = commandLabel;
+ return this;
+ }
+
+ /**
+ * Get timeout
+ * @return the timeout
+ */
+ public Long getTimeout() {
+ return timeout;
+ }
+
+ /**
+ * Set timeout
+ * @param commandTimeout the timeout to set
+ * @return Form data object.
+ */
+ public FormData setTimeout(Long commandTimeout) {
+ this.timeout = commandTimeout;
+ return this;
+ }
+ }
+
+
+ /**
+ * Validate form has required fields.
+ *
+ * @param form
+ * @param errorMessages
+ * @return
+ */
+ private boolean validate(DynaActionForm form,
+ ActionErrors errorMessages) {
+ boolean formValid = true;
+ for (String fid : SystemRemoteCommandAction.FormData.MANDATORY_FIELDS) {
+ if (StringUtil.nullOrValue(form.getString(fid)) == null) {
+ if (formValid) {
+ formValid = false;
+ }
+ errorMessages.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage(String.format(
+ "ssm.operations.provisioning." +
+ "remotecommand.form.%s.missing", fid)));
+ }
+ }
+
+ // Check if Script looks legit :-)
+ if (StringUtil.nullOrValue(form.getString(FormData.SCRIPT)) != null) {
+ ScriptCheckResult checkResult = StringUtil.scriptPrematureCheck(
+ form.getString(FormData.SCRIPT));
+ if (checkResult != null) {
+ formValid = false;
+ errorMessages.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage(checkResult.getMessageKey()));
+ }
+ }
+
+ return formValid;
+ }
+
+
+ /**
+ * Schedule remote action script.
+ *
+ * @param form
+ * @param user
+ * @param server
+ * @return Script action details.
+ */
+ private ScriptRunAction scheduleScript(DynaActionForm form,
+ User user,
+ Server server) {
+ Date scheduleDate = getStrutsDelegate().readDatePicker(
+ form, "date", DatePicker.YEAR_RANGE_POSITIVE);
+ List<Long> servers = new ArrayList<Long>();
+ servers.add(server.getId());
+ String label = StringUtil.nullIfEmpty(form.getString("lbl"));
+ String msg = LocalizationService
+ .getInstance()
+
.getMessage("ssm.overview.provisioning.remotecommand.staticname");
+
+ return ActionManager.scheduleScriptRun(
+ user,
+ servers,
+ (label != null ? label : MessageFormat.format(msg, server.getName())),
+ ActionManager.createScript(form.getString(FormData.UID),
+ form.getString(FormData.GID),
+ form.get(FormData.TIMEOUT) == null ?
+ FormData.DEFAULT_TIMEOUT :
+ (Long) form.get(FormData.TIMEOUT),
+ form.getString(FormData.SCRIPT)), scheduleDate);
+ }
+
+
+ /**
+ * Get form into the bean.
+ *
+ * @param form
+ * @return FormData object.
+ */
+ private FormData getFormData(DynaActionForm form) {
+ FormData data = new FormData();
+ data.setUid(form.getString(FormData.UID));
+ data.setGid(form.getString(FormData.GID));
+ data.setLabel(form.getString(FormData.LABEL));
+ data.setScriptBody(form.getString(FormData.SCRIPT));
+ data.setTimeout((Long) form.get(FormData.TIMEOUT));
+
+ return data;
+ }
+
+
+ @Override
+ public ActionForward execute(ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws Exception {
+ // Prepare
+ DynaActionForm form = (DynaActionForm) actionForm;
+ RequestContext context = new RequestContext(request);
+ User user = context.getLoggedInUser();
+ Server server = SystemManager.lookupByIdAndUser(
+ context.getRequiredParam(RequestContext.SID), user);
+ ActionErrors errorMessages = new ActionErrors();
+ ActionMessages infoMessages = new ActionMessages();
+
+ // Default form values
+ request.setAttribute("formData", new
SystemRemoteCommandAction.FormData());
+
+ // Process submit
+ if (form.get(RhnAction.SUBMITTED) != null) {
+ if (this.validate(form, errorMessages)) {
+ try {
+ ScriptRunAction action = this.scheduleScript(form, user, server);
+ infoMessages.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("ssm.overview.provisioning"
+
+ ".remotecommand.succeed",
+ server.getId().toString(),
+ action.getId().toString(),
+ LocalizationService
+ .getInstance()
+ .formatDate(action.getEarliestAction())));
+ }
+ catch (Exception ex) {
+ errorMessages.add(ActionMessages.GLOBAL_MESSAGE,
+ new
ActionMessage("ssm.operations.actionchaindetails." +
+
"scheduleerror.general.param",
+ ex.getLocalizedMessage()));
+ }
+ }
+ else {
+ request.setAttribute("formData", this.getFormData(form));
+ }
+ }
+
+ // End the page
+ request.setAttribute("date",
this.getStrutsDelegate().prepopulateDatePicker(
+ request, form, "date", DatePicker.YEAR_RANGE_POSITIVE));
+ request.setAttribute("system", server);
+
+ this.getStrutsDelegate().saveMessages(request, errorMessages);
+ this.getStrutsDelegate().saveMessages(request, infoMessages);
+
+ form.getMap().clear();
+
+ return getStrutsDelegate().forwardParam(
+ mapping.findForward(RhnHelper.DEFAULT_FORWARD),
+ RequestContext.SID, server.getId().toString()
+ );
+ }
+}
diff --git a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
index 62d01a2..f6dc757 100644
--- a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
+++ b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
@@ -14735,6 +14735,23 @@ any of these revisions. Are you sure you want to do
this?</source>
<source>No script has been specified.</source>
</trans-unit>
+ <!-- Single System Remote Command Form Labels -->
+ <trans-unit
id="ssm.overview.provisioning.remotecommand.staticname">
+ <source>Remote Command on {0}.</source>
+ </trans-unit>
+ <trans-unit
id="ssm.overview.provisioning.remotecommand.succeed">
+ <source>Remote Command has been <a
href="/network/systems/details/history/event.pxt?sid={0}&hid={1}">scheduled
successfully</a> at
<strong>{2}</strong>.</source>
+ </trans-unit>
+ <trans-unit
id="ssm.overview.provisioning.remotecommand.header">
+ <source>Remote Command on {0}</source>
+ </trans-unit>
+ <trans-unit id="">
+ <source></source>
+ </trans-unit>
+ <trans-unit id="">
+ <source></source>
+ </trans-unit>
+
<!-- SSM Remote Command Form Labels -->
<trans-unit
id="ssm.operations.provisioning.remotecommand.header">
<source>Schedule Remote Command</source>
diff --git a/java/code/webapp/WEB-INF/nav/system_detail.xml
b/java/code/webapp/WEB-INF/nav/system_detail.xml
index 5d2cdf9..cfd8456 100644
--- a/java/code/webapp/WEB-INF/nav/system_detail.xml
+++ b/java/code/webapp/WEB-INF/nav/system_detail.xml
@@ -4,9 +4,7 @@
<rhn-tab name="Details"
url="/rhn/systems/details/Overview.do">
<rhn-tab name="Overview"
url="/rhn/systems/details/Overview.do" />
<rhn-tab name="Properties" url="/rhn/systems/details/Edit.do"
/>
- <rhn-tab name="Remote Command"
acl="system_feature(ftr_remote_command)">
-
<rhn-tab-url>/network/systems/details/remote_commands.pxt</rhn-tab-url>
- </rhn-tab>
+ <rhn-tab name="Remote Command"
url="/rhn/systems/details/SystemRemoteCommand.do" />
<rhn-tab name="Connection"
url="/network/systems/details/connection.pxt"
acl="org_has_proxies()"/>
<rhn-tab name="Proxy" url="/network/systems/details/proxy.pxt"
acl="user_role(org_admin); system_feature(ftr_proxy_capable) or system_is_proxy();
org_channel_family(rhn-proxy) or system_is_proxy(); child_channel_candidate(rhn-proxy) or
system_is_proxy(); not system_is_satellite(); not
is_solaris();system_feature(ftr_kickstart) or system_feature(ftr_snapshotting)">
<rhn-tab name="Activation"
url="/network/systems/details/proxy.pxt" />
@@ -14,7 +12,7 @@
</rhn-tab>
<rhn-tab name="Reactivation"
url="/network/systems/details/activation.pxt"
acl="system_feature(ftr_agent_smith)"/>
<rhn-tab name="Hardware">
- <rhn-tab-url>/rhn/systems/details/SystemHardware.do</rhn-tab-url>
+ <rhn-tab-url>/rhn/systems/details/SystemHardware.do</rhn-tab-url>
</rhn-tab>
<rhn-tab name="Migrate" acl="user_role(org_admin)"
url="/rhn/systems/details/SystemMigrate.do" />
<rhn-tab name="Notes">
diff --git a/java/code/webapp/WEB-INF/pages/systems/system-remote-command.jsp
b/java/code/webapp/WEB-INF/pages/systems/system-remote-command.jsp
new file mode 100644
index 0000000..9d9dc22
--- /dev/null
+++ b/java/code/webapp/WEB-INF/pages/systems/system-remote-command.jsp
@@ -0,0 +1,60 @@
+<%@ taglib
uri="http://rhn.redhat.com/rhn" prefix="rhn" %>
+<%@ taglib
uri="http://java.sun.com/jsp/jstl/core" prefix="c"
%>
+<%@ taglib
uri="http://struts.apache.org/tags-html" prefix="html"
%>
+<%@ taglib
uri="http://struts.apache.org/tags-bean" prefix="bean"
%>
+<%@ taglib
uri="http://rhn.redhat.com/tags/list" prefix="rl"
%>
+<%@ page language="java"
import="com.redhat.rhn.frontend.action.systems.SystemRemoteCommandAction.FormData"%>
+
+<html:xhtml/>
+
+<html>
+ <head><meta name="page-decorator" content="none"
/></head>
+ <body>
+ <%@ include
file="/WEB-INF/pages/common/fragments/systems/system-header.jspf" %>
+ <h2><bean:message
key="ssm.overview.provisioning.remotecommand.header"
arg0="${system.name}"/></h2>
+ <html:form action="/systems/details/SystemRemoteCommand"
method="post">
+ <rhn:csrf />
+ <table class="details" align="center">
+ <tbody>
+ <tr>
+ <th><bean:message
key="ssm.operations.provisioning.remotecommand.form.uid.label"/><span
class="required-form-field">*</span>:</th>
+ <td><input type="text" name="uid"
maxlength="32" value="${formData.uid}"
size=""></td>
+ </tr>
+ <tr>
+ <th><bean:message
key="ssm.operations.provisioning.remotecommand.form.gid.label"/><span
class="required-form-field">*</span>:</th>
+ <td><input type="text" name="gid"
maxlength="32" value="${formData.gid}"
size=""></td>
+ </tr>
+ <tr>
+ <th><bean:message
key="ssm.operations.provisioning.remotecommand.form.timeout.label"/>:</th>
+ <td><input type="text"
name="timeout" maxlength="" value="${formData.timeout}"
size="6"></td>
+ </tr>
+ <tr>
+ <th><bean:message
key="ssm.operations.provisioning.remotecommand.form.lbl.label"/>:</th>
+ <td><input type="text" id="lbl"
name="lbl" value="${formData.label}" style="width:
100%;"></td>
+ </tr>
+ <tr>
+ <th><bean:message
key="ssm.operations.provisioning.remotecommand.form.script_body.label"/><span
class="required-form-field">*</span>:</th>
+ <td><textarea name="script_body"
rows="8" wrap="off" style="width:
100%;">${formData.scriptBody}</textarea></td>
+ </tr>
+ <tr>
+ <th><bean:message
key="ssm.operations.provisioning.remotecommand.form.date.label"/>:</th>
+ <td>
+ <jsp:include
page="/WEB-INF/pages/common/fragments/date-picker.jsp">
+ <jsp:param name="widget"
value="date"/>
+ </jsp:include>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+
+ <input type="hidden" name="sid"
value="${system.id}">
+ <div align="right">
+ <hr>
+ <input type="submit" name="schedule"
value="<bean:message
key="ssm.operations.provisioning.remotecommand.form.submit" />">
+ <input type="hidden" name="submitted"
value="true">
+ <hidden name="use_date" value="true" />
+ </div>
+ </html:form>
+
+ </body>
+</html>
diff --git a/java/code/webapp/WEB-INF/struts-config.xml
b/java/code/webapp/WEB-INF/struts-config.xml
index 58c6247..9b36a6e 100644
--- a/java/code/webapp/WEB-INF/struts-config.xml
+++ b/java/code/webapp/WEB-INF/struts-config.xml
@@ -3805,6 +3805,16 @@
path="/systems/details/SoftwareCrashNotes.do"
redirect="true"/>
</action>
+ <action path="/systems/details/SystemRemoteCommand"
+ scope="request"
+ name="remoteCommandForm"
+
type="com.redhat.rhn.frontend.action.systems.SystemRemoteCommandAction"
+ className="com.redhat.rhn.frontend.struts.RhnActionMapping">
+ <set-property property="acls"
+ value="system_feature(ftr_system_grouping)"/>
+ <forward name="default"
+ path="/WEB-INF/pages/systems/system-remote-command.jsp" />
+ </action>
<action path="/systems/details/groups/ListRemove"
scope="request"