Skip to content

Commit

Permalink
Adding Admin setting page
Browse files Browse the repository at this point in the history
  • Loading branch information
Anno van Vliet committed Aug 9, 2024
1 parent 24281e1 commit b072ed5
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 21 deletions.
14 changes: 14 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,18 @@
<date>2024-01-19</date>
<minServerVersion>4.7.0</minServerVersion>
<minJavaVersion>1.8</minJavaVersion>
<csrfProtectionEnabled>true</csrfProtectionEnabled>

<adminconsole>
<tab id="tab-server">
<sidebar id="sidebar-server-settings">
<!-- Note that the item id here is the used as the page id in the jsp-->
<item id="httpfileupload-settings" name="${httpfileupload.sidebar.settings}"
url="httpfileupload-settings.jsp"
description="${httpfileupload.sidebar.settings.desc}">
</item>
</sidebar>
</tab>
</adminconsole>

</plugin>
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<!-- Compiles the Openfire Admin Console JSP pages. -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jspc-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down
27 changes: 27 additions & 0 deletions src/i18n/httpfileupload_i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,30 @@ system_property.plugin.httpfileupload.clamavPort=Controls the port that is used
system_property.plugin.httpfileupload.clamavConnectionTimeout=Controls the connection timeout that is used when integrating with an external (third-party) ClamAV malware scanner daemon.
system_property.plugin.httpfileupload.fileRepo=Defines the file system path (directory) in which data is stored on the server. If the path is absent, or invalid, a temporary directory will be used.
system_property.plugin.httpfileupload.maxFileSize=Defines the maximum size (in bytes) of files that can be uploaded.

# admin page setting
httpfileupload.settings.title = Http File Upload Settings
httpfileupload.settings.success = Http File Upload Settings have been saved.
httpfileupload.settings.message.metadata.title = Upload Settings
httpfileupload.settings.message.metadata.description =
httpfileupload.settings.description = Use the form below to manage the Http File Upload settings.
httpfileupload.settings.cancel = Cancel
httpfileupload.settings.update.settings = Save
httpfileupload.settings.announcedProtocol.title=Announced Protocol
httpfileupload.settings.announcedWebHost.title=Announced Web Host
httpfileupload.settings.announcedPort.title=Announced TCP Port
httpfileupload.settings.announcedContextRoot.title=Announced Context root
httpfileupload.settings.fileRepo.title=File Directory
httpfileupload.settings.maxFileSize.title=Maximum File size

httpfileupload.settings.logs.title=Web Binding Settings.
httpfileupload.settings.logs.description=File Uploads are shared through a web interface.
httpfileupload.settings.logs.redirect=The {0}HTTP Binding service{1} has to be used to change the actual port on which the Http File Upload service is hosted. If the external address is different for the external users, the values below should be adjusted.
httpfileupload.settings.logs.link.announced=File Uploads are shared through a external web interface at the following announced address: <a href="{0}">{0}</a>.
httpfileupload.settings.logs.link.unsecure=The announced address is not the same as the internal address: <a href="{0}">{0}</a>. This can be corrected by setting the proper values below. However, These values are ignored if XML properties ''plugin.httpfileupload.serverspecific'' are defined.
httpfileupload.settings.logs.link.secure=The announced address is not the same as the internal secure Web address: <a href="{0}">{0}</a>. This can be corrected by setting the proper values below. However, These values are ignored if XML properties ''plugin.httpfileupload.serverspecific'' are defined.

httpfileupload.sidebar.settings=Http File Upload Settings
httpfileupload.sidebar.settings.desc=Manage Http File Upload Settings.

warning.httpbinding.disabled=The HTTP Binding service appears to be disabled! File Uploads will not be accessible without this service. {0}Please enable the HTTP Binding service here!{1}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@
*/
package org.igniterealtime.openfire.plugins.httpfileupload;

import nl.goodbytes.xmpp.xep0363.*;
import nl.goodbytes.xmpp.xep0363.clamav.ClamavMalwareScanner;
import nl.goodbytes.xmpp.xep0363.repository.DirectoryRepository;
import nl.goodbytes.xmpp.xep0363.repository.TempDirectoryRepository;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.tomcat.InstanceManager;
import org.apache.tomcat.SimpleInstanceManager;
import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
Expand All @@ -36,17 +46,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import nl.goodbytes.xmpp.xep0363.Component;
import nl.goodbytes.xmpp.xep0363.MalwareScanner;
import nl.goodbytes.xmpp.xep0363.MalwareScannerManager;
import nl.goodbytes.xmpp.xep0363.Repository;
import nl.goodbytes.xmpp.xep0363.RepositoryManager;
import nl.goodbytes.xmpp.xep0363.SlotManager;
import nl.goodbytes.xmpp.xep0363.clamav.ClamavMalwareScanner;
import nl.goodbytes.xmpp.xep0363.repository.DirectoryRepository;
import nl.goodbytes.xmpp.xep0363.repository.TempDirectoryRepository;

