X-Git-Url: http://git.megacz.com/?p=org.ibex.jinetd.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjinetd%2FHost.java;h=d745222a367109f16367001898ee9f4b9d92d8b0;hp=a5c392359f472beef5410af596254d77437a4633;hb=c28d954263d3a9b5f8ea3ff37368ae811ff48f6c;hpb=70604175e53b4c6ca71a82108f35e74b1ac1993a diff --git a/src/org/ibex/jinetd/Host.java b/src/org/ibex/jinetd/Host.java index a5c3923..d745222 100644 --- a/src/org/ibex/jinetd/Host.java +++ b/src/org/ibex/jinetd/Host.java @@ -6,25 +6,63 @@ package org.ibex.jinetd; import org.ibex.util.*; import java.io.*; import java.util.*; +import java.net.*; import java.lang.reflect.*; -public class Host extends Loader { +public class Host extends TreeClassLoader { - final String hostname; - public Host(String path, String hostname) { super(path); this.hostname = hostname; } + public final String hostname; + public final String path; - public void changed(Watched w) { - super.changed(w); - Log.debug(this, "changed(" + w + ")"); + private static final Hashtable hosts = new Hashtable(); + private static boolean initted = false; + + public static Host getHost(String hostname) { return (Host)hosts.get(hostname); } + public static Enumeration enumerateHosts() { return hosts.elements(); } + + public Host(String path, String hostname, ClassLoader pcl) { + super(new File(path + File.separatorChar + "WEB-INF"), pcl); + this.hostname = hostname; + this.path = path; + } + + public static void init() { + if (initted) return; + initted = true; + init(org.ibex.jinetd.Main.ROOT + "/host", "", 0, Main.getRootClassLoader()); + } + public static void init(String path, String host, int depth, ClassLoader pcl) { + if (!new File(path).exists() || !new File(path).isDirectory()) return; try { - ClassLoader cl = getClassLoader(); - if (cl == null) return; - Class c = cl.loadClass("Main"); - if (c == null) return; - Method m = c.getMethod("main", new Class[] { }); - m.invoke(null, new Object[] { }); - } catch (Exception e) { - Log.warn(this, "nope"); + Log.warn(Host.class, "resolving " + host); + InetAddress addr = InetAddress.getByName(host); + + /* + boolean good = false; + try { + if (NetworkInterface.getByInetAddress(addr) != null) good = true; + if (!good) Log.warn(Host.class, "host " + host + "resolves to " + addr + " which is not local"); + } catch (Exception e) { + Log.warn(Host.class, "host " + host + "resolves to " + addr + " which is not local because:"); + Log.warn(Host.class, e); + } + if (!good) return; + */ + + if (new File(path + File.separatorChar + "WEB-INF").exists()) { + String pad = ""; + while(pad.length() + host.length() < 30) pad += " "; + Log.info(Main.class, pad + host + " => " + path); + hosts.put(host, pcl = new Host(path, host, pcl)); + if (!"ibex.org".equals(host)) return; + } + } catch (UnknownHostException e) { + if (depth >= 3) return; } + String[] subdirs = new File(path).list(); + if (subdirs != null) + for(int i=0; i