-
- // ProxyAutoConfigRootJSScope ////////////////////////////////////////////////////////////////////
- /*
- public static class ProxyAutoConfigRootScope extends JSScope.Global {
-
- public ProxyAutoConfigRootScope() { super(); }
-
- public Object get(Object name) throws JSExn {
- // #switch(name)
- case "isPlainHostName": return METHOD;
- case "dnsDomainIs": return METHOD;
- case "localHostOrDomainIs": return METHOD;
- case "isResolvable": return METHOD;
- case "isInNet": return METHOD;
- case "dnsResolve": return METHOD;
- case "myIpAddress": return METHOD;
- case "dnsDomainLevels": return METHOD;
- case "shExpMatch": return METHOD;
- case "weekdayRange": return METHOD;
- case "dateRange": return METHOD;
- case "timeRange": return METHOD;
- case "ProxyConfig": return ProxyConfig;
- // #end
- return super.get(name);
- }
-
- private static final JS proxyConfigBindings = new JS();
- private static final JS ProxyConfig = new JS() {
- public Object get(Object name) {
- if (name.equals("bindings")) return proxyConfigBindings;
- return null;
- }
- };
-
- public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
- // #switch(method)
- case "isPlainHostName": return (a0.toString().indexOf('.') == -1) ? Boolean.TRUE : Boolean.FALSE;
- case "dnsDomainIs": return (a0.toString().endsWith(a1.toString())) ? Boolean.TRUE : Boolean.FALSE;
- case "localHostOrDomainIs":
- return (a0.equals(a1) || (a0.toString().indexOf('.') == -1 && a1.toString().startsWith(a0.toString()))) ? T:F;
- case "isResolvable": try {
- return (InetAddress.getByName(a0.toString()) != null) ? Boolean.TRUE : Boolean.FALSE;
- } catch (UnknownHostException e) { return F; }
- case "isInNet":
- if (nargs != 3) return Boolean.FALSE;
- try {
- byte[] host = InetAddress.getByName(a0.toString()).getAddress();
- byte[] net = InetAddress.getByName(a1.toString()).getAddress();
- byte[] mask = InetAddress.getByName(a2.toString()).getAddress();
- return ((host[0] & mask[0]) == net[0] &&
- (host[1] & mask[1]) == net[1] &&
- (host[2] & mask[2]) == net[2] &&
- (host[3] & mask[3]) == net[3]) ?
- Boolean.TRUE : Boolean.FALSE;
- } catch (Exception e) {
- throw new JSExn("exception in isInNet(): " + e);
- }
- case "dnsResolve":
- try {
- return InetAddress.getByName(a0.toString()).getHostAddress();
- } catch (UnknownHostException e) {
- return null;
- }
- case "myIpAddress":
- try {
- return InetAddress.getLocalHost().getHostAddress();
- } catch (UnknownHostException e) {
- if (Log.on) Log.info(this, "strange... host does not know its own address");
- return null;
- }
- case "dnsDomainLevels":
- String s = a0.toString();
- int i = 0;
- while((i = s.indexOf('.', i)) != -1) i++;
- return new Integer(i);
- case "shExpMatch":
- StringTokenizer st = new StringTokenizer(a1.toString(), "*", false);
- String[] arr = new String[st.countTokens()];
- String s = a0.toString();
- for (int i=0; st.hasMoreTokens(); i++) arr[i] = st.nextToken();
- return match(arr, s, 0) ? Boolean.TRUE : Boolean.FALSE;
- case "weekdayRange":
- TimeZone tz = (nargs < 3 || a2 == null || !a2.equals("GMT")) ?
- TimeZone.getTimeZone("UTC") : TimeZone.getDefault();
- Calendar c = new GregorianCalendar();
- c.setTimeZone(tz);
- c.setTime(new java.util.Date());
- java.util.Date d = c.getTime();
- int day = d.getDay();
- String d1s = a0.toString().toUpperCase();
- int d1 = 0, d2 = 0;
- for(int i=0; i<days.length; i++) if (days[i].equals(d1s)) d1 = i;
-
- if (nargs == 1)
- return d1 == day ? Boolean.TRUE : Boolean.FALSE;
-
- String d2s = a1.toString().toUpperCase();
- for(int i=0; i<days.length; i++) if (days[i].equals(d2s)) d2 = i;
-
- return ((d1 <= d2 && day >= d1 && day <= d2) || (d1 > d2 && (day >= d1 || day <= d2))) ? T : F;
-
- case "dateRange": throw new JSExn("Ibex does not support dateRange() in PAC scripts");
- case "timeRange": throw new JSExn("Ibex does not support timeRange() in PAC scripts");
- // #end
- return super.callMethod(method, a0, a1, a2, rest, nargs);
- }
- private static boolean match(String[] arr, String s, int index) {
- if (index >= arr.length) return true;
- for(int i=0; i<s.length(); i++) {
- String s2 = s.substring(i);
- if (s2.startsWith(arr[index]) && match(arr, s2.substring(arr[index].length()), index + 1)) return true;
- }
- return false;
- }
- public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
- }
- */
-