Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,23 @@
<name>Registration Plugin</name>
<version>1.7.3-SNAPSHOT</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
<sourceDirectory>src/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
Expand Down
74 changes: 70 additions & 4 deletions src/java/org/jivesoftware/openfire/plugin/RegistrationPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ public class RegistrationPlugin implements Plugin {
* when they register, if the property #WELCOME_ENABLED is set to true.
*/
private static final String WELCOME_MSG = "registration.welcome.message";

/**
* The expected value is a String that contains the raw XMPP message that will be sent to a new user
* when they register, if the property #WELCOME_ENABLED is set to true.
*/
private static final String WELCOME_RAW_MSG = "registration.welcome.message.raw";

/**
* The expected value is a String that contains the JID of the account sending the
* welcome message. Defaults to the server itself
*/
private static final String WELCOME_MSG_FROM = "registration.welcome.message.from";

/**
* The expected value is a String that contains the name of the group that a new user will
Expand Down Expand Up @@ -161,6 +173,8 @@ public class RegistrationPlugin implements Plugin {
*/
private static final String HEADER = "registration.header";

private static final Logger LOG = LoggerFactory.getLogger(RegistrationPlugin.class);

private RegistrationUserEventListener listener = new RegistrationUserEventListener();

private String serverName;
Expand Down Expand Up @@ -278,9 +292,25 @@ public void setWelcomeMessage(String message) {
JiveGlobals.setProperty(WELCOME_MSG, message);
}

public void setWelcomeRawMessage(String message) {
JiveGlobals.setProperty(WELCOME_RAW_MSG, message);
}

public void setWelcomeMessageFrom(String from) {
JiveGlobals.setProperty(WELCOME_MSG_FROM, from);
}

public String getWelcomeMessage() {
return JiveGlobals.getProperty(WELCOME_MSG, "Welcome to Openfire!");
}

public String getWelcomeRawMessage() {
return JiveGlobals.getProperty(WELCOME_RAW_MSG);
}

public String getWelcomeMessageFrom() {
return JiveGlobals.getProperty(WELCOME_MSG_FROM);
}

public void setGroupEnabled(boolean enable) {
JiveGlobals.setProperty(GROUP_ENABLED, enable ? "true" : "false");
Expand Down Expand Up @@ -405,7 +435,12 @@ public void userCreated(User user, Map<String, Object> params) {
}

if (welcomeEnabled()) {
sendWelcomeMessage(user);
try {
sendWelcomeMessage(user);
} catch (DocumentException e) {
Log.error("Unable to convert welcome text into Message");
e.printStackTrace();
}
}

if (groupEnabled()) {
Expand Down Expand Up @@ -453,9 +488,16 @@ private void sendAlertEmail(User user) {
}
}

private void sendWelcomeMessage(User user) {
router.route(createServerMessage(user.getUsername() + "@" + serverName, "Welcome",
getWelcomeMessage()));
private void sendWelcomeMessage(User user) throws DocumentException {
String rawWelcomeMessage = getWelcomeRawMessage();
List<Message> welcomeMessages = new ArrayList();
String to = user.getUsername() + "@" + serverName;
if (rawWelcomeMessage != null && !rawWelcomeMessage.isEmpty()) {
welcomeMessages = createServerMessage(to, rawWelcomeMessage);
} else {
welcomeMessages.add(createServerMessage(to, "Welcome", getWelcomeMessage()));
}
welcomeMessages.forEach(router::route);
}

private Message createServerMessage(String to, String subject, String body) {
Expand All @@ -468,6 +510,30 @@ private Message createServerMessage(String to, String subject, String body) {
message.setBody(body);
return message;
}

private List<Message> createServerMessage(String to, String rawMessage) throws DocumentException {
Document document = DocumentHelper.parseText(rawMessage);
// It could be a single message or an array of messages
// An array of messages has "messages" as a root element
List<Message> messages = new ArrayList();
JID from = getWelcomeMessageFrom() != null ? new JID(getWelcomeMessageFrom()) : serverAddress;
if (document.getRootElement().getName().equals("messages")) {
for (Iterator i = document.getRootElement().elementIterator(); i.hasNext();) {
Element element = (Element) i.next();
messages.add(messageFromElement(element, to, from));
}
} else {
messages.add(messageFromElement(document.getRootElement(), to, from));
}
return messages;
}

private Message messageFromElement(Element element, String to, JID from) {
Message message = new Message(element);
message.setTo(to);
message.setFrom(from);
return message;
}

private void addUserToGroup(User user) {
try {
Expand Down
27 changes: 21 additions & 6 deletions src/web/registration-props-form.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
boolean deleteEmail = ParamUtils.getBooleanParameter(request, "deleteEmail");

String welcomeMessage = ParamUtils.getParameter(request, "welcomemessage");
String welcomeRawMessage = ParamUtils.getParameter(request, "welcomerawmessage");
String welcomeMessageFrom = ParamUtils.getParameter(request, "welcomemessagefrom");
String group = ParamUtils.getParameter(request, "groupname");

String header = ParamUtils.getParameter(request, "header");
Expand Down Expand Up @@ -172,11 +174,17 @@
}

if (saveWelcome) {
if (welcomeMessage == null || welcomeMessage.trim().length() < 1) {
boolean hasWelcomeMessage = welcomeMessage != null && welcomeMessage.trim().length() > 0;
boolean hasWelcomeRawMessage = welcomeRawMessage != null && welcomeRawMessage.trim().length() > 0;
plugin.setWelcomeMessageFrom(welcomeMessageFrom);
if (!hasWelcomeMessage && !hasWelcomeRawMessage) {
errors.put("missingWelcomeMessage", "missingWelcomeMessage");
}
else {
plugin.setWelcomeMessage(welcomeMessage);
if (hasWelcomeMessage) {
plugin.setWelcomeMessage(welcomeMessage);
}
plugin.setWelcomeRawMessage(welcomeRawMessage);
response.sendRedirect("registration-props-form.jsp?welcomeSaved=true");
return;
}
Expand Down Expand Up @@ -237,6 +245,8 @@
privacyListEnabled = plugin.privacyListEnabled();

welcomeMessage = plugin.getWelcomeMessage();
welcomeRawMessage = plugin.getWelcomeRawMessage() != null ? plugin.getWelcomeRawMessage() : "";
welcomeMessageFrom = plugin.getWelcomeMessageFrom();
group = plugin.getGroup();
header = plugin.getHeader();
privacyListName = plugin.getPrivacyListName();
Expand Down Expand Up @@ -616,10 +626,15 @@ function addEmailContact() {
<tbody>
<tr>
<td width="5%" valign="top">Message:&nbsp;</td>
<td width="95%"><textarea cols="45" rows="5" wrap="virtual" name="welcomemessage"><c:out value="${welcomeMessage}"/></textarea></td>
<% if (errors.containsKey("missingWelcomeMessage")) { %>
<span class="jive-error-text"><br><fmt:message key="registration.props.form.welcome_message_missing" /></span>
<% } %>
<td width="95%"><textarea cols="45" rows="5" wrap="virtual" name="welcomemessage"><%= welcomeMessage %></textarea></td>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These <%= outputs need to be properly escaped, to avoid XSS.

</tr>
<tr>
<td width="15%" valign="top">Message from:&nbsp;</td>
<td width="85%"><textarea cols="45" rows="1" wrap="virtual" name="welcomemessagefrom"><%= welcomeMessageFrom %></textarea></td>
</tr>
<tr>
<td width="15%" valign="top">Raw XMPP message:&nbsp;</td>
<td width="85%"><textarea cols="45" rows="5" name="welcomerawmessage"><%= welcomeRawMessage %></textarea></td>
</tr>
</tbody>
</table>
Expand Down