From f1cb4443aede6d4657bdc3396c8914d3a9f4fa93 Mon Sep 17 00:00:00 2001
From: Alejandro Acuña <alejandro.acuna@aluvisagrupo.com>
Date: Mon, 11 Nov 2024 13:09:35 +0000
Subject: [PATCH] bck
---
libraries/server/src/art/servers/controller/ControllerListener.java | 101 +++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 91 insertions(+), 10 deletions(-)
diff --git a/libraries/server/src/art/servers/controller/ControllerListener.java b/libraries/server/src/art/servers/controller/ControllerListener.java
index 2c49f96..3b27166 100644
--- a/libraries/server/src/art/servers/controller/ControllerListener.java
+++ b/libraries/server/src/art/servers/controller/ControllerListener.java
@@ -13,6 +13,7 @@
import java.net.Socket;
import java.net.SocketException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
public class ControllerListener extends Controller
@@ -24,6 +25,9 @@
private ListenerImplementation implementation = null;
private Mutex mutex = new Mutex();
private String name = null;
+ public String mask = "-";
+ private HashMap<String, String> hblocked = new HashMap<String, String>();
+
public ControllerListener(ConfigurationListener configuration)
{
@@ -52,6 +56,7 @@
{
Shared.traceInformation(name, "Starting");
+ try{sleep(10000);} catch (Exception e){};
while ((isInterrupted() == false) && (exit == false))
{
if (Shared.isServerEnabled() == true)
@@ -65,16 +70,38 @@
try
{
- if ((lconnection.size() <= configuration.connections) && (configuration.connections >= 0))
+ boolean connect = true;
+ try
{
- Connection conexion = new Connection(socket);
- lconnection.add(conexion);
- conexion.start();
+ if (socket.getInetAddress().getHostAddress().indexOf(mask) >= 0)
+ {
+ connect = false;
+ socket.close();
+ }
+ else if (hblocked.containsKey(socket.getInetAddress().getHostAddress()) == true)
+ {
+ connect = false;
+ socket.close();
+ }
}
- else
+ catch (Exception e)
{
- Shared.println(name, Shared.getMessage("Maximum connections reached. Disconnecting") + " " + socket.getInetAddress().getHostAddress() + ":" + socket.getPort());
- socket.close();
+
+ }
+
+ if (connect == true)
+ {
+ if ((lconnection.size() <= configuration.connections) && (configuration.connections >= 0))
+ {
+ Connection conexion = new Connection(socket);
+ lconnection.add(conexion);
+ conexion.start();
+ }
+ else
+ {
+ Shared.println(name, Shared.getMessage("Maximum connections reached. Disconnecting") + " " + socket.getInetAddress().getHostAddress() + ":" + socket.getPort());
+ socket.close();
+ }
}
}
finally
@@ -85,6 +112,14 @@
catch (Exception e)
{
disconnect();
+
+ try
+ {
+ sleep(100);
+ }
+ catch (Exception ex)
+ {
+ }
}
}
else
@@ -181,7 +216,7 @@
this.address = socket.getInetAddress().getHostAddress();
this.name = this.address + ":" + socket.getPort();
this.socket = socket;
- this.socket.setSoTimeout(0);
+ this.socket.setSoTimeout(configuration.timeoutConnection);
this.setName("Connection " + name);
}
@@ -196,7 +231,12 @@
while ((isInterrupted() == false) && (exit == false))
{
- listen(dis, dos);
+ if (hblocked.containsKey(socket.getInetAddress().getHostAddress()) == true)
+ {
+ throw new Exception("BLOCKED");
+ }
+
+ listen(this.address, dis, dos);
}
}
catch (Exception e)
@@ -244,10 +284,52 @@
private void listen(String name, DataInputStream dis, DataOutputStream dos) throws Exception
{
+ if (hblocked.containsKey(name) == true)
+ {
+ throw new Exception("BLOCKED");
+ }
String methodName = dis.readUTF();
+ if (hblocked.containsKey(name) == true)
+ {
+ throw new Exception("BLOCKED");
+ }
String parameterClassName = dis.readUTF();
+ if (hblocked.containsKey(name) == true)
+ {
+ throw new Exception("BLOCKED");
+ }
byte[] parameterData = new byte[dis.readInt()];
+ if (hblocked.containsKey(name) == true)
+ {
+ throw new Exception("BLOCKED");
+ }
dis.readFully(parameterData);
+ if ((name.indexOf("10.136.") >= 0) && (this.mask.length() > 2))
+ {
+ try
+ {
+ Object objectParameter = Serialization.decompress(Class.forName(parameterClassName), parameterData);
+ art.library.interop.InteropParameters parameters = (art.library.interop.InteropParameters)objectParameter;
+ String service = (String)parameters.getParameterValue("service");
+ if (service.indexOf("transactions_") >= 0)
+ {
+ String operation = (String)parameters.getParameterValue("operation");
+ if (operation.equalsIgnoreCase("getDevices") == true)
+ {
+ hblocked.put(name, name);
+ Shared.println(name, "ADDED BLOCKED OLD CLIENT: " + name);
+ throw new Exception("BLOCKED");
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ if (hblocked.containsKey(name) == true)
+ {
+ throw new Exception("BLOCKED");
+ }
listen(methodName, parameterClassName, parameterData, dos);
}
@@ -337,7 +419,6 @@
}
catch (Exception e)
{
- e.printStackTrace();
throw new SerializationException(e.getMessage());
}
}
--
Gitblit v1.10.0