protected DCServerFactory.ResultCode sendEmail(
     String frEmail, String toEmail, String subj, String body) {
   if (StringTools.isBlank(frEmail)) {
     Print.logError("'From' Email address not specified");
     return DCServerFactory.ResultCode.TRANSMIT_FAIL;
   } else if (StringTools.isBlank(toEmail) || !CommandPacketHandler.validateAddress(toEmail)) {
     Print.logError("'To' SMS Email address invalid, or not specified");
     return DCServerFactory.ResultCode.TRANSMIT_FAIL;
   } else if (StringTools.isBlank(subj) && StringTools.isBlank(body)) {
     Print.logError("Command string not specified");
     return DCServerFactory.ResultCode.INVALID_ARG;
   } else {
     try {
       Print.logInfo("SMS email: to <" + toEmail + ">");
       Print.logDebug("  From   : " + frEmail);
       Print.logDebug("  To     : " + toEmail);
       Print.logDebug("  Subject: " + subj);
       Print.logDebug("  Message: " + body);
       SendMail.send(frEmail, toEmail, null, null, subj, body, null);
       return DCServerFactory.ResultCode.SUCCESS;
     } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
       // this will fail if JavaMail support for SendMail is not available.
       Print.logWarn("SendMail error: " + t);
       return DCServerFactory.ResultCode.TRANSMIT_FAIL;
     }
   }
 }
    public void run() {
      StringBuffer data = new StringBuffer();
      Print.logDebug("Client:InputThread started");

      while (true) {
        data.setLength(0);
        boolean timeout = false;
        try {
          if (this.readTimeout > 0L) {
            this.socket.setSoTimeout((int) this.readTimeout);
          }
          ClientSocketThread.socketReadLine(this.socket, -1, data);
        } catch (InterruptedIOException ee) { // SocketTimeoutException ee) {
          // error("Read interrupted (timeout) ...");
          if (getRunStatus() != THREAD_RUNNING) {
            break;
          }
          timeout = true;
          // continue;
        } catch (Throwable t) {
          Print.logError("Client:InputThread - " + t);
          t.printStackTrace();
          break;
        }
        if (!timeout || (data.length() > 0)) {
          ClientSocketThread.this.handleMessage(data.toString());
        }
      }

      synchronized (this.threadLock) {
        this.isRunning = false;
        Print.logDebug("Client:InputThread stopped");
        this.threadLock.notify();
      }
    }
Beispiel #3
0
  protected boolean _setDevice(Device device, String ipAddress, int clientPort) {

    /* valid device? */
    if (device == null) {
      return false;
    }

    /* validate ID address */
    DataTransport dataXPort = device.getDataTransport();
    if ((ipAddress != null) && !dataXPort.isValidIPAddress(ipAddress)) {
      Print.logError(
          "Invalid IPAddr: "
              + device.getAccountID()
              + "/"
              + device.getDeviceID()
              + " Found="
              + ipAddress
              + " Expect="
              + dataXPort.getIpAddressValid());
      return false;
    }

    /* update device */
    this.device = device;
    this.dataXPort = dataXPort;
    this.dataXPort.setIpAddressCurrent(ipAddress); // FLD_ipAddressCurrent
    this.dataXPort.setRemotePortCurrent(clientPort); // FLD_remotePortCurrent
    this.dataXPort.setDeviceCode(this.getDeviceCode()); // FLD_deviceCode
    this.device.setLastTotalConnectTime(DateTime.getCurrentTimeSec()); // FLD_lastTotalConnectTime

    /* ok */
    return true;
  }
  /** ** Main entry point for testing/debugging ** @param argv Comand-line arguments */
  public static void main(String argv[]) {
    RTConfig.setCommandLineArgs(argv);
    String host = RTConfig.getString(ARG_HOST, null);
    int port = RTConfig.getInt(ARG_PORT, 0);

    /* send data */
    if (RTConfig.hasProperty(ARG_SEND)) {
      if (StringTools.isBlank(host)) {
        Print.logError("Target host not specified");
        usage();
      }
      if (port <= 0) {
        Print.logError("Target port not specified");
        usage();
      }
      String dataStr = RTConfig.getString(ARG_SEND, "hello");
      byte data[] =
          dataStr.startsWith("0x") ? StringTools.parseHex(dataStr, null) : dataStr.getBytes();
      ClientSocketThread cst = new ClientSocketThread(host, port);
      try {
        cst.openSocket();
        cst.socketWriteBytes(data);
      } catch (Throwable t) {
        Print.logException("Error", t);
      } finally {
        cst.closeSocket();
      }
      System.exit(0);
    }

    /* receive data */
    if (RTConfig.hasProperty(ARG_RECEIVE)) {
      if (port <= 0) {
        Print.logError("Target port not specified");
        usage();
      }
      if (!StringTools.isBlank(host)) {
        Print.logWarn("Specified 'host' will be ignored");
      }
      Print.logError("Receive not yet implemented ...");
      System.exit(99);
    }

    /* show usage */
    usage();
  }
