Примерный java-скрипт для Automatic proxy configuration

Примерный java-скрипт для Automatic proxy configuration

 
  • Примерный java-скрипт для Automatic proxy configuration
  • Более-менее рабочий вариант скрипта в довесок


  •       Ответ: From Artem Belevich art.rtg@iae.nsk.su подробнее об Proxy Autoconfig смотри

    Более-менее рабочий вариант скрипта в довесок


    DebugLevel = 0;
    // Proxy hosts. First parameter - Enable/Disable flag var nop = new Proxy( 1, "" ); var iae = new Proxy( 1, "proxy", "http:8000", "ftp:8000" ); var nsc = new Proxy( 1, "proxy.nsc.ru", "http:8080", "ftp:8080", "gopher:8080" ); var sun = new Proxy( 1, "sunsite.doc.ic.ac.uk", "http:3128", "ftp:3128"); var hpl = new Proxy( 0, "hplyot.obspm.fr", "http:6661" );
    // No proxy var nop_domain = new Domain( nop );
    // Default proxy configuration var def_domain = new Domain( nsc, iae );
    // Proxy configuration if DNS fails var dns_domain = new Domain( sun, hpl );
    // Proxy configuration if host is given by address var adr_domain = new Domain( sun, nsc, iae );
    // Additional configurations var sun_domain = new Domain( sun, hpl, nsc, iae );
    /*
          * Domains
          */ ProxyConfig.bindings[ "radio-msu.net" ] = nop_domain; ProxyConfig.bindings.com = sun_domain; ProxyConfig.bindings.ca = sun_domain; ProxyConfig.bindings.edu = sun_domain; ProxyConfig.bindings.net = sun_domain; ProxyConfig.bindings.gov = sun_domain; ProxyConfig.bindings.no = sun_domain; ProxyConfig.bindings.nl = sun_domain;
    /****************************************************************************
          * IMPLEMENTATION *
          ****************************************************************************/ function Domain() {
          this.num = Domain.arguments.length;
          this.getProxy = getProxy;

          for( var i = 0; i < this.num; ++i )
          this[ i ] = Domain.arguments[ i ]; }
    function getProxy( proto ) {
          var ret = "";

          for( var i = 0; i < this.num; ++i )
          ret += this[ i ].string( proto );
          return ret; }
    function Proxy( flag, hst ) {
          this.host = hst;
          this.string = proxyString;
          this.avail = flag;

          this.num = 0;
          for( var i = 2; i < Proxy.arguments.length; ++i )
          {
          var proxy = Proxy.arguments[ i ];
          var delim = proxy.indexOf( ":" );
          this[ this.num++ ] = new Proto( proxy.substring( 0, delim ),
          proxy.substring( delim + 1, proxy.length ));
          } }
    function proxyString( proto ) {
          if( this.avail )
          for( var i = 0; i < this.num; ++i )
          if( this[ i ].protocol == proto )
          return "PROXY " + this.host + ":" + this[ i ].port + ";";
          return ""; }
    function Proto( pr, po ) {
          this.protocol = pr;
          this.port = po; }
    function show_props( obj, obj_name ) {
          var result = ""
          for (var i in obj)
          result += obj_name + "." + i + " = " + obj[i] + "\n"
          return result; }
    /* function isAddress( str ) {
          for( var i = 0; i <= dnsDomainLevels( str ); ++i )
          {
          var dot = str.indexOf( "." );
          var part1 = str.substring( 0, dot );
          str = str.substring( dot + 1, str.length );
          if( part1 != "0" && parseInt( part1 ) == 0 )
          return false;
          }
          return true; } */
    /*
          * "Main" program
          */ function FindProxyForURL( url, host ) {
          var proto = url.substring( 0, url.indexOf( ":" ) );
          var System = java.lang.System;
          var result = "";

          if( DebugLevel > 1 )
          System.out.println( "Searching proxy for host '" + host + "'" );
    /* if( isAddress( host ) )
          {
          // If host name is unknown
          if( isInNet( host, myIpAddress(), "255.255.0.0") )
          result = "DIRECT";
          else
          {
          System.out.println( "Don't know how to determine hostname by address " + host );
          result = adr_domain.getProxy( proto ) + "DIRECT";
          }
          }
          else*/ if( !isPlainHostName( host )
          && !dnsDomainIs( host, ".nsk.su")
          && !dnsDomainIs( host, ".nsc.ru") )
          // Look in configuration array
          for( var dom in ProxyConfig.bindings )
          {
          if( DebugLevel > 1 )
          System.out.println( "\tLooking for " + host + " in bindings." + dom );
          if( dnsDomainIs( host, "." + dom ) )
          {
          result = ProxyConfig.bindings[ dom ].getProxy( proto );
          if( DebugLevel > 1 )
          System.out.println( "\t\tFound " + result );
          break;
          }
          }
          if( result.length == 0 )
          {
          // Not found in array - try to resolve host name
          if( isResolvable( host ) )
          {
          if( DebugLevel > 1 )
          System.out.println( "\t\t" + host + " has IP address " + dnsResolve( host ) );
          if( isInNet( host, myIpAddress(), "255.255.0.0") )
          result = "DIRECT";
          else
          result = def_domain.getProxy( proto ) + "DIRECT";
          }
          else
          // DNS problem or - try additional default proxy
          result = dns_domain.getProxy( proto );
          }
          else
          result += "DIRECT";
          if( DebugLevel > 1 )
          System.out.println( "Using: " + result );
          return result; }


    Home | UK Shop Center |Contact | Buy Domain | Directory | Web Hosting | Resell Domains


    Copyleft 2005 ruslib.us