Commit 970100f2 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Imported motd plugin from Ryan Graham.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9635 b35dd754-fafc-0310-a699-88a17e54d16e
parent e015662a
......@@ -13,6 +13,7 @@
<sourceFolder url="file://$MODULE_DIR$/../../src/plugins/gateway/src/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/plugins/gateway/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../src/plugins/loadStats/src/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/plugins/motd/src/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/plugins/presence/src/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/plugins/registration/src/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/plugins/search/src/java" isTestSource="false" />
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>MotD Plugin Changelog</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H2 {
font-size : 10pt;
font-weight : bold;
padding-left : 1em;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
</style>
</head>
<body>
<h1>MotD Plugin Changelog</h1>
<p><b>1.0.2</b> -- October 16, 2007</p>
<ul>
<li>Updated to work with Openfire 3.4.0.</li>
</ul>
<p><b>1.0.1</b> -- May 11, 2007</p>
<ul>
<li>Updated to work with Openfire 3.3.0.</li>
</ul>
<p><b>1.0.0</b> -- January 25, 2007</p>
<ul>
<li>Initial release.</li>
</ul>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<class>org.jivesoftware.openfire.plugin.MotDPlugin</class>
<name>MotD (Message of the Day)</name>
<description>Allows admins to have a message sent to users each time they log in.</description>
<author>Ryan Graham</author>
<version>1.0.2</version>
<date>10/16/2007</date>
<minServerVersion>3.4.0</minServerVersion>
<adminconsole>
<tab id="tab-users">
<sidebar id="sidebar-users">
<item id="motd-form" name="MotD Properties" url="motd-form.jsp" description="Settings for MotD" />
</sidebar>
</tab>
</adminconsole>
</plugin>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>MotD Plugin Readme</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H2 {
font-size : 10pt;
font-weight : bold;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
</style>
</head>
<body>
<h1>MotD Plugin Readme</h1>
<h2>Overview</h2>
<p>The MotD (Message of the Day) plugin allows admins to have a message sent to a user each time they login.</p>
<h2>Installation</h2>
<p>Copy the motd.jar into the plugins directory of your Wildfire installation. The plugin will then be automatically deployed. To upgrade to a new version, copy the new motd.jar file over the existing file.</p>
<h2>Configuration</h2>
<p>The MotD plugin is configured via the "MotD Properties" sidebar item located in the "Users" sidebar item under the "Users/Groups" tab in the Wildfire Admin Console. By default, after the motd plugin has been deployed it is disabled. To enable the message of the day select the checkbox "Enable MotD message" and then click on the "Save Settings" button. To change the message of the day subject or the message itself enter the desired text in the corresponding text field and then click on the "Save Settings" button.</p>
<h2>Using the Plugin</h2>
<p>Presently, after the MotD plugin has been configured nothing else needs to be done to use it.</p>
</body>
</html>
login.title=Admin Console
motd.title=MotD (Message of the Day)
motd.options=MotD Options
motd.saved.success=Settings saved successfully.
motd.enable=Enable MotD message.
motd.directions=Enter the message that will be sent to users when they sign-in.
motd.subject=Subject
motd.subject.missing=Please enter a subject.
motd.message=Message
motd.message.missing=Please enter a message.
motd.button.save=Save Settings
\ No newline at end of file
package org.jivesoftware.openfire.plugin;
import java.io.File;
import java.util.TimerTask;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.TaskEngine;
import org.jivesoftware.openfire.MessageRouter;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.event.SessionEventDispatcher;
import org.jivesoftware.openfire.event.SessionEventListener;
import org.jivesoftware.openfire.session.Session;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
/**
* MotD (Message of the Day) plugin.
*
* @author <a href="mailto:ryan@version2software.com">Ryan Graham</a>
*/
public class MotDPlugin implements Plugin {
private static final String SUBJECT = "plugin.motd.subject";
private static final String MESSAGE = "plugin.motd.message";
private static final String ENABLED = "plugin.motd.enabled";
private JID serverAddress;
private MessageRouter router;
private MotDSessionEventListener listener = new MotDSessionEventListener();
public void initializePlugin(PluginManager manager, File pluginDirectory) {
serverAddress = new JID(XMPPServer.getInstance().getServerInfo().getName());
router = XMPPServer.getInstance().getMessageRouter();
SessionEventDispatcher.addListener(listener);
}
public void destroyPlugin() {
SessionEventDispatcher.removeListener(listener);
listener = null;
serverAddress = null;
router = null;
}
public void setSubject(String message) {
JiveGlobals.setProperty(SUBJECT, message);
}
public String getSubject() {
return JiveGlobals.getProperty(SUBJECT, "Message of the Day");
}
public void setMessage(String message) {
JiveGlobals.setProperty(MESSAGE, message);
}
public String getMessage() {
return JiveGlobals.getProperty(MESSAGE, "Big Brother is watching.");
}
public void setEnabled(boolean enable) {
JiveGlobals.setProperty(ENABLED, enable ? Boolean.toString(true) : Boolean.toString(false));
}
public boolean isEnabled() {
return JiveGlobals.getBooleanProperty(ENABLED, false);
}
private class MotDSessionEventListener implements SessionEventListener {
public void sessionCreated(Session session) {
if (isEnabled()) {
final Message message = new Message();
message.setTo(session.getAddress());
message.setFrom(serverAddress);
message.setSubject(getSubject());
message.setBody(getMessage());
TimerTask messageTask = new TimerTask() {
public void run() {
router.route(message);
}
};
TaskEngine.getInstance().schedule(messageTask, 5000);
}
}
public void sessionDestroyed(Session session) {
//ignore
}
public void anonymousSessionCreated(Session session) {
//ignore
}
public void anonymousSessionDestroyed(Session session) {
//ignore
}
}
}
<%@ page
import="org.jivesoftware.openfire.XMPPServer,
org.jivesoftware.openfire.plugin.MotDPlugin,
org.jivesoftware.util.ParamUtils,
java.util.HashMap,
java.util.Map"
errorPage="error.jsp"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<%
boolean save = request.getParameter("save") != null;
boolean motdEnabled = ParamUtils.getBooleanParameter(request, "motdenabled", false);
String motdSubject = ParamUtils.getParameter(request, "motdSubject");
String motdMessage = ParamUtils.getParameter(request, "motdMessage");
MotDPlugin plugin = (MotDPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("motd");
Map<String, String> errors = new HashMap<String, String>();
if (save) {
if (motdSubject == null || motdSubject.trim().length() < 1) {
errors.put("missingMotdSubject", "missingMotdSubject");
}
if (motdMessage == null || motdMessage.trim().length() < 1) {
errors.put("missingMotdMessage", "missingMotdMessage");
}
if (errors.size() == 0) {
plugin.setEnabled(motdEnabled);
plugin.setSubject(motdSubject);
plugin.setMessage(motdMessage);
response.sendRedirect("motd-form.jsp?settingsSaved=true");
return;
}
}
motdEnabled = plugin.isEnabled();
motdSubject = plugin.getSubject();
motdMessage = plugin.getMessage();
%>
<html>
<head>
<title><fmt:message key="motd.title" /></title>
<meta name="pageID" content="motd-form"/>
</head>
<body>
<form action="motd-form.jsp?save" method="post">
<div class="jive-contentBoxHeader"><fmt:message key="motd.options" /></div>
<div class="jive-contentBox">
<% if (ParamUtils.getBooleanParameter(request, "settingsSaved")) { %>
<div class="jive-success">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0"></td>
<td class="jive-icon-label"><fmt:message key="motd.saved.success" /></td>
</tr>
</tbody>
</table>
</div>
<% } %>
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td width="1%" align="center" nowrap><input type="checkbox" name="motdenabled" <%=motdEnabled ? "checked" : "" %>></td>
<td width="99%" align="left"><fmt:message key="motd.enable" /></td>
</tr>
</tbody>
</table>
<br><br>
<p><fmt:message key="motd.directions" /></p>
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td width="5%" valign="top"><fmt:message key="motd.subject" />:&nbsp;</td>
<td width="95%"><input type="text" name="motdSubject" value="<%= motdSubject %>"></td>
<% if (errors.containsKey("missingMotdSubject")) { %>
<span class="jive-error-text"><fmt:message key="motd.subject.missing" /></span>
<% } %>
</tr>
<tr>
<td width="5%" valign="top"><fmt:message key="motd.message" />:&nbsp;</td>
<td width="95%"><textarea cols="45" rows="5" wrap="virtual" name="motdMessage"><%= motdMessage %></textarea></td>
<% if (errors.containsKey("missingMotdMessage")) { %>
<span class="jive-error-text"><fmt:message key="motd.message.missing" /></span>
<% } %>
</tr>
</tbody>
</table>
</div>
<input type="submit" value="<fmt:message key="motd.button.save" />"/>
</form>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment