From 6f072ac7a7d80f50d51b57b4a0570da080292af3 Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Thu, 19 Sep 2024 22:21:32 +0200 Subject: [PATCH] Replace API no longer available in Openfire 4.9.0 --- changelog.html | 3 +- plugin.xml | 2 +- src/java/org/ifsoft/mta/MtaManager.java | 14 ++++--- src/java/org/ifsoft/upload/Servlet.java | 12 +++--- .../pushnotification/WebPushInterceptor.java | 2 +- .../openfire/archive/ArchiveSearcher.java | 8 ++-- .../archive/ConversationPDFServlet.java | 24 ++++++------ .../openfire/plugin/ofmeet/LobbyMuc.java | 4 +- .../openfire/plugin/ofmeet/OfMeetPlugin.java | 34 ++++++++--------- .../openfire/plugins/pade/PadePlugin.java | 38 +++++++++---------- 10 files changed, 71 insertions(+), 70 deletions(-) diff --git a/changelog.html b/changelog.html index 366e1f2d..1f1d007a 100644 --- a/changelog.html +++ b/changelog.html @@ -44,8 +44,9 @@

Pade Changelog

-

1.8.3 -- May 31, 2024

+

1.8.3 -- (tbd)

1.8.2 -- April 30, 2024

diff --git a/plugin.xml b/plugin.xml index 03ac7684..ea9751a3 100644 --- a/plugin.xml +++ b/plugin.xml @@ -5,7 +5,7 @@ ${project.description} Ignite Realtime ${project.version} - 04/30/2024 + 2024-09-19 4.8.0 1.11 diff --git a/src/java/org/ifsoft/mta/MtaManager.java b/src/java/org/ifsoft/mta/MtaManager.java index 3e6f3fc4..586dbc3e 100644 --- a/src/java/org/ifsoft/mta/MtaManager.java +++ b/src/java/org/ifsoft/mta/MtaManager.java @@ -1,6 +1,8 @@ package org.ifsoft.mta; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -63,13 +65,13 @@ public final class MtaManager { static { keyStoreLocation = JiveGlobals.getProperty("xmpp.socket.ssl.keystore", "resources" + File.separator + "security" + File.separator + "keystore"); - keyStoreLocation = JiveGlobals.getHomeDirectory() + File.separator + keyStoreLocation; + keyStoreLocation = JiveGlobals.getHomePath().toString() + File.separator + keyStoreLocation; keypass = JiveGlobals.getProperty("xmpp.socket.ssl.keypass", "changeit"); keypass = keypass.trim(); c2sTrustStoreLocation = JiveGlobals.getProperty("xmpp.socket.ssl.client.truststore", "resources" + File.separator + "security" + File.separator + "client.truststore"); - c2sTrustStoreLocation = JiveGlobals.getHomeDirectory() + File.separator + c2sTrustStoreLocation; + c2sTrustStoreLocation = JiveGlobals.getHomePath().toString() + File.separator + c2sTrustStoreLocation; c2sTrustpass = JiveGlobals.getProperty("xmpp.socket.ssl.client.trustpass", "changeit"); c2sTrustpass = c2sTrustpass.trim(); @@ -217,13 +219,13 @@ private String getBindInterface() { */ protected Handler createStaticContentHandler() { - final File mtaDirectory = new File( JiveGlobals.getHomeDirectory() + File.separator + "resources" + File.separator + "mta" ); + final Path mtaDirectory = JiveGlobals.getHomePath().resolve("resources").resolve("mta"); - if ( mtaDirectory.exists() ) + if (Files.exists(mtaDirectory) ) { - if ( mtaDirectory.canRead() ) + if ( Files.isReadable(mtaDirectory) ) { - final WebAppContext context = new WebAppContext( null, mtaDirectory.getPath(), "/" ); + final WebAppContext context = new WebAppContext( null, mtaDirectory.normalize().toString(), "/" ); final List initializers = new ArrayList<>(); initializers.add(new ContainerInitializer(new JettyJasperInitializer(), null)); context.setAttribute("org.eclipse.jetty.containerInitializers", initializers); diff --git a/src/java/org/ifsoft/upload/Servlet.java b/src/java/org/ifsoft/upload/Servlet.java index 6d116aa2..837305aa 100644 --- a/src/java/org/ifsoft/upload/Servlet.java +++ b/src/java/org/ifsoft/upload/Servlet.java @@ -63,8 +63,7 @@ protected void doPut( HttpServletRequest request, HttpServletResponse response ) if (name.endsWith(".webm")) { - String dir = JiveGlobals.getHomeDirectory() + File.separator + "resources" + File.separator + "spank" + File.separator + "ofmeet-cdn" + File.separator + "recordings"; - Path path = Paths.get( dir, name); + Path path = JiveGlobals.getHomePath().resolve("resources").resolve("spank").resolve("ofmeet-cdn").resolve("recordings").resolve(name); try { writeFile(path, request); @@ -85,12 +84,13 @@ protected void doPut( HttpServletRequest request, HttpServletResponse response ) String source = path.toString(); String folder = name.substring(0, name.lastIndexOf(".")); - String destination = JiveGlobals.getHomeDirectory() + File.separator + "resources" + File.separator + "spank" + File.separator + username + File.separator + folder; + Path destination = JiveGlobals.getHomePath().resolve("resources").resolve("spank").resolve(username).resolve(folder); Log.debug( "Extracting application..." + source + " " + destination); - ZipFile zipFile = new ZipFile(path.toFile()); - zipFile.extractAll(destination); + try (ZipFile zipFile = new ZipFile(path.toFile())) { + zipFile.extractAll(destination.toString()); + } Files.deleteIfExists(path); @@ -142,4 +142,4 @@ private void writeFile(Path path, HttpServletRequest request) throws Exception outStream.close(); } -} \ No newline at end of file +} diff --git a/src/java/org/igniterealtime/openfire/plugins/pushnotification/WebPushInterceptor.java b/src/java/org/igniterealtime/openfire/plugins/pushnotification/WebPushInterceptor.java index 25144fba..a8e8f72b 100644 --- a/src/java/org/igniterealtime/openfire/plugins/pushnotification/WebPushInterceptor.java +++ b/src/java/org/igniterealtime/openfire/plugins/pushnotification/WebPushInterceptor.java @@ -158,7 +158,7 @@ public void interceptPacket( final Packet packet, final Session session, final b } message.addChildElement("origin-id", "urn:xmpp:sid:0").addAttribute("id", msgId); - XMPPServer.getInstance().getRoutingTable().routePacket(packet.getTo(), message, true); + XMPPServer.getInstance().getRoutingTable().routePacket(packet.getTo(), message); } } } diff --git a/src/java/org/jivesoftware/openfire/archive/ArchiveSearcher.java b/src/java/org/jivesoftware/openfire/archive/ArchiveSearcher.java index 28007c6e..bdd845bb 100644 --- a/src/java/org/jivesoftware/openfire/archive/ArchiveSearcher.java +++ b/src/java/org/jivesoftware/openfire/archive/ArchiveSearcher.java @@ -17,6 +17,8 @@ package org.jivesoftware.openfire.archive; import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; import java.sql.Connection; import java.sql.PreparedStatement; @@ -98,15 +100,15 @@ public Collection search(ArchiveSearch search) { private Collection luceneSearch(ArchiveSearch search) { Log.debug( "Executing new Lucene search for query string {}", search.getQueryString() ); try { - File searchDir = new File(JiveGlobals.getHomeDirectory() + File.separator + MonitoringConstants.NAME + File.separator + "search"); + Path searchDir = JiveGlobals.getHomePath().resolve(MonitoringConstants.NAME).resolve("search"); - if (!searchDir.exists()) + if (!Files.exists(searchDir)) { Log.error("Search folder missing " + searchDir); return Collections.emptySet(); } try { - directory = FSDirectory.open(searchDir.toPath()); + directory = FSDirectory.open(searchDir); } catch (IOException ioe) { Log.error(ioe.getMessage(), ioe); diff --git a/src/java/org/jivesoftware/openfire/archive/ConversationPDFServlet.java b/src/java/org/jivesoftware/openfire/archive/ConversationPDFServlet.java index 3466e79d..4565573c 100644 --- a/src/java/org/jivesoftware/openfire/archive/ConversationPDFServlet.java +++ b/src/java/org/jivesoftware/openfire/archive/ConversationPDFServlet.java @@ -15,6 +15,8 @@ */ package org.jivesoftware.openfire.archive; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.util.*; import java.text.*; import java.io.*; @@ -91,19 +93,18 @@ public static void doSearch(OutputStream out, String username, String keywords, if (start != null) { - Date startDate = null; + Instant startDate; try { if (start.contains("T")) { - startDate = Date.from(Instant.parse(start)); + startDate = Instant.parse(start); } else { - DateFormat formatter = new SimpleDateFormat("MM/dd/yy"); - startDate = formatter.parse(start); + startDate = DateTimeFormatter.ofPattern("MM/dd/yy").parse(start, Instant::from); } - startDate = new Date(startDate.getTime() - JiveConstants.MINUTE * 5); - search.setDateRangeMin(startDate); + startDate = startDate.plus(5, ChronoUnit.MINUTES); + search.setDateRangeMin(Date.from(startDate)); } catch (Exception e) { Log.error("ConversationPDFServlet", e); @@ -112,19 +113,18 @@ public static void doSearch(OutputStream out, String username, String keywords, if (end != null) { - Date endDate = null; + Instant endDate; try { if (end.contains("T")) { - endDate = Date.from(Instant.parse(end)); + endDate = Instant.parse(end); } else { - DateFormat formatter = new SimpleDateFormat("MM/dd/yy"); - endDate = formatter.parse(end); + endDate = DateTimeFormatter.ofPattern("MM/dd/yy").parse(end, Instant::from); } - endDate = new Date(endDate.getTime() + JiveConstants.DAY - 1); - search.setDateRangeMax(endDate); + endDate = endDate.plus(1, ChronoUnit.DAYS).minus(1, ChronoUnit.MILLIS); + search.setDateRangeMax(Date.from(endDate)); } catch (Exception e) { Log.error("ConversationPDFServlet", e); diff --git a/src/java/org/jivesoftware/openfire/plugin/ofmeet/LobbyMuc.java b/src/java/org/jivesoftware/openfire/plugin/ofmeet/LobbyMuc.java index fa91fef6..366f2441 100644 --- a/src/java/org/jivesoftware/openfire/plugin/ofmeet/LobbyMuc.java +++ b/src/java/org/jivesoftware/openfire/plugin/ofmeet/LobbyMuc.java @@ -87,7 +87,7 @@ private void broadcast_json_msg(JID to, JID from, JSONObject jsonMsg) message.setType(Message.Type.groupchat); Element json = message.addChildElement("json-message", "http://jitsi.org/jitmeet"); json.setText(jsonMsg.toString()); - XMPPServer.getInstance().getRoutingTable().routePacket(to, message, true); + XMPPServer.getInstance().getRoutingTable().routePacket(to, message); } private void notify_configuration_change(JID to, String from) @@ -98,7 +98,7 @@ private void notify_configuration_change(JID to, String from) message.setType(Message.Type.groupchat); Element x = message.addChildElement("x", "http://jabber.org/protocol/muc#user"); x.addElement("status").addAttribute("code", "104"); - XMPPServer.getInstance().getRoutingTable().routePacket(to, message, true); + XMPPServer.getInstance().getRoutingTable().routePacket(to, message); } private void notify_lobby_enabled(JID to, JID from, boolean value) diff --git a/src/java/org/jivesoftware/openfire/plugin/ofmeet/OfMeetPlugin.java b/src/java/org/jivesoftware/openfire/plugin/ofmeet/OfMeetPlugin.java index e8807bad..f37d5cda 100644 --- a/src/java/org/jivesoftware/openfire/plugin/ofmeet/OfMeetPlugin.java +++ b/src/java/org/jivesoftware/openfire/plugin/ofmeet/OfMeetPlugin.java @@ -452,7 +452,7 @@ protected void loadPublicWebApp() throws Exception Log.debug( "Initialized public web application", publicWebApp.toString() ); File source = new File(pluginDirectory.getPath() + "/classes/docs"); - File destination = new File(JiveGlobals.getHomeDirectory() + "/resources/spank/pade"); + File destination = JiveGlobals.getHomePath().resolve("resources").resolve("spank").resolve("pade").toFile(); if ("/".equals(config.getWebappContextPath())) { destination = new File(pluginDirectory.getPath() + "/classes/jitsi-meet/pade"); @@ -575,33 +575,29 @@ public URL getWebappURL() private void checkDownloadFolder(File pluginDirectory) { - String ofmeetHome = JiveGlobals.getHomeDirectory() + File.separator + "resources" + File.separator + "spank" + File.separator + "ofmeet-cdn"; + Path ofmeetHome = JiveGlobals.getHomePath().resolve("resources").resolve("spank").resolve("ofmeet-cdn"); try { - File ofmeetFolderPath = new File(ofmeetHome); - - if(!ofmeetFolderPath.exists()) + if(!Files.exists(ofmeetHome)) { - ofmeetFolderPath.mkdirs(); - + Files.createDirectories(ofmeetHome); } - List lines = Arrays.asList("Move on, nothing here...."); - Path file = Paths.get(ofmeetHome + File.separator + "index.html"); - Files.write(file, lines, Charset.forName("UTF-8")); + List lines = List.of("Move on, nothing here...."); + Path file = ofmeetHome.resolve("index.html"); + Files.write(file, lines, StandardCharsets.UTF_8); - File downloadHome = new File(ofmeetHome + File.separator + "download"); + Path downloadHome = ofmeetHome.resolve("download"); - if(!downloadHome.exists()) + if(!Files.exists(downloadHome)) { - downloadHome.mkdirs(); - + Files.createDirectories(downloadHome); } - lines = Arrays.asList("Move on, nothing here...."); - file = Paths.get(downloadHome + File.separator + "index.html"); - Files.write(file, lines, Charset.forName("UTF-8")); + lines = List.of("Move on, nothing here...."); + file = downloadHome.resolve("index.html"); + Files.write(file, lines, StandardCharsets.UTF_8); } catch (Exception e) { @@ -1157,7 +1153,7 @@ public void occupantJoined(final JID roomJID, JID user, String nickname) pollMsg.setTo(user); Element pollJson = pollMsg.addChildElement("json-message", "http://jitsi.org/jitmeet"); pollJson.setText(pollsMsg.toString()); - XMPPServer.getInstance().getRoutingTable().routePacket(user, pollMsg, true); + XMPPServer.getInstance().getRoutingTable().routePacket(user, pollMsg); Log.debug("occupantJoined polls\n" + pollsMsg); } @@ -1180,7 +1176,7 @@ public void occupantJoined(final JID roomJID, JID user, String nickname) message.setTo(user); Element json = message.addChildElement("json", "urn:xmpp:json:0"); json.setText(jsonMsg.toString()); - XMPPServer.getInstance().getRoutingTable().routePacket(user, message, true); + XMPPServer.getInstance().getRoutingTable().routePacket(user, message); Log.debug("occupantJoined json\n" + jsonMsg); } diff --git a/src/java/uk/ifsoft/openfire/plugins/pade/PadePlugin.java b/src/java/uk/ifsoft/openfire/plugins/pade/PadePlugin.java index b3967962..b6fbd964 100644 --- a/src/java/uk/ifsoft/openfire/plugins/pade/PadePlugin.java +++ b/src/java/uk/ifsoft/openfire/plugins/pade/PadePlugin.java @@ -32,6 +32,7 @@ import org.jivesoftware.openfire.group.*; import org.jivesoftware.util.*; +import java.nio.charset.StandardCharsets; import java.security.SecureRandom; import java.io.File; import java.util.*; @@ -252,44 +253,43 @@ public OfMeetPlugin getContainer() private void checkRecordingsFolder() { - String resourcesHome = JiveGlobals.getHomeDirectory() + File.separator + "resources" + File.separator + "spank"; + Path resourcesHome = JiveGlobals.getHomePath().resolve("resources").resolve("spank"); try { - File ofmeetHome = new File(resourcesHome + File.separator + "ofmeet-cdn"); + Path ofmeetHome = resourcesHome.resolve("ofmeet-cdn"); - if(!ofmeetHome.exists()) + if(!Files.exists(ofmeetHome)) { - ofmeetHome.mkdirs(); - - List lines = Arrays.asList("Move on, nothing here...."); - Path file = Paths.get(ofmeetHome + File.separator + "index.html"); - Files.write(file, lines, Charset.forName("UTF-8")); + Files.createDirectory(ofmeetHome); + List lines = List.of("Move on, nothing here...."); + Path file = ofmeetHome.resolve("index.html"); + Files.write(file, lines, StandardCharsets.UTF_8); } - File recordingsHome = new File(ofmeetHome + File.separator + "recordings"); + Path recordingsHome = ofmeetHome.resolve("recordings"); - if(!recordingsHome.exists()) + if(!Files.exists(recordingsHome)) { - recordingsHome.mkdirs(); + Files.createDirectory(recordingsHome); - List lines = Arrays.asList("Move on, nothing here...."); + List lines = List.of("Move on, nothing here...."); Path file = Paths.get(recordingsHome + File.separator + "index.html"); - Files.write(file, lines, Charset.forName("UTF-8")); + Files.write(file, lines, StandardCharsets.UTF_8); } // create .well-known/host-meta - File wellknownFolder = new File(resourcesHome + File.separator + ".well-known"); + Path wellknownFolder = resourcesHome.resolve(".well-known"); - if(!wellknownFolder.exists()) + if(!Files.exists(wellknownFolder)) { - wellknownFolder.mkdirs(); + Files.createDirectory(wellknownFolder); } List lines = Arrays.asList("", "", "", ""); - Path file = Paths.get(wellknownFolder + File.separator + "host-meta"); - Files.write(file, lines, Charset.forName("UTF-8")); + Path file = wellknownFolder.resolve("host-meta"); + Files.write(file, lines, StandardCharsets.UTF_8); } catch (Exception e) @@ -448,7 +448,7 @@ private void notifyRoomActivity(JID subscriberJID, MUCRoom room, JID roomJID, Me notification.setTo(subscriberJID); Element rai = notification.addChildElement("rai", "urn:xmpp:rai:0"); rai.addElement("activity").setText(roomJID.toString()); - XMPPServer.getInstance().getRoutingTable().routePacket(subscriberJID, notification, true); + XMPPServer.getInstance().getRoutingTable().routePacket(subscriberJID, notification); } else { // user is offline, send web push notification if user mentioned