| | |
| | | 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 |
| | |
| | | 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) |
| | | { |
| | |
| | | { |
| | | Shared.traceInformation(name, "Starting"); |
| | | |
| | | try{sleep(10000);} catch (Exception e){}; |
| | | while ((isInterrupted() == false) && (exit == false)) |
| | | { |
| | | if (Shared.isServerEnabled() == true) |
| | |
| | | |
| | | try |
| | | { |
| | | boolean connect = true; |
| | | try |
| | | { |
| | | if (socket.getInetAddress().getHostAddress().indexOf(mask) >= 0) |
| | | { |
| | | connect = false; |
| | | socket.close(); |
| | | } |
| | | else if (hblocked.containsKey(socket.getInetAddress().getHostAddress()) == true) |
| | | { |
| | | connect = false; |
| | | socket.close(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | |
| | | } |
| | | |
| | | if (connect == true) |
| | | { |
| | | if ((lconnection.size() <= configuration.connections) && (configuration.connections >= 0)) |
| | | { |
| | | Connection conexion = new Connection(socket); |
| | |
| | | socket.close(); |
| | | } |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | mutex.releaseWrite(); |
| | |
| | | catch (Exception e) |
| | | { |
| | | disconnect(); |
| | | |
| | | try |
| | | { |
| | | sleep(100); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | } |
| | | } |
| | | else |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | |
| | | 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) |
| | |
| | | |
| | | 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); |
| | | } |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | e.printStackTrace(); |
| | | throw new SerializationException(e.getMessage()); |
| | | } |
| | | } |