コード例 #1
0
ファイル: Weights.java プロジェクト: dengtong/godlike
 public boolean update(Weight weight, Map<String, Object> context) {
   if (!super.currentUser.hasServicePrivilege(weight.getService())) {
     context.put("message", getMessage("HaveNoServicePrivilege", weight.getService()));
     return false;
   }
   weight.setAddress(Tool.getIP(weight.getAddress()));
   overrideService.updateOverride(OverrideUtils.weightToOverride(weight));
   return true;
 }
コード例 #2
0
ファイル: Weights.java プロジェクト: dengtong/godlike
  /**
   * 删除动作
   *
   * @param ids
   * @return
   */
  public boolean delete(Long[] ids, Map<String, Object> context) {
    for (Long id : ids) {
      Weight w = OverrideUtils.overrideToWeight(overrideService.findById(id));
      if (!super.currentUser.hasServicePrivilege(w.getService())) {
        context.put("message", getMessage("HaveNoServicePrivilege", w.getService()));
        return false;
      }
    }

    for (Long id : ids) {
      overrideService.deleteOverride(id);
    }
    return true;
  }
コード例 #3
0
ファイル: Weights.java プロジェクト: dengtong/godlike
  public boolean create(Map<String, Object> context) throws Exception {
    String addr = (String) context.get("address");
    String services = (String) context.get("multiservice");
    if (services == null || services.trim().length() == 0) {
      services = (String) context.get("service");
    }
    String weight = (String) context.get("weight");

    int w = Integer.parseInt(weight);

    Set<String> addresses = new HashSet<String>();
    BufferedReader reader = new BufferedReader(new StringReader(addr));
    while (true) {
      String line = reader.readLine();
      if (null == line) break;

      String[] split = line.split("[\\s,;]+");
      for (String s : split) {
        if (s.length() == 0) continue;

        String ip = s;
        String port = null;
        if (s.indexOf(":") != -1) {
          ip = s.substring(0, s.indexOf(":"));
          port = s.substring(s.indexOf(":") + 1, s.length());
          if (port.trim().length() == 0) port = null;
        }
        if (!IP_PATTERN.matcher(ip).matches()) {
          context.put("message", "illegal IP: " + s);
          return false;
        }
        if (LOCAL_IP_PATTERN.matcher(ip).matches() || ALL_IP_PATTERN.matcher(ip).matches()) {
          context.put("message", "local IP or any host ip is illegal: " + s);
          return false;
        }
        if (port != null) {
          if (!NumberUtils.isDigits(port)) {
            context.put("message", "illegal port: " + s);
            return false;
          }
        }
        addresses.add(s);
      }
    }

    Set<String> aimServices = new HashSet<String>();
    reader = new BufferedReader(new StringReader(services));
    while (true) {
      String line = reader.readLine();
      if (null == line) break;

      String[] split = line.split("[\\s,;]+");
      for (String s : split) {
        if (s.length() == 0) continue;
        if (!super.currentUser.hasServicePrivilege(s)) {
          context.put("message", getMessage("HaveNoServicePrivilege", s));
          return false;
        }
        aimServices.add(s);
      }
    }

    for (String aimService : aimServices) {
      for (String a : addresses) {
        Weight wt = new Weight();
        wt.setUsername((String) context.get("operator"));
        wt.setAddress(Tool.getIP(a));
        wt.setService(aimService);
        wt.setWeight(w);
        overrideService.saveOverride(OverrideUtils.weightToOverride(wt));
      }
    }
    return true;
  }