Commit deb9eaf4 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

More exciting web interface work!

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@6362 b35dd754-fafc-0310-a699-88a17e54d16e
parent c87e3f9a
...@@ -59,6 +59,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -59,6 +59,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
public void setup(TransportType type, String description) { public void setup(TransportType type, String description) {
this.description = description; this.description = description;
this.transportType = type; this.transportType = type;
permissionManager = new PermissionManager(transportType);
} }
/** /**
...@@ -86,7 +87,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -86,7 +87,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* Manages permission information. * Manages permission information.
* @see org.jivesoftware.wildfire.gateway.PermissionManager * @see org.jivesoftware.wildfire.gateway.PermissionManager
*/ */
public final PermissionManager permissionManager = new PermissionManager(); public PermissionManager permissionManager = null;
/** /**
* JID of the transport in question. * JID of the transport in question.
...@@ -601,7 +602,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -601,7 +602,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
registered = true; registered = true;
} }
if (!registered && !permissionManager.hasAccess(this.transportType, from)) { if (!registered && !permissionManager.hasAccess(from)) {
// User does not have permission to register with transport. // User does not have permission to register with transport.
// We want to allow them to change settings if they are already registered. // We want to allow them to change settings if they are already registered.
IQ result = IQ.createResultIQ(packet); IQ result = IQ.createResultIQ(packet);
...@@ -694,7 +695,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -694,7 +695,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
registered = true; registered = true;
} }
if (!registered && !permissionManager.hasAccess(this.transportType, from)) { if (!registered && !permissionManager.hasAccess(from)) {
// User does not have permission to register with transport. // User does not have permission to register with transport.
// We want to allow them to change settings if they are already registered. // We want to allow them to change settings if they are already registered.
result.setError(Condition.bad_request); result.setError(Condition.bad_request);
......
...@@ -16,6 +16,7 @@ import org.jivesoftware.util.Log; ...@@ -16,6 +16,7 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.wildfire.group.GroupManager; import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.Group; import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.user.User;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
...@@ -39,24 +40,60 @@ public class PermissionManager { ...@@ -39,24 +40,60 @@ public class PermissionManager {
"SELECT count(*) FROM gatewayRestrictions WHERE transportType=? AND username=?"; "SELECT count(*) FROM gatewayRestrictions WHERE transportType=? AND username=?";
private static final String GROUPS_LISTED = private static final String GROUPS_LISTED =
"SELECT groupname FROM gatewayRestrictions WHERE transportType=?"; "SELECT groupname FROM gatewayRestrictions WHERE transportType=?";
private static final String DELETE_ALL_USERS =
"DELETE FROM gatewayRestrictions WHERE transportType=?";
private static final String DELETE_ALL_GROUPS =
"DELETE FROM gatewayRestrictions WHERE transportType=?";
private static final String ADD_NEW_USER =
"INSERT INTO gatewayRestrictions(transportType,username) VALUES(?,?)";
private static final String ADD_NEW_GROUP =
"INSERT INTO gatewayRestrictions(transportType,groupname) VALUES(?,?)";
private static final String GET_ALL_USERS =
"SELECT username FROM gatewayRestrictions WHERE transportType=? AND username IS NOT NULL ORDER BY username";
private static final String GET_ALL_GROUPS =
"SELECT groupname FROM gatewayRestrictions WHERE transportType=? AND groupname IS NOT NULL ORDER BY groupname";
public boolean hasAccess(TransportType type, JID jid) { private TransportType transportType = null;
int setting = JiveGlobals.getIntProperty("plugin.gateway."+type.toString()+".registration", 1);
/**
* Create a permissionManager instance.
*
* @param type Type of the transport that this permission manager serves.
*/
public PermissionManager(TransportType type) {
this.transportType = type;
}
/**
* Checks if a user has access to the transport, via a number of methods.
*
* @param jid JID of the user who may or may not have access.
* @return True or false if the user has access.
*/
public boolean hasAccess(JID jid) {
int setting = JiveGlobals.getIntProperty("plugin.gateway."+transportType.toString()+".registration", 1);
if (setting == 1) { return true; } if (setting == 1) { return true; }
if (setting == 3) { return false; } if (setting == 3) { return false; }
if (isUserAllowed(type, jid)) { return true; } if (isUserAllowed(jid)) { return true; }
if (isUserInAllowedGroup(type, jid)) { return true; } if (isUserInAllowedGroup(jid)) { return true; }
return false; return false;
} }
public boolean isUserAllowed(TransportType type, JID jid) { /**
* Checks if a user has specific access to the transport.
*
* @param jid JID of the user who may or may not have access.
* @return True or false of the user has access.
*/
public boolean isUserAllowed(JID jid) {
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(IS_USER_LISTED); pstmt = con.prepareStatement(IS_USER_LISTED);
pstmt.setString(1, type.toString()); pstmt.setString(1, transportType.toString());
pstmt.setString(2, jid.getNode()); pstmt.setString(2, jid.getNode());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
rs.next(); rs.next();
...@@ -71,7 +108,13 @@ public class PermissionManager { ...@@ -71,7 +108,13 @@ public class PermissionManager {
return false; return false;
} }
public boolean isUserInAllowedGroup(TransportType type, JID jid) { /**
* Checks if a user is in a group that has access to the transport.
*
* @param jid JID of the user who may or may not have access.
* @return True or false of the user is in a group that has access.
*/
public boolean isUserInAllowedGroup(JID jid) {
ArrayList<String> allowedGroups = new ArrayList<String>(); ArrayList<String> allowedGroups = new ArrayList<String>();
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
...@@ -79,7 +122,7 @@ public class PermissionManager { ...@@ -79,7 +122,7 @@ public class PermissionManager {
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GROUPS_LISTED); pstmt = con.prepareStatement(GROUPS_LISTED);
pstmt.setString(1, type.toString()); pstmt.setString(1, transportType.toString());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
allowedGroups.add(rs.getString(1)); allowedGroups.add(rs.getString(1));
...@@ -100,4 +143,121 @@ public class PermissionManager { ...@@ -100,4 +143,121 @@ public class PermissionManager {
return false; return false;
} }
/**
* Stores a list of users as having access to the transport in question.
*
* @param users list of users who should have access.
*/
public void storeUserList(ArrayList<User> users) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_ALL_USERS);
pstmt.setString(1, transportType.toString());
pstmt.executeUpdate();
for (User user : users) {
pstmt = con.prepareStatement(ADD_NEW_USER);
pstmt.setString(1, transportType.toString());
pstmt.setString(2, user.getUsername());
pstmt.executeUpdate();
}
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
/**
* Stores a list of groups as having access to the transport in question.
*
* @param groups list of groups who should have access.
*/
public void storeGroupList(ArrayList<Group> groups) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_ALL_GROUPS);
pstmt.setString(1, transportType.toString());
pstmt.executeUpdate();
for (Group group : groups) {
pstmt = con.prepareStatement(ADD_NEW_GROUP);
pstmt.setString(1, transportType.toString());
pstmt.setString(2, group.getName());
pstmt.executeUpdate();
}
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
/**
* Retrieves a list of all of the users permitted to access this transport.
*
* @return List of users (as strings)
*/
public ArrayList<String> getAllUsers() {
ArrayList<String> userList = new ArrayList<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_ALL_USERS);
pstmt.setString(1, transportType.toString());
rs = pstmt.executeQuery();
while (rs.next()) {
userList.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return userList;
}
/**
* Retrieves a list of all of the groups permitted to access this transport.
*
* @return List of groups (as strings)
*/
public ArrayList<String> getAllGroups() {
ArrayList<String> groupList = new ArrayList<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_ALL_GROUPS);
pstmt.setString(1, transportType.toString());
rs = pstmt.executeQuery();
while (rs.next()) {
groupList.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupList;
}
} }
...@@ -11,8 +11,15 @@ package org.jivesoftware.wildfire.gateway.web; ...@@ -11,8 +11,15 @@ package org.jivesoftware.wildfire.gateway.web;
import org.jivesoftware.wildfire.container.PluginManager; import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.GroupNotFoundException;
import org.jivesoftware.wildfire.gateway.GatewayPlugin; import org.jivesoftware.wildfire.gateway.GatewayPlugin;
import org.jivesoftware.wildfire.gateway.TransportType; import org.jivesoftware.wildfire.gateway.TransportType;
import org.jivesoftware.wildfire.gateway.PermissionManager;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.dom4j.Document; import org.dom4j.Document;
...@@ -20,6 +27,7 @@ import org.dom4j.Element; ...@@ -20,6 +27,7 @@ import org.dom4j.Element;
import org.dom4j.Attribute; import org.dom4j.Attribute;
import java.util.HashMap; import java.util.HashMap;
import java.util.ArrayList;
/** /**
* Transport Configuration Manager (for web interface) * Transport Configuration Manager (for web interface)
...@@ -129,4 +137,43 @@ public class ConfigManager { ...@@ -129,4 +137,43 @@ public class ConfigManager {
} }
} }
/**
* Saves permissions settings from web interface.
*
* We validate all of the groups before actually adding them.
*
* @param transportName Name of the transport to have it's options saved (type of transport)
* @param overallSetting The general "all(1), some(2), or none(3)" setting for the permissions.
* @param users List of specific users that have access.
* @param groups List of specific groups that have access.
*/
public void savePermissions(String transportName, Integer overallSetting, ArrayList<String> users, ArrayList<String> groups) {
JiveGlobals.setProperty("plugin.gateway."+transportName+".registration", overallSetting.toString());
PermissionManager permissionManager = new PermissionManager(TransportType.valueOf(transportName));
ArrayList<User> userList = new ArrayList<User>();
UserManager userManager = UserManager.getInstance();
for (String username : users) {
try {
User user = userManager.getUser(username);
userList.add(user);
}
catch (UserNotFoundException e) {
Log.error("User "+username+" not found while adding access rules.");
}
}
permissionManager.storeUserList(userList);
ArrayList<Group> groupList = new ArrayList<Group>();
GroupManager groupManager = GroupManager.getInstance();
for (String grpname : groups) {
try {
Group group = groupManager.getGroup(grpname);
groupList.add(group);
}
catch (GroupNotFoundException e) {
Log.error("Group "+grpname+" not found while adding access rules.");
}
}
permissionManager.storeGroupList(groupList);
}
} }
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
<%@ page import="org.jivesoftware.util.Log" %> <%@ page import="org.jivesoftware.util.Log" %>
<%@ page import="org.dom4j.Document" %> <%@ page import="org.dom4j.Document" %>
<%@ page import="org.jivesoftware.util.JiveGlobals" %> <%@ page import="org.jivesoftware.util.JiveGlobals" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="org.jivesoftware.wildfire.gateway.PermissionManager" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.Iterator" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
...@@ -27,13 +31,52 @@ ...@@ -27,13 +31,52 @@
Integer jsID = 0; // Javascript incrementable id Integer jsID = 0; // Javascript incrementable id
String connectHost = null; String connectHost = null;
String connectPort = null; String connectPort = null;
String userPermText = "[none selected]";
GatewaySettings(JspWriter out, GatewayPlugin plugin, TransportType gatewayType, String desc) { String groupPermText = "[none selected]";
String userPermEntry = "";
String groupPermEntry = "";
Integer globalPermSetting = 1;
GatewaySettings(JspWriter out, GatewayPlugin plugin, TransportType gatewayType,
String desc) {
this.description = desc; this.description = desc;
this.gatewayType = gatewayType; this.gatewayType = gatewayType;
this.gwEnabled = plugin.serviceEnabled(gatewayType.toString()); this.gwEnabled = plugin.serviceEnabled(gatewayType.toString());
this.out = out; this.out = out;
getConnectHostAndPort(); getConnectHostAndPort();
getPermissionsList();
}
/**
* Borrowed from http://www.bigbold.com/snippets/posts/show/91
*/
public String join(Collection s, String delimiter) {
StringBuffer buffer = new StringBuffer();
Iterator iter = s.iterator();
while (iter.hasNext()) {
buffer.append(iter.next());
if (iter.hasNext()) {
buffer.append(delimiter);
}
}
return buffer.toString();
}
void getPermissionsList() {
PermissionManager permissionManager = new PermissionManager(this.gatewayType);
ArrayList<String> userList = permissionManager.getAllUsers();
if (userList.size() > 0) {
String joinedString = join(userList, " ");
userPermText = joinedString;
userPermEntry = joinedString;
}
ArrayList<String> groupList = permissionManager.getAllGroups();
if (groupList.size() > 0) {
String joinedString = join(groupList, " ");
groupPermText = joinedString;
groupPermEntry = joinedString;
}
globalPermSetting = JiveGlobals.getIntProperty("plugin.gateway."+this.gatewayType.toString()+".registration", 1);
} }
void getConnectHostAndPort() { void getConnectHostAndPort() {
...@@ -48,7 +91,7 @@ ...@@ -48,7 +91,7 @@
Element rightPanel = optConfig.getRootElement().element("rightpanel"); Element rightPanel = optConfig.getRootElement().element("rightpanel");
if (leftPanel != null && leftPanel.nodeCount() > 0) { if (leftPanel != null && leftPanel.nodeCount() > 0) {
for (Object nodeObj : leftPanel.elements("item")) { for (Object nodeObj : leftPanel.elements("item")) {
Element node = (Element)nodeObj; Element node = (Element) nodeObj;
Attribute type = node.attribute("type"); Attribute type = node.attribute("type");
Attribute var = node.attribute("var"); Attribute var = node.attribute("var");
Attribute sysprop = node.attribute("sysprop"); Attribute sysprop = node.attribute("sysprop");
...@@ -71,7 +114,7 @@ ...@@ -71,7 +114,7 @@
} }
if (rightPanel != null && rightPanel.nodeCount() > 0) { if (rightPanel != null && rightPanel.nodeCount() > 0) {
for (Object nodeObj : rightPanel.elements("item")) { for (Object nodeObj : rightPanel.elements("item")) {
Element node = (Element)nodeObj; Element node = (Element) nodeObj;
Attribute type = node.attribute("type"); Attribute type = node.attribute("type");
Attribute var = node.attribute("var"); Attribute var = node.attribute("var");
Attribute sysprop = node.attribute("sysprop"); Attribute sysprop = node.attribute("sysprop");
...@@ -120,15 +163,21 @@ ...@@ -120,15 +163,21 @@
String setting = JiveGlobals.getProperty(sysprop.getText(), defStr); String setting = JiveGlobals.getProperty(sysprop.getText(), defStr);
String inputId = gatewayType.toString()+var.getText(); String inputId = gatewayType.toString() + var.getText();
out.println("<tr valign='middle'>"); out.println("<tr valign='middle'>");
out.println("<td align='right' width='1%'><label for='" + inputId + "'>" + desc.getText() + "</label>:</td>"); out.println("<td align='right' width='1%'><label for='" + inputId + "'>" +
out.print("<td><input type='text' id='" + inputId + "' name='" + inputId + "'"+(size != null ? " size='"+size.getText()+"'" : "")+(size != null ? " maxlength='"+maxlen.getText()+"'" : "")+" value='"+setting+"'"); desc.getText() + "</label>:</td>");
out.print("<td><input type='text' id='" + inputId + "' name='" + inputId + "'" +
(size != null ? " size='" + size.getText() + "'" : "") +
(size != null ? " maxlength='" + maxlen.getText() + "'" : "") +
" value='" + setting + "'");
if (var.getText().equals("host")) { if (var.getText().equals("host")) {
out.print(" onChange='document.getElementById(\""+gatewayType.toString()+"testhost\").innerHTML = this.value'"); out.print(" onChange='document.getElementById(\"" + gatewayType.toString() +
"testhost\").innerHTML = this.value'");
} }
if (var.getText().equals("port")) { if (var.getText().equals("port")) {
out.print(" onChange='document.getElementById(\""+gatewayType.toString()+"testport\").innerHTML = this.value'"); out.print(" onChange='document.getElementById(\"" + gatewayType.toString() +
"testport\").innerHTML = this.value'");
} }
out.println("/></td>"); out.println("/></td>");
out.println("</tr>"); out.println("</tr>");
...@@ -148,20 +197,26 @@ ...@@ -148,20 +197,26 @@
} }
boolean defBool = false; boolean defBool = false;
if (def != null && (def.getText().equals("1") || def.getText().equals("true") || def.getText().equals("enabled") || def.getText().equals("yes"))) { if (def != null && (def.getText().equals("1") || def.getText().equals("true") ||
def.getText().equals("enabled") || def.getText().equals("yes"))) {
defBool = true; defBool = true;
} }
boolean setting = JiveGlobals.getBooleanProperty(sysprop.getText(), defBool); boolean setting = JiveGlobals.getBooleanProperty(sysprop.getText(), defBool);
String jsStr = gatewayType.toString()+(++jsID); String jsStr = gatewayType.toString() + (++jsID);
String checkId = gatewayType.toString()+var.getText(); String checkId = gatewayType.toString() + var.getText();
out.println("<tr valign='top'>"); out.println("<tr valign='top'>");
out.println("<td align='right' width='1%'><input type='checkbox' id='" + checkId +"' name='" + checkId + "' value='true' "+(setting ? " checked='checked'" : "")+" onClick='elem = document.getElementById(\""+jsStr+"\"); if (elem) { if (this.checked) { elem.style.display=\"table\"} else { elem.style.display=\"none\"} }'/></td>"); out.println("<td align='right' width='1%'><input type='checkbox' id='" +
checkId + "' name='" + checkId + "' value='true' " +
(setting ? " checked='checked'" : "") +
" onClick='elem = document.getElementById(\"" + jsStr +
"\"); if (elem) { if (this.checked) { elem.style.display=\"table\"} else { elem.style.display=\"none\"} }'/></td>");
out.print("<td><label for='" + checkId + "'>" + desc.getText() + "</label>"); out.print("<td><label for='" + checkId + "'>" + desc.getText() + "</label>");
for (Object itemObj : node.elements("item")) { for (Object itemObj : node.elements("item")) {
Element item = (Element)itemObj; Element item = (Element) itemObj;
out.println("<table id='"+jsStr+"' width='100%' style='display: "+(defBool ? "table" : "none")+"'>"); out.println("<table id='" + jsStr + "' width='100%' style='display: " +
(defBool ? "table" : "none") + "'>");
printConfigNode(item); printConfigNode(item);
out.println("</table>"); out.println("</table>");
} }
...@@ -198,7 +253,7 @@ ...@@ -198,7 +253,7 @@
<!-- Tests Window --> <!-- Tests Window -->
<div class="jive-gatewayPanel" id="jive<%= this.gatewayType.toString().toUpperCase() %>tests" style="display: none;"> <div class="jive-gatewayPanel" id="jive<%= this.gatewayType.toString().toUpperCase() %>tests" style="display: none;">
<div> <div>
<form id="jive<%= this.gatewayType.toString().toUpperCase() %>testsform" action=""> <form id="jive<%= this.gatewayType.toString().toUpperCase() %>testsform" action="" onSubmit="return false">
<span style="font-weight: bold">Connect to host:</span> <span id="<%= this.gatewayType.toString() %>testhost"><%= connectHost %></span><br /> <span style="font-weight: bold">Connect to host:</span> <span id="<%= this.gatewayType.toString() %>testhost"><%= connectHost %></span><br />
<span style="font-weight: bold">Connect to port:</span> <span id="<%= this.gatewayType.toString() %>testport"><%= connectPort %></span><br /> <span style="font-weight: bold">Connect to port:</span> <span id="<%= this.gatewayType.toString() %>testport"><%= connectPort %></span><br />
...@@ -210,7 +265,7 @@ ...@@ -210,7 +265,7 @@
<!-- Options Window --> <!-- Options Window -->
<div class="jive-gatewayPanel" id="jive<%= this.gatewayType.toString().toUpperCase() %>options" style="display: none;"> <div class="jive-gatewayPanel" id="jive<%= this.gatewayType.toString().toUpperCase() %>options" style="display: none;">
<div> <div>
<form id="jive<%= this.gatewayType.toString().toUpperCase() %>optionsform" action=""> <form id="jive<%= this.gatewayType.toString().toUpperCase() %>optionsform" action="" onSubmit="return false">
<table border="0" cellpadding="0" cellspacing="0"> <table border="0" cellpadding="0" cellspacing="0">
<tr valign="top"> <tr valign="top">
<td align="left" width="50%"> <td align="left" width="50%">
...@@ -252,29 +307,31 @@ ...@@ -252,29 +307,31 @@
</div> </div>
</div> </div>
<!-- Permissions Window --> <!-- Permissions Window -->
<div class="jive-gatewayPanel" id="jive<%= this.gatewayType.toString().toUpperCase() %>perms" style="display: none;"> <div class="jive-gatewayPanel" id="jive<%= this.gatewayType.toString().toUpperCase() %>perms" style="display: none;" onSubmit="return false">
<div> <div>
<form id="jive<%= this.gatewayType.toString().toUpperCase() %>permsform" action=""> <form id="jive<%= this.gatewayType.toString().toUpperCase() %>permsform" action="">
<input type="radio" name="userreg" value="all" onClick="getElementById('userreg_specific').style.display = 'none'" checked> All users can register<br> <input type="radio" name="<%= this.gatewayType.toString() %>userreg" value="all" onClick="hideSpecificChoices('<%= this.gatewayType.toString() %>')" <%= (this.globalPermSetting == 1 ? "checked='checked'" : "") %> /> All users can register<br>
<input type="radio" name="userreg" value="specific" onClick="getElementById('userreg_specific').style.display = 'block'"> These users and/or groups can register<br> <input type="radio" name="<%= this.gatewayType.toString() %>userreg" value="specific" onClick="showSpecificChoices('<%= this.gatewayType.toString() %>')" <%= (this.globalPermSetting == 2 ? "checked='checked'" : "") %> /> These users and/or groups can register<br>
<div id="userreg_specific" style="display: none; margin: 0; padding: 0; font-size: 80%"> <div id="<%= this.gatewayType.toString() %>userreg_specific" style="<%= (this.globalPermSetting == 2 ? "" : "display: none; ") %>margin: 0; padding: 0; font-size: 80%">
<table border="0" cellpadding="0" cellspacing="0" style="padding-left: 30.0px"> <table border="0" cellpadding="0" cellspacing="0" style="padding-left: 30.0px">
<tr valign="top"> <tr valign="top">
<td align="left"> <td align="left">
<span style="font-weight: bold">Users</span> <a href="">(Modify Users)</a><br /> <span style="font-weight: bold">Users</span> <a href="javascript:noop()" onClick="activateModifyUsers('<%= this.gatewayType.toString() %>'); return false">(Modify Users)</a><br />
(none selected) <span id="<%= this.gatewayType.toString() %>userpermtext"><%= this.userPermText %></span>
<div id="<%= this.gatewayType.toString() %>userpermentrydiv" style="display:none"><textarea class='permissionListTextArea' rows="5" cols="20" id="<%= this.gatewayType.toString() %>userpermentry" name="<%= this.gatewayType.toString() %>userpermentry"><%= this.userPermEntry %></textarea></div>
</td> </td>
<td align="left" style="padding-left: 30.0px"> <td align="left" style="padding-left: 30.0px">
<span style="font-weight: bold">Groups</span> <a href="">(Modify Groups)</a><br /> <span style="font-weight: bold">Groups</span> <a href="javascript:noop()" onClick="activateModifyGroups('<%= this.gatewayType.toString() %>'); return false">(Modify Groups)</a><br />
(none selected) <span id="<%= this.gatewayType.toString() %>grouppermtext"><%= this.groupPermText %></span>
<div id="<%= this.gatewayType.toString() %>grouppermentrydiv" style="display:none"><textarea class='permissionListTextArea' rows="5" cols="20" id="<%= this.gatewayType.toString() %>grouppermentry" name="<%= this.gatewayType.toString() %>grouppermentry"><%= this.groupPermEntry %></textarea></div>
</td> </td>
</tr> </tr>
</table> </table>
</div> </div>
<input type="radio" name="userreg" value="manual" onClick="getElementById('userreg_specific').style.display = 'none'"> Manual registration only (see the Registrations section to manage)<br> <input type="radio" name="<%= this.gatewayType.toString() %>userreg" value="manual" onClick="hideSpecificChoices('<%= this.gatewayType.toString() %>')" <%= (this.globalPermSetting == 3 ? "checked='checked'" : "") %> /> Manual registration only (see the Registrations section to manage)<br>
<input type="submit" name="submit" value="Save Permissions" onclick="return false" class="jive-formButton"> <input type="submit" name="submit" value="Save Permissions" onclick="savePermissions('<%= this.gatewayType.toString() %>'); return false" class="jive-formButton">
<input type="reset" name="cancel" value="Cancel Changes" class="jive-formButton"> <input type="reset" name="cancel" value="Cancel Changes" onclick="cancelPermissions('<%= this.gatewayType.toString() %>'); return true" class="jive-formButton">
<span id="<%= this.gatewayType.toString() %>permsresults" class="saveResultsMsg"></span> <span id="<%= this.gatewayType.toString() %>permsresults" class="saveResultsMsg"></span>
</form> </form>
</div> </div>
...@@ -372,12 +429,79 @@ ...@@ -372,12 +429,79 @@
function to_testConnect(transportID) { function to_testConnect(transportID) {
Effect.Fade(transportID+"testsresults"); Effect.Fade(transportID+"testsresults");
} }
function savePermissions(transportID) {
var userEntry = DWRUtil.getValue(transportID+"userpermentry");
var groupEntry = DWRUtil.getValue(transportID+"grouppermentry");
var globalSettingStr = DWRUtil.getValue(transportID+"userreg");
var globalSetting = 1; // Allow all as default
if (globalSettingStr == "all") {
globalSetting = 1;
}
else if (globalSettingStr == "specific") {
globalSetting = 2;
}
else if (globalSettingStr == "manual") {
globalSetting = 3;
}
var userList = userEntry.split(/\s+/);
var groupList = groupEntry.split(/\s+/);
ConfigManager.savePermissions(transportID, globalSetting, userList, groupList);
document.getElementById(transportID+"permsresults").style.display = "";
document.getElementById(transportID+"permsresults").innerHTML = "<span class='successresults'><img src='images/success-16x16.gif' align='absmiddle' />Permissions Saved!</span>";
setTimeout("to_savePermissions('"+transportID+"')", 5000);
}
function cancelPermissions(transportID) {
deactivateModifyUsers(transportID);
deactivateModifyGroups(transportID);
document.getElementById(transportID+"permsresults").style.display = "";
document.getElementById(transportID+"permsresults").innerHTML = "<span class='warningresults'><img src='images/warning-16x16.gif' align='absmiddle' />Changes Cancelled!</span>";
setTimeout("to_savePermissions('"+transportID+"')", 5000);
}
function to_savePermissions(transportID) {
Effect.Fade(transportID+"permsresults");
}
function activateModifyUsers(transportID) {
document.getElementById(transportID+"userpermtext").style.display = "none";
document.getElementById(transportID+"userpermentrydiv").style.display = "block";
}
function deactivateModifyUsers(transportID) {
document.getElementById(transportID+"userpermtext").style.display = "inline";
document.getElementById(transportID+"userpermentrydiv").style.display = "none";
}
function activateModifyGroups(transportID) {
document.getElementById(transportID+"grouppermtext").style.display = "none";
document.getElementById(transportID+"grouppermentrydiv").style.display = "block";
}
function deactivateModifyGroups(transportID) {
document.getElementById(transportID+"grouppermtext").style.display = "inline";
document.getElementById(transportID+"grouppermentrydiv").style.display = "none";
}
function hideSpecificChoices(transportID) {
var targElement = document.getElementById(transportID+"userreg_specific");
if (targElement.style.display != "none") {
Effect.toggle(targElement,'slide', {duration: .4});
}
}
function showSpecificChoices(transportID) {
var targElement = document.getElementById(transportID+"userreg_specific");
if (targElement.style.display == "none") {
Effect.toggle(targElement,'slide', {duration: .4});
}
}
</script> </script>
</head> </head>
<body> <body>
<p><fmt:message key="gateway.web.settings.instructions" /> <p><fmt:message key="gateway.web.settings.instructions" />
<b>Note:</b> Please be aware that Tests, Options, and Permissions are not yet functional. They are only present for demonstration.</p>
<form action="" name="gatewayForm"> <form action="" name="gatewayForm">
......
...@@ -18,9 +18,9 @@ function togglePanel(thisID) { ...@@ -18,9 +18,9 @@ function togglePanel(thisID) {
Effect.toggle($(thisID),'slide', {duration: .4}); Effect.toggle($(thisID),'slide', {duration: .4});
$(activeLink).className = ""; $(activeLink).className = "";
} else if ($(thisID).style.display == 'none' && $(lastID).style.display != 'none') { } else if ($(thisID).style.display == 'none' && $(lastID).style.display != 'none') {
$(lastID).style.display = 'none'; Effect.toggle($(lastID),'slide', {duration: .4});
$(thisID).style.display = 'block'; $(oldLink).className = "";
$(oldLink).className = ""; Effect.toggle($(thisID),'slide', {duration: .4, delay: .5});
$(activeLink).className = "jive-gatewayButtonOn"; $(activeLink).className = "jive-gatewayButtonOn";
} else { } else {
Effect.toggle($(thisID),'slide', {duration: .4}); Effect.toggle($(thisID),'slide', {duration: .4});
......
...@@ -125,8 +125,19 @@ a.jive-gatewayButtonOn { ...@@ -125,8 +125,19 @@ a.jive-gatewayButtonOn {
margin-right: 3px; margin-right: 3px;
margin-bottom: 2px; margin-bottom: 2px;
} }
.saveResultsMsg .warningresults {
border: 1.0px solid #550000;
background-color: #ffff00;
color: #550000;
padding: 3.0px;
}
.saveResultsMsg .warningresults img {
margin-right: 3px;
margin-bottom: 2px;
}
.permissionListTextArea {
font-size: 70%;
}
/* ******************************************** */ /* ******************************************** */
......
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