networkmodule.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 888 行 · 第 1/2 页
JAVA
888 行
return false; DirContext ictx = new InitialDirContext(); Attributes attributes; if (type.equals("ANY") || type.equals("ALL")) attributes = ictx.getAttributes("dns:/" + hostname); else attributes = ictx.getAttributes("dns:/" + hostname, new String[] { type }); ArrayValue hosts = new ArrayValueImpl(); ArrayValue weights = new ArrayValueImpl(); NamingEnumeration list = attributes.getAll(); if (! (list.hasMore())) return false; while (list.hasMore()) { Attribute record = (Attribute) list.next(); String id = record.getID(); NamingEnumeration attrList = record.getAll(); while (attrList.hasMore()) { String target = String.valueOf(attrList.next()); if (target.endsWith(".")) target = target.substring(0, target.length() -1); int weight = 0; if ("MX".equals(id)) { int space = target.indexOf(" "); if (space > -1) { String priorityPart = target.substring(0, space); String hostPart = target.substring(space + 1); target = hostPart; try { weight = Integer.valueOf(priorityPart); } catch (NumberFormatException ex) { log.log(Level.FINE, ex.toString(), ex); } } } weights.append(LongValue.create(weight)); hosts.append(StringValue.create(target)); } } ArrayModule.array_multisort(env, new Value[] { weights, hosts }); if (hostsRef != null) hostsRef.set(hosts); if (weightRef != null) weightRef.set(weights); return true; } catch (NameNotFoundException e) { return false; } catch (NamingException e) { throw new QuercusModuleException(e); } } /** * Finds the mx hosts for the given hostname, placing them in mxhosts and * their corresponding weights in weight, if provided. Returns true if any * hosts were found. False otherwise. * * @param hostname the hostname to find records for * @param mxhosts an array to add the mx hosts to * @param weight an array to add the weights to * * @return true if records are found, false otherwise */ public static boolean dns_get_mx(Env env, @NotNull String hostname, @Reference Value mxhosts, @Optional @Reference Value weight) { return dns_get(env, hostname, "MX", mxhosts, weight); } public static boolean checkdnsrr(Env env, @NotNull String hostname, @Optional("MX") String type) { return dns_get(env, hostname, type, null, null); } /** * Finds the mx hosts for the given hostname, placing them in mxhosts and * their corresponding weights in weight, if provided. Returns true if any * hosts were found. False otherwise. * * @param hostname the hostname to find records for * * @return true if records are found, false otherwise */ public static boolean dns_check_record(Env env, @NotNull String hostname, @Optional("MX") String type) { return dns_get(env, hostname, type, null, null); } public ArrayValue dns_get_record(Env env, @NotNull String hostname, @Optional("-1") int type, @Optional @Reference Value authnsRef, @Optional @Reference Value addtlRef) { ArrayValue result = new ArrayValueImpl(); ArrayValueImpl authns = null; if (authnsRef != null && !authnsRef.isNull()) { authns = new ArrayValueImpl(); authnsRef.set(authns); env.stub("authns unimplemented"); } ArrayValueImpl addtl = null; if (addtlRef != null && !addtlRef.isNull()) { addtl = new ArrayValueImpl(); addtlRef.set(addtl); env.stub("addtl unimplemented"); } if (hostname == null) return result; if (type == -1) type = DNS_ANY; String typeName; switch (type) { case DNS_A: typeName = "A"; break; case DNS_CNAME: typeName = "CNAME"; break; case DNS_HINFO: typeName = "HINFO"; break; case DNS_MX: typeName = "MX"; break; case DNS_NS: typeName = "NS"; break; case DNS_PTR: typeName = "PTR"; break; case DNS_SOA: typeName = "SOA"; break; case DNS_TXT: typeName = "TXT"; break; case DNS_AAAA: typeName = "AAAA"; break; case DNS_SRV: typeName = "SRV"; break; case DNS_NAPTR: typeName = "NAPTR"; break; case DNS_A6: typeName = "A6"; break; default: typeName = null; } try { DirContext ictx = new InitialDirContext(); Attributes attributes; if (typeName == null) attributes = ictx.getAttributes("dns:/" + hostname); else attributes = ictx.getAttributes("dns:/" + hostname, new String[] { typeName }); NamingEnumeration list = attributes.getAll(); while (list.hasMore()) { Attribute record = (Attribute) list.next(); String id = record.getID(); NamingEnumeration attrList = record.getAll(); while (attrList.hasMore()) { String attr = String.valueOf(attrList.next()); String target = attr; if (target.endsWith(".")) target = target.substring(0, target.length() -1); ArrayValueImpl recordValue = new ArrayValueImpl(); recordValue.put("host", hostname); recordValue.put("type", id); if ("MX".equals(id)) { int space = target.indexOf(" "); if (space > -1) { String priorityPart = target.substring(0, space); String hostPart = target.substring(space + 1); try { recordValue.put("pri", Integer.valueOf(priorityPart)); target = hostPart; } catch (NumberFormatException ex) { log.log(Level.FINE, ex.toString(), ex); } } } else if ("A".equals(id)) { try { recordValue.put("ip", target); target = null; } catch (Exception e) { log.log(Level.FINE, e.toString(), e); } } if (target != null) recordValue.put("target", target); result.put(recordValue); } } } catch (NameNotFoundException ex) { log.log(Level.FINER, ex.toString(), ex); } catch (NamingException ex) { throw new QuercusModuleException(ex); } return result; } /** * Initialization of syslog. */ public static Value define_syslog_variables(Env env) { env.stub("unimplemented"); return NullValue.NULL; } /** * Opens syslog. * * XXX: stubbed for now */ public static boolean openlog(Env env, String ident, int option, int facility) { env.stub("unimplemented"); return true; } /** * Closes syslog. */ public static boolean closelog() { return true; } /** * syslog */ public static boolean syslog(Env env, int priority, String message) { Level level = Level.OFF; switch (priority) { case LOG_EMERG: case LOG_ALERT: case LOG_CRIT: level = Level.SEVERE; break; case LOG_ERR: case LOG_WARNING: level = Level.WARNING; break; case LOG_NOTICE: level = Level.CONFIG; break; case LOG_INFO: level = Level.INFO; break; case LOG_DEBUG: level = Level.FINE; break; } env.getLogger().log(level, message); return true; } private static class ServiceNode { private LongValue _port; private boolean _isTCP; private boolean _isUDP; ServiceNode(int port, boolean tcp, boolean udp) { _port = LongValue.create(port); _isTCP = tcp; _isUDP = udp; } public LongValue getPort() { return _port; } public boolean protocolCheck(String protocol) { if (protocol.equals("tcp")) return _isTCP; else if (protocol.equals("udp")) return _isUDP; else return false; } public boolean isTCP() { return _isTCP; } public boolean isUDP() { return _isUDP; } } static { _protoToNum.put("ip", LongValue.create(0)); _protoToNum.put("icmp", LongValue.create(1)); _protoToNum.put("ggp", LongValue.create(3)); _protoToNum.put("tcp", LongValue.create(6)); _protoToNum.put("egp", LongValue.create(8)); _protoToNum.put("pup", LongValue.create(12)); _protoToNum.put("udp", LongValue.create(17)); _protoToNum.put("hmp", LongValue.create(12)); _protoToNum.put("xns-idp", LongValue.create(22)); _protoToNum.put("rdp", LongValue.create(27)); _protoToNum.put("rvd", LongValue.create(66)); _servToNum.put("echo", new ServiceNode(7, true, true)); _servToNum.put("discard", new ServiceNode(9, true, true)); _servToNum.put("systat", new ServiceNode(11, true, true)); _servToNum.put("daytime", new ServiceNode(13, true, true)); _servToNum.put("qotd", new ServiceNode(17, true, true)); _servToNum.put("chargen", new ServiceNode(19, true, true)); _servToNum.put("ftp-data", new ServiceNode(20, true, false)); _servToNum.put("ftp", new ServiceNode(21, true, false)); _servToNum.put("telnet", new ServiceNode(23, true, false)); _servToNum.put("smtp", new ServiceNode(25, true, false)); _servToNum.put("time", new ServiceNode(37, true, true)); _servToNum.put("rlp", new ServiceNode(39, false, true)); _servToNum.put("nameserver", new ServiceNode(42, true, true)); _servToNum.put("nicname", new ServiceNode(43, true, false)); _servToNum.put("domain", new ServiceNode(53, true, true)); _servToNum.put("bootps", new ServiceNode(67, false, true)); _servToNum.put("bootpc", new ServiceNode(68, false, true)); _servToNum.put("tftp", new ServiceNode(69, false, true)); _servToNum.put("gopher", new ServiceNode(70, true, false)); _servToNum.put("finger", new ServiceNode(79, true, false)); _servToNum.put("http", new ServiceNode(80, true, false)); _servToNum.put("kerberos", new ServiceNode(88, true, true)); _servToNum.put("hostname", new ServiceNode(101, true, false)); _servToNum.put("iso-tsap", new ServiceNode(102, true, false)); _servToNum.put("rtelnet", new ServiceNode(107, true, false)); _servToNum.put("pop2", new ServiceNode(109, true, false)); _servToNum.put("pop3", new ServiceNode(110, true, false)); _servToNum.put("sunrpc", new ServiceNode(111, true, true)); _servToNum.put("auth", new ServiceNode(113, true, false)); _servToNum.put("uucp-path", new ServiceNode(117, true, false)); _servToNum.put("nntp", new ServiceNode(119, true, false)); _servToNum.put("ntp", new ServiceNode(123, false, true)); _servToNum.put("epmap", new ServiceNode(135, true, true)); _servToNum.put("netbios-ns", new ServiceNode(137, true, true)); _servToNum.put("netbios-dgm", new ServiceNode(138, false, true)); _servToNum.put("netbios-ssn", new ServiceNode(139, true, false)); _servToNum.put("imap", new ServiceNode(143, true, false)); _servToNum.put("pcmail-srv", new ServiceNode(158, true, false)); _servToNum.put("snmp", new ServiceNode(161, false, true)); _servToNum.put("snmptrap", new ServiceNode(162, false, true)); _servToNum.put("print-srv", new ServiceNode(170, true, false)); _servToNum.put("bgp", new ServiceNode(179, true, false)); _servToNum.put("irc", new ServiceNode(194, true, false)); _servToNum.put("ipx", new ServiceNode(213, false, true)); _servToNum.put("ldap", new ServiceNode(389, true, false)); _servToNum.put("https", new ServiceNode(443, true, true)); _servToNum.put("microsoft-ds", new ServiceNode(445, true, true)); _servToNum.put("kpasswd", new ServiceNode(464, true, true)); _servToNum.put("isakmp", new ServiceNode(500, false, true)); _servToNum.put("exec", new ServiceNode(512, true, false)); _servToNum.put("biff", new ServiceNode(512, false, true)); _servToNum.put("login", new ServiceNode(513, true, false)); _servToNum.put("who", new ServiceNode(513, false, true)); _servToNum.put("cmd", new ServiceNode(514, true, false)); _servToNum.put("syslog", new ServiceNode(514, false, true)); _servToNum.put("printer", new ServiceNode(515, true, false)); _servToNum.put("talk", new ServiceNode(517, false, true)); _servToNum.put("ntalk", new ServiceNode(518, false, true)); _servToNum.put("efs", new ServiceNode(520, true, false)); _servToNum.put("router", new ServiceNode(520, false, true)); _servToNum.put("timed", new ServiceNode(525, false, true)); _servToNum.put("tempo", new ServiceNode(526, true, false)); _servToNum.put("courier", new ServiceNode(530, true, false)); _servToNum.put("conference", new ServiceNode(531, true, false)); _servToNum.put("netnews", new ServiceNode(532, true, false)); _servToNum.put("netwall", new ServiceNode(533, false, true)); _servToNum.put("uucp", new ServiceNode(540, true, false)); _servToNum.put("klogin", new ServiceNode(543, true, false)); _servToNum.put("kshell", new ServiceNode(544, true, false)); _servToNum.put("new-rwho", new ServiceNode(550, false, true)); _servToNum.put("remotefs", new ServiceNode(556, true, false)); _servToNum.put("rmonitor", new ServiceNode(560, false, true)); _servToNum.put("monitor", new ServiceNode(561, false, true)); _servToNum.put("ldaps", new ServiceNode(636, true, false)); _servToNum.put("doom", new ServiceNode(666, true, true)); _servToNum.put("kerberos-adm", new ServiceNode(749, true, true)); _servToNum.put("kerberos-iv", new ServiceNode(750, false, true)); _servToNum.put("kpop", new ServiceNode(1109, true, false)); _servToNum.put("phone", new ServiceNode(1167, false, true)); _servToNum.put("ms-sql-s", new ServiceNode(1433, true, true)); _servToNum.put("ms-sql-m", new ServiceNode(1434, true, true)); _servToNum.put("wins", new ServiceNode(1512, true, true)); _servToNum.put("ingreslock", new ServiceNode(1524, true, false)); _servToNum.put("12tp", new ServiceNode(1701, false, true)); _servToNum.put("pptp", new ServiceNode(1723, true, false)); _servToNum.put("radius", new ServiceNode(1812, false, true)); _servToNum.put("radacct", new ServiceNode(1813, false, true)); _servToNum.put("nfsd", new ServiceNode(2049, false, true)); _servToNum.put("knetd", new ServiceNode(2053, true, false)); _servToNum.put("man", new ServiceNode(9535, true, false)); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?