/** Armazenamento de cache em disco. */ public static synchronized void store() { if (HANDLE_CHANGED) { try { Server.logDebug("Storing handle.map..."); FileOutputStream outputStream = new FileOutputStream("handle.map"); try { SerializationUtils.serialize(HANDLE_MAP, outputStream); // Atualiza flag de atualização. HANDLE_CHANGED = false; } finally { outputStream.close(); } } catch (Exception ex) { Server.logError(ex); } } }
/** Carregamento de cache do disco. */ public static synchronized void load() { Server.logDebug("Loading handle.map..."); File file = new File("handle.map"); if (file.exists()) { try { FileInputStream fileInputStream = new FileInputStream(file); try { HashMap<String, Handle> map = SerializationUtils.deserialize(fileInputStream); HANDLE_MAP.putAll(map); } finally { fileInputStream.close(); } } catch (Exception ex) { Server.logError(ex); } } }
/** Carregamento de cache do disco. */ public static synchronized void load() { long time = System.currentTimeMillis(); File file = new File("owner.map"); if (file.exists()) { try { HashMap<String, Owner> map; FileInputStream fileInputStream = new FileInputStream(file); try { map = SerializationUtils.deserialize(fileInputStream); } finally { fileInputStream.close(); } OWNER_MAP.putAll(map); Server.logLoad(time, file); } catch (Exception ex) { Server.logError(ex); } } }
/** Armazenamento de cache em disco. */ public static synchronized void store() { if (OWNER_CHANGED) { try { long time = System.currentTimeMillis(); File file = new File("owner.map"); FileOutputStream outputStream = new FileOutputStream(file); try { SerializationUtils.serialize(OWNER_MAP, outputStream); // Atualiza flag de atualização. OWNER_CHANGED = false; } finally { outputStream.close(); } Server.logStore(time, file); } catch (Exception ex) { Server.logError(ex); } } }
/** * Altera a data de criação do registro. * * @param created a nova data de criação do registro. * @throws ProcessException se houver falha no processamento. */ public void setCreated(String created) throws ProcessException { if (created == null) { throw new ProcessException("ERROR: INVALID CREATED"); } else { try { Date createdDate = DATE_FORMATTER.parse(created); if (!createdDate.equals(this.created)) { this.created = createdDate; // Atualiza flag de atualização. HANDLE_CHANGED = true; } } catch (ParseException ex) { Server.logError(ex); throw new ProcessException("ERROR: PARSING CREATED " + created); } } }
/** * Altera a data de allteração do registro. * * @param changed a nova data de alteração do registro. * @throws ProcessException se houver falha no processamento. */ public void setChanged(String changed) throws ProcessException { if (changed == null) { throw new ProcessException("ERROR: CREATED CHANGED"); } else if (changed.length() == 0) { if (this.changed != null) { this.changed = null; // Atualiza flag de atualização. HANDLE_CHANGED = true; } } else { try { Date changedDate = DATE_FORMATTER.parse(changed); if (!changedDate.equals(this.changed)) { this.changed = changedDate; // Atualiza flag de atualização. HANDLE_CHANGED = true; } } catch (ParseException ex) { Server.logError(ex); throw new ProcessException("ERROR: PARSING CHANGED " + changed); } } }
/** * 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. reducedLocal = true; } 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); } }
private boolean refresh() throws ProcessException { server = Server.WHOIS_BR; // Temporário até final de transição. String result = Server.whoisID(ownerid, server); String ownerResult = refresh(result); return ownerid.equals(ownerResult); }