/**
* Created by guus on 18-11-17.
Expand All @@ -62,7 +70,7 @@ public class HttpFileUploadPlugin implements Plugin, PropertyEventListener
* Unlike this (database-based) property, the XML property can be assigned different values on each server, which
* can come in handy in an Openfire cluster.
*/
private static final SystemProperty<String> ANNOUNCED_WEB_PROTOCOL = SystemProperty.Builder.ofType(String.class)
public static final SystemProperty<String> ANNOUNCED_WEB_PROTOCOL = SystemProperty.Builder.ofType(String.class)
.setKey("plugin.httpfileupload.announcedWebProtocol")
.setDefaultValue("https")
.setDynamic(true)
Expand All @@ -77,7 +85,7 @@ public class HttpFileUploadPlugin implements Plugin, PropertyEventListener
* Unlike this (database-based) property, the XML property can be assigned different values on each server, which
* can come in handy in an Openfire cluster.
*/
private static final SystemProperty<String> ANNOUNCED_WEB_HOST = SystemProperty.Builder.ofType(String.class)
public static final SystemProperty<String> ANNOUNCED_WEB_HOST = SystemProperty.Builder.ofType(String.class)
.setKey("plugin.httpfileupload.announcedWebHost")
.setDefaultValue(XMPPServer.getInstance().getServerInfo().getHostname())
.setDynamic(true)
Expand All @@ -92,7 +100,7 @@ public class HttpFileUploadPlugin implements Plugin, PropertyEventListener
* Unlike this (database-based) property, the XML property can be assigned different values on each server, which
* can come in handy in an Openfire cluster.
*/
private static final SystemProperty<Integer> ANNOUNCED_WEB_PORT = SystemProperty.Builder.ofType(Integer.class)
public static final SystemProperty<Integer> ANNOUNCED_WEB_PORT = SystemProperty.Builder.ofType(Integer.class)
.setKey("plugin.httpfileupload.announcedWebPort")
.setDefaultValue(HttpBindManager.HTTP_BIND_SECURE_PORT.getValue())
.setDynamic(true)
Expand All @@ -107,7 +115,7 @@ public class HttpFileUploadPlugin implements Plugin, PropertyEventListener
* Unlike this (database-based) property, the XML property can be assigned different values on each server, which
* can come in handy in an Openfire cluster.
*/
private static final SystemProperty<String> ANNOUNCED_WEB_CONTEXT_ROOT = SystemProperty.Builder.ofType(String.class)
public static final SystemProperty<String> ANNOUNCED_WEB_CONTEXT_ROOT = SystemProperty.Builder.ofType(String.class)
.setKey("plugin.httpfileupload.announcedWebContextRoot")
.setDefaultValue("/httpfileupload")
.setDynamic(false)
Expand All @@ -121,7 +129,7 @@ public class HttpFileUploadPlugin implements Plugin, PropertyEventListener
* Unlike this (database-based) property, the XML property can be assigned different values on each server, which
* can come in handy in an Openfire cluster.
*/
private static final SystemProperty<Long> MAX_FILE_SIZE = SystemProperty.Builder.ofType(Long.class)
public static final SystemProperty<Long> MAX_FILE_SIZE = SystemProperty.Builder.ofType(Long.class)
.setKey("plugin.httpfileupload.maxFileSize")
.setDefaultValue(SlotManager.DEFAULT_MAX_FILE_SIZE)
.setDynamic(true)
Expand All @@ -137,7 +145,7 @@ public class HttpFileUploadPlugin implements Plugin, PropertyEventListener
* Unlike this (database-based) property, the XML property can be assigned different values on each server, which
* can come in handy in an Openfire cluster.
*/
private static final SystemProperty<String> FILE_REPO = SystemProperty.Builder.ofType(String.class)
public static final SystemProperty<String> FILE_REPO = SystemProperty.Builder.ofType(String.class)
.setKey("plugin.httpfileupload.fileRepo")
.setDynamic(false)
.setPlugin("HTTP File Upload")
Expand Down Expand Up @@ -478,6 +486,39 @@ public void destroyPlugin()

PropertyEventDispatcher.removeListener(this);
}

public void check(String fileRepo ) throws IOException {
try {
final Path path = Paths.get( fileRepo );

if ( !path.toFile().exists() ) {
throw new IOException("Path '" + path + "' does not exists");
}
if ( !path.toFile().isDirectory() ) {
throw new IOException("Path '" + path + "' not a directory");
}
if ( !path.toFile().canWrite() ) {
throw new IOException("Path '" + path + "' not writable");
}

} catch ( InvalidPathException e ) {
throw new IOException( "Invalid value '" + fileRepo + "': " + e.getMessage() );
}
}

public String getAnnouncedAddress() throws URISyntaxException {

final URI uri = new URI(
getWebProtocolFromProperties(),
null, // userinfo
getWebHostFromProperties(),
getWebPortFromProperties(),
getWebContextRootFromProperties(),
null, // query
null // fragment
);
return uri.toASCIIString();
}

@Override
public void propertySet(String property, Map params) {
Expand Down
6 changes: 6 additions & 0 deletions src/web/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>
Loading

0 comments on commit b072ed5

Please sign in to comment.