Beispiel #5
0
  /* private constructor */
  private TrackServer(int tcpPorts[], int udpPorts[], int commandPort) throws Throwable {
    int listeners = 0;

    // Start TCP listeners
    if (!ListTools.isEmpty(tcpPorts)) {
      for (int i = 0; i < tcpPorts.length; i++) {
        int port = tcpPorts[i];
        if (ServerSocketThread.isValidPort(port)) {
          try {
            this._startTCP(port);
            listeners++;
          } catch (java.net.BindException be) {
            Print.logError("TCP: Error binding to port: %d", port);
          }
        } else {
          throw new Exception("TCP: Invalid port number: " + port);
        }
      }
    }

    // Start UDP listeners
    if (!ListTools.isEmpty(udpPorts)) {
      for (int i = 0; i < udpPorts.length; i++) {
        int port = udpPorts[i];
        if (ServerSocketThread.isValidPort(port)) {
          try {
            ServerSocketThread sst = this._startUDP(port);
            if (this.udpSocket == null) {
              this.udpSocket = sst.getDatagramSocket();
            }
            listeners++;
          } catch (java.net.BindException be) {
            Print.logError("UDP: Error binding to port: %d", port);
          }
        } else {
          throw new Exception("UDP: Invalid port number: " + port);
        }
      }
    }

    /* do we have any active listeners? */
    if (listeners <= 0) {
      Print.logWarn("No active device communication listeners!");
    }
  }
Beispiel #6
0
 protected Device loadDevice(String acctID, String devID) {
   if (StringTools.isBlank(acctID)) {
     return this.loadDevice(devID); // load ad ModemID
   } else {
     try {
       Account account = Account.getAccount(acctID);
       if (account == null) {
         Print.logError("Account-ID not found: " + acctID);
         return null;
       } else {
         Device dev = Transport.loadDeviceByTransportID(account, devID);
         return dev;
       }
     } catch (DBException dbe) {
       Print.logError("Error getting Device: " + acctID + "/" + devID + " [" + dbe + "]");
       return null;
     }
   }
 }
 /**
  * ** Invokes all listeners with an assciated command ** @param r a string that may specify a
  * command (possibly one ** of several) associated with the event
  */
 protected void invokeListeners(String r) {
   if (this.actionListeners != null) {
     for (Iterator i = this.actionListeners.iterator(); i.hasNext(); ) {
       ActionListener al = (ActionListener) i.next();
       ActionEvent ae = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, r);
       try {
         al.actionPerformed(ae);
       } catch (Throwable t) {
         Print.logError("Exception: " + t.getMessage());
       }
     }
   }
 }
Beispiel #8
0
 /** ** Descrambles String */
 public static String _des64(String e) {
   if (!StringTools.isBlank(e)) {
     try {
       byte b[] = Base64.decode(e, getBase64Alphabet(), Base64Pad);
       return StringTools.toStringValue(b, ' ');
     } catch (Base64.Base64DecodeException bde) {
       Print.logError("Invalid Base64 characters", bde);
       return "";
     }
   } else {
     return "";
   }
 }
    public void run() {
      String command = null;
      Print.logInfo("Client:OutputThread started");

      while (true) {

        /* wait for commands */
        synchronized (this.cmdList) {
          while ((this.cmdList.size() <= 0) && (getRunStatus() == THREAD_RUNNING)) {
            try {
              this.cmdList.wait(5000L);
            } catch (Throwable t) {
              /*ignore*/
            }
          }
          if (getRunStatus() != THREAD_RUNNING) {
            break;
          }
          command = this.cmdList.remove(0).toString();
        }

        /* send commands */
        try {
          ClientSocketThread.socketWriteLine(this.socket, command);
        } catch (Throwable t) {
          Print.logError("Client:OutputThread - " + t);
          t.printStackTrace();
          break;
        }
      }

      if (getRunStatus() == THREAD_RUNNING) {
        Print.logWarn("Client:OutputThread stopped due to error");
      } else {
        Print.logInfo("Client:OutputThread stopped");
      }

      synchronized (this.threadLock) {
        this.isRunning = false;
        Print.logInfo("Client:OutputThread stopped");
        this.threadLock.notify();
      }
    }