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

Ooookay. IntelliJ's SVN didn't want to commit the whole thing.


git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9792 b35dd754-fafc-0310-a699-88a17e54d16e
parent d941d5ae
CREATE TABLE pfRules(
id INT NOT NULL,
ruleorder INT ,
type varchar2(255) ,
tojid varchar2(255) ,
fromjid varchar2(255) ,
rulef varchar2(255) ,
disabled INT,
log INT,
description varchar2(255),
sourcetype varchar2(255),
desttype varchar2(255),
CONSTRAINT pfRules_pk PRIMARY KEY (id)
);
CREATE SEQUENCE pfRules_seq
START WITH 1
INCREMENT BY 1
MINVALUE 1
NOCACHE
NOCYCLE
NOORDER;
CREATE OR REPLACE TRIGGER pfRules_pkcreate BEFORE INSERT ON pfRules FOR EACH ROW WHEN ( NEW.id IS NULL ) BEGIN SELECT pfRules_seq.NEXTVAL INTO :NEW.id FROM DUAL; END pfRules_pkcreate;
INSERT INTO jiveVersion (name,version) values ('packetfilter',1);
CREATE TABLE pfRules (
id BIGINT IDENTITY,
ruleorder BIGINT ,
type varchar(255) ,
tojid varchar(255) ,
fromjid varchar(255) ,
rulef varchar(255) ,
disabled boolean,
log boolean,
description varchar(255),
sourcetype varchar(255),
desttype varchar(255),
CONSTRAINT pfRules_pk PRIMARY KEY (id)
);
CREATE INDEX pfRules_idx ON pfRules(id);
INSERT INTO jiveVersion(name,version) values('packetfilter',1);
\ No newline at end of file
CREATE TABLE pfRules (
id BIGINT NOT NULL AUTO_INCREMENT,
ruleorder BIGINT ,
type varchar(255) ,
tojid varchar(255) ,
fromjid varchar(255) ,
rulef varchar(255) ,
disabled boolean,
log boolean,
description varchar(255),
sourcetype varchar(255),
desttype varchar(255),
PRIMARY KEY (id)
);
INSERT INTO jiveVersion(name,version) values('packetfilter',1);
\ No newline at end of file
CREATE TABLE pfRules (
id SERIAL,
ruleorder BIGINT ,
type varchar(255) ,
tojid varchar(255) ,
fromjid varchar(255) ,
rulef varchar(255) ,
disabled boolean,
log boolean,
description varchar(255),
sourcetype varchar(255),
desttype varchar(255),
CONSTRAINT pfRules_id PRIMARY KEY(id)
);
INSERT INTO jiveVersion(name,version) values('packetfilter',1);
\ No newline at end of file
CREATE TABLE pfRules (
id BIGINT IDENTITY(10,2),
ruleorder BIGINT,
type varchar(255),
tojid varchar(255),
fromjid varchar(255),
rulef varchar(255),
disabled bit,
log bit,
description varchar(255),
sourcetype varchar(255),
desttype varchar(255),
PRIMARY KEY (id)
);
INSERT INTO jiveVersion(name,version) values('packetfilter',1);
\ No newline at end of file
DROP TABLE pfRules;
CREATE TABLE pfRules (
id BIGINT IDENTITY,
ruleorder BIGINT ,
type varchar(255) ,
tojid varchar(255) ,
fromjid varchar(255) ,
rulef varchar(255) ,
disabled boolean,
log boolean,
description varchar(255),
sourcetype varchar(255),
desttype varchar(255),
CONSTRAINT pfRules_pk PRIMARY KEY (id)
);
CREATE INDEX pfRules_idx ON pfRules(id);
UPDATE jiveVersion set version=1 where name='packetfilter';
\ No newline at end of file
DROP TABLE pfRules;
CREATE TABLE pfRules (
id BIGINT NOT NULL AUTO_INCREMENT,
ruleorder BIGINT ,
type varchar(255) ,
tojid varchar(255) ,
fromjid varchar(255) ,
rulef varchar(255) ,
disabled boolean,
log boolean,
description varchar(255),
sourcetype varchar(255),
desttype varchar(255),
PRIMARY KEY (id)
);
UPDATE jiveVersion set version=1 where name='packetfilter';
\ No newline at end of file
DROP TABLE pfRules;
CREATE TABLE pfRules (
id SERIAL,
ruleorder BIGINT ,
type varchar(255) ,
tojid varchar(255) ,
fromjid varchar(255) ,
rulef varchar(255) ,
disabled boolean,
log boolean,
description varchar(255),
sourcetype varchar(255),
desttype varchar(255),
CONSTRAINT pfRules_id PRIMARY KEY(id)
);
UPDATE jiveVersion set version=1 where name='packetfilter';
\ No newline at end of file
DROP TABLE pfRules;
CREATE TABLE pfRules (
id BIGINT IDENTITY(10,2),
ruleorder BIGINT,
type varchar(255),
tojid varchar(255),
fromjid varchar(255),
rulef varchar(255),
disabled bit,
log bit,
description varchar(255),
sourcetype varchar(255),
desttype varchar(255),
PRIMARY KEY (id)
);
UPDATE jiveVersion set version=1 where name='packetfilter';
\ No newline at end of file
pf.create.rule=Create Rule
pf.create.new.rule=Create New Rule
pf.delete.title=Delete Rule
pf.delete.delete=Delete Rule
pf.global.cancel=Cancel
login.title=Packet Filter
pf.summary.title=Packet Filter Rules
pf.save.edit=Edit Rule
global.click_delete=Delete Rule
pf.click.edit=Edit
pf.click.up=Move Rule Up
pf.click.down=Move Rule Down
pf.error.sourceOther=Please specify a valid source JID or Domain
pf.error.destOther=Please specify a valid destination JID or Domain
package org.jivesoftware.openfire.plugin;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.jivesoftware.openfire.plugin.rules.Rule;
import org.jivesoftware.openfire.plugin.rules.RuleManager;
import org.jivesoftware.util.Log;
import org.xmpp.packet.*;
public class PacketFilter {
private static PacketFilter packetFilter = new PacketFilter();
RuleManager ruleManager;
private PacketFilter() {
}
public static PacketFilter getInstance() {
return packetFilter;
}
public void setRuleManager(RuleManager ruleManager) {
this.ruleManager = ruleManager;
}
public Rule findMatch(Packet packet) {
if (packet.getTo() == null || packet.getFrom() == null) return null;
String to = packet.getTo().toBareJID();
String from = packet.getFrom().toBareJID();
//TODO Would it be better to keep a local copy of the rules?
for (Rule rule : ruleManager.getRules()) {
if (!rule.isDisabled() &&
typeMatch(rule.getPackeType().toString(), packet) &&
sourceDestMatch(rule.getDestType(), rule.getDestination(), to) &&
sourceDestMatch(rule.getSourceType(), rule.getSource(), from)) {
return rule;
}
}
return null;
}
private boolean typeMatch(String rulePacketType, Packet packet) {
//Simple case. Any.
if (rulePacketType.equals(Rule.PacketType.Any.toString())) return true;
else if (packet instanceof Message) {
Message message = (Message) packet;
if (rulePacketType.equals(Rule.PacketType.Message.toString())) {
return true;
}
//Try some types.
else if (rulePacketType.equals(Rule.PacketType.MessageChat.toString())
&& message.getType().toString().equals("chat")) {
return true;
} else if (rulePacketType.equals(Rule.PacketType.MessageGroupChat.toString())
&& message.getType().toString().equals("groupchat")) {
return true;
}
return false;
} else if (packet instanceof Presence) {
if (rulePacketType.equals(Rule.PacketType.Presence.toString())) {
return true;
} else return false;
} else if (packet instanceof IQ) {
if (rulePacketType.equals(Rule.PacketType.Iq.toString())) {
return true;
} else return false;
}
return false;
}
private boolean sourceDestMatch(String type, String ruleToFrom, String packetToFrom) {
if (type.equals(Rule.SourceDestType.Any.toString())) return true;
if (type.equals(Rule.SourceDestType.User.toString())) {
if (ruleToFrom.equals(packetToFrom)) {
return true;
}
} else if (type.equals(Rule.SourceDestType.Group.toString())) {
return packetToFromGroup(ruleToFrom, packetToFrom);
} else if (type.equals(Rule.SourceDestType.Component.toString())) {
if (ruleToFrom.toLowerCase().equals(PacketFilterUtil.getComponent(packetToFrom).toLowerCase())) {
return true;
}
} else if (type.equals(Rule.SourceDestType.Other.toString())) {
if (matchUser(ruleToFrom, packetToFrom)) {
return true;
}
}
return false;
}
private boolean matchUser(String ruleToFrom, String packetToFrom) {
boolean match = false;
//Escape the text so I get a rule to packet match.
packetToFrom = JID.unescapeNode(packetToFrom);
if (ruleToFrom.indexOf("*") == 0 && ruleToFrom.indexOf("@") == 1) {
if (PacketFilterUtil.getDomain(ruleToFrom).equals(PacketFilterUtil.getDomain(packetToFrom))) {
match = true;
}
} else {
if (ruleToFrom.equals(packetToFrom)) {
match = true;
}
}
return match;
}
private boolean packetToFromGroup(String rulegroup, String packetToFrom) {
Group group = PacketFilterUtil.getGroup(rulegroup);
if (group == null) {
return false;
} else {
for (JID jid : group.getMembers()) {
if (jid.toBareJID().equals(packetToFrom)) {
return true;
}
}
}
return false;
}
}
package org.jivesoftware.openfire.plugin;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.interceptor.InterceptorManager;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.rules.Rule;
import org.jivesoftware.openfire.plugin.rules.RuleManager;
import org.jivesoftware.openfire.plugin.rules.RuleManagerProxy;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.Log;
import org.xmpp.packet.Packet;
import java.io.File;
public class PacketFilterPlugin implements Plugin, PacketInterceptor {
private static PluginManager pluginManager;
public PacketFilterPlugin() {
XMPPServer server = XMPPServer.getInstance();
interceptorManager = InterceptorManager.getInstance();
}
//Packet Filter
private PacketFilter pf;
//Hook for intercpetorn
private InterceptorManager interceptorManager;
public void initializePlugin(PluginManager manager, File pluginDirectory) {
// register with interceptor manager
Log.info("Packet Filter loaded...");
interceptorManager.addInterceptor(this);
this.pluginManager = manager;
pf = PacketFilter.getInstance();
RuleManager ruleManager = new RuleManagerProxy();
pf.setRuleManager(ruleManager);
}
public void destroyPlugin() {
// unregister with interceptor manager
interceptorManager.removeInterceptor(this);
}
public String getName() {
return "packetFilter";
}
public static PluginManager getPluginManager() {
return pluginManager;
}
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
Rule rule = pf.findMatch(packet);
if (rule != null) {
rule.doAction(packet);
}
}
}
package org.jivesoftware.openfire.plugin;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.jivesoftware.openfire.plugin.component.ComponentList;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID;
import java.util.Collection;
/*
Static util methods.
*/
public class PacketFilterUtil {
static String serverName = XMPPServer.getInstance().getServerInfo().getName();
public static boolean isGroup(String name) {
try {
GroupManager.getInstance().getGroup(name);
return true;
} catch (GroupNotFoundException e) {
return false;
}
}
public static Group getGroup(String name) {
Group group = null;
try {
group = GroupManager.getInstance().getProvider().getGroup(name);
} catch (GroupNotFoundException e) {
e.printStackTrace();
}
return group;
}
//Faster the better. This will break if virtual hosts is ever implemented.
public static boolean isLocalUser(String jid) {
Collection<String> users = UserManager.getUserProvider().getUsernames();
for (String username : users) {
if (jid.equals(username+"@"+serverName)) {
return true;
}
}
return false;
}
/*
Method to get the component part from a jid. The packet could
be from the component itself so just return.
*/
public static String getComponent(String jid) {
if (jid.contains("@")) {
int atIndex = jid.indexOf("@");
return (jid.substring(atIndex+1,jid.length()));
}
else {
return jid;
}
}
public static String getDomain(String jid) {
return getComponent(jid);
}
/*
Figure out if the packet is going to a component
*/
/* public static boolean isComponent(String jid) {
ComponentList cList = ComponentList.getInstance();
if (cList.getComponentName(jid) == null) {
return false;
}
else {
return true;
}
}
*/
/*
Make reasonably sure that the string is a valid
JID.
*/
/*public static boolean isJID(String jid) {
try {
JID _jid = new JID(jid);
}
catch (IllegalArgumentException e) {
Log.error(e);
return false;
}
return true;
} */
}
package org.jivesoftware.openfire.plugin.cluster;
import org.jivesoftware.openfire.plugin.rules.RuleManager;
import org.jivesoftware.openfire.plugin.rules.RuleManagerProxy;
import org.jivesoftware.util.cache.ClusterTask;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
public class RulesUpdatedEvent implements ClusterTask {
public RulesUpdatedEvent() {
}
public Object getResult() {
return null;
}
public void run() {
RuleManager ruleManager = new RuleManagerProxy();
ruleManager.rulesUpdated();
}
public void writeExternal(ObjectOutput objectOutput) throws IOException {
}
public void readExternal(ObjectInput objectInput) throws IOException, ClassNotFoundException {
}
}
package org.jivesoftware.openfire.plugin.component;
import org.dom4j.Element;
import org.jivesoftware.openfire.IQResultListener;
import org.jivesoftware.openfire.IQRouter;
import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.util.Log;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class ComponentList implements IQResultListener {
private static ComponentList instance = new ComponentList();
private XMPPServer server = XMPPServer.getInstance();
private RoutingTable routingTable = server.getRoutingTable();
Map<String, String> componentMap = new ConcurrentHashMap<String, String>();
private ComponentList() {
getComponentInfo();
}
public Map<String, String> getComponentMap() {
return componentMap;
}
public static ComponentList getInstance() {
return instance;
}
public String getComponentName(JID jid) {
return componentMap.get(jid.toString());
}
public String getComponentName(String jid) {
return componentMap.get(jid);
}
public void receivedAnswer(IQ packet) {
if (IQ.Type.result == packet.getType()) {
Element child = packet.getChildElement();
if (child != null) {
for (Iterator it = child.elementIterator("identity"); it.hasNext();) {
Element identity = (Element) it.next();
String name = identity.attributeValue("name");
componentMap.put(packet.getFrom().toString(), name);
}
}
}
}
public void answerTimeout(String packetId) {
Log.warn("An answer to a previously sent IQ stanza was never received. Packet id: " + packetId);
}
public Collection<String> getComponentDomains() {
return routingTable.getComponentsDomains();
}
public Collection<String> getComponentNames() {
return componentMap.values();
}
private void getComponentInfo() {
IQRouter iqRouter;
Collection<String> components = routingTable.getComponentsDomains();
iqRouter = server.getIQRouter();
for (String componentDomain : components) {
IQ iq = new IQ(IQ.Type.get);
iq.setFrom(server.getServerInfo().getName());
iq.setTo(componentDomain);
iq.setChildElement("query", "http://jabber.org/protocol/disco#info");
iqRouter.addIQResultListener(iq.getID(), this);
iqRouter.route(iq);
}
}
}
package org.jivesoftware.openfire.plugin.rules;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.xmpp.packet.Packet;
import java.util.List;
public abstract class AbstractRule implements Rule {
private Action packetAction;
private PacketType packetType;
private Boolean disabled;
private String source;
private String destination;
private Boolean log;
private String description;
private String ruleId;
private String displayName;
private String sourceType;
private String destType;
public String getDestType() {
return destType;
}
public void setDestType(String destType) {
this.destType = destType;
}
public String getSourceType() {
return sourceType;
}
public void setSourceType(String sourceType) {
this.sourceType = sourceType;
}
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
private int order;
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getDisplayName() {
return displayName;
}
public String getRuleId() {
return ruleId;
}
public void setRuleId(String ruleId) {
this.ruleId = ruleId;
}
public String getRuleType() {
return this.getClass().getName();
}
public Action getPacketAction() {
return packetAction;
}
public void setPacketAction(Action packetAction) {
this.packetAction = packetAction;
}
public PacketType getPackeType() {
return packetType;
}
public void setPacketType(PacketType packetType) {
this.packetType = packetType;
}
public Boolean isDisabled() {
return disabled;
}
public void isDisabled(Boolean disabled) {
this.disabled = disabled;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public Boolean doLog() {
return log;
}
public void doLog(Boolean log) {
this.log = log;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Packet doAction(Packet packet) throws PacketRejectedException {
return null;
}
public boolean sourceMustMatch() {
return true;
}
public boolean destMustMatch() {
return true;
}
public String toString() {
StringBuffer sb = new StringBuffer();
if (packetAction != null)
sb.append("Type : "+packetAction.toString()+'\n');
sb.append("Order : "+getOrder()+'\n');
sb.append("Diplay Name : "+getDisplayName()+'\n');
sb.append("Packet Type : "+packetType+'\n');
sb.append("ID : "+ruleId+'\n');
sb.append("Soruce Type : "+sourceType+'\n');
sb.append("Source : "+source+'\n');
sb.append("Dest Type : "+destType+'\n');
sb.append("Destination : "+destination+'\n');
sb.append("Loging : "+log+'\n');
sb.append("Disabled : "+disabled+'\n');
return sb.toString();
}
}
package org.jivesoftware.openfire.plugin.rules;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.plugin.cluster.RulesUpdatedEvent;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.cache.CacheFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class DbRuleManager {
//SQL Statments
private static final String UPDATE_RULE =
"UPDATE pfRules" +
" SET type=?,tojid=?,fromjid=?,rulef=?,disabled=?,log=?,description=?,ruleorder=?,sourcetype=?,desttype=? WHERE id=?";
private static final String DELETE_RULE =
"DELETE FROM pfRules WHERE id=?";
private static final String INSERT_RULE =
"INSERT INTO pfRules(ruleorder,type,tojid,fromjid,rulef,disabled,log,description,sourcetype,desttype) VALUES(?,?,?,?,?,?,?,?,?,?)";
private static final String COUNT =
"select count(*) from pfRules";
private static final String GET_RULES =
"SELECT rulef,id,type,tojid,fromjid,disabled,log,description,ruleorder,sourcetype,desttype from pfRules order by ruleorder";
private static final String RULE_OPTIONS =
"SELECT optionKey, optionValue, optionRequired, classType from pfRulesOptions where ruleId = ?";
/*private static final String GET_RULE_BY_ID =
"SELECT rule,id,type,tojid,fromjid,disabled,log,description,ruleorder from pfRules where id=?";*/
private static final String GET_RULE_BY_ORDER_ID =
"SELECT ruleorder,rulef,id,type,tojid,fromjid,disabled,log,description,sourcetype,desttype from pfRules where ruleorder=? order by ruleorder DESC";
private static final String GET_LAST_ORDERID =
"SELECT ruleorder from pfRules order by ruleorder DESC";
private static final DbRuleManager DB_RULE_MANAGER = new DbRuleManager();
private List<Rule> rules = new CopyOnWriteArrayList<Rule>();
private DbRuleManager() {
rules = getRules();
}
public static DbRuleManager getInstance() {
return DB_RULE_MANAGER;
}
public List<Rule> getRules() {
if (rules.isEmpty()) {
synchronized (rules) {
if (rules.isEmpty()) {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_RULES);
rs = pstmt.executeQuery();
while (rs.next()) {
Rule rule = null;
String ruleType = rs.getString(1);
if (ruleType.equals(Reject.class.getName()))
rule = new Reject();
else if (ruleType.equals(Pass.class.getName()))
rule = new Pass();
else if (ruleType.equals(Drop.class.getName()))
rule = new Drop();
else if (ruleType.equals(Redirect.class.getName()))
rule = new Redirect();
rule.setRuleId(rs.getString(2));
rule.setPacketType(Rule.PacketType.valueOf(rs.getString(3)));
rule.setDestination(rs.getString(4));
rule.setSource(rs.getString(5));
rule.isDisabled(rs.getBoolean(6));
rule.doLog(rs.getBoolean(7));
rule.setDescription(rs.getString(8));
rule.setOrder(rs.getInt(9));
rule.setSourceType(rs.getString(10));
rule.setDestType(rs.getString(11));
rules.add(rule);
}
} catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
}
}
return rules;
}
private void getSavedOptions() {
if (rules != null) {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
for (Rule rule : rules) {
Log.info("getting options for rule " + rule.getRuleId());
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(RULE_OPTIONS);
pstmt.setInt(1, Integer.parseInt(rule.getRuleId()));
rs = pstmt.executeQuery();
List<RuleOption> savedOptions = new ArrayList<RuleOption>();
while (rs.next()) {
RuleOption option = new RuleOption();
option.setName(rs.getString(1));
Log.info("Name " + option.getName());
option.setValue(rs.getString(2));
option.setRequired(rs.getBoolean(3));
option.setType(rs.getString(4));
savedOptions.add(option);
}
//rule.setSavedOptions(savedOptions);
pstmt.close();
rs.close();
}
} catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
}
public int getLastOrderId() {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = -1;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_LAST_ORDERID);
rs = pstmt.executeQuery();
rs.next();
count = rs.getInt(1);
} catch (SQLException sqle) {
Log.error(sqle);
//If error dataset is probably empty
return 0;
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return count;
}
public int getCount() {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = -1;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(COUNT);
rs = pstmt.executeQuery();
rs.next();
count = rs.getInt(1);
} catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return count;
}
public boolean addRule(Rule rule) {
return addRule(rule, null);
}
public boolean addRule(Rule rule, Integer order) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(INSERT_RULE);
if (order == null) {
order = getLastOrderId() + 1;
pstmt.setInt(1, order);
} else {
pstmt.setInt(1, order);
}
rule.setOrder(order);
pstmt.setString(2, rule.getPackeType().toString());
if (rule.getDestination().contains(" ")) {
rule.setDestination(rule.getDestination().replace(" ", ""));
}
pstmt.setString(3, rule.getDestination());
if (rule.getSource().contains(" ")) {
rule.setSource(rule.getSource().replace(" ", ""));
}
pstmt.setString(4, rule.getSource());
pstmt.setString(5, rule.getClass().getName());
if (rule.isDisabled()) {
pstmt.setByte(6, new Byte("1"));
}
else {
pstmt.setByte(6, new Byte("0"));
}
if (rule.doLog()) {
pstmt.setByte(7, new Byte("1"));
}
else {
pstmt.setByte(7, new Byte("0"));
}
pstmt.setString(8, rule.getDescription());
pstmt.setString(9, rule.getSourceType());
pstmt.setString(10, rule.getDestType());
pstmt.execute();
rules.clear();
} catch (SQLException sqle) {
Log.error(sqle);
return false;
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
updateCluster();
}
return true;
}
public boolean deleteRule(String ruleId) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(DELETE_RULE);
pstmt.setString(1, ruleId);
pstmt.execute();
rules.remove(getRuleById(new Integer(ruleId)));
} catch (SQLException sqle) {
Log.error(sqle);
return false;
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
updateCluster();
}
return true;
}
public void moveRuleOrder(int ruleId, int order) {
Rule rule = getRuleById(ruleId);
//See if there is a gap that we can just update the rule with
Rule orderIWant = getRuleByOrderId(order);
if (orderIWant == null) {
updateRule(rule, order);
}
//No gap. Move all rules >= to the order.
else {
List<Rule> rules = getRules();
for (int i = rules.size(); i > 0; i--) {
Rule moveRule = rules.get(i);
if (new Integer(moveRule.getOrder()) >= order) {
updateRule(moveRule, order + 1);
} else break;
}
updateRule(rule, order);
}
}
public Rule getRuleByOrderId(int order) {
Rule rule = null;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_RULE_BY_ORDER_ID);
pstmt.setInt(1, order);
rs = pstmt.executeQuery();
while (rs.next()) {
rule.setOrder(rs.getInt(1));
String ruleType = rs.getString(2);
if (ruleType.equals(Reject.class.getName())) {
rule = new Reject();
}
else if (ruleType.equals(Pass.class.getName())) {
rule = new Pass();
}
else if (ruleType.equals(Drop.class.getName())) {
rule = new Drop();
}
rule.setRuleId(rs.getString(3));
rule.setPacketType(Rule.PacketType.valueOf(rs.getString(4)));
rule.setDestination(rs.getString(5));
rule.setSource(rs.getString(6));
rule.isDisabled(rs.getBoolean(7));
rule.doLog(rs.getBoolean(8));
rule.setDescription(rs.getString(9));
rule.setSourceType(rs.getString(10));
rule.setDestType(rs.getString(11));
}
} catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return rule;
}
public Rule getRuleById(int id) {
Rule rule = null;
String ruleId = Integer.toString(id);
for (Rule cRule : rules) {
if (cRule.getRuleId().equals(ruleId)) {
rule = cRule;
break;
}
}
return rule;
}
public boolean updateRule(Rule rule) {
return updateRule(rule, rule.getOrder());
}
public boolean updateRule(Rule rule, Integer order) {
//SET type=?,tojid=?,fromjid=?,rulef=?,disabled=?,log=?,description=?,ruleorder=?,sourcetype=?,desttype=? WHERE id=?";
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(UPDATE_RULE);
pstmt.setString(1, rule.getPackeType().toString());
pstmt.setString(2, rule.getDestination());
pstmt.setString(3, rule.getSource());
pstmt.setString(4, rule.getClass().getName());
if (rule.isDisabled())
pstmt.setByte(5, new Byte("1"));
else
pstmt.setByte(5, new Byte("0"));
if (rule.doLog())
pstmt.setByte(6, new Byte("1"));
else
pstmt.setByte(6, new Byte("0"));
pstmt.setString(7, rule.getDescription());
pstmt.setInt(8, order);
pstmt.setString(9, rule.getSourceType());
pstmt.setString(10, rule.getDestType());
pstmt.setInt(11, new Integer(rule.getRuleId()));
pstmt.executeUpdate();
rules.clear();
} catch (SQLException sqle) {
Log.error(sqle);
return false;
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
updateCluster();
}
return true;
}
/*
Moving a rule one up or down so we can just swap
*/
public boolean moveOne(Rule src, Rule dest) {
int srcOrder = src.getOrder();
int destOrder = dest.getOrder();
dest.setOrder(srcOrder);
src.setOrder(destOrder);
updateRule(src);
updateRule(dest);
return true;
}
private void updateCluster() {
boolean isClustered = ClusterManager.isClusteringEnabled();
if (isClustered) {
RulesUpdatedEvent request = new RulesUpdatedEvent();
CacheFactory.doClusterTask(request);
}
}
public void clear() {
if (!rules.isEmpty()) {
rules.clear();
}
}
}
package org.jivesoftware.openfire.plugin.rules;
import org.xmpp.packet.Packet;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
public class Drop extends AbstractRule implements Rule {
public String getDisplayName() {
return "Drop";
}
public Packet doAction(Packet packet) throws PacketRejectedException {
if (doLog()) {
Log.info("Dropping from "+packet.getFrom()+" to "+packet.getTo());
}
throw new PacketRejectedException();
}
}
package org.jivesoftware.openfire.plugin.rules;
import org.xmpp.packet.Packet;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.util.Log;
public class Pass extends AbstractRule implements Rule {
public String getDisplayName() {
return "Pass";
}
public Packet doAction(Packet packet) throws PacketRejectedException {
if (doLog()) {
Log.info("Passing from "+packet.getFrom()+" to "+packet.getTo());
}
return null;
}
}
package org.jivesoftware.openfire.plugin.rules;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.PacketFilterUtil;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import java.util.Collection;
public class Redirect extends AbstractRule implements Rule {
public String getDisplayName() {
return "Redirect";
}
public Packet doAction(Packet packet) throws PacketRejectedException {
Message newPacket = null;
if (packet instanceof Message) {
if (getDestType().equals(Rule.SourceDestType.Group.toString())) {
Group sendGroup = PacketFilterUtil.getGroup(getDestination());
ClientSession clientSession;
for (JID jid : sendGroup.getMembers()) {
newPacket = (Message) packet.createCopy();
newPacket.setTo(jid);
sendPacket(newPacket);
}
}
else {
JID jid = new JID(getDestination());
newPacket = (Message) packet.createCopy();
newPacket.setFrom("test@machintosh.local");
newPacket.setTo(jid);
sendPacket(newPacket);
}
if (doLog()) {
Log.info("Redirecting from "+packet.getFrom()+" to "+packet.getTo());
}
}
throw new PacketRejectedException();
}
public boolean destMustMatch() {
return false;
}
private static void sendPacket(Packet packet) {
SessionManager sessionManager = XMPPServer.getInstance().getSessionManager();
ClientSession clientSession;
clientSession = sessionManager.getSession(packet.getTo());
Log.info("Sending to "+packet.getTo());
if (clientSession != null) {
Log.info("***** Session Not Null ******");
clientSession.process(packet);
}
}
}
package org.jivesoftware.openfire.plugin.rules;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.xmpp.packet.*;
import java.util.ArrayList;
import java.util.List;
public class Reject extends AbstractRule implements Rule {
public String getDisplayName() {
return "Reject";
}
public Packet doAction(Packet packet) throws PacketRejectedException {
SessionManager sessionManager = SessionManager.getInstance();
ClientSession clientSession = sessionManager.getSession(packet.getFrom());
Packet rejectPacket;
String pfFrom = JiveGlobals.getProperty("pf.From", "packetfilter");
if (packet instanceof Message) {
Message in = (Message) packet.createCopy();
if (clientSession != null && in.getBody() != null) {
in.setFrom(new JID(pfFrom));
String rejectMessage = JiveGlobals.getProperty("pf.rejectMessage", "Your message was rejected by the packet filter");
in.setBody(rejectMessage);
in.setType(Message.Type.error);
in.setTo(packet.getFrom());
String rejectSubject = JiveGlobals.getProperty("pf.rejectSubject", "Rejected");
in.setSubject(rejectSubject);
clientSession.process(in);
}
} else if (packet instanceof Presence) {
rejectPacket = new Presence();
rejectPacket.setTo(packet.getFrom());
rejectPacket.setError(PacketError.Condition.forbidden);
} else if (packet instanceof IQ) {
rejectPacket = new IQ();
rejectPacket.setTo(packet.getFrom());
rejectPacket.setError(PacketError.Condition.forbidden);
}
if (doLog()) {
Log.info("Rejecting packet from " + packet.getFrom() + " to " + packet.getTo());
}
throw new PacketRejectedException();
}
}
package org.jivesoftware.openfire.plugin.rules;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.xmpp.packet.Packet;
import java.util.List;
public interface Rule {
enum Action {
Pass,
Drop,
Reject
}
;
enum PacketType {
Message("Message"),
MessageChat("MUC Private Message"),
MessageGroupChat("MUC"),
Presence("Presence"),
Iq("Iq"),
Any("Any");
private String display;
PacketType(String display) {
this.display = display;
}
public String getDisplayName() {
return display;
}
}
;
enum SourceDestType {
Any,
User,
Group,
Component,
Other
}
;
public Action getPacketAction();
public void setPacketAction(Action action);
public PacketType getPackeType();
public void setPacketType(PacketType packetType);
public Boolean isDisabled();
public void isDisabled(Boolean disabled);
public String getSource();
public void setSource(String source);
public String getDestination();
public void setDestination(String destination);
public Boolean doLog();
public void doLog(Boolean log);
public String getDescription();
public void setDescription(String description);
public String getRuleId();
public void setRuleId(String id);
public int getOrder();
public void setOrder(int order);
public String getRuleType();
public String getDisplayName();
public void setDisplayName(String displayName);
public String getSourceType();
public void setSourceType(String sourceType);
public String getDestType();
public void setDestType(String destType);
public Packet doAction(Packet packet) throws PacketRejectedException;
}
package org.jivesoftware.openfire.plugin.rules;
import java.util.List;
public interface RuleManager {
public Rule getRuleById(int id);
public List<Rule> getRules();
public void addRule(Rule rule, Integer order);
public void addRule(Rule rule);
public void deleteRule(String ruleId);
public void moveOne(int srcId, int destId);
public int getLastOrder();
public void moveRuleOrder(int ruleId,int orderId) ;
public void updateRule(Rule rule);
public void rulesUpdated();
}
package org.jivesoftware.openfire.plugin.rules;
import java.util.List;
public class RuleManagerProxy implements RuleManager {
private DbRuleManager dbRuleManager = DbRuleManager.getInstance();
private List<Rule> rules = null;
public RuleManagerProxy() {
// rules = dbRuleManager.getRules();
}
public Rule getRuleById(int id) {
//Pull it from the db
return dbRuleManager.getRuleById(id);
}
public List<Rule> getRules() {
return dbRuleManager.getRules();
}
public void addRule(Rule rule, Integer order) {
/*if (order != null && order.intValue() > 0) {
DbRuleManager.getInstance().addRule(rule,order);
}
rules.add(order.intValue(),rule);
*/
}
public void addRule(Rule rule) {
dbRuleManager.addRule(rule);
//rulesUpdated();
}
public void deleteRule(String ruleId) {
//Remove rule from storage (db)
dbRuleManager.deleteRule(ruleId);
//Recreate array.
/*for (Rule rule : rules) {
if (rule == null) break;
if (rule.getRuleId().equals(ruleId)) {
rules.remove(rule);
}
} */
}
public void moveOne(int srcId, int destId) {
Rule srcRule = dbRuleManager.getRuleById(srcId);
Rule destRule = dbRuleManager.getRuleById(destId);
dbRuleManager.moveOne(srcRule,destRule);
//rulesUpdated();
}
public int getLastOrder() {
//Get the last rule in the "Cache" and return it's order
//if (rules.size() == 0) return 0;
// return rules.get(rules.size()-1).getOrder();
return dbRuleManager.getLastOrderId();
}
public void moveRuleOrder(int ruleId,int orderId) {
dbRuleManager.moveRuleOrder(ruleId,orderId);
// rulesUpdated();
}
public void updateRule(Rule rule) {
dbRuleManager.updateRule(rule);
//rulesUpdated();
}
public void rulesUpdated() {
reloadRules();
}
private void reloadRules() {
dbRuleManager.clear();
}
}
package org.jivesoftware.openfire.plugin.rules;
public class RuleOption {
private String name;
private String type;
private boolean required;
private String value;
public RuleOption() {}
public RuleOption(String name, String type, boolean required, String value) {
this.name = name;
this.value = value;
this.type = type;
this.required = required;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
import org.jivesoftware.openfire.plugin.rules.RuleManager;
import org.jivesoftware.openfire.plugin.rules.Rule;
import java.util.List;
import java.util.ArrayList;
public class MockRuleManager implements RuleManager {
List<Rule> rules = new ArrayList<Rule>();
public Rule getRuleById(int id) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public List<Rule> getRules() {
return rules;
}
public void addRule(Rule rule, Integer order) {
rules.add(order,rule);
}
public void addRule(Rule rule) {
rules.add(rule);
}
public void deleteRule(String ruleId) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void moveOne(int srcId, int destId) {
//To change body of implemented methods use File | Settings | File Templates.
}
public int getLastOrder() {
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
public void moveRuleOrder(int ruleId, int orderId) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void updateRule(Rule rule) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void rulesUpdated() {
//To change body of implemented methods use File | Settings | File Templates.
}
}
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.PacketFilter;
import org.jivesoftware.openfire.plugin.rules.Drop;
import org.jivesoftware.openfire.plugin.rules.Rule;
import org.jivesoftware.openfire.plugin.rules.RuleManager;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
public class PacketFilterTest {
private PacketFilter packetFilter;
private RuleManager rmp;
@BeforeClass
public void setup() {
//Create a packetFilter
packetFilter = PacketFilter.getInstance();
rmp = new MockRuleManager();
packetFilter.setRuleManager(rmp);
}
@Test(groups = {"default"}, expectedExceptions = PacketRejectedException.class)
public void testDropMessage() throws PacketRejectedException {
//Create some rules
Rule drop = new Drop();
drop.setSource("bart@localhost");
drop.setSourceType("User");
drop.setDestination("Any");
drop.setDestType("Any");
drop.isDisabled(false);
drop.setPacketType(Rule.PacketType.Message);
drop.doLog(false);
rmp.addRule(drop);
Message message = new Message();
message.setFrom("bart@localhost");
message.setTo("lisa@localhost");
Rule rule = packetFilter.findMatch(message);
assert (rule != null);
rule.doAction(message);
}
@Test(groups = {"default"}, expectedExceptions = PacketRejectedException.class)
public void testDropIQ() throws PacketRejectedException {
//Create some rules
Rule drop = new Drop();
drop.setSource("bart@localhost");
drop.setSourceType("User");
drop.setDestination("Any");
drop.setDestType("Any");
drop.isDisabled(false);
drop.setPacketType(Rule.PacketType.Iq);
drop.doLog(false);
rmp.addRule(drop);
IQ iq = new IQ();
iq.setFrom("bart@localhost");
iq.setTo("lisa@localhost");
Rule rule = packetFilter.findMatch(iq);
assert (rule != null);
rule.doAction(iq);
}
@Test(groups = {"default"}, expectedExceptions = PacketRejectedException.class)
public void testDropPresence() throws PacketRejectedException {
//Create some rules
Rule drop = new Drop();
drop.setSource("bart@localhost");
drop.setSourceType("User");
drop.setDestination("Any");
drop.setDestType("Any");
drop.isDisabled(false);
drop.setPacketType(Rule.PacketType.Presence);
drop.doLog(false);
rmp.addRule(drop);
Presence presence = new Presence();
presence.setFrom("bart@localhost");
presence.setTo("lisa@localhost");
Rule rule = packetFilter.findMatch(presence);
assert (rule != null);
rule.doAction(presence);
}
@Test(groups = {"default"}, expectedExceptions = PacketRejectedException.class)
public void testDropAnyType() throws PacketRejectedException {
//Create some rules
Rule drop = new Drop();
drop.setSource("bart@localhost");
drop.setSourceType(Rule.SourceDestType.User.toString());
drop.setDestination("Any");
drop.setDestType(Rule.SourceDestType.Any.toString());
drop.isDisabled(false);
drop.setPacketType(Rule.PacketType.Any);
drop.doLog(false);
rmp.addRule(drop);
Presence presence = new Presence();
presence.setFrom("bart@localhost");
presence.setTo("lisa@localhost");
Rule rule = packetFilter.findMatch(presence);
assert (rule != null);
rule.doAction(presence);
}
/*@Test(groups = {"default"}, expectedExceptions = PacketRejectedException.class)
public void testGroupDrop() throws PacketRejectedException {
Group
} */
}
import org.jivesoftware.openfire.plugin.PacketFilterUtil;
import org.xmpp.packet.JID;
public class Test {
public static void main(String... args) {
String jid = JID.escapeNode("test@domain1.com@otherdomain.com");
String allDomain = "*@domain1.com@otherdomain.com";
System.out.println(matchUser(allDomain,jid));
}
public static String getComponent(String jid) {
if (jid.contains("@")) {
int atIndex = jid.indexOf("@");
return (jid.substring(atIndex,jid.length()));
}
else {
return jid;
}
}
public static String getDomain(String jid) {
return getComponent(jid);
}
public static boolean isJID(String jid) {
if (jid != null &&
(jid.split("@").length == 1) &&
jid.length() < 255 &&
jid.trim().length() > 0) {
return true;
} else return false;
}
private static boolean matchUser(String ruleToFrom, String packetToFrom) {
boolean match = false;
packetToFrom = JID.unescapeNode(packetToFrom);
if (ruleToFrom.indexOf("*") == 0 && ruleToFrom.indexOf("@") == 1) {
System.out.println(getDomain(ruleToFrom));
System.out.println(getDomain(packetToFrom));
if (getDomain(ruleToFrom).equals(getDomain(packetToFrom))) {
match = true;
}
}
else {
if (ruleToFrom.equals(packetToFrom)) {
match = true;
}
}
return match;
}
}
<%@ page import="org.jivesoftware.util.*"%>
<%@ page import="org.jivesoftware.openfire.plugin.rules.RuleManagerProxy" %>
<%@ page import="org.jivesoftware.openfire.plugin.rules.Rule" %>
<%@ page import="org.jivesoftware.openfire.plugin.rules.RuleManager" %>
<%@ 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="webManager" class="org.jivesoftware.util.WebManager" />
<% webManager.init(request, response, session, application, out ); %>
<% // Get parameters //
boolean cancel = request.getParameter("cancel") != null;
boolean delete = request.getParameter("delete") != null;
String ruleId = ParamUtils.getParameter(request, "ruleId");
RuleManager rm = new RuleManagerProxy();
Rule rule = rm.getRuleById(new Integer(ruleId));
// Handle a cancel
if (cancel) {
response.sendRedirect("pf-main.jsp");
return;
}
if (delete) {
rm.deleteRule(ruleId);
response.sendRedirect("pf-main.jsp");
}
%>
<html>
<head>
<title><fmt:message key="pf.delete.title"/></title>
<meta name="pageID" content="packetFilter"/>
</head>
<body>
You have choosen to delete the rule form <%=rule.getSource()%> to <%=rule.getDestination()%>. Are you sure?
<br>
<br>
<form action="delete-rule.jsp">
<input type="hidden" name="ruleId" value="<%=ruleId%>">
<input type="submit" name="delete" value="<fmt:message key="pf.delete.delete" />">
<input type="submit" name="cancel" value="<fmt:message key="pf.global.cancel" />">
</form>
</body>
</html>
<%@ page import="org.jivesoftware.openfire.component.InternalComponentManager,
org.jivesoftware.openfire.plugin.component.ComponentList,
org.jivesoftware.openfire.plugin.rules.Rule,
org.jivesoftware.openfire.plugin.rules.RuleManager"
%>
<%@ page import="org.jivesoftware.openfire.plugin.rules.RuleManagerProxy" %>
<%@ page import="org.xmpp.packet.JID" %>
<%@ page import="java.util.List" %>
<%@ 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="webManager" class="org.jivesoftware.util.WebManager"/>
<%
webManager.init(request, response, session, application, out);
RuleManager rm = new RuleManagerProxy();
ComponentList componentManager = ComponentList.getInstance();
int i = 0;
boolean moveOne = request.getParameter("moveOne") != null;
if (moveOne) {
int destId = new Integer(request.getParameter("moveOne")).intValue();
int srcId = new Integer(request.getParameter("ruleId")).intValue();
rm.moveOne(srcId, destId);
response.sendRedirect("pf-main.jsp");
}
List<Rule> rules = rm.getRules();
int lastOrder = rm.getLastOrder();
%>
<html>
<head>
<style type="text/css">
<!--
@import url( "style/packetfilter.css" );
-->
</style>
<title>
<fmt:message key="pf.summary.title"/>
</title>
<meta name="pageID" content="packetFilter"/>
<meta name="helpPage" content=""/>
<script language="JavaScript" type="text/javascript" src="scripts/packetfilter.js"></script>
</head>
<body>
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th nowrap>Rule Type</th>
<th nowrap>From</th>
<th nowrap>To</th>
<th nowrap>Packet Type</th>
<th nowrap>Log</th>
<th>&nbsp</th>
</tr>
</thead>
<tbody>
<%
for (Rule rule : rules) {
%>
<tr class="jive-<%= (((i%2)==0) ? "even" : "odd") %>">
<% if (rule.isDisabled()) { %>
<td><strike><%=rule.getDisplayName()%></strike></td>
<%} else {%>
<td><%=rule.getDisplayName()%></td>
<%}%>
<% if (rule.isDisabled()) { %>
<td><strike><%=rule.getSource()%></strike></td>
<%} else if (rule.getSourceType().equals(Rule.SourceDestType.Component.toString())
&& componentManager.getComponentName(new JID(rule.getSource()))!= null) { %>
<td><%=componentManager.getComponentName(new JID(rule.getSource()))%></td>
<% } else {%>
<td><%=rule.getSource()%></td>
<%}%>
<% if (rule.isDisabled()) { %>
<td><strike><%=rule.getDestination()%></strike></td>
<%} else if (rule.getDestType().equals(Rule.SourceDestType.Component.toString())
&& componentManager.getComponentName(new JID(rule.getDestination()))!= null) {%>
<td><%=componentManager.getComponentName(new JID(rule.getDestination()))%></td>
<% }else {%>
<td><%=rule.getDestination()%></td>
<%}%>
<% if (rule.isDisabled()) { %>
<td><strike><%=rule.getPackeType()%></strike></td>
<%} else {%>
<td><%=rule.getPackeType().getDisplayName()%></td>
<%}%>
<% if (rule.isDisabled()) { %>
<td><strike><%=rule.doLog()%></strike></td>
<%} else {%>
<td><%=rule.doLog()%></td>
<%}%>
<td><a href="delete-rule.jsp?ruleId=<%=rule.getRuleId()%>"><img src="/images/delete-16x16.gif"
width="16" height="16"
border="0"
alt="<fmt:message key="global.click_delete" />"></a>
<!--<a href="rule-form.jsp?beforeId=<%=rule.getRuleId()%>">Before</a>
<a href="rule-form.jsp?afterId=<%=rule.getRuleId()%>">After</a>-->
<%if (rule.getOrder() > 1 && i>0) {%>
<a href="pf-main.jsp?moveOne=<%=rules.get(i-1).getRuleId()%>&ruleId=<%=rule.getRuleId()%>"><img src="arrow_up.png" width="16" height="16" border="0" alt="<fmt:message key="pf.click.up"/>"></a>
<%}%>
<%if (rule.getOrder() != lastOrder) {%>
<a href="pf-main.jsp?moveOne=<%=rules.get(i+1).getRuleId()%>&ruleId=<%=rule.getRuleId()%>"><img src="arrow_down.png" width="16" height="16" border="0" alt="<fmt:message key="pf.click.down"/>"></a>
<%}%>
<a href="rule-edit-form.jsp?edit=<%=rule.getRuleId()%>"><img src="/images/edit-16x16.gif" width="16" height="16" border="0" alt="<fmt:message key="pf.click.edit"/>"></a>
</td>
</tr>
<%
i++;
} %>
</tbody>
</table>
</div>
<input type="button" ONCLICK="window.location.href='rule-form.jsp'" name="create" value="<fmt:message key="pf.create.new.rule"/>">
</body>
</html>
<%@ page import="org.jivesoftware.openfire.XMPPServer,
org.jivesoftware.openfire.component.InternalComponentManager,
org.jivesoftware.openfire.group.Group,
org.jivesoftware.openfire.plugin.component.ComponentList"
%>
<%@ page import="org.jivesoftware.openfire.plugin.rules.*" %>
<%@ page import="org.jivesoftware.openfire.user.UserManager" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.xmpp.component.Component" %>
<%@ page import="org.xmpp.packet.JID" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ 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="webManager" class="org.jivesoftware.util.WebManager"/>
<%
webManager.init(request, response, session, application, out);
Collection<Group> groups = webManager.getGroupManager().getGroups();
ComponentList cList = ComponentList.getInstance();
Collection<String> components = cList.getComponentDomains();
RuleManager rm = new RuleManagerProxy();
Rule rule = null;
//Get Action
boolean editSave = request.getParameter("editSave") != null;
boolean edit = request.getParameter("edit") != null;
boolean cancel = request.getParameter("cancel") != null;
boolean isDestOther = false;
boolean isDestGroup = false;
boolean isDestUser = false;
boolean isDestAny = false;
boolean isDestComponent = false;
boolean isSourceOther = false;
boolean isSourceGroup = false;
boolean isSourceUser = false;
boolean isSourceAny = false;
boolean isSourceComponent = false;
//Get data
String packetAction = ParamUtils.getParameter(request, "packetAction");
String disable = ParamUtils.getParameter(request, "disable");
String packetType = ParamUtils.getParameter(request, "packetType");
String source = ParamUtils.getParameter(request, "source");
String destination = ParamUtils.getParameter(request, "destination");
String log = ParamUtils.getParameter(request, "log");
String description = ParamUtils.getParameter(request, "description");
String order = ParamUtils.getParameter(request, "order");
Collection<String> userList = UserManager.getInstance().getUsernames();
String serverName = XMPPServer.getInstance().getServerInfo().getName();
Map<String, String> errors = new HashMap<String, String>();
String sourceJID = "";
String destJID = "";
if (cancel) {
response.sendRedirect("pf-main.jsp");
return;
}
if (edit) {
rule = rm.getRuleById(new Integer(request.getParameter("edit")));
disable = rule.isDisabled().toString();
packetType = rule.getPackeType().toString();
source = rule.getSource();
destination = rule.getDestination();
log = rule.doLog().toString();
description = rule.getDescription();
String destType = rule.getDestType();
String sourceType = rule.getSourceType();
destJID = destination;
sourceJID = source;
if (destType.equals(Rule.SourceDestType.Any.toString())) {
isDestAny = true;
} else if (destType.equals(Rule.SourceDestType.Group.toString())) {
isDestGroup = true;
} else if (destType.equals(Rule.SourceDestType.Component.toString())) {
isDestComponent = true;
} else if (destType.equals(Rule.SourceDestType.User.toString())) {
isDestUser = true;
} else if (destType.equals(Rule.SourceDestType.Other.toString())) {
isDestOther = true;
}
if (sourceType.equals(Rule.SourceDestType.Any.toString())) {
isSourceAny = true;
} else if (sourceType.equals(Rule.SourceDestType.Group.toString())) {
isSourceGroup = true;
} else if (sourceType.equals(Rule.SourceDestType.Component.toString())) {
isSourceComponent = true;
} else if (sourceType.equals(Rule.SourceDestType.User.toString())) {
isSourceUser = true;
} else if (sourceType.equals(Rule.SourceDestType.Other.toString())) {
isSourceOther = true;
}
}
if (editSave) {
//Destination simple case any
if (destination.equals(Rule.SourceDestType.Any.toString())) isDestAny = true;
else if (destination.equals(Rule.SourceDestType.Group.toString())) isDestGroup = true;
else if (destination.equals(Rule.SourceDestType.User.toString())) isDestUser = true;
else if (destination.equals(Rule.SourceDestType.Other.toString())) isDestOther = true;
else if (destination.equals(Rule.SourceDestType.Component.toString())) isDestComponent = true;
//Do the same thing as above for source. I'm repeating myself a little but
//it will make things much easier to read.
if (source.equals(Rule.SourceDestType.Any.toString())) isSourceAny = true;
else if (source.equals(Rule.SourceDestType.Group.toString())) isSourceGroup = true;
else if (source.equals(Rule.SourceDestType.User.toString())) isSourceUser = true;
else if (source.equals(Rule.SourceDestType.Other.toString())) isSourceOther = true;
else if (source.equals(Rule.SourceDestType.Component.toString())) isSourceComponent = true;
if (packetAction.equals("Pass")) {
rule = new Pass();
} else if (packetAction.equals("Reject")) {
rule = new Reject();
} else if (packetAction.equals("Drop")) {
rule = new Drop();
}
if (rule != null) {
rule.setDescription(description);
rule.setPacketType(Rule.PacketType.valueOf(packetType));
if (source.equals(Rule.SourceDestType.Any.toString())) {
rule.setSource(source);
rule.setSourceType(Rule.SourceDestType.Any.toString());
} else if (source.equals(Rule.SourceDestType.Other.toString())) {
sourceJID = ParamUtils.getParameter(request, "sourceOtherJID");
if (sourceJID == null || !(sourceJID.length() > 0)) {
sourceJID = "";
errors.put("sourceOther", "");
}
rule.setSource(sourceJID);
rule.setSourceType(Rule.SourceDestType.Other.toString());
} else if (source.equals(Rule.SourceDestType.User.toString())) {
sourceJID = ParamUtils.getParameter(request, "sourceUserJID");
rule.setSource(sourceJID);
rule.setSourceType(Rule.SourceDestType.User.toString());
} else if (source.equals(Rule.SourceDestType.Group.toString())) {
sourceJID = ParamUtils.getParameter(request, "sourceGroupJID");
rule.setSource(sourceJID);
rule.setSourceType(Rule.SourceDestType.Group.toString());
} else if (source.equals(Rule.SourceDestType.Component.toString())) {
sourceJID = ParamUtils.getParameter(request, "sourceComponentJID");
rule.setSource(sourceJID);
rule.setSourceType(Rule.SourceDestType.Component.toString());
}
if (destination.equals(Rule.SourceDestType.Any.toString())) {
rule.setDestination(destination);
rule.setDestType(Rule.SourceDestType.Any.toString());
} else if (destination.equals(Rule.SourceDestType.Other.toString())) {
destJID = ParamUtils.getParameter(request, "destOtherJID");
if (destJID == null || !(sourceJID.length() > 0)) {
destJID = "";
errors.put("destOther", "");
}
rule.setDestination(destJID);
rule.setDestType(Rule.SourceDestType.Other.toString());
} else if (destination.equals(Rule.SourceDestType.User.toString())) {
destJID = ParamUtils.getParameter(request, "destUserJID");
rule.setDestination(destJID);
rule.setDestType(Rule.SourceDestType.User.toString());
} else if (destination.equals(Rule.SourceDestType.Group.toString())) {
destJID = ParamUtils.getParameter(request, "destGroupJID");
rule.setDestination(destJID);
rule.setDestType(Rule.SourceDestType.Group.toString());
} else if (destination.equals(Rule.SourceDestType.Component.toString())) {
destJID = ParamUtils.getParameter(request, "destComponentJID");
rule.setDestination(destJID);
rule.setDestType(Rule.SourceDestType.Component.toString());
}
rule.doLog(new Boolean(log).booleanValue());
rule.isDisabled(new Boolean(disable).booleanValue());
rule.setRuleId(request.getParameter("ruleId"));
rule.setOrder(new Integer(order));
if (errors.isEmpty()) {
rule.setSource(rule.getSource().toLowerCase());
rule.setDestination(rule.getDestination().toLowerCase());
rm.updateRule(rule);
response.sendRedirect("pf-main.jsp");
}
}
}
%>
<html>
<head>
<title>
<fmt:message key="pf.save.edit"/>
</title>
<meta name="pageID" content="packetFilter"/>
<script language="JavaScript" type="text/javascript" src="scripts/packetfilter.js"></script>
</head>
<body>
<% if (!errors.isEmpty()) { %>
<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">
<% if (errors.get("sourceOther") != null) { %>
<fmt:message key="pf.error.sourceOther"/>
<% } else if (errors.get("destOther") != null) { %>
<fmt:message key="pf.error.destOther"/>
<% } %>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<% } %>
<form action="rule-edit-form.jsp?editSave" method="get">
<input type="hidden" name="ruleId" value="<%=rule.getRuleId()%>">
<input type="hidden" name="order" value="<%=rule.getOrder()%>">
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tbody>
<tr class="jive-even">
<td>Action</td>
<td>
<select label="packetAction" name="packetAction">
<% Rule.Action[] actions = Rule.Action.values();
for (int i = 0; i < actions.length; i++) {
String action = actions[i].toString();
%>
<option value="<%=action%>" <%if ((packetAction != null && packetAction.equals(action))||rule.getDisplayName().equals(action) ) {%>
selected<%}%>
>
<%=action%>
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-odd">
<td>Disable</td>
<td><input type="checkbox" name="disable" value="true"
<%if (rule.isDisabled()) {%>
checked
<%}%>
></td>
</tr>
<tr class="jive-even">
<td>Packet Type</td>
<td>
<select label="packetType" name="packetType">
<%
Rule.PacketType[] packetTypes = Rule.PacketType.values();
for (int i = 0; i < packetTypes.length; i++) {
%>
<option value="<%=packetTypes[i].toString()%>"
<%if (packetType != null && packetType.equals(packetTypes[i].toString())) {%>
selected <%}%>
>
<%=packetTypes[i].getDisplayName()%>
</option>
<% } %>
</select>
</td>
</tr>
<tr class="jive-odd">
<td>From</td>
<td>
<select id="source" name="source" onChange="ShowSourceField('source')">
<option value="Any" <%if (isSourceAny) {%> selected <%}%>>Any</option>
<option value="User" <%if (isSourceUser) {%> selected <%}%>>User</option>
<option value="Group" <%if (isSourceGroup) {%> selected <%}%>>Group</option>
<option value="Other" <%if (isSourceOther) {%> selected <%}%>>Other</option>
<option value="Component" <%if (isSourceComponent) {%> selected <%}%>>Component</option>
</select>
</td>
</tr>
<tr class="jive-odd" name="SourceOther" id="SourceOther" <%if (!isSourceOther) {%> style="display:none;"<%}%>>
<td>
Other JID
</td>
<td>
<input type="text" name="sourceOtherJID" id="sourceOtherJID" <%if (isSourceOther) {%>
value="<%=sourceJID%>"<%}%>></input>
</td>
</tr>
<tr class="jive-odd" name="SourceGroup" id="SourceGroup" <% if (!isSourceGroup) {%> style="display:none;"<%}%>>
<td>
Source Group
</td>
<td>
<select id="sourceGroupJID" name="sourceGroupJID">
<% for (Group group : groups) {%>
<option value="<%=group.getName()%>"
<%if (isSourceGroup && source.equals(group.getName())) {%> selected<%}%>
><%=group.getName()%>
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-odd" name="SourceUser" id="SourceUser" <% if (!isSourceUser) {%> style="display:none;"<%}%>>
<td>
Source User
</td>
<td>
<select id="sourceUserJID" name="sourceUserJID">
<% for (String userName : userList) {%>
<option value="<%=userName+"@"+serverName%>"
<% if (isSourceUser && source.equals(userName + "@" + serverName)) {%>
selected
<%}%>
><%=userName + "@" + serverName%>
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-odd" name="SourceComponent" id="SourceComponent" <%if (!isSourceComponent) {%>
style="display:none;"<%}%>
>
<td>
Component
</td>
<td>
<select id="sourceComponentJID" name="sourceComponentJID">
<% for (String component : components) {
if (component != null && cList.getComponentName(component) != null) {%>
<option value="<%=component%>"
<%if (sourceJID != null && sourceJID.equals(component)) {%>
selected<%}%>>
<%=cList.getComponentName(component)%>
</option>
<% }
}%>
</select>
</td>
</tr>
<tr class="jive-even">
<td>To</td>
<td>
<select name="destination" id="destination" onChange="ShowDestinationField('destination')">
<option value="Any" <%if (isDestAny) {%> selected <%}%>>Any</option>
<option value="User" <%if (isDestUser) {%> selected <%}%>>User</option>
<option value="Group" <%if (isDestGroup) {%> selected <%}%>>Group</option>
<option value="Other" <%if (isDestOther) {%> selected <%}%>>Other</option>
<option value="Component" <% if (isDestComponent) { %> selected <%}%>>Component</option>
</select>
</td>
</tr>
<tr class="jive-even" name="DestOther" id="DestOther" <%if (!isDestOther) {%> style="display:none;"<%}%>>
<td>
Other JID
</td>
<td>
<input type="text" name="destOtherJID" id="destOtherJID"
<% if (isDestOther) {%> value="<%=destJID%>"<%}%>
></input>
</td>
</tr>
<tr class="jive-odd" name="DestGroup" id="DestGroup" <%if (!isDestGroup) {%> style="display:none;"<%}%>>
<td>
Destination Group
</td>
<td>
<select id="destGroupJID" name="destGroupJID">
<% for (Group group : groups) {%>
<option value="<%=group.getName()%>"
<%if (isDestGroup && destination.equals(group.getName())) {%> selected<%}%>
><%=group.getName()%>
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-odd" name="DestUser" id="DestUser" <%if (!isDestUser) {%> style="display:none;"<%}%>>
<td>
Destination User
</td>
<td>
<select id="destUserJID" name="destUserJID">
<% for (String userName : userList) {%>
<option value="<%=userName+"@"+serverName%>"
<% if (isDestUser && destination.equals(userName + "@" + serverName)) {%>
selected
<%}%>
><%=userName + "@" + serverName%>
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-even" name="DestComponent" id="DestComponent" <%if (!isDestComponent) {%>
style="display:none;"<%}%>
>
<td>
Component
</td>
<td>
<select id="destComponentJID" name="destComponentJID">
<% for (String component : components) {
if (component != null && cList.getComponentName(component) != null) {%>
<option value="<%=component%>"
<%if (destJID != null && destJID.equals(component)) {%>
selected<%}%>>
<%=cList.getComponentName(component)%>
</option>
<% }
}%>
</select>
</td>
</tr>
<tr class="jive-odd">
<td>Log</td>
<td><input type="checkbox" name="log" value="true"
<%if(rule.doLog()) {%> checked<%}%>></td>
</tr>
<tr class="jive-even">
<td>Description</td>
<td><input type="text" size="40" name="description"
<%if (rule.getDescription() != null) {%>
value="<%=rule.getDescription()%>"
<%}%>
></input></td>
</tr>
<tr>
<td>
<input type="submit" name="editSave" value="<fmt:message key="pf.save.edit" />">
<input type="submit" name="cancel" value="<fmt:message key="pf.global.cancel" />">
</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</div>
</form>
</body>
</html>
<%@ page import="org.jivesoftware.openfire.XMPPServer,
org.jivesoftware.openfire.group.Group"
%>
<%@ page import="org.jivesoftware.openfire.plugin.component.ComponentList" %>
<%@ page import="org.jivesoftware.openfire.plugin.rules.*" %>
<%@ page import="org.jivesoftware.openfire.user.UserManager" %>
<%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.xmpp.component.Component" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="org.jivesoftware.openfire.RoutingTable" %>
<%@ 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="webManager" class="org.jivesoftware.util.WebManager"/>
<%
webManager.init(request, response, session, application, out);
Collection<Group> groups = webManager.getGroupManager().getGroups();
ComponentList cList = ComponentList.getInstance();
RuleManager rm = new RuleManagerProxy();
Rule rule = null;
//Get Action
boolean create = request.getParameter("create") != null;
boolean cancel = request.getParameter("cancel") != null;
//Get data
String packetAction = ParamUtils.getParameter(request, "packetAction");
String disable = ParamUtils.getParameter(request, "disable");
String packetType = ParamUtils.getParameter(request, "packetType");
String source = ParamUtils.getParameter(request, "source");
String destination = ParamUtils.getParameter(request, "destination");
String log = ParamUtils.getParameter(request, "log");
String description = ParamUtils.getParameter(request, "description");
String order = ParamUtils.getParameter(request, "order");
Rule.SourceDestType[] type = Rule.SourceDestType.values();
Collection<String> userList = UserManager.getInstance().getUsernames();
String serverName = XMPPServer.getInstance().getServerInfo().getName();
Collection<String> components = cList.getComponentDomains();
Map<String, String> errors = new HashMap<String, String>();
String sourceJID = "";
String destJID = "";
if (cancel) {
response.sendRedirect("pf-main.jsp");
return;
}
if (create) {
if (packetAction.equals("Pass")) {
rule = new Pass();
} else if (packetAction.equals("Reject")) {
rule = new Reject();
} else if (packetAction.equals("Drop")) {
rule = new Drop();
}
if (rule != null) {
rule.setDescription(description);
rule.setPacketType(Rule.PacketType.valueOf(packetType));
if (source.equals(Rule.SourceDestType.Any.toString())) {
rule.setSource(source);
rule.setSourceType(Rule.SourceDestType.Any.toString());
} else if (source.equals(Rule.SourceDestType.Other.toString())) {
sourceJID = ParamUtils.getParameter(request, "sourceOtherJID");
if (sourceJID == null || !(sourceJID.length() > 0)) {
sourceJID = "";
errors.put("sourceOther", "");
}
rule.setSource(sourceJID);
rule.setSourceType(Rule.SourceDestType.Other.toString());
} else if (source.equals(Rule.SourceDestType.User.toString())) {
sourceJID = ParamUtils.getParameter(request, "sourceUserJID");
rule.setSource(sourceJID);
rule.setSourceType(Rule.SourceDestType.User.toString());
} else if (source.equals(Rule.SourceDestType.Group.toString())) {
sourceJID = ParamUtils.getParameter(request, "sourceGroupJID");
rule.setSource(sourceJID);
rule.setSourceType(Rule.SourceDestType.Group.toString());
} else if (source.equals(Rule.SourceDestType.Component.toString())) {
sourceJID = ParamUtils.getParameter(request, "sourceComponentJID");
rule.setSource(sourceJID);
rule.setSourceType(Rule.SourceDestType.Component.toString());
}
if (destination.equals(Rule.SourceDestType.Any.toString())) {
rule.setDestination(destination);
rule.setDestType(Rule.SourceDestType.Any.toString());
} else if (destination.equals(Rule.SourceDestType.Other.toString())) {
destJID = ParamUtils.getParameter(request, "destOtherJID");
if (destJID == null || !(destJID.length() > 0)) {
destJID = "";
errors.put("destOther", "");
}
rule.setDestination(destJID);
rule.setDestType(Rule.SourceDestType.Other.toString());
} else if (destination.equals(Rule.SourceDestType.User.toString())) {
destJID = ParamUtils.getParameter(request, "destUserJID");
rule.setDestination(destJID);
rule.setDestType(Rule.SourceDestType.User.toString());
} else if (destination.equals(Rule.SourceDestType.Group.toString())) {
destJID = ParamUtils.getParameter(request, "destGroupJID");
rule.setDestination(destJID);
rule.setDestType(Rule.SourceDestType.Group.toString());
} else if (destination.equals(Rule.SourceDestType.Component.toString())) {
destJID = ParamUtils.getParameter(request, "destComponentJID");
rule.setDestination(destJID);
rule.setDestType(Rule.SourceDestType.Component.toString());
}
rule.doLog(new Boolean(log).booleanValue());
rule.isDisabled(new Boolean(disable).booleanValue());
if (errors.size() == 0) {
rule.setSource(rule.getSource().toLowerCase());
rule.setDestination(rule.getDestination().toLowerCase());
rm.addRule(rule);
response.sendRedirect("pf-main.jsp");
}
}
}
%>
<html>
<head>
<title>
<fmt:message key="pf.create.new.rule"/>
</title>
<meta name="pageID" content="packetFilter"/>
<script language="JavaScript" type="text/javascript" src="scripts/packetfilter.js"></script>
</head>
<body>
<% if (!errors.isEmpty()) { %>
<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">
<% if (errors.get("sourceOther") != null) { %>
<fmt:message key="pf.error.sourceOther"/>
<% } else if (errors.get("destOther") != null) { %>
<fmt:message key="pf.error.destOther"/>
<% } %>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<% } %>
<form action="rule-form.jsp" method="get">
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tbody>
<tr class="jive-even">
<td>Action</td>
<td>
<select id="packetAction" name="packetAction" onChange="ShowExtraOptions('packetAction')">
<% Rule.Action[] actions = Rule.Action.values();
for (int i = 0; i < actions.length; i++) {
String action = actions[i].toString();
%>
<option value="<%=action%>" <%if (packetAction != null && packetAction.equals(action)) {%>
selected<%}%>
>
<%=action%>
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-odd">
<td>Disable</td>
<td><input type="checkbox" name="disable" value="true"
<%if (disable != null && disable.equals("true")){%>
checked <%}%>
></td>
</tr>
<tr class="jive-even">
<td>Packet Type</td>
<td>
<select label="packetType" name="packetType">
<%
Rule.PacketType[] packetTypes = Rule.PacketType.values();
for (int i = 0; i < packetTypes.length; i++) {
%>
<option value="<%=packetTypes[i].toString()%>"
<%if (packetType != null && packetType.equals(packetTypes[i].toString())) {%>
selected <%}%>
>
<%=packetTypes[i].getDisplayName()%>
</option>
<% } %>
</select>
</td>
</tr>
<tr class="jive-odd">
<td>From</td>
<td>
<select id="source" name="source" onChange="ShowSourceField('source')">
<%
for (int i = 0; i < type.length; i++) {
String option = type[i].toString();%>
<option value="<%=option%>" <%
if (source != null &&
source.equals(option)) {
%>
selected <%}%>
><%=option%>
</option>
<% } %>
</select>
</td>
</tr>
<tr class="jive-odd" name="SourceOther"
id="SourceOther" <%if (source == null || !source.equals(Rule.SourceDestType.Other.toString())) {%>
style="display:none;"<%}%>
>
<td>
Other JID
</td>
<td>
<input type="text" name="sourceOtherJID" id="sourceOtherJID"
<%if (source != null && source.equals(Rule.SourceDestType.Other.toString())) {%>
value="<%=sourceJID%>"
<%}%>
></input>
</td>
</tr>
<tr class="jive-odd" name="SourceGroup"
id="SourceGroup" <%if (source == null || !source.equals(Rule.SourceDestType.Group.toString())) {%>
style="display:none;"<%}%>
>
<td>
Source Group
</td>
<td>
<select id="sourceGroupJID" name="sourceGroupJID">
<% for (Group group : groups) {%>
<option value="<%=group.getName()%>" <%if (sourceJID != null && sourceJID.equals(group.getName())) {%>
selected<%}%>
><%=group.getName()%>
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-odd" name="SourceUser"
id="SourceUser" <%if (source == null || !source.equals(Rule.SourceDestType.User.toString())) {%>
style="display:none;"><%}%>
<td>
Source User
</td>
<td>
<select id="sourceUserJID" name="sourceUserJID">
<% for (String userName : userList) {%>
<option value="<%=userName+"@"+serverName%>"
<%if (sourceJID != null && sourceJID.equals(userName + "@" + serverName)) {%>
selected<%}%>
><%=userName + "@" + serverName%>
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-odd" name="SourceComponent"
id="SourceComponent" <%if (source == null || !source.equals(Rule.SourceDestType.Component.toString())) {%>
style="display:none;"<%}%>
>
<td>
Component
</td>
<td>
<select id="sourceComponentJID" name="sourceComponentJID">
<% if (components != null && components.size() > 0) {
for (String component : components) {
if (component != null && cList.getComponentName(component) != null) { %>
<option value="<%=component%>"
<%if (sourceJID != null && sourceJID.equals(component)) {%>
selected<%}%>>
<%=cList.getComponentName(component)%>
</option>
<% }
}
}else {%>
<option value="">
None Installed
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-even">
<td>To</td>
<td>
<select name="destination" id="destination" onChange="ShowDestinationField('destination')">
<% for (int i = 0; i < type.length; i++) {
String option = type[i].toString();%>
<option value="<%=option%>" <%
if (destination != null &&
destination.equals(option)) {
%>
selected <%}%>
><%=option%>
</option>
<% } %>
</select>
</td>
</tr>
<tr class="jive-even" name="DestComponent"
id="DestComponent" <%if (destination == null || !destination.equals(Rule.SourceDestType.Component.toString())) {%>
style="display:none;"<%}%>
>
<td>
Component
</td>
<td>
<select id="destComponentJID" name="destComponentJID">
<% if (components != null && components.size() > 0) {
for (String component : components) {
if (component != null && cList.getComponentName(component) != null) { %>
<option value="<%=component%>"
<%if (destJID != null && destJID.equals(component)) {%>
selected<%}%>>
<%=cList.getComponentName(component)%>
</option>
<% }
}
} else {%>
<option value="">
None Installed
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-even" name="DestOther"
id="DestOther" <%if (destination == null || !destination.equals(Rule.SourceDestType.Other.toString())) {%>
style="display:none;"<%}%>
>
<td>
Other JID
</td>
<td>
<input type="text" name="destOtherJID" id="destOtherJID"
<%if (destination != null && destination.equals(Rule.SourceDestType.Other.toString())) {%>
value="<%=destJID%>"
<%}%>
></input>
</td>
</tr>
<tr class="jive-odd" name="DestGroup" id="DestGroup" <%
if (destination == null ||
!destination.equals(Rule.SourceDestType.Group.toString())) {
%>
style="display:none;"<%}%>
>
<td>
Destination Group
</td>
<td>
<select id="destGroupJID" name="destGroupJID">
<% for (Group group : groups) {%>
<option value="<%=group.getName()%>" <%if (destJID != null && destJID.equals(group.getName())) {%>
selected<%}%>
><%=group.getName()%>
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-odd" name="DestUser" id="DestUser" <%
if (destination == null
|| !destination.equals(Rule.SourceDestType.User.toString())) {
%>
style="display:none;"<%}%>>
<td>
Destination User
</td>
<td>
<select id="destUserJID" name="destUserJID">
<% for (String userName : userList) {%>
<option value="<%=userName+"@"+serverName%>" <%if (destJID != null && destJID.equals(userName + "@" + serverName)) {%>
selected<%}%>
><%=userName + "@" + serverName%>
</option>
<%}%>
</select>
</td>
</tr>
<tr class="jive-odd">
<td>Log</td>
<td><input type="checkbox" name="log" value="true"
<% if (log != null && log.equals("true")) {%>
checked <%}%>
></td>
</tr>
<tr class="jive-even">
<td>Description</td>
<td><input type="text" size="40" name="description"
<%if (description != null) {%>
value="<%=description%>"<%}%>
></input></td>
</tr>
<tr>
<td>
<input type="submit" name="create" value="<fmt:message key="pf.create.rule" />">
<input type="submit" name="cancel" value="<fmt:message key="pf.global.cancel" />">
</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
</div>
</form>
</body>
</html>
/* Ajax is hard :( */
function HideField(fieldName) {
$(fieldName).hide();
}
function ShowSourceField(decidingElement) {
if ($(decidingElement).value.toString() == "Other") {
$("SourceOther").show();
}
else {
$("SourceOther").hide();
}
if ($(decidingElement).value.toString() == "Group") {
$("SourceGroup").show();
}
else {
$("SourceGroup").hide();
}
if ($(decidingElement).value.toString() == "User") {
$("SourceUser").show();
}
else {
$("SourceUser").hide();
}
if ($(decidingElement).value.toString() == "Component") {
$("SourceComponent").show();
}
else {
$("SourceComponent").hide();
}
}
function ShowDestinationField(decidingElement) {
if ($(decidingElement).value.toString() == "Other") {
$("DestOther").show();
}
else {
$("DestOther").hide();
}
if ($(decidingElement).value.toString() == "Group") {
$("DestGroup").show();
}
else {
$("DestGroup").hide();
}
if ($(decidingElement).value.toString() == "User") {
$("DestUser").show();
}
else {
$("DestUser").hide();
}
if ($(decidingElement).value.toString() == "Component") {
$("DestComponent").show();
}
else {
$("DestComponent").hide();
}
}
function ShowExtraOptions(decidingElement) {
var value = $(decidingElement).value.toString();
if ($(decidingElement).value.toString() =="Redirect") {
$("RedirectOptions").show();
}
else {
$("RedirectOptions").hide();
}
}
\ No newline at end of file
/* Maybe some css in here someday */
\ No newline at end of file
<script type="text/javascript"
src="/plugins/packetfilter/dwr2/interface/RuleManagerProxy.js"> </script>
<script type="text/javascript"
src="/plugins/packetfilter/dwr2/engine.js"> </script>
<script language="JavaScript" type="text/javascript">
function handleGetData(str) {
alert(str);
}
</script>
<body onload="RuleManagerProxy.getRuleById(4, handleGetData);">
</body>
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