@Override
  protected void initFlow(HierarchicalConfiguration flowCfg) {
    // int node = flowCfg.getInt("[@node]");

    int inLink = flowCfg.getInt("[@inLink]", -1);
    int outLink = flowCfg.getInt("[@outLink]", -1);

    // int next = flowCfg.getInt("[@next]");
    int no = flowCfg.getInt("[@no]", 0);

    Node node;
    Node next;

    if (inLink != -1) {
      Link link = idToLinkMap.get(Id.create(inLink, Link.class));

      node = link.getFromNode();
      next = link.getToNode();
    } else {
      Link link = idToLinkMap.get(Id.create(outLink, Link.class));

      node = link.getToNode();
      next = link.getFromNode();
    }

    int nodeId = Integer.parseInt(node.getId().toString());
    int nextId = Integer.parseInt(next.getId().toString());

    flows[nodeId] = new MATSimFlow(nodeId, inLink, outLink, nextId, no);
  }
Exemple #2
0
  public void load(HierarchicalConfiguration config) throws IOException {
    HierarchicalConfiguration localConfig = config.configurationAt(this.getClass().getName());
    String dictionaryFilename = "/dict/single.txt";
    if (dictionaryFilename == null)
      throw new IllegalArgumentException("Must specify dictionary filename");
    String dictionaryTypeName = localConfig.getString("dictionaryType");
    if (dictionaryTypeName == null)
      throw new IllegalArgumentException("Must specify dictionary type");
    String delimiter = localConfig.getString("delimiter");
    int column = localConfig.getInt("column", -1);
    if (delimiter != null && column == -1)
      throw new IllegalArgumentException("Must specify column if delimiter specified");
    EntityType dictionaryType = EntityType.getType(dictionaryTypeName);

    // Load data
    java.util.Scanner s =
        new java.util.Scanner(getClass().getResourceAsStream(dictionaryFilename))
            .useDelimiter("\\A");

    while (s.hasNext()) {
      String line = s.nextLine();
      line = line.trim();
      if (line.length() > 0) {
        if (delimiter == null) {
          add(line, dictionaryType);
        } else {
          // TODO Performance - don't use split
          String[] split = line.split(delimiter);
          add(split[column], dictionaryType);
        }
      }
    }
    s.close();
  }
  @Override
  @SuppressWarnings("unchecked")
  public List<UserAlert> getAvailableAlerts() {
    List<UserAlert> alerts = new ArrayList<UserAlert>();

    final SortedMap<Integer, Pair> categoryNames = new ConcurrentSkipListMap<Integer, Pair>();

    HierarchicalConfiguration hc = (HierarchicalConfiguration) configuration;
    List<HierarchicalConfiguration> categories = hc.configurationsAt(ALERTS_CATEGORIES_CATEGORY);

    for (HierarchicalConfiguration c : categories) {
      String key = c.getString("[@key]");
      int order = c.getInt("[@displayOrder]", categoryNames.size());
      String value = c.getString("");

      categoryNames.put(order, new Pair<String, String>(key, value));
    }

    final String[] weeklyCategories = hc.getStringArray(ALERTS_WEEKLY);
    final String[] monthlyCategories = hc.getStringArray(ALERTS_MONTHLY);
    final String[] subjectFilters = hc.getStringArray(SUBJECT_FILTER);

    final Set<Map.Entry<Integer, Pair>> categoryNamesSet = categoryNames.entrySet();

    for (final Map.Entry<Integer, Pair> category : categoryNamesSet) {
      final String key = (String) category.getValue().getFirst();
      boolean weeklyCategoryKey = false;
      boolean monthlyCategoryKey = false;
      boolean subjectFilter = false;

      if (ArrayUtils.contains(weeklyCategories, key)) {
        weeklyCategoryKey = true;
      }
      if (ArrayUtils.contains(monthlyCategories, key)) {
        monthlyCategoryKey = true;
      }
      if (ArrayUtils.contains(subjectFilters, key)) {
        subjectFilter = true;
      }

      alerts.add(
          new UserAlert(
              (String) category.getValue().getFirst(),
              (String) category.getValue().getSecond(),
              weeklyCategoryKey,
              monthlyCategoryKey,
              subjectFilter));
    }
    return alerts;
  }
  public void processQueries(String instanceName, String xmlFile) {

    XMLConfiguration config = null;
    /** clear'em out */
    if (collectionQueries.get(instanceName) != null) {
      collectionQueries.get(instanceName).clear();
    }
    if (relationshipQueries.get(instanceName) != null) {
      relationshipQueries.get(instanceName).clear();
    }

    if (jdbcDriver != null) {
      jdbcDriver = null;
    }

    if (validationQuery != null) {
      validationQuery = null;
    }

    if (url != null) {
      url = null;
    }

    try {
      /**
       * use strange ethiopic unicode character so that it never delimits the properties
       *
       * <p>This is a workaround becuase config.setDelimiterParsingDisabled(true) doesn't disable
       * parsing
       */
      AbstractConfiguration.setDefaultListDelimiter('\u12BF');
      config = new XMLConfiguration(xmlFile);
      config.setDelimiterParsingDisabled(true);
      Map<String, String> instanceCollectionQueryMap = new TreeMap<String, String>();
      Map<String, String> instanceRelationshipQueryMap = new TreeMap<String, String>();
      Map<String, String> instanceAttributeQueryMap = new TreeMap<String, String>();

      @SuppressWarnings("unchecked")
      List<HierarchicalConfiguration> params = config.configurationsAt("configuration");
      for (HierarchicalConfiguration param : params) {
        this.jdbcDriver = param.getString("driver");
        this.validationQuery = param.getString("validationquery");
        this.url = param.getString("url");
        this.cycleTimeOffset = param.getInt("cycletimeoffset");
        if (log.isDebugEnabled()) {
          log.debug("jdbcDriver:" + param.getString("driver"));
          log.debug("validationQuery:" + param.getString("validationquery"));
          log.debug("url:" + param.getString("url"));
          log.debug("cycleTimeOffset:" + param.getInt("cycletimeoffset"));
        }
      }

      @SuppressWarnings("unchecked")
      List<HierarchicalConfiguration> queries = config.configurationsAt("queries.query");
      for (HierarchicalConfiguration sub : queries) {
        String name = sub.getString("name");
        String type = sub.getString("type");
        String sql = sub.getString("sql");

        if (type.equalsIgnoreCase("collection")) {
          instanceCollectionQueryMap.put(name, sql);
        } else if (type.equalsIgnoreCase("relationship")) {
          instanceRelationshipQueryMap.put(name, sql);
        } else if (type.equalsIgnoreCase("attribute")) {
          instanceAttributeQueryMap.put(name, sql);
        }
      }

      collectionQueries.put(instanceName, instanceCollectionQueryMap);
      relationshipQueries.put(instanceName, instanceRelationshipQueryMap);
      attributeQueries.put(instanceName, instanceAttributeQueryMap);

    } catch (ConfigurationException e) {
      log.error(e);
    }
  }
