⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capsdconfigfactory.java

📁 opennms得相关源码 请大家看看
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * <code>long</code> value. The address is converted in network byte order     * (big endin). This is compatable with the number format of the JVM, and     * thus the return longs can be compared with other converted IP Addresses     * to determine inclusion.     *      * @param addr     *            The IP address to convert.     *      * @return The converted IP address.     *      * @deprecated Use org.opennms.netmgt.utils.IPSorter.convertToLong()     *             instead.     */    private static long toLong(InetAddress addr) {        byte[] baddr = addr.getAddress();        return ((((long) baddr[0] & 0xffL) << 24) | (((long) baddr[1] & 0xffL) << 16) | (((long) baddr[2] & 0xffL) << 8) | ((long) baddr[3] & 0xffL));    }    /**     * Returns the list of protocol plugins and the associated actions for the     * named address. The currently loaded configuration is used to find, build,     * and return the protocol information. The returns information has all the     * necessary element to check the address for capabilities.     *      * @param address     *            The address to get protocol information for.     *      * @return The array of protocol information instances for the address.     *      */    public ProtocolInfo[] getProtocolSpecification(InetAddress address) {        // get a logger        //        Category log = ThreadCategory.getInstance(CapsdConfigFactory.class);        // The list of protocols that will be turned into        // and array and returned to the caller. These are        // of type ProtocolInfo        //        List lprotos = new ArrayList(m_config.getProtocolPluginCount());        // go through all the defined plugins        //        Enumeration eplugins = m_config.enumerateProtocolPlugin();        PLUGINLOOP: while (eplugins.hasMoreElements()) {            ProtocolPlugin plugin = (ProtocolPlugin) eplugins.nextElement();            boolean found = false;            // Loop through the specific and ranges to find out            // if there is a particular protocol specification            //            Enumeration epluginconf = plugin.enumerateProtocolConfiguration();            PLUGINCONFLOOP: while (epluginconf.hasMoreElements()) {                ProtocolConfiguration pluginConf = (ProtocolConfiguration) epluginconf.nextElement();                // Check specifics first                //                Enumeration espec = pluginConf.enumerateSpecific();                while (espec.hasMoreElements() && !found) {                    String saddr = (String) espec.nextElement();                    try {                        InetAddress taddr = InetAddress.getByName(saddr);                        if (taddr.equals(address)) {                            found = true;                        }                    } catch (UnknownHostException e) {                        log.warn("CapsdConfigFactory: failed to convert address " + saddr + " to InetAddress", e);                    }                }                // check the ranges                //                long laddr = IPSorter.convertToLong(address.getAddress());                Enumeration erange = pluginConf.enumerateRange();                while (erange.hasMoreElements() && !found) {                    Range rng = (Range) erange.nextElement();                    InetAddress start = null;                    try {                        start = InetAddress.getByName(rng.getBegin());                    } catch (UnknownHostException e) {                        log.warn("CapsdConfigFactory: failed to convert address " + rng.getBegin() + " to InetAddress", e);                        continue;                    }                    InetAddress stop = null;                    try {                        stop = InetAddress.getByName(rng.getEnd());                    } catch (UnknownHostException e) {                        log.warn("CapsdConfigFactory: failed to convert address " + rng.getEnd() + " to InetAddress", e);                        continue;                    }                    if (toLong(start) <= laddr && laddr <= toLong(stop)) {                        found = true;                    }                }                // if it has not be found yet then it's not                // in this particular plugin conf, check the                // next                //                if (!found)                    continue;                // if found then build protocol                // specification if on, else next protocol.                //                String scan = null;                if ((scan = pluginConf.getScan()) != null) {                    if (scan.equals("enable")) {                        lprotos.add(new ProtocolInfo(plugin.getProtocol(), (Plugin) m_plugins.get(plugin.getProtocol()), null, AUTO_SET));                        continue PLUGINLOOP;                    } else if (scan.equals("off")) {                        continue PLUGINLOOP;                    }                } else if ((scan = plugin.getScan()) != null) {                    if (scan.equals("off"))                        continue PLUGINLOOP;                }                // it's either on specifically, or by default                // so map it parameters                //                Map params = new TreeMap();                // add the default first                //                Enumeration eparams = plugin.enumerateProperty();                while (eparams.hasMoreElements()) {                    Property p = (Property) eparams.nextElement();                    params.put(p.getKey(), p.getValue());                }                eparams = pluginConf.enumerateProperty();                while (eparams.hasMoreElements()) {                    Property p = (Property) eparams.nextElement();                    params.put(p.getKey(), p.getValue());                }                lprotos.add(new ProtocolInfo(plugin.getProtocol(), (Plugin) m_plugins.get(plugin.getProtocol()), params, SCAN));            } // end ProtocolConfiguration loop            if (!found) // use default config            {                // if found then build protocol                // specification if on, else next protocol.                //                String scan = null;                if ((scan = plugin.getScan()) != null) {                    if (scan.equals("off"))                        continue PLUGINLOOP;                }                // it's either on specifically, or by default                // so map it parameters                //                Map params = new TreeMap();                // add the default first                //                Enumeration eparams = plugin.enumerateProperty();                while (eparams.hasMoreElements()) {                    Property p = (Property) eparams.nextElement();                    params.put(p.getKey(), p.getValue());                }                lprotos.add(new ProtocolInfo(plugin.getProtocol(), (Plugin) m_plugins.get(plugin.getProtocol()), params, SCAN));            }        } // end ProtocolPlugin        // copy the protocol information to        // the approriate array and return that        // result        //        ProtocolInfo[] result = new ProtocolInfo[lprotos.size()];        return (ProtocolInfo[]) lprotos.toArray(result);    }    /**     * Returns the protocol identifier from the service table that was loaded     * during class initialization. The identifier is used determines the     * result. If a String is passed then the integer value is returned. If an     * interger value is passed then the string protocol name is returned.     *      * @param key     *            The value used to lookup the result in in the preloaded map.     *      * @return The result of the lookup, either a String or an Integer.     *      */    public Object getServiceIdentifier(Object key) {        return m_serviceIds.get(key);    }    /**     * Finds the SMB authentication object using the netbios name.     *      * The target of the search.     */    public SmbAuth getSmbAuth(String target) {        SmbConfig cfg = m_config.getSmbConfig();        if (cfg != null) {            Enumeration es = cfg.enumerateSmbAuth();            while (es.hasMoreElements()) {                SmbAuth a = (SmbAuth) es.nextElement();                if (a.getContent() != null && a.getContent().equalsIgnoreCase(target))                    return a;            }        }        return null;    }    /**     * Checks the configuration to determine if the target is managed or     * unmanaged.     *      * @param target     *            The target to check against.     */    public boolean isAddressUnmanaged(InetAddress target) {        Category log = ThreadCategory.getInstance(CapsdConfigFactory.class);        String temp = m_config.getManagementPolicy();        boolean managed_by_default = (temp == null || temp.equalsIgnoreCase("managed"));        boolean found_denial = false;        boolean found_accept = false;        Enumeration e = m_config.enumerateIpManagement();        while (e.hasMoreElements() && !found_denial) {            IpManagement mgt = (IpManagement) e.nextElement();            Enumeration f = mgt.enumerateSpecific();            while (f.hasMoreElements()) {                String saddr = f.nextElement().toString();                try {                    InetAddress addr = InetAddress.getByName(saddr);                    if (addr.equals(target)) {                        if (mgt.getPolicy() == null || mgt.getPolicy().equalsIgnoreCase("managed"))                            found_accept = true;                        else                            found_denial = true;                        break;                    }                } catch (UnknownHostException ex) {                    log.info("Failed to convert management address " + saddr + " to an InetAddress", ex);                }            }            // now check the ranges            //            f = mgt.enumerateRange();            while (!found_denial && f.hasMoreElements()) {                Range rng = (Range) f.nextElement();                try {                    InetAddress saddr = InetAddress.getByName(rng.getBegin());                    InetAddress eaddr = InetAddress.getByName(rng.getEnd());                    long start = toLong(saddr);                    long stop = toLong(eaddr);                    long tgt = toLong(target);                    if (start <= tgt && tgt <= stop) {                        if (mgt.getPolicy() == null || mgt.getPolicy().equalsIgnoreCase("managed"))                            found_accept = true;                        else                            found_denial = true;                        break;                    }                } catch (UnknownHostException ex) {                    log.info("Failed to convert management addresses (" + rng.getBegin() + ", " + rng.getEnd() + ")", ex);                }            }            // now check urls            //            f = mgt.enumerateIncludeUrl();            boolean match = false;            while (!found_denial && !match && f.hasMoreElements()) {                String url = f.nextElement().toString();                // Retrieve address list from url map                List addresses = (List) m_urlMap.get(url);                // Iterate over addresses looking for target match                Iterator iter = addresses.iterator();                while (iter.hasNext()) {                    String saddr = (String) iter.next();                    try {                        InetAddress addr = InetAddress.getByName(saddr);                        if (addr.equals(target)) {                            if (mgt.getPolicy() == null || mgt.getPolicy().equalsIgnoreCase("managed"))                                found_accept = true;                            else                                found_denial = true;                            match = true;                            break;                        }                    } catch (UnknownHostException ex) {                        log.info("Failed to convert management address " + saddr + " to an InetAddress", ex);                    }                }            }        }        boolean result = !managed_by_default;        if (found_denial)            result = t

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -