mirror of
https://github.com/linuxserver/fleet.git
synced 2026-02-20 05:11:08 +08:00
Only add setup routes if no users
This commit is contained in:
parent
b18567e1fc
commit
52c5ea952d
@ -17,6 +17,7 @@
|
||||
|
||||
package io.linuxserver.fleet.core;
|
||||
|
||||
import io.linuxserver.fleet.web.WebServer;
|
||||
import io.linuxserver.fleet.web.pages.HomePage;
|
||||
import io.linuxserver.fleet.web.pages.LoginPage;
|
||||
import io.linuxserver.fleet.web.pages.ManageRepositoriesPage;
|
||||
@ -32,11 +33,30 @@ import java.util.concurrent.TimeUnit;
|
||||
* through this class.
|
||||
* </p>
|
||||
*/
|
||||
class FleetApp {
|
||||
public class FleetApp {
|
||||
|
||||
private static final String FLEET_USER_UNDEFINED = "fleet.user.undefined";
|
||||
|
||||
private static FleetApp instance;
|
||||
|
||||
public static FleetApp instance() {
|
||||
|
||||
if (null == instance) {
|
||||
|
||||
synchronized (FleetApp.class) {
|
||||
|
||||
if (null == instance) {
|
||||
instance = new FleetApp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final FleetBeans beans;
|
||||
|
||||
FleetApp() {
|
||||
private FleetApp() {
|
||||
beans = new FleetBeans();
|
||||
}
|
||||
|
||||
@ -56,25 +76,41 @@ class FleetApp {
|
||||
SynchronisationWebSocket synchronisationWebSocket = new SynchronisationWebSocket();
|
||||
beans.getSynchronisationDelegate().registerListener(synchronisationWebSocket);
|
||||
|
||||
beans.getWebServer().addWebSocket("/admin/ws/sync", synchronisationWebSocket);
|
||||
beans.getWebServer().addFilter( "*", new InitialUserFilterRoute(beans.getProperties().getAuthenticationType(), beans.getUserDelegate()));
|
||||
beans.getWebServer().start();
|
||||
WebServer webServer = beans.getWebServer();
|
||||
|
||||
beans.getWebServer().addPage( "/", new HomePage(beans.getRepositoryDelegate(), beans.getImageDelegate()));
|
||||
beans.getWebServer().addGetApi( "/api/v1/images", new AllImagesApi(beans.getRepositoryDelegate(), beans.getImageDelegate()));
|
||||
beans.getWebServer().addPage( "/setup", new SetupPage());
|
||||
beans.getWebServer().addPostRoute( "/setup", new RegisterInitialUserRoute(beans.getUserDelegate()));
|
||||
beans.getWebServer().addPage( "/admin", new ManageRepositoriesPage(beans.getRepositoryDelegate()));
|
||||
beans.getWebServer().addPage( "/admin/login", new LoginPage());
|
||||
beans.getWebServer().addPostRoute( "/admin/login", new LoginRoute(beans.getAuthenticationDelegate()));
|
||||
beans.getWebServer().addPostRoute( "/admin/logout", new LogoutRoute());
|
||||
beans.getWebServer().addPostApi( "/admin/manageImage", new ManageImageApi(beans.getImageDelegate()));
|
||||
beans.getWebServer().addGetApi( "/admin/getImage", new GetImageApi(beans.getImageDelegate()));
|
||||
beans.getWebServer().addPostApi( "/admin/manageRepository", new ManageRepositoryApi(beans.getRepositoryDelegate()));
|
||||
beans.getWebServer().addPostApi( "/admin/forceSync", new ForceSyncApi(beans.getTaskDelegate()));
|
||||
webServer.addWebSocket("/admin/ws/sync", synchronisationWebSocket);
|
||||
webServer.addFilter( "*", new InitialUserFilterRoute(beans.getProperties().getAuthenticationType(), beans.getUserDelegate()));
|
||||
webServer.start();
|
||||
|
||||
webServer.addPage( "/", new HomePage(beans.getRepositoryDelegate(), beans.getImageDelegate()));
|
||||
webServer.addGetApi( "/api/v1/images", new AllImagesApi(beans.getRepositoryDelegate(), beans.getImageDelegate()));
|
||||
webServer.addPage( "/admin", new ManageRepositoriesPage(beans.getRepositoryDelegate()));
|
||||
webServer.addPage( "/admin/login", new LoginPage());
|
||||
webServer.addPostRoute( "/admin/login", new LoginRoute(beans.getAuthenticationDelegate()));
|
||||
webServer.addPostRoute( "/admin/logout", new LogoutRoute());
|
||||
webServer.addPostApi( "/admin/manageImage", new ManageImageApi(beans.getImageDelegate()));
|
||||
webServer.addGetApi( "/admin/getImage", new GetImageApi(beans.getImageDelegate()));
|
||||
webServer.addPostApi( "/admin/manageRepository", new ManageRepositoryApi(beans.getRepositoryDelegate()));
|
||||
webServer.addPostApi( "/admin/forceSync", new ForceSyncApi(beans.getTaskDelegate()));
|
||||
|
||||
if (initialUserNeedsConfiguring()) {
|
||||
|
||||
webServer.addPage( "/setup", new SetupPage());
|
||||
webServer.addPostRoute( "/setup", new RegisterInitialUserRoute(beans.getUserDelegate()));
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleSync() {
|
||||
beans.getTaskDelegate().scheduleSynchronisationTask(beans.getProperties().getRefreshIntervalInMinutes(), TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
private boolean initialUserNeedsConfiguring() {
|
||||
|
||||
String configured = System.getProperty(FLEET_USER_UNDEFINED);
|
||||
if (null == configured || "true".equalsIgnoreCase(configured)) {
|
||||
System.setProperty(FLEET_USER_UNDEFINED, String.valueOf(beans.getUserDelegate().isUserRepositoryEmpty()));
|
||||
}
|
||||
|
||||
return "true".equalsIgnoreCase(System.getProperty(FLEET_USER_UNDEFINED));
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,8 +20,6 @@ package io.linuxserver.fleet.core;
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
FleetApp app = new FleetApp();
|
||||
app.run();
|
||||
FleetApp.instance().run();
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,10 +37,19 @@ public class WebServer {
|
||||
staticFiles.expireTime(600);
|
||||
}
|
||||
|
||||
public void stopServer() {
|
||||
|
||||
stop();
|
||||
|
||||
started = false;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
||||
started = true;
|
||||
|
||||
init();
|
||||
|
||||
path("/admin", configureAuthorisationRoute(""));
|
||||
path("/admin", configureAuthorisationRoute("/images"));
|
||||
path("/admin", configureAuthorisationRoute("/manageImage"));
|
||||
|
||||
@ -53,7 +53,7 @@ public class InitialUserFilterRoute implements Filter {
|
||||
if (databaseAuthenticationEnabled) {
|
||||
|
||||
if (!initialUserNeedsConfiguring() && "/setup".equals(request.pathInfo())) {
|
||||
halt(401);
|
||||
halt(401); // FIXME: I'm unhappy halting here. Need to get the filter chain correct.
|
||||
}
|
||||
|
||||
else if (initialUserNeedsConfiguring() && !pathIsExempted(request.pathInfo())) {
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
<h3 class="mb-3">Create a user</h3>
|
||||
|
||||
<form action="/admin/setup" method="POST" class="needs-validation" novalidate>
|
||||
<form action="/setup" method="POST" class="needs-validation" novalidate>
|
||||
<div class="form-group row">
|
||||
<label for="username" class="col-sm-2 col-form-label">Username</label>
|
||||
<div class="col-sm-10">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user