Exemple #5
0
  @Override
  protected void parse() {
    removeOldOptions();

    try {
      this.threadPerHost = getConfig().getInt(THREAD_PER_HOST, 1);
    } catch (Exception e) {
    }

    try {
      this.hostPerScan = getConfig().getInt(HOST_PER_SCAN, 2);
    } catch (Exception e) {
    }

    try {
      this.delayInMs = getConfig().getInt(DELAY_IN_MS, 0);
    } catch (Exception e) {
    }

    try {
      this.maxResultsToList = getConfig().getInt(MAX_RESULTS_LIST, 1000);
    } catch (Exception e) {
    }

    try {
      this.maxScansInUI = getConfig().getInt(MAX_SCANS_IN_UI, 5);
    } catch (Exception e) {
    }

    try {
      this.injectPluginIdInHeader = getConfig().getBoolean(INJECT_PLUGIN_ID_IN_HEADER, false);
    } catch (Exception e) {
    }

    try {
      this.handleAntiCSRFTokens = getConfig().getBoolean(HANDLE_ANTI_CSRF_TOKENS, false);
    } catch (Exception e) {
    }

    try {
      this.promptInAttackMode = getConfig().getBoolean(PROMPT_IN_ATTACK_MODE, true);
    } catch (Exception e) {
    }

    try {
      this.rescanInAttackMode = getConfig().getBoolean(RESCAN_IN_ATTACK_MODE, true);
    } catch (Exception e) {
    }

    try {
      this.promptToClearFinishedScans = getConfig().getBoolean(PROMPT_TO_CLEAR_FINISHED, true);
    } catch (Exception e) {
    }

    try {
      this.showAdvancedDialog = getConfig().getBoolean(SHOW_ADV_DIALOG, false);
    } catch (Exception e) {
    }

    try {
      this.defaultPolicy = getConfig().getString(DEFAULT_POLICY, null);
    } catch (Exception e) {
    }

    try {
      this.attackPolicy = getConfig().getString(ATTACK_POLICY, null);
    } catch (Exception e) {
    }

    try {
      this.targetParamsInjectable =
          getConfig().getInt(TARGET_INJECTABLE, TARGET_INJECTABLE_DEFAULT);
    } catch (Exception e) {
    }

    try {
      this.targetParamsEnabledRPC =
          getConfig().getInt(TARGET_ENABLED_RPC, TARGET_ENABLED_RPC_DEFAULT);
    } catch (Exception e) {
    }

    try {
      this.allowAttackOnStart = getConfig().getBoolean(ALLOW_ATTACK_ON_START, false);
    } catch (Exception e) {
    }

    // Parse the parameters that need to be excluded
    // ------------------------------------------------
    try {
      List<HierarchicalConfiguration> fields =
          ((HierarchicalConfiguration) getConfig()).configurationsAt(EXCLUDED_PARAMS_KEY);

      this.excludedParams.clear();
      this.excludedParamsMap.clear();
      List<String> tempParamNames = new ArrayList<>(fields.size());

      for (HierarchicalConfiguration sub : fields) {
        String name = sub.getString(EXCLUDED_PARAM_NAME, "");
        if (!name.isEmpty() && !tempParamNames.contains(name)) {
          tempParamNames.add(name);

          addScannerParamFilter(
              name,
              sub.getInt(EXCLUDED_PARAM_TYPE, NameValuePair.TYPE_UNDEFINED),
              sub.getString(EXCLUDED_PARAM_URL));
        }
      }

    } catch (ConversionException e) {
      logger.error("Error while loading the exluded parameter list: " + e.getMessage(), e);
    }

    // If the list is null probably we've to use defaults!!!
    if (this.excludedParams.isEmpty()) {
      // OK let's set the Default parameter exclusion list
      // Evaluate the possibility to load it from an external file...
      addScannerParamFilter("(?i)ASP.NET_SessionId", NameValuePair.TYPE_UNDEFINED, "*");
      addScannerParamFilter("(?i)ASPSESSIONID.*", NameValuePair.TYPE_UNDEFINED, "*");
      addScannerParamFilter("(?i)PHPSESSID", NameValuePair.TYPE_UNDEFINED, "*");
      addScannerParamFilter("(?i)SITESERVER", NameValuePair.TYPE_UNDEFINED, "*");
      addScannerParamFilter("(?i)sessid", NameValuePair.TYPE_UNDEFINED, "*");
      addScannerParamFilter("__VIEWSTATE", NameValuePair.TYPE_POST_DATA, "*");
      addScannerParamFilter("__EVENTVALIDATION", NameValuePair.TYPE_POST_DATA, "*");
      addScannerParamFilter("__EVENTTARGET", NameValuePair.TYPE_POST_DATA, "*");
      addScannerParamFilter("__EVENTARGUMENT", NameValuePair.TYPE_POST_DATA, "*");
      addScannerParamFilter("(?i)jsessionid", NameValuePair.TYPE_UNDEFINED, "*");
      addScannerParamFilter("cfid", NameValuePair.TYPE_COOKIE, "*");
      addScannerParamFilter("cftoken", NameValuePair.TYPE_COOKIE, "*");
    }
  }
