Apache-MONITOR

 view release on metacpan or  search on metacpan

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

	}
	else
	{	
		my $monitor_code = get_monitor_code($r,$monitored_uri);
		$r->warn( "monitor_code: " . ( $monitor_code ? $monitor_code : "undef" ));

		if( (!$monitor_code) && (  ($r->filename =~ /cgi/) || (! -f $r->filename)) )
		{
			$r->warn( "monitor_handler HTTP_METHOD_NOT_ALLOWED");
			return HTTP_METHOD_NOT_ALLOWED;
		}
		if( $monitor_code )
		{
			$mon_string = "apply:" . $monitor_code;
		}
		else
		{
			$mon_string = "mtime:" . $r->filename;
		}

	}
 
	$r->warn( "monitor_handler 3 , monstring=$mon_string");
        my $reply_uri = $r->header_in( 'Reply-To' );
 
        if( !defined $reply_uri || !$reply_uri)
        {
		$r->warn( "--------BAD REQUEST -------------" );
		$r->warn( $r->method );
		$r->warn( $r->method_number );
		$r->warn( "--------BAD REQUEST -------------" );
                return BAD_REQUEST;
        }

 
        my ($mon_url,$rv) = add_subscription($r,$monitored_uri,$mon_string,$state,$reply_uri);
	if($rv == SUBSCRIBE_ERROR)
	{
		return SERVER_ERROR;
	}
 
	if( 
	   ($r->header_in('Accept') =~ /text\/html/)
	|| ($r->header_in('Accept') =~ /\*\/\*/)

	 )
	{
		my $msg = ($rv == SUBSCRIBE_OK) ? "You have been subscribed to the URL"
						: "You are already subscribed to the URL";
		$r->status(200);
        	$r->send_http_header("text/html");
		
		$r->print(qq{
		<html>
		<title>Subscribed</title>
		<body>
		$msg
		<a href="$monitored_uri">$monitored_uri</a>
		<br />
		<br />
		To edit or remove your subscription, visit the
		<a href="$mon_url">monitor page</a>
		</body>
		</html>
		});
	}
	else
	{
		$r->header_out('Content-type' => undef);
		$r->header_out('Content-Type' => undef);
        	$r->header_out("Location" => $mon_url );
		$r->status(201);
        	$r->send_http_header();
	}
 
        return OK;
}

sub moo
{
        my $r = shift;

	

        my $dir = $r->dir_config('MonitorDataDir');
	my $host = $r->header_in( 'Host' );
	my $mon_uri = 'http://' . $host . $r->uri();

	if($r->method eq "GET")
	{
	my %uris;
	my %monitors;

	open(LOCK,">$dir/lock") || die("unable to open $dir/lock, $!");
	flock(LOCK,1);	

	dbmopen(%monitors , "$dir/monitors", 0666) || die("unable to open $dir/monitors, $!");
	my $value = $monitors{$mon_uri};
	dbmclose(%monitors);
	close(LOCK);

	if(!defined $value)
	{
		return NOT_FOUND;
	}	


	my ($u,$re) = split( / / , $value);

        $r->send_http_header("text/html" );
	$r->print( qq{
	<html>
	<head>
	<title>Monitor $mon_uri</title>
	</head>
	<body>
	
	<p>
	<b>Monitor $mon_uri</b>
	</p>



( run in 1.524 second using v1.01-cache-2.11-cpan-39bf76dae61 )