Commit 576e8962 authored by Ryan Graham's avatar Ryan Graham Committed by ryang

initial check-in


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1199 b35dd754-fafc-0310-a699-88a17e54d16e
parent 018f9313
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<class>org.jivesoftware.messenger.plugin.RegistrationNotificationPlugin</class>
<name>Registration Notification Plugin</name>
<description>Adds the ability to allow an specified user to be notified whenever a new user attempts to register with the server.</description>
<author>Ryan Graham</author>
<version>1.0</version>
<minServerVersion>2.1.3</minServerVersion>
<adminconsole>
<tab id="tab-users">
<sidebar id="registration-notification-props-form" name="Registration Notification">
<item id="registration-notification-props-form" name="Notification Properties"
url="registration-notification-props-form.jsp"
description="User Registration Notification" />
</sidebar>
</tab>
</adminconsole>
</plugin>
\ No newline at end of file
/**
* Copyright (C) 2005 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.plugin;
import java.io.File;
import java.util.Iterator;
import org.dom4j.Element;
import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.messenger.Session;
import org.jivesoftware.messenger.SessionManager;
import org.jivesoftware.messenger.SessionNotFoundException;
import org.jivesoftware.messenger.XMPPServer;
import org.jivesoftware.messenger.container.Plugin;
import org.jivesoftware.messenger.container.PluginManager;
import org.jivesoftware.messenger.forms.spi.XDataFormImpl;
import org.jivesoftware.messenger.interceptor.InterceptorManager;
import org.jivesoftware.messenger.interceptor.PacketInterceptor;
import org.jivesoftware.util.Log;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
public class RegistrationNotificationPlugin implements Plugin {
private RegistrationInterceptor interceptor;
private PluginManager pluginManager;
private SessionManager sessionManager;
private static String serverName;
private boolean serviceEnabled;
private String contact;
public RegistrationNotificationPlugin() {
interceptor = new RegistrationInterceptor();
sessionManager = SessionManager.getInstance();
serverName = XMPPServer.getInstance().getServerInfo().getName();
serviceEnabled = JiveGlobals.getBooleanProperty("registration.notification.enabled", true);
setServiceEnabled(serviceEnabled);
contact = JiveGlobals.getProperty("registration.notification.contact");
if (contact == null) {
contact = "admin";
JiveGlobals.setProperty("registration.notification.contact", contact);
}
}
public String getName() {
return pluginManager.getName(this);
}
public String getDescription() {
return pluginManager.getDescription(this);
}
public String getAuthor() {
return pluginManager.getAuthor(this);
}
public String getVersion() {
return pluginManager.getVersion(this);
}
public void processPacket(Packet packet) {
}
public void initializePlugin(PluginManager manager, File pluginDirectory) {
pluginManager = manager;
}
public void destroyPlugin() {
InterceptorManager.getInstance().removeInterceptor(interceptor);
pluginManager = null;
sessionManager = null;
}
public void setServiceEnabled(boolean enable) {
serviceEnabled = enable;
JiveGlobals.setProperty("registration.notification.enabled", serviceEnabled ? "true" : "false");
if (enable) {
InterceptorManager.getInstance().addInterceptor(interceptor);
} else {
InterceptorManager.getInstance().removeInterceptor(interceptor);
}
}
public boolean serviceEnabled() {
return "true".equals(JiveGlobals.getProperty("registration.notification.enabled"));
}
public void setContact(String contact) {
this.contact = contact;
JiveGlobals.setProperty("registration.notification.contact", contact);
}
public String getContact() {
return contact;
}
private void interceptRegistration(Packet packet) {
if (packet instanceof IQ) {
IQ iqPacket = (IQ) packet;
if (IQ.Type.set.equals(iqPacket.getType())) {
Element childElement = iqPacket.getChildElement();
String namespace = null;
if (childElement != null) {
namespace = childElement.getNamespaceURI();
}
if ("jabber:iq:register".equals(namespace)) {
//this is similiar to the logic used in IQRegisterHandler
XDataFormImpl registrationForm = null;
Element iqElement = iqPacket.getChildElement();
Element formElement = iqElement.element("x");
String username = null;;
// Check if a form was used to provide the registration info
if (formElement != null) {
Iterator<String> values = registrationForm.getField("username").getValues();
username = (values.hasNext() ? values.next() : " ");
}
else {
// Get the registration info from the query elements
username = iqElement.elementText("username");
}
String msg = " A new user with the username of '" + username + "' just attempted to register";
try {
sessionManager.sendServerMessage(new JID(getContact() + "@" + serverName),
"Registration Notification",
msg);
}
catch (SessionNotFoundException e) {
Log.error("SessionNotFoundException: could not send the following message to: "
+ getContact()
+ msg);
}
}
}
}
}
private class RegistrationInterceptor implements PacketInterceptor {
public void interceptPacket(Packet packet, Session session, boolean read, boolean processed) {
if (serviceEnabled()) {
interceptRegistration(packet);
}
}
}
}
<%@ page import="java.util.*,
org.jivesoftware.admin.*,
org.jivesoftware.messenger.XMPPServer,
org.jivesoftware.messenger.user.*,
org.jivesoftware.messenger.plugin.RegistrationNotificationPlugin,
org.jivesoftware.util.*"
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" %>
<jsp:useBean id="admin" class="org.jivesoftware.util.WebManager" />
<c:set var="admin" value="${admin.manager}" />
<% admin.init(request, response, session, application, out ); %>
<%
boolean save = request.getParameter("save") != null;
boolean success = request.getParameter("success") != null;
boolean notificationEnabled = ParamUtils.getBooleanParameter(request, "notificationenabled");
String contactName = ParamUtils.getParameter(request, "contactname");
RegistrationNotificationPlugin plugin = (RegistrationNotificationPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("registrationnotification");
Map errors = new HashMap();
if (save) {
if (notificationEnabled) {
plugin.setServiceEnabled(notificationEnabled);
response.sendRedirect("registration-notification-props-form.jsp?success=true");
return;
}
else {
if (contactName == null) {
errors.put("missingContactName", "missingContactName");
}
else {
contactName = contactName.trim().toLowerCase();
try {
UserManager.getInstance().getUser(contactName);
} catch (UserNotFoundException unfe) {
errors.put("userNotFound", "userNotFound");
}
}
if (errors.size() == 0) {
plugin.setServiceEnabled(notificationEnabled);
plugin.setContact(contactName);
response.sendRedirect("registration-notification-props-form.jsp?success=true");
return;
}
}
}
else {
contactName = plugin.getContact();
}
if (errors.size() == 0) {
contactName = plugin.getContact();
}
notificationEnabled = plugin.serviceEnabled();
%>
<jsp:useBean id="pageinfo" scope="request" class="org.jivesoftware.admin.AdminPageBean" />
<%
String title = "User Registration Notification";
pageinfo.setTitle(title);
pageinfo.getBreadcrumbs().add(new AdminPageBean.Breadcrumb(LocaleUtils.getLocalizedString("global.main"), "index.jsp"));
pageinfo.getBreadcrumbs().add(new AdminPageBean.Breadcrumb(title, "registration-notification-props-form.jsp"));
pageinfo.setPageID("registration-notification-props-form");
%>
<jsp:include page="top.jsp" flush="true" />
<jsp:include page="title.jsp" flush="true" />
<p>
Use the form below to edit user registration notification settings. The contact person will the be the user that recieves a notification whenever a new user attempts to register.<br>
Note: This service does not detect the addition of users via the admin console.
</p>
<% if (success) { %>
<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">
Service settings updated successfully.
</td></tr>
</tbody>
</table>
</div><br>
<% } else if (errors.size() > 0) { %>
<div class="jive-error">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0"></td>
<td class="jive-icon-label">Error saving the contact username.</td>
</tr>
</tbody>
</table>
</div><br>
<% } %>
<form action="registration-notification-props-form.jsp?save" method="post">
<fieldset>
<legend>Service Enabled</legend>
<div>
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td width="1%">
<input type="radio" name="notificationenabled" value="true" id="rb01"
<%= ((notificationEnabled) ? "checked" : "") %>>
</td>
<td width="99%">
<label for="rb01"><b>Enabled</b></label> - Notifications will be sent out.
</td>
</tr>
<tr>
<td width="1%">
<input type="radio" name="notificationenabled" value="false" id="rb02"
<%= ((!notificationEnabled) ? "checked" : "") %>>
</td>
<td width="99%">
<label for="rb02"><b>Disabled</b></label> - Notifications will not be sent out.
</td>
</tr>
</tbody>
</table>
</div>
</fieldset>
<br><br>
<fieldset>
<legend>Contact Person</legend>
<div>
<table cellpadding="3" cellspacing="0" border="0">
<tr>
<td class="c1">Username:</td>
<td>
<input type="text" size="30" maxlength="75" name="contactname" <%= notificationEnabled ? "" : "disabled" %>"
value="<%= (contactName != null ? contactName : "") %>">@<%= XMPPServer.getInstance().getServerInfo().getName() %>
<% if (errors.containsKey("missingContactName")) { %>
<span class="jive-error-text">
<br>Please enter a username.
</span>
<% } else if (errors.containsKey("userNotFound")) { %>
<span class="jive-error-text">
<br>Could not find user. Please try again.
</span>
<% } %>
</td>
</tr>
</table>
</div>
</fieldset>
<br><br>
<input type="submit" value="Save Properties">
</form>
<jsp:include page="bottom.jsp" flush="true" />
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