Exemple #6
0
  private void readVehiclesAndTheirTypes(XMLConfiguration vrpProblem) {

    // read vehicle-types
    Map<String, VehicleType> types = new HashMap<String, VehicleType>();
    List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type");
    for (HierarchicalConfiguration typeConfig : typeConfigs) {
      String typeId = typeConfig.getString("id");
      if (typeId == null) throw new IllegalStateException("typeId is missing.");

      String capacityString = typeConfig.getString("capacity");
      boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)");
      if (capacityString == null && !capacityDimensionsExist) {
        throw new IllegalStateException("capacity of type is not set. use 'capacity-dimensions'");
      }
      if (capacityString != null && capacityDimensionsExist) {
        throw new IllegalStateException(
            "either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
      }

      VehicleTypeImpl.Builder typeBuilder;
      if (capacityString != null) {
        typeBuilder =
            VehicleTypeImpl.Builder.newInstance(typeId)
                .addCapacityDimension(0, Integer.parseInt(capacityString));
      } else {
        typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId);
        List<HierarchicalConfiguration> dimensionConfigs =
            typeConfig.configurationsAt("capacity-dimensions.dimension");
        for (HierarchicalConfiguration dimension : dimensionConfigs) {
          Integer index = dimension.getInt("[@index]");
          Integer value = dimension.getInt("");
          typeBuilder.addCapacityDimension(index, value);
        }
      }
      Double fix = typeConfig.getDouble("costs.fixed");
      Double timeC = typeConfig.getDouble("costs.time");
      Double distC = typeConfig.getDouble("costs.distance");

      if (fix != null) typeBuilder.setFixedCost(fix);
      if (timeC != null) typeBuilder.setCostPerTime(timeC);
      if (distC != null) typeBuilder.setCostPerDistance(distC);
      VehicleType type = typeBuilder.build();
      String id = type.getTypeId();
      String penalty = typeConfig.getString("[@type]");
      if (penalty != null) {
        if (penalty.equals("penalty")) {
          String penaltyFactor = typeConfig.getString("[@penaltyFactor]");
          if (penaltyFactor != null) {
            type = new PenaltyVehicleType(type, Double.parseDouble(penaltyFactor));
          } else type = new PenaltyVehicleType(type);
          id = id + "_penalty";
        }
      }

      types.put(id, type);
    }

    // read vehicles
    List<HierarchicalConfiguration> vehicleConfigs =
        vrpProblem.configurationsAt("vehicles.vehicle");
    boolean doNotWarnAgain = false;
    for (HierarchicalConfiguration vehicleConfig : vehicleConfigs) {
      String vehicleId = vehicleConfig.getString("id");
      if (vehicleId == null) throw new IllegalStateException("vehicleId is missing.");
      Builder builder = VehicleImpl.Builder.newInstance(vehicleId);
      String typeId = vehicleConfig.getString("typeId");
      if (typeId == null) throw new IllegalStateException("typeId is missing.");
      String vType = vehicleConfig.getString("[@type]");
      if (vType != null) {
        if (vType.equals("penalty")) {
          typeId += "_penalty";
        }
      }
      VehicleType type = types.get(typeId);
      if (type == null)
        throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing.");
      builder.setType(type);
      String locationId = vehicleConfig.getString("location.id");
      if (locationId == null) {
        locationId = vehicleConfig.getString("startLocation.id");
      }
      if (locationId == null) throw new IllegalStateException("location.id is missing.");
      builder.setStartLocationId(locationId);
      String coordX = vehicleConfig.getString("location.coord[@x]");
      String coordY = vehicleConfig.getString("location.coord[@y]");
      if (coordX == null || coordY == null) {
        coordX = vehicleConfig.getString("startLocation.coord[@x]");
        coordY = vehicleConfig.getString("startLocation.coord[@y]");
      }
      if (coordX == null || coordY == null) {
        if (!doNotWarnAgain) {
          logger.warn("location.coord is missing. will not warn you again.");
          doNotWarnAgain = true;
        }
      } else {
        Coordinate coordinate =
            Coordinate.newInstance(Double.parseDouble(coordX), Double.parseDouble(coordY));
        builder.setStartLocationCoordinate(coordinate);
      }

      String endLocationId = vehicleConfig.getString("endLocation.id");
      if (endLocationId != null) builder.setEndLocationId(endLocationId);
      String endCoordX = vehicleConfig.getString("endLocation.coord[@x]");
      String endCoordY = vehicleConfig.getString("endLocation.coord[@y]");
      if (endCoordX == null || endCoordY == null) {
        if (!doNotWarnAgain) {
          logger.warn("endLocation.coord is missing. will not warn you again.");
          doNotWarnAgain = true;
        }
      } else {
        Coordinate coordinate =
            Coordinate.newInstance(Double.parseDouble(endCoordX), Double.parseDouble(endCoordY));
        builder.setEndLocationCoordinate(coordinate);
      }

      String start = vehicleConfig.getString("timeSchedule.start");
      String end = vehicleConfig.getString("timeSchedule.end");
      if (start != null) builder.setEarliestStart(Double.parseDouble(start));
      if (end != null) builder.setLatestArrival(Double.parseDouble(end));
      String returnToDepot = vehicleConfig.getString("returnToDepot");
      if (returnToDepot != null) {
        builder.setReturnToDepot(vehicleConfig.getBoolean("returnToDepot"));
      }
      VehicleImpl vehicle = builder.build();
      vrpBuilder.addVehicle(vehicle);
      vehicleMap.put(vehicleId, vehicle);
    }
  }
