forked from Cookies_Github_mirror/AquaDX
[billing] Add billing server
This commit is contained in:
@@ -1,20 +1,98 @@
|
||||
package icu.samnyan.aqua.spring.configuration;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.SecureRequestCustomizer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.server.SslConnectionFactory;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
|
||||
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Configuration
|
||||
public class Config {
|
||||
|
||||
private final int SERVER_PORT;
|
||||
private final boolean ENABLE_BILLING;
|
||||
private final int BILLING_PORT;
|
||||
|
||||
public Config(@Value("${server.port}") int SERVER_PORT,
|
||||
@Value("${billing.server.port}") int BILLING_PORT,
|
||||
@Value("${billing.server.enable}") boolean ENABLE_BILLING) {
|
||||
this.SERVER_PORT = SERVER_PORT;
|
||||
this.BILLING_PORT = BILLING_PORT;
|
||||
this.ENABLE_BILLING = ENABLE_BILLING;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommonsMultipartResolver multipartResolver() {
|
||||
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
||||
multipartResolver.setMaxUploadSize(-1);
|
||||
return multipartResolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebServerFactoryCustomizer<JettyServletWebServerFactory> webServerFactoryCustomizer() {
|
||||
|
||||
return new WebServerFactoryCustomizer<JettyServletWebServerFactory>() {
|
||||
|
||||
@Override
|
||||
public void customize(JettyServletWebServerFactory factory) {
|
||||
|
||||
factory.addServerCustomizers(new JettyServerCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Server server) {
|
||||
|
||||
ServerConnector httpConnector = new ServerConnector(server);
|
||||
httpConnector.setPort(SERVER_PORT);
|
||||
|
||||
if (ENABLE_BILLING) {
|
||||
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
|
||||
|
||||
// TLS_RSA_* ciphers must be enabled, otherwise Auth NG
|
||||
String[] excludedCiphersWithoutTlsRsaExclusion = Arrays
|
||||
.stream(sslContextFactory.getExcludeCipherSuites())
|
||||
.filter(cipher -> !cipher.equals("^TLS_RSA_.*$")).toArray(String[]::new);
|
||||
|
||||
URL keystoreURL = getClass().getClassLoader().getResource("server.p12");
|
||||
sslContextFactory.setKeyStoreResource(Resource.newResource(keystoreURL));
|
||||
sslContextFactory.setKeyStorePassword("aquaserver");
|
||||
sslContextFactory.setCertAlias("ib");
|
||||
sslContextFactory.setExcludeCipherSuites(excludedCiphersWithoutTlsRsaExclusion);
|
||||
|
||||
HttpConfiguration httpsConfiguration = new HttpConfiguration();
|
||||
httpsConfiguration.addCustomizer(new SecureRequestCustomizer());
|
||||
|
||||
ServerConnector httpsConnector = new ServerConnector(server,
|
||||
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
|
||||
new HttpConnectionFactory(httpsConfiguration));
|
||||
httpsConnector.setPort(BILLING_PORT);
|
||||
|
||||
server.setConnectors(new Connector[] { httpConnector, httpsConnector });
|
||||
} else {
|
||||
server.setConnectors(new Connector[] { httpConnector });
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,19 +27,26 @@ public class AutoChecker {
|
||||
private final String AIMEDB_BIND;
|
||||
private final int AIMEDB_PORT;
|
||||
private final boolean AIMEDB_ENABLED;
|
||||
private final boolean BILLING_ENABLED;
|
||||
private final int BILLING_PORT;
|
||||
|
||||
public AutoChecker(
|
||||
@Value("${server.host:}") String SERVER_PORT,
|
||||
@Value("${allnet.server.host:}") String ALLNET_HOST,
|
||||
@Value("${allnet.server.port:}") String ALLNET_PORT,
|
||||
@Value("${aimedb.server.address}") String AIMEDB_BIND,
|
||||
@Value("${aimedb.server.port}") int AIMEDB_PORT,
|
||||
@Value("${aimedb.server.enable}") boolean AIMEDB_ENABLED) {
|
||||
@Value("${aimedb.server.enable}") boolean AIMEDB_ENABLED,
|
||||
@Value("${billing.server.port}") int BILLING_PORT,
|
||||
@Value("${billing.server.enable}") boolean BILLING_ENABLED) {
|
||||
this.SERVER_PORT = SERVER_PORT;
|
||||
this.ALLNET_HOST_OVERRIDE = ALLNET_HOST;
|
||||
this.ALLNET_PORT_OVERRIDE = ALLNET_PORT;
|
||||
this.AIMEDB_BIND = AIMEDB_BIND;
|
||||
this.AIMEDB_PORT = AIMEDB_PORT;
|
||||
this.AIMEDB_ENABLED = AIMEDB_ENABLED;
|
||||
this.BILLING_PORT = BILLING_PORT;
|
||||
this.BILLING_ENABLED = BILLING_ENABLED;
|
||||
}
|
||||
|
||||
public void check() {
|
||||
@@ -70,6 +77,19 @@ public class AutoChecker {
|
||||
}
|
||||
}
|
||||
|
||||
// Check billing
|
||||
System.out.print(" Billing : ");
|
||||
if(!BILLING_ENABLED) {
|
||||
System.out.println("DISABLED, SKIP");
|
||||
} else {
|
||||
String host = ALLNET_HOST_OVERRIDE.equals("") ? "127.0.0.1" : ALLNET_HOST_OVERRIDE;
|
||||
try (Socket test = new Socket(host, BILLING_PORT)){
|
||||
System.out.println("OK");
|
||||
} catch (Exception e) {
|
||||
System.out.println("ERROR!!");
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Check http part
|
||||
System.out.print(" AllNet : ");
|
||||
|
||||
Reference in New Issue
Block a user