Exemple #1
0
 /**
  * Atualiza os campos do registro com resultado do WHOIS.
  *
  * @param result o resultado do WHOIS.
  * @return o ownerid real apresentado no resultado do WHOIS.
  * @throws QueryException se houver alguma falha da atualização do registro.
  */
 private String refresh(String result) throws ProcessException {
   try {
     boolean reducedLocal = false;
     String owneridResult = null;
     BufferedReader reader = new BufferedReader(new StringReader(result));
     try {
       String line;
       while ((line = reader.readLine()) != null) {
         line = line.trim();
         if (line.startsWith("owner:")) {
           int index = line.indexOf(':') + 1;
           owner = line.substring(index).trim();
         } else if (line.startsWith("ownerid:")) {
           int index = line.indexOf(':') + 1;
           owneridResult = line.substring(index).trim();
         } else if (line.startsWith("responsible:")) {
           int index = line.indexOf(':') + 1;
           responsible = line.substring(index).trim();
         } else if (line.startsWith("country:")) {
           int index = line.indexOf(':') + 1;
           country = line.substring(index).trim();
         } else if (line.startsWith("owner-c:")) {
           int index = line.indexOf(':') + 1;
           owner_c = line.substring(index).trim();
         } else if (line.startsWith("domain:")) {
           int index = line.indexOf(':') + 1;
           String domain = line.substring(index).trim();
           domainList.add(domain);
         } else if (line.startsWith("created:")) {
           int index = line.indexOf(':') + 1;
           String valor = line.substring(index).trim();
           if (valor.startsWith("before ")) {
             index = line.indexOf(' ');
             valor = valor.substring(index);
           }
           created = DATE_FORMATTER.parse(valor);
         } else if (line.startsWith("changed:")) {
           int index = line.indexOf(':') + 1;
           changed = DATE_FORMATTER.parse(line.substring(index).trim());
         } else if (line.startsWith("provider:")) {
           int index = line.indexOf(':') + 1;
           provider = line.substring(index).trim();
         } else if (line.startsWith("nic-hdl-br:")) {
           int index = line.indexOf(':') + 1;
           String nic_hdl_br = line.substring(index).trim();
           line = reader.readLine().trim();
           index = line.indexOf(':') + 1;
           String person = line.substring(index).trim();
           line = reader.readLine().trim();
           index = line.indexOf(':') + 1;
           String e_mail;
           if (reducedLocal) {
             e_mail = null;
           } else {
             e_mail = line.substring(index).trim();
             line = reader.readLine().trim();
             index = line.indexOf(':') + 1;
           }
           String created2 = line.substring(index).trim();
           line = reader.readLine().trim();
           index = line.indexOf(':') + 1;
           String changed2 = line.substring(index).trim();
           Handle handle = Handle.getHandle(nic_hdl_br);
           handle.setPerson(person);
           handle.setEmail(e_mail);
           handle.setCreated(created2);
           handle.setChanged(changed2);
         } else if (line.startsWith("% No match for domain")) {
           throw new ProcessException("ERROR: OWNER NOT FOUND");
         } else if (line.startsWith("% Permission denied.")) {
           throw new ProcessException("ERROR: WHOIS DENIED");
         } else if (line.startsWith("% Permissão negada.")) {
           throw new ProcessException("ERROR: WHOIS DENIED");
         } else if (line.startsWith("% Maximum concurrent connections limit exceeded")) {
           throw new ProcessException("ERROR: WHOIS CONCURRENT");
         } else if (line.startsWith("% Query rate limit exceeded. Reduced information.")) {
           // Informação reduzida devido ao estouro de limite de consultas.
           Server.removeWhoisQueryHour();
           reducedLocal = true;
         } else if (line.startsWith("% Query rate limit exceeded")) {
           // Restrição total devido ao estouro de limite de consultas.
           Server.removeWhoisQueryDay();
           throw new ProcessException("ERROR: WHOIS QUERY LIMIT");
         } else if (line.length() > 0 && Character.isLetter(line.charAt(0))) {
           Server.logError("Linha não reconhecida: " + line);
         }
       }
     } finally {
       reader.close();
     }
     if (owneridResult == null) {
       throw new ProcessException("ERROR: OWNER NOT FOUND");
     } else {
       this.lastRefresh = System.currentTimeMillis();
       this.reduced = reducedLocal;
       this.queries = 1;
       // Atualiza flag de atualização.
       OWNER_CHANGED = true;
       // Retorna o ownerid real indicado pelo WHOIS.
       return owneridResult;
     }
   } catch (ProcessException ex) {
     throw ex;
   } catch (Exception ex) {
     Server.logError(ex);
     throw new ProcessException("ERROR: PARSING", ex);
   }
 }