Exemple #7
0
  private void readServices(XMLConfiguration vrpProblem) {
    List<HierarchicalConfiguration> serviceConfigs =
        vrpProblem.configurationsAt("services.service");
    for (HierarchicalConfiguration serviceConfig : serviceConfigs) {
      String id = serviceConfig.getString("[@id]");
      if (id == null) throw new IllegalStateException("service[@id] is missing.");
      String type = serviceConfig.getString("[@type]");
      if (type == null) type = "service";

      String capacityString = serviceConfig.getString("capacity-demand");
      boolean capacityDimensionsExist =
          serviceConfig.containsKey("capacity-dimensions.dimension(0)");
      if (capacityString == null && !capacityDimensionsExist) {
        throw new IllegalStateException(
            "capacity of service is not set. use 'capacity-dimensions'");
      }
      if (capacityString != null && capacityDimensionsExist) {
        throw new IllegalStateException(
            "either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
      }

      Service.Builder builder;
      if (capacityString != null) {
        builder = serviceBuilderFactory.createBuilder(type, id, Integer.parseInt(capacityString));
      } else {
        builder = serviceBuilderFactory.createBuilder(type, id, null);
        List<HierarchicalConfiguration> dimensionConfigs =
            serviceConfig.configurationsAt("capacity-dimensions.dimension");
        for (HierarchicalConfiguration dimension : dimensionConfigs) {
          Integer index = dimension.getInt("[@index]");
          Integer value = dimension.getInt("");
          builder.addSizeDimension(index, value);
        }
      }
      String serviceLocationId = serviceConfig.getString("locationId");
      if (serviceLocationId != null) builder.setLocationId(serviceLocationId);
      Coordinate serviceCoord = getCoord(serviceConfig, "");
      if (serviceCoord != null) {
        builder.setCoord(serviceCoord);
        if (serviceLocationId != null) {
          //					vrpBuilder.addLocation(serviceLocationId,serviceCoord);
        } else {
          //					vrpBuilder.addLocation(serviceCoord.toString(),serviceCoord);
          builder.setLocationId(serviceCoord.toString());
        }
      }
      if (serviceConfig.containsKey("duration")) {
        builder.setServiceTime(serviceConfig.getDouble("duration"));
      }
      List<HierarchicalConfiguration> deliveryTWConfigs =
          serviceConfig.configurationsAt("timeWindows.timeWindow");
      if (!deliveryTWConfigs.isEmpty()) {
        for (HierarchicalConfiguration twConfig : deliveryTWConfigs) {
          builder.setTimeWindow(
              TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end")));
        }
      }
      Service service = builder.build();
      serviceMap.put(service.getId(), service);
      //			vrpBuilder.addJob(service);

    }
  }
Exemple #8
0
  private void readShipments(XMLConfiguration config) {
    List<HierarchicalConfiguration> shipmentConfigs = config.configurationsAt("shipments.shipment");
    for (HierarchicalConfiguration shipmentConfig : shipmentConfigs) {
      String id = shipmentConfig.getString("[@id]");
      if (id == null) throw new IllegalStateException("shipment[@id] is missing.");

      String capacityString = shipmentConfig.getString("capacity-demand");
      boolean capacityDimensionsExist =
          shipmentConfig.containsKey("capacity-dimensions.dimension(0)");
      if (capacityString == null && !capacityDimensionsExist) {
        throw new IllegalStateException(
            "capacity of shipment is not set. use 'capacity-dimensions'");
      }
      if (capacityString != null && capacityDimensionsExist) {
        throw new IllegalStateException(
            "either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
      }

      Shipment.Builder builder;
      if (capacityString != null) {
        builder =
            Shipment.Builder.newInstance(id).addSizeDimension(0, Integer.parseInt(capacityString));
      } else {
        builder = Shipment.Builder.newInstance(id);
        List<HierarchicalConfiguration> dimensionConfigs =
            shipmentConfig.configurationsAt("capacity-dimensions.dimension");
        for (HierarchicalConfiguration dimension : dimensionConfigs) {
          Integer index = dimension.getInt("[@index]");
          Integer value = dimension.getInt("");
          builder.addSizeDimension(index, value);
        }
      }

      // pickup-locationId
      String pickupLocationId = shipmentConfig.getString("pickup.locationId");
      if (pickupLocationId != null) {
        builder.setPickupLocation(pickupLocationId);
      }

      // pickup-coord
      Coordinate pickupCoord = getCoord(shipmentConfig, "pickup.");
      if (pickupCoord != null) {
        builder.setPickupCoord(pickupCoord);
        if (pickupLocationId != null) {
          //					vrpBuilder.addLocation(pickupLocationId,pickupCoord);
        } else {
          //					vrpBuilder.addLocation(pickupCoord.toString(),pickupCoord);
          builder.setPickupLocation(pickupCoord.toString());
        }
      }
      // pickup-serviceTime
      String pickupServiceTime = shipmentConfig.getString("pickup.duration");
      if (pickupServiceTime != null)
        builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime));

      // pickup-tw
      String pickupTWStart = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).start");
      String pickupTWEnd = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).end");
      if (pickupTWStart != null && pickupTWEnd != null) {
        TimeWindow pickupTW =
            TimeWindow.newInstance(
                Double.parseDouble(pickupTWStart), Double.parseDouble(pickupTWEnd));
        builder.setPickupTimeWindow(pickupTW);
      }

      // delivery-locationId
      String deliveryLocationId = shipmentConfig.getString("delivery.locationId");
      if (deliveryLocationId != null) {
        builder.setDeliveryLocation(deliveryLocationId);
      }

      // delivery-coord
      Coordinate deliveryCoord = getCoord(shipmentConfig, "delivery.");
      if (deliveryCoord != null) {
        builder.setDeliveryCoord(deliveryCoord);
        if (deliveryLocationId != null) {
          //					vrpBuilder.addLocation(deliveryLocationId,deliveryCoord);
        } else {
          //					vrpBuilder.addLocation(deliveryCoord.toString(),deliveryCoord);
          builder.setDeliveryLocation(deliveryCoord.toString());
        }
      }
      // delivery-serviceTime
      String deliveryServiceTime = shipmentConfig.getString("delivery.duration");
      if (deliveryServiceTime != null)
        builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime));

      // delivery-tw
      String delTWStart = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).start");
      String delTWEnd = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).end");
      if (delTWStart != null && delTWEnd != null) {
        TimeWindow delTW =
            TimeWindow.newInstance(Double.parseDouble(delTWStart), Double.parseDouble(delTWEnd));
        builder.setDeliveryTimeWindow(delTW);
      }

      Shipment shipment = builder.build();
      //			vrpBuilder.addJob(shipment);
      shipmentMap.put(shipment.getId(), shipment);
    }
  }