- #!/usr/bin/perl
- # $Id: webserver,v 1.6 14:45:09 gilles Exp gilles $
- package Imapsync;
- use strict ;
- use warnings ;
- use Data::Dumper ;
- my $server = Imapsync->new(
- 'port' => [8080],
- 'access_log_file' => 'STDERR',
- 'log_level' => 4,
- 'timeout_header' => 20,
- 'timeout_idle' => 60,
- ) ;
- $server->run() ;
- sub default_server_type { 'Fork' }
- sub post_configure_hook
- {
- }
- sub output_file
- {
- my ( $self, $file, $type ) = @_ ;
- $type ||= 'text/plain' ;
- my $string = file_to_string( $file ) ;
- my $output ;
- my( $status, $msg, $body ) ;
- {
- $output = "Content-type: $type\r\n\r\n" ;
- $output .= $string ;
- # body can not be sent by send_status() because then it
- # sets Content-type to text/html
- $self->send_status( '200', 'OK' ) ;
- }
- else
- {
- $self->send_status( '404', 'Not found', "File not found: $file " ) ;
- }
- return ;
- }
- sub process_path_info
- {
- my $sitemap =
- {
- '/imapsync_form_extra.html' => sub {
- output_file( $self, './X/imapsync_form_extra.html', 'text/html' )
- },
- '/imapsync_form.html' => sub {
- output_file( $self, './X/imapsync_form.html', 'text/html' )
- },
- '/imapsync_form.css' => sub {
- output_file( $self, './X/imapsync_form.css', 'text/css' )
- },
- '/imapsync_form.js' => sub {
- output_file( $self, './X/imapsync_form.js', 'text/javascript' )
- },
- '/imapsync_form_new.js' => sub {
- output_file( $self, './X/imapsync_form_new.js', 'text/javascript' )
- },
- '/' => sub {
- output_file( $self, './X/imapsync_form_extra.html', 'text/html' )
- },
- '/vnstat/vnstati.html' => sub {
- output_file( $self, './X/vnstati.html', 'text/html' )
- },
- } ;
- {
- $sitemap->{ $path_info }->() ;
- }
- else
- {
- $self->send_status( '404', 'Not found', "Error: $path_info not found!\n" ) ;
- }
- return ;
- }
- sub process_http_request
- {
- #$self->log( 2, Data::Dumper->Dump( [ $self ], ['self'] ) ) ;
- $ENV{'SERVER_SOFTWARE'} = $PROGRAM_NAME ;
- if ( '/cgi-bin/imapsync' eq $ENV{'PATH_INFO'} ) {
- #$self->exec_trusted_perl( './imapsync' ) ;
- $self->exec_cgi( './imapsync' ) ;
- #$self->exec_cgi( './imapsync_bin_Linux_i686' ) ;
- #$self->exec_trusted_perl( '.\imapsync.pl' );
- #return ;
- #return $self->exec_cgi( 'C:\Strawberry\perl\bin\perl.exe .\imapsync.pl' );
- #return $self->exec_cgi( 'imapsyncbat' );
- #return $self->exec_trusted_perl( 'imapsyncbat' );
- }
- else
- {
- process_path_info( $self, $ENV{'PATH_INFO'} ) ;
- }
- #$self->log( 4, Data::Dumper->Dump( [ $self ], ['self'] ) ) ;
- }
- sub file_to_string
- {
- my @string ;
- @string = <$FILE> ;
- }else{
- return ;
- }
- }
Raw Paste