use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class emailOnAway method interceptPacket.
public void interceptPacket(Packet packet, Session session, boolean read, boolean processed) throws PacketRejectedException {
String emailTo = null;
String emailFrom = null;
if ((!processed) && (!read) && (packet instanceof Message) && (packet.getTo() != null)) {
Message msg = (Message) packet;
if (msg.getType() == Message.Type.chat) {
try {
User userTo = userManager.getUser(packet.getTo().getNode());
if (presenceManager.getPresence(userTo).toString().toLowerCase().indexOf("away") != -1) {
// Status isn't away
if (msg.getBody() != null) {
// Build email/sms
// The to email address
emailTo = vcardManager.getVCardProperty(userTo.getUsername(), "EMAIL");
if (emailTo == null || emailTo.length() == 0) {
emailTo = vcardManager.getVCardProperty(userTo.getUsername(), "EMAIL:USERID");
if (emailTo == null || emailTo.length() == 0) {
emailTo = userTo.getEmail();
if (emailTo == null || emailTo.length() == 0) {
emailTo = packet.getTo().getNode() + "@" + packet.getTo().getDomain();
}
}
}
// The From email address
User userFrom = userManager.getUser(packet.getFrom().getNode());
emailFrom = vcardManager.getVCardProperty(userFrom.getUsername(), "EMAIL");
if (emailFrom == null || emailFrom.length() == 0) {
emailFrom = vcardManager.getVCardProperty(userFrom.getUsername(), "EMAIL:USERID");
if (emailFrom == null || emailFrom.length() == 0) {
emailFrom = userFrom.getEmail();
if (emailFrom == null || emailFrom.length() == 0) {
emailFrom = packet.getFrom().getNode() + "@" + packet.getFrom().getDomain();
}
}
}
// System.err.println(vcardManager.getVCardProperty(userTo.getUsername(), "EMAIL:USERID"));
// Send email/sms
// if this is an sms... modify the recipient address
emailService.sendMessage(userTo.getName(), emailTo, userFrom.getName(), emailFrom, "IM", msg.getBody(), null);
// Notify the sender that this went to email/sms
messageRouter.route(createServerMessage(packet.getFrom().getNode() + "@" + packet.getFrom().getDomain(), packet.getTo().getNode() + "@" + packet.getTo().getDomain(), emailTo));
}
}
} catch (UserNotFoundException e) {
}
}
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class FastpathPlugin method workgroupManagerStart.
private void workgroupManagerStart() {
workgroupManager = WorkgroupManager.getInstance();
// Register Fastpath service
try {
ComponentManagerFactory.getComponentManager().addComponent("workgroup", workgroupManager);
} catch (ComponentException e) {
// Do nothing. Should never happen.
Log.error(e.getMessage(), e);
}
// Register the provider of workgroup names
UserNameManager.addUserNameProvider(workgroupManager.getAddress().toString(), new UserNameProvider() {
public String getUserName(JID entity) {
try {
Workgroup workgroup = workgroupManager.getWorkgroup(entity);
return workgroup.getDisplayName();
} catch (UserNotFoundException e) {
return entity.toString();
}
}
});
// Start the Fastpath module
workgroupManager.start();
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class SoundServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String workgroupName = request.getParameter("workgroup");
String action = request.getParameter("action");
Workgroup workgroup = null;
try {
workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
} catch (UserNotFoundException e) {
Log.error(e.getMessage(), e);
}
try {
response.setContentType("audio/wav");
if (action != null) {
if ("incoming".equals(action.trim())) {
String incomingMessage = workgroup.getProperties().getProperty("incomingSound");
byte[] incomingBytes = StringUtils.decodeBase64(incomingMessage);
response.getOutputStream().write(incomingBytes);
} else if ("outgoing".equals(action.trim())) {
String outgoingMessage = workgroup.getProperties().getProperty("outgoingSound");
String outgoingBytes = StringUtils.encodeBase64(outgoingMessage);
response.getOutputStream().write(outgoingBytes.getBytes("UTF-8"));
}
}
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class WorkgroupUtils method toggleStatus.
public static void toggleStatus(String workgroupName) {
final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
Workgroup workgroup;
try {
workgroup = workgroupManager.getWorkgroup(new JID(workgroupName));
} catch (UserNotFoundException e) {
return;
}
Workgroup.Status status = workgroup.getStatus();
if (status == Workgroup.Status.READY) {
workgroup.setStatus(Workgroup.Status.CLOSED);
} else {
workgroup.setStatus(Workgroup.Status.READY);
}
}
use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.
the class IQDiscoInfoHandler method handleIQ.
public IQ handleIQ(IQ packet) {
if (packet.getType() == IQ.Type.result) {
List<Element> features = packet.getChildElement().elements("feature");
// Detect if this item is the MUC service
for (Element feature : features) {
String variable = feature.attributeValue("var");
if ("http://jabber.org/protocol/muc".equals(variable)) {
workgroupManager.setMUCServiceName(packet.getFrom().getDomain());
}
}
return null;
}
// Create a copy of the sent pack that will be used as the reply
// we only need to add the requested info to the reply if any, otherwise add
// a not found error
IQ reply = IQ.createResultIQ(packet);
// Check if the disco#info was sent to the workgroup service itself
if (workgroupManager.getAddress().equals(packet.getTo())) {
Element iq = packet.getChildElement();
String node = iq.attributeValue("node");
reply.setChildElement(iq.createCopy());
Element queryElement = reply.getChildElement();
if (node == null) {
// Create and add a the identity of the workgroup service
Element identity = queryElement.addElement("identity");
identity.addAttribute("category", "collaboration");
// TODO Get the name from a property
identity.addAttribute("name", "Fastpath");
identity.addAttribute("type", "workgroup");
// Create and add a the feature provided by the workgroup service
Element feature = queryElement.addElement("feature");
feature.addAttribute("var", "http://jabber.org/protocol/workgroup");
// Create and add a the disco#info feature
feature = queryElement.addElement("feature");
feature.addAttribute("var", "http://jabber.org/protocol/disco#info");
// Indicate that we can provide information about the software version being used
feature = queryElement.addElement("feature");
feature.addAttribute("var", "jabber:iq:version");
// Indicate that we support ad-hoc commands
feature = queryElement.addElement("feature");
feature.addAttribute("var", "http://jabber.org/protocol/commands");
// Add the features provided by the features providers
for (DiscoFeaturesProvider provider : featuresProviders) {
for (String newFeature : provider.getFeatures()) {
feature = queryElement.addElement("feature");
feature.addAttribute("var", newFeature);
}
}
} else if ("http://jabber.org/protocol/commands".equals(node)) {
// Create and add a the identity of the workgroup service
Element identity = queryElement.addElement("identity");
identity.addAttribute("category", "collaboration");
// TODO Get the name from a property
identity.addAttribute("name", "Fastpath");
identity.addAttribute("type", "workgroup");
// Create and add a the disco#info feature
Element feature = queryElement.addElement("feature");
feature.addAttribute("var", "http://jabber.org/protocol/disco#info");
// Indicate that we support ad-hoc commands
feature = queryElement.addElement("feature");
feature.addAttribute("var", "http://jabber.org/protocol/commands");
} else {
// Check if the node matches a supported command
boolean found = false;
for (AdHocCommand command : commandManager.getCommands()) {
if (node.equals(command.getCode())) {
found = true;
// Only include commands that the sender can invoke (i.e. has enough permissions)
if (command.hasPermission(packet.getFrom())) {
// Create and add a the identity of the command
Element identity = queryElement.addElement("identity");
identity.addAttribute("category", "automation");
identity.addAttribute("name", command.getLabel());
identity.addAttribute("type", "command-node");
// Indicate that we support ad-hoc commands
Element feature = queryElement.addElement("feature");
feature.addAttribute("var", "http://jabber.org/protocol/commands");
} else {
// Return Forbidden error
reply.setError(PacketError.Condition.forbidden);
}
}
}
if (!found) {
// Return item_not_found error
reply.setError(PacketError.Condition.item_not_found);
}
}
} else {
// Check if the disco#info was sent to a given workgroup
try {
Workgroup workgroup = workgroupManager.getWorkgroup(packet.getTo());
Element iq = packet.getChildElement();
reply.setChildElement(iq.createCopy());
Element queryElement = reply.getChildElement();
// Create and add a the identity of the workgroup service
Element identity = queryElement.addElement("identity");
identity.addAttribute("category", "collaboration");
identity.addAttribute("name", workgroup.getJID().getNode());
identity.addAttribute("type", "workgroup");
// Create and add a the disco#info feature
Element feature = queryElement.addElement("feature");
feature.addAttribute("var", "http://jabber.org/protocol/disco#info");
Element form = queryElement.addElement("x", "jabber:x:data");
form.addAttribute("type", "result");
// Add static field
Element field = form.addElement("field");
field.addAttribute("var", "FORM_TYPE");
field.addAttribute("type", "hidden");
field.addElement("value").setText("http://jabber.org/protocol/workgroup#workgroupinfo");
// Add workgroup description
field = form.addElement("field");
field.addAttribute("var", "workgroup#description");
field.addAttribute("label", "Description");
field.addElement("value").setText(workgroup.getDescription() == null ? "" : workgroup.getDescription());
// Add workgroup online status
field = form.addElement("field");
field.addAttribute("var", "workgroup#online");
field.addAttribute("label", "Status");
field.addElement("value").setText(workgroup.getStatus().name());
} catch (UserNotFoundException e) {
// If we didn't find a workgroup then answer a not found error
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.item_not_found);
}
}
return reply;
}
Aggregations