Apache-iNcom

 view release on metacpan or  search on metacpan

demo/conf/startup.pl  view on Meta::CPAN

# mod_perl startup file
#
# Add module to preload here
use Apache;
use Apache::Cookie;
use Apache::Request;

use Apache::DBI;
use HTML::Embperl;

use lib "/home/francis/copiscan/lib";

# Preload all the iNcom modules
use iNcom;
use iNcom::Session;

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

package Apache::iNcom;

use strict;

require 5.005;

use DBI;

use Apache;
use Apache::Log;
use Apache::Cookie;
use Apache::Request;
use Apache::File;
use Apache::Constants qw( :common :response HTTP_PRECONDITION_FAILED );

use HTML::Embperl;

use Apache::iNcom::Request;
use Apache::iNcom::Localizer;

use vars qw($VERSION);

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

    # If we are in a subrequest, just copy
    # what was initialized to the new request
    if ( $r->is_main ) {
	my $prefix	    = $r->dir_config( "INCOM_URL_PREFIX" ) || "/";
	unless ( $prefix =~ m|/$| ) {
	    $r->log_error( "iNcom configuration error: INCOM_URL_PREFIX must ends with /" );
	    return SERVER_ERROR;
	}

	# Parse cookies
	my $c = $r->header_in( "Cookie" );
	my $cookies = Apache::Cookie->new( $r )->parse( $c );
	$r->pnotes( "INCOM_COOKIES", $cookies );

	# Parse languages
	my $rv = i18n_init( $r );
	return $rv if $rv != OK;

    } else {
	my $prev = $r->prev;
	foreach my $name ( keys %VALID_PNOTES ) {
	    $r->pnotes( $name, $prev->pnotes( $name ) );

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

sub bake_session_cookie {
    my ($r, $session_id) = @_;

    my $prefix		= $r->dir_config( "INCOM_URL_PREFIX" ) || "/";
    my $session_secure  = $r->dir_config( "INCOM_SESSION_SECURE" );
    my $session_domain  = $r->dir_config( "INCOM_SESSION_DOMAIN" );
    my $session_expires = $r->dir_config( "INCOM_SESSION_EXPIRES" );
    my $session_path    = $r->dir_config( "INCOM_SESSION_PATH" )
      || $prefix;

    my $cookie = new Apache::Cookie( $r,
				     -name   => "INCOM_SESSION",
				     -value  => $session_id,
				     -path   => $session_path
				   );
    $cookie->domain( $session_domain )	    if $session_domain;
    $cookie->expires( $session_expires )    if $session_expires;
    $cookie->secure( 1 )		    if $session_secure;

    # Add cookie to outgoing headers
    $cookie->bake;

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

	session_init( $r );

	# To clean DB connection and Session
	$r->push_handlers( PerlCleanupHandler => \&request_cleanup );
    }

    # Determine the handler
    if ( $uri =~ s!^incom_cookie_check/!! ) {
	# Check if the session was loaded properly
	if ( ref $r->pnotes( "INCOM_SESSION") ) {
	    # Cookie test suceeded. Tell browser to refetch
	    # original file
	    $r->pnotes( "INCOM_REDIRECT_TO", $prefix . $uri );
	    $r->push_handlers( PerlHandler => \&redirect_handler );
	    $r->handler( "perl-script" );
	} else {
	    # Cookie test failed
	    $r->pnotes( "INCOM_ERROR", "no_cookies" );
	    return return_error( $r, HTTP_PRECONDITION_FAILED );
	}
    } elsif ( $uri =~ s!^incom_set_lang/([-\w]+)/!! ) {
	$r->pnotes( "INCOM_NEW_LANG", "$1" );
	$r->pnotes( "INCOM_REDIRECT_TO", $prefix . $uri );

	$r->push_handlers( PerlHandler => \&set_lang_handler );
	$r->handler( "perl-script" );

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

    my $r = shift;

    my $prefix	    = $r->dir_config( "INCOM_URL_PREFIX" ) || "/";
    my $session_domain  = $r->dir_config( "INCOM_SESSION_DOMAIN" );
    my $session_path    = $r->dir_config( "INCOM_SESSION_PATH" )
      || $prefix;
    my $session_expires = $r->dir_config( "INCOM_SESSION_EXPIRES" );

    # Create a cookie which has the same lifespan than
    # the session cookie.
    my $cookie = new Apache::Cookie( $r,
				     -name  => "INCOM_LANGUAGE",
				     -value => $r->pnotes( "INCOM_NEW_LANG" ),
				     -path  => $session_path,
				   );
    $cookie->domain( $session_domain )	    if $session_domain;
    $cookie->expires( $session_expires )    if $session_expires;

    # Add cookie to outgoing headers
    $cookie->bake;

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


On the user's first request, a new session is created. Each and every
other request will be part of a session which will used to track the
user's cart and other such things.

The session id is returned to the user in a cookie. COOKIES MUST BE
ENABLED for Apache::iNcom to function. Fortunately, Apache::iNcom
detects if the user has cookies turned off and will send the user an
error.

Cookies are used for security and confidentiality. The session id is a
truly random 128bits number, which is make it very much unguessable.
That means that you can't try to stomp into another user's session.
That is a good thing since having access to the session id means
having access to a whole bunch of informations. (What information is
application specific.) IP address aren't used to restrict the session
access because of the various problems with proxies and other Internet
niceties.

Now, what has this to do with cookies ? Well, using URL rewriting was
originally considered, but then two big issues cralwed in : proxies



( run in 0.462 second using v1.01-cache-2.11-cpan-e9199f4ba4c )