Esempio n. 1
0
  protected void logAlert(int type, String resource, String[] params) {
    String text =
        plugin_interface
            .getUtilities()
            .getLocaleUtilities()
            .getLocalisedMessageText(resource, params);

    log.logAlertRepeatable(type, text);
  }
Esempio n. 2
0
  protected void closeDown(final boolean end_of_day) {
    // problems here at end of day regarding devices that hang and cause AZ to hang around
    // got ages before terminating

    final AESemaphore sem = new AESemaphore("UPnPPlugin:closeTimeout");

    new AEThread("UPnPPlugin:closeTimeout", true) {
      public void runSupport() {
        try {
          for (int i = 0; i < mappings.size(); i++) {

            UPnPMapping mapping = (UPnPMapping) mappings.get(i);

            if (!mapping.isEnabled()) {

              continue;
            }

            for (int j = 0; j < services.size(); j++) {

              UPnPPluginService service = (UPnPPluginService) services.get(j);

              service.removeMapping(log, mapping, end_of_day);
            }
          }
        } finally {

          sem.release();
        }
      }
    }.start();

    if (!sem.reserve(end_of_day ? 15 * 1000 : 0)) {

      String msg =
          "A UPnP device is taking a long time to release its port mappings, consider disabling this via the UPnP configuration.";

      if (upnp_log_listener != null) {

        upnp_log_listener.logAlert(msg, false, UPnPLogListener.TYPE_ONCE_PER_SESSION);

      } else {

        log.logAlertRepeatable(LoggerChannel.LT_WARNING, msg);
      }
    }
  }
Esempio n. 3
0
  protected void removeService(UPnPWANConnection wan_service, boolean replaced) {
    try {
      this_mon.enter();

      String name =
          wan_service.getGenericService().getServiceType().indexOf("PPP") == -1
              ? "WANIPConnection"
              : "WANPPPConnection";

      String text =
          MessageText.getString(
              "upnp.alert.lostdevice",
              new String[] {
                name,
                wan_service.getGenericService().getDevice().getRootDevice().getLocation().getHost()
              });

      log.log(text);

      if ((!replaced) && alert_device_probs_param.getValue()) {

        log.logAlertRepeatable(LoggerChannel.LT_WARNING, text);
      }

      for (int i = 0; i < services.size(); i++) {

        UPnPPluginService ps = (UPnPPluginService) services.get(i);

        if (ps.getService() == wan_service) {

          services.remove(i);

          break;
        }
      }
    } finally {

      this_mon.exit();
    }
  }
Esempio n. 4
0
  protected void ignoreDevice(String USN, URL location) {
    // only take note of this if enabled to do so

    if (ignore_bad_devices.getValue()) {

      try {
        PluginConfig pc = plugin_interface.getPluginconfig();

        Map ignored = pc.getPluginMapParameter("upnp.device.ignorelist", new HashMap());

        Map entry = (Map) ignored.get(USN);

        if (entry == null) {

          entry = new HashMap();

          entry.put("Location", location.toString().getBytes());

          ignored.put(USN, entry);

          pc.setPluginMapParameter("upnp.device.ignorelist", ignored);

          updateIgnoreList();

          String text =
              plugin_interface
                  .getUtilities()
                  .getLocaleUtilities()
                  .getLocalisedMessageText(
                      "upnp.ignorebaddevices.alert", new String[] {location.toString()});

          log.logAlertRepeatable(LoggerChannel.LT_WARNING, text);
        }
      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }
  }
Esempio n. 5
0
  protected void addService(UPnPWANConnection wan_service) throws UPnPException {

    wan_service.addListener(this);

    mapping_manager.serviceFound(wan_service);

    try {
      this_mon.enter();

      log.log(
          "    Found "
              + (wan_service.getGenericService().getServiceType().indexOf("PPP") == -1
                  ? "WANIPConnection"
                  : "WANPPPConnection"));

      UPnPWANConnectionPortMapping[] ports;

      String usn = wan_service.getGenericService().getDevice().getRootDevice().getUSN();

      if (getDeviceStats(usn, STATS_READ_OK) == 0 && getDeviceStats(usn, STATS_READ_BAD) > 2) {

        ports = new UPnPWANConnectionPortMapping[0];

        wan_service.periodicallyRecheckMappings(false);

        log.log("    Not reading port mappings from device due to previous failures");

      } else {

        ports = wan_service.getPortMappings();
      }

      for (int j = 0; j < ports.length; j++) {

        log.log(
            "      mapping ["
                + j
                + "] "
                + ports[j].getExternalPort()
                + "/"
                + (ports[j].isTCP() ? "TCP" : "UDP")
                + " ["
                + ports[j].getDescription()
                + "] -> "
                + ports[j].getInternalHost());
      }

      services.add(
          new UPnPPluginService(
              wan_service,
              ports,
              alert_success_param,
              grab_ports_param,
              alert_other_port_param,
              release_mappings_param));

      if (services.size() > 1) {

        // check this isn't a single device with multiple services

        String new_usn = wan_service.getGenericService().getDevice().getRootDevice().getUSN();

        boolean multiple_found = false;

        for (int i = 0; i < services.size() - 1; i++) {

          UPnPPluginService service = (UPnPPluginService) services.get(i);

          String existing_usn =
              service.getService().getGenericService().getDevice().getRootDevice().getUSN();

          if (!new_usn.equals(existing_usn)) {

            multiple_found = true;

            break;
          }
        }

        if (multiple_found) {

          PluginConfig pc = plugin_interface.getPluginconfig();

          if (!pc.getPluginBooleanParameter("upnp.device.multipledevices.warned", false)) {

            pc.setPluginParameter("upnp.device.multipledevices.warned", true);

            String text = MessageText.getString("upnp.alert.multipledevice.warning");

            log.logAlertRepeatable(LoggerChannel.LT_WARNING, text);
          }
        }
      }

      checkState();

    } finally {

      this_mon.exit();
    }
  }