Apache-HTTunnel

 view release on metacpan or  search on metacpan

Client/lib/HTTunnel/Client.java  view on Meta::CPAN

					port = st.nextToken() ; 
					st.nextToken() ; // waste ':'
					StringBuffer sbdata = new StringBuffer() ;
					while (st.hasMoreTokens()){
						sbdata.append(st.nextToken()) ;
					}
					peer_info = addr + ":" + port ;
					data = sbdata.toString() ;
				}
			}
			catch (ClientTimeoutException hcte){
				continue ;
			}
			catch (ClientException hce){
				throw hce ;
			}

			return data ;
		}
	}

Client/lib/HTTunnel/Client.java  view on Meta::CPAN

		if (code.equals("err")){
			throw new ClientException("Apache::HTTunnel error:" + content.substring(3)) ;
		}
		else if (code.equals("okn")){
			return null ;
		}
		else if (code.equals("okd")){
			return content.substring(3) ;
		}
		else if (code.equals("okt")){
			throw new ClientTimeoutException() ;
		}
		else{
			throw new ClientException("Invalid Apache::HTTunnel response code '" + code + "'") ;
		}
	}


	protected void request_callback(HttpURLConnection huc){
	}

Client/lib/HTTunnel/Client.java  view on Meta::CPAN

	}


	public class ClientException extends Exception {
		ClientException(String msg){
			super(msg) ;
		}
	}


	private class ClientTimeoutException extends ClientException {
		ClientTimeoutException(){
			super("Apache::HTTunnel voluntary timeout") ;
		}
	}
}

Client/lib/HTTunnel/Client.pm  view on Meta::CPAN

		eval {
			$data = $this->_execute(
				'read', 
				[$this->{__PACKAGE__}->{fhid}, $this->{__PACKAGE__}->{proto}, $len, $timeout],
			) ;
			if ($this->{__PACKAGE__}->{proto} eq 'udp'){
				($addr, $port, $data) = split(':', $data, 3) ;
				$this->{__PACKAGE__}->{peer_info} = "$addr:$port" ;
			}
		} ;
		if ((ref($@))&&(UNIVERSAL::isa($@, "HTTunnel::Client::TimeoutException"))){
			next ;
		}
		elsif ($@){
			die("$@\n") ;
		}

		return $data ;
	}
}

Client/lib/HTTunnel/Client.pm  view on Meta::CPAN

	if ($code eq 'err'){
		croak("Apache::HTTunnel error: " . substr($content, 3)) ;
	}
	elsif ($code eq 'okn'){
		return undef ;
	}
	elsif ($code eq 'okd'){
		return substr($content, 3) ;
	}
	elsif ($code eq 'okt'){
		die(bless({}, "HTTunnel::Client::TimeoutException")) ;
	}
	else{
		croak("Invalid Apache::HTTunnel response code '$code'") ;
	}
}


sub request_callback {
	my $shift = shift ;
	my $req = shift ;

lib/Apache/HTTunnel.pm  view on Meta::CPAN


# Specifiy the location of the fifo (UNIX domain socket or named pipe)
# that will be used byb the Apache children to communicate with the "keeper"
# process.
PerlSetVar		HTTunnelFifo				/var/lib/httunnel/httunnel.sock

# The maximum connect timeout that may be specified by the client. This value
# should be kept low (< 60) since that Apache children maybe be blocked up 
# to that ammount of time.
# In seconds.
PerlSetVar		HTTunnelMaxConnectTimeout	15

# The maximum read length that may be specified by the client.
# In bytes.
PerlSetVar		HTTunnelMaxReadLength		131072

# The maximum read timeout that may be specified by the client. This value
# should be kept low (< 60) since that Apache children maybe be blocked up 
# to that ammount of time.
# In seconds.
PerlSetVar		HTTunnelMaxReadTimeout		15

# Connections that remain inactive after this amount of time will be closed.
# In seconds.
PerlSetVar		HTTunnelConnectionTimeout	900


# Load up the module
PerlPostConfigRequire	Apache/HTTunnel.pm


# Setup the location that will be used.
<Location "/httunnel">
  SetHandler		perl-script
  PerlResponseHandler	Apache::HTTunnel

lib/Apache/HTTunnel.pod  view on Meta::CPAN

mod_perl. The C<HTTunnel::Client> class (or the C<httunnel> daemon) can be
used to configure the tunnels.


=head1 CONFIGURATION

The following configuration directives can be used inside httpd.conf (or
some other file in the conf.d directory) to control the behaviour of 
C<Apache::HTTunnel>. 

Please note that HTTunnelFifo and HTTunnelConnectionTimeout must be used
before the PerlPostConfigRequire directive since they are used at startup 
time. The other directives can be specified at the Location level.

=over 4

=item HTTunnelFifo

Specifies the path to be used for the fifo that allows communication
between the keeper process and the Apache workers.

  Ex: HTTunnelFifo              /var/lib/httunnel/httunnel.sock

There is no default value. This directive is mandatory.

=item HTTunnelConnectionTimeout

Specifies the number of seconds after which inactive connections
will be closed. The connection table is checked at least every 15 
seconds.

  Ex: HTTunnelConectionTimeout  900

The default value is 900, meaning connections idle for more than
15 minutes will be closed.

=item HTTunnelAllowedTunnels

Specifies towards which host/port combinations this server allows tunnels
to be established. The format is as such:

  Ex: HTTunnelAllowedTunnels    "\
        *              => 22, \
        myhost         => 3389 | 5800, \
        host1 | host2  => * "

You can specify many sections by separating them by commas (,). Within each 
section, multiple hosts/ports may be specified by separating them with pipes 
(|). The asterisk (*) can be used as a wildcard, allowing any host/port.
There is no default value. This directive is mandatory.

=item HTTunnelMaxConnectTimeout

When a client sends a connection request, it may specify a timeout
value for the connection. In order to prevent blocking in the Apache child
in cases when the connection blocks, this directive limits the 
connection timeout that may be specified by the client.

  Ex: HTTunnelMaxConnectTimeout 10

The default value is 15 seconds. It is best to keep the value relatively
low to prevent blocking in the Apache child.

=item HTTunnelMaxReadTimeout

C<HTTunnel::Client> needs to poll to check if there is some data to be 
read from the remote socket. In order to not be troubled by proxies or 
other intermediaries that may terminate long lasting connections 
prematurely, C<Apache::HTTunnel> will purposely time-out read requests 
that take longer than HTTunnelReadTimeout seconds. A special response 
is sent to the client telling it to retry the read request.

  Ex: HTTunnelMaxReadTimeout    10

The default value is 15 seconds. It is best to keep the value relatively
low to prevent blocking in the Apache child.

=item HTTunnelMaxReadLength

The maximum number of bytes that a client may request for a read.

  Ex: HTTunnelMaxReadLength     16384

lib/Apache/HTTunnel/Handler.pm  view on Meta::CPAN


sub connect_cmd {
	my $r = shift ;
	my @params = @_ ;

	my $slog = $r->log() ;
	my $proto = shift @params ;
	my $host = shift @params ;
	my $port = shift @params ;
	my $timeout = shift @params || 15 ;
	my $max_timeout = $r->dir_config('HTTunnelMaxConnectTimeout') || 15 ;
	if ($timeout > $max_timeout){
		$slog->notice("HTTunnel Handler: Requested connect timeout ($timeout) decreased " .
			"to HTTunnelMaxConnectTimeout ($max_timeout)") ;
		$timeout = $max_timeout ;
	}

	check_access($r, $host, $port) ;
	$slog->info("HTTunnel Handler: Connecting to $host:$port...") ;

	my $sock = undef ;
	my $peer_info = undef ;
	eval {
		local $SIG{ALRM} = sub {die "timeout\n"} ;

lib/Apache/HTTunnel/Handler.pm  view on Meta::CPAN

	my $fhid = shift @params ;
	my $proto = shift @params ;
	my $len = shift @params ;
	my $timeout = shift @params || 15 ;
	my $max_len = $r->dir_config('HTTunnelMaxReadLength') || 131072 ;
	if ($len > $max_len){
		$slog->notice("HTTunnel Handler: Requested read length ($len) decreased " .
			"to HTTunnelMaxReadLength ($max_len)") ;
		$len = $max_len ;
	}
	my $max_timeout = $r->dir_config('HTTunnelMaxReadTimeout') || 15 ;
	if ($timeout > $max_timeout){
		$slog->notice("HTTunnel Handler: Requested read timeout ($timeout) decreased " .
			"to HTTunnelMaxReadTimeout ($max_timeout)") ;
		$timeout = $max_timeout ;
	}

	my $data = undef ;
	$slog->notice("HTTunnel Handler: Getting filehandle '$fhid'...") ;
	my $fh = $fdk->get($fhid) or die("Unknown filehandle '$fhid'") ;
	$slog->notice("HTTunnel Handler: Filehandle '$fhid' gotten") ;

	my $timed_out = 0 ;
	my $peer_info = undef ;

lib/Apache/HTTunnel/Keeper.pm  view on Meta::CPAN


# Get configuration info from the Apache config file.
my $s = Apache2::ServerUtil->server() ;
my $slog = $s->log() ;
my $tree = Apache2::Directive::conftree() ;
my $apache_user = $tree->lookup('User') ;
my $apache_uid = getpwnam($apache_user) ;
my $apache_group = $tree->lookup('Group') ;
my $apache_gid = getgrnam($apache_group) ;
my $fifo = $s->dir_config('HTTunnelFifo') or die("HTTunnelFifo not defined in Apache configuration file") ;
my $conn_timeout = $s->dir_config('HTTunnelConnectionTimeout') || 900 ;


# Setup File::FDkeeper 
$slog->info("HTTunnel Keeper: Creating File::FDkeeper\@$fifo...") ;
my $fdk = new File::FDkeeper(
	Local => $fifo,
	AccessTimeout => $conn_timeout,
	AccessTimeoutCheck => 15,
) ;
$slog->notice("HTTunnel Keeper: File::FDkeeper\@$fifo created") ;

# Setup proper permissions on the fifo...
if (($apache_user)||($apache_group)){
	if (! defined($apache_uid)){
		$apache_uid = -1 ;
	}
	if (! defined($apache_gid)){
		$apache_gid = -1 ;

t/conf/extra.conf.in  view on Meta::CPAN

PerlSwitches -w 

PerlSetVar		HTTunnelFifo				@ServerRoot@/httunnel.sock
PerlSetVar		HTTunnelMaxReadLength		131072
PerlSetVar		HTTunnelMaxReadTimeout		15
PerlSetVar		HTTunnelConnectionTimeout	900

PerlPostConfigRequire	Apache/HTTunnel.pm

<Location "/httunnel">
  SetHandler			perl-script
  PerlResponseHandler	Apache::HTTunnel 
  PerlSetVar			HTTunnelAllowedTunnels  "\
	localhost             => @Port@, \
	localhost.localdomain => @Port@, \
	"



( run in 0.289 second using v1.01-cache-2.11-cpan-4d50c553e7e )