]> git.donarmstrong.com Git - biopieces.git/blobdiff - www/index.cgi
added security to browser
[biopieces.git] / www / index.cgi
index 38957c3761bd51aba0e3dc4cf186cb64d1dc2a66..0da25999dfc111cedc77cec42144471291e40dd1 100755 (executable)
@@ -27,11 +27,13 @@ use lib $ENV{ 'BP_PERL' };
 
 use CGI;
 use Data::Dumper;
+use Digest::MD5;
 use Maasha::Common;
 use Maasha::Filesys;
 use Maasha::Calc;
 use Maasha::XHTML;
 use Maasha::KISS;
+use Maasha::BBrowser::Session;
 use Maasha::BBrowser::Track;
 use Maasha::BBrowser::Draw;
 
@@ -51,7 +53,7 @@ push @html, Maasha::XHTML::html_header(
 );
 
 push @html, Maasha::XHTML::h1( txt => "Biopieces Genome Browser", class => 'center' );
-push @html, Maasha::XHTML::form_beg( action => $cookie->{ 'SCRIPT' }, method => "get", enctype => "multipart/form-data" );
+push @html, Maasha::XHTML::form_beg( action => $cookie->{ 'SCRIPT' }, method => "post", enctype => "multipart/form-data" );
 
 push @html, page( $cookie );
 
@@ -59,8 +61,9 @@ push @html, Maasha::XHTML::form_end;
 push @html, Maasha::XHTML::body_end;
 push @html, Maasha::XHTML::html_end;
 
-# push @html, Maasha::XHTML::hdump( $cgi->param );  # DEBUG
-# push @html, Maasha::XHTML::hdump( $cookie );      # DEBUG
+# push @html, Maasha::XHTML::hdump( [ $cgi->Vars ] );  # DEBUG
+# push @html, Maasha::XHTML::hdump( \%ENV );           # DEBUG
+# push @html, Maasha::XHTML::hdump( $cookie );         # DEBUG
 
 print "$_\n" foreach @html;
 
@@ -86,17 +89,42 @@ sub cookie_default
 
     $cookie = {};
 
+    if ( $cgi->param( 'nav_search' ) )
+    {
+        if ( $cgi->param( 'nav_search' ) =~ /([0-9,]+)[ -]([0-9,]+)/ )
+        {
+            $cookie->{ 'NAV_START' } = $1;
+            $cookie->{ 'NAV_END' }   = $2;
+        }
+        else
+        {
+            $cookie->{ 'SEARCH' } = $cgi->param( 'nav_search' );
+
+            $cgi->param( 'page', 'search' );
+        }
+    }
+
     $cookie->{ 'SCRIPT' }          = Maasha::Common::get_scriptname();
     $cookie->{ 'DATA_DIR' }        = "Data";
-    $cookie->{ 'LIST_PAGES' }      = [ qw( user clade genome assembly contig browse ) ];
-    $cookie->{ 'PAGE' }            = $cgi->param( 'page' )     || 'user';
-    $cookie->{ 'USER' }            = $cgi->param( 'user' )     || '';
+    $cookie->{ 'SESSION_DIR' }     = "Sessions";
+    $cookie->{ 'LIST_PAGES' }      = [ qw( clade genome assembly contig browse ) ];
+
+    $cookie->{ 'USER' }            = $cgi->param( 'user' );
+    $cookie->{ 'PASSWORD' }        = $cgi->param( 'password' );
+    $cookie->{ 'SESSION_ID' }      = $cgi->param( 'session_id' );
+
+    cookie_session( $cookie );
+    cookie_login( $cookie );
+
+    $cookie->{ 'PAGE' }          ||= $cgi->param( 'page' )     || 'login';
     $cookie->{ 'CLADE' }           = $cgi->param( 'clade' )    || '';
     $cookie->{ 'GENOME' }          = $cgi->param( 'genome' )   || '';
     $cookie->{ 'ASSEMBLY' }        = $cgi->param( 'assembly' ) || '';
     $cookie->{ 'CONTIG' }          = $cgi->param( 'contig' )   || '';
-    $cookie->{ 'NAV_START' }       = $cgi->param( 'nav_start' );
-    $cookie->{ 'NAV_END' }         = $cgi->param( 'nav_end' );
+    $cookie->{ 'Q_ID' }            = $cgi->param( 'q_id' );
+    $cookie->{ 'S_BEG' }           = $cgi->param( 's_beg' );
+    $cookie->{ 'S_END' }           = $cgi->param( 's_end' );
+    $cookie->{ 'STRAND' }          = $cgi->param( 'strand' );
     $cookie->{ 'ZOOM_IN1' }        = $cgi->param( 'zoom_in1' );
     $cookie->{ 'ZOOM_IN2' }        = $cgi->param( 'zoom_in2' );
     $cookie->{ 'ZOOM_IN3' }        = $cgi->param( 'zoom_in3' );
@@ -150,10 +178,74 @@ sub cookie_default
         cookie_move( $cookie );
     }
 
+    $cookie->{ 'STRAND' } = '+' if defined $cookie->{ 'STRAND' } and $cookie->{ 'STRAND' } eq ' ';   # FIXME ugly HTML fix
+
     return wantarray ? %{ $cookie } : $cookie;
 }
 
 
+sub cookie_session
+{
+    # Martin A. Hansen, December 2009.
+
+    # Check cookie information against session information.
+
+    my ( $cookie,   # cookie hash
+       ) = @_;
+
+    # Returns nothing.
+
+    my ( $session );
+
+    $session = Maasha::BBrowser::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
+
+    $cookie->{ 'PAGE' } = 'login' if not $cookie->{ 'SESSION_ID' };
+    $cookie->{ 'PAGE' } = 'login' if $cookie->{ 'SESSION_ID' } ne $ENV{ 'SSL_SESSION_ID' };
+    $cookie->{ 'PAGE' } = 'login' if not exists $session->{ $cookie->{ 'USER' } };
+    $cookie->{ 'PAGE' } = 'login' if $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ne $cookie->{ 'SESSION_ID' };
+}
+
+
+sub cookie_login
+{
+    # Martin A. Hansen, December 2009.
+
+    # Check a user and password from CGI against the password file and
+    # set the session ID, if found, in the cookie.
+
+    my ( $cookie,   # cookie hash
+       ) = @_;
+
+    # Returns nothing.
+
+    my ( $session );
+
+    $session = Maasha::BBrowser::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
+    
+    if ( $cookie->{ 'USER' } and $cookie->{ 'PASSWORD' } )
+    {
+        if ( exists $session->{ $cookie->{ 'USER' } } and
+             $session->{ $cookie->{ 'USER' } }->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
+        {
+            # $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ||= Maasha::BBrowser::Session::session_new();
+            $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' }   = $ENV{ 'SSL_SESSION_ID' };
+            $session->{ $cookie->{ 'USER' } }->{ 'TIME' }         = Maasha::Common::time_stamp();
+
+            $cookie->{ 'SESSION_ID' } = $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' };
+            $cookie->{ 'LOGIN' }      = "OK";
+            $cookie->{ 'USER' }       = $cookie->{ 'USER' };
+            $cookie->{ 'PAGE' }       = 'clade'; 
+
+            Maasha::BBrowser::Session::session_store( "$cookie->{ 'SESSION_DIR' }/sessions.txt", $session );
+        }
+        else
+        {
+            $cookie->{ 'LOGIN' } = "ERROR";
+        }
+    }
+}
+
+
 sub cookie_start
 {
     # Martin A. Hansen, November 2009.
@@ -169,11 +261,11 @@ sub cookie_start
     if ( defined $cookie->{ 'NAV_START' } )
     {
         $cookie->{ 'NAV_START' } =~ tr/,//d;
-        $cookie->{ 'NAV_START' } = 1 if $cookie->{ 'NAV_START' } <= 0;
+        $cookie->{ 'NAV_START' } = 0 if $cookie->{ 'NAV_START' } < 0;
     }
     else
     {
-        $cookie->{ 'NAV_START' } = 1;
+        $cookie->{ 'NAV_START' } = 0;
     }
 }
 
@@ -246,7 +338,7 @@ sub cookie_zoom
         $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
         $cookie->{ 'NAV_END' }   = int( $cookie->{ 'NAV_END' }   - ( $dist_diff / 2 ) );
 
-        $cookie->{ 'NAV_START' } = 1     if $cookie->{ 'NAV_START' } <= 0;
+        $cookie->{ 'NAV_START' } = 0    if $cookie->{ 'NAV_START' } < 0;
         $cookie->{ 'NAV_END' }   = $max if $cookie->{ 'NAV_END' } > $max;
     }
 }
@@ -309,25 +401,40 @@ sub cookie_href
 
     # Returns a string.
 
-    my ( @href );
+    my ( @href_list, %href_hash, $href );
+
+    $href_hash{ "user" } = $cookie->{ 'USER' } if $cookie->{ 'USER' };
 
     while ( 1 )
     {
-        push @href, "$cookie->{ 'SCRIPT' }?page=$page";
-        push @href, "user=$cookie->{ 'USER' }"         if $cookie->{ 'USER' };
-        last if $page eq 'user';
-        push @href, "clade=$cookie->{ 'CLADE' }"       if $cookie->{ 'CLADE' };
+        $href_hash{ "clade" } = $cookie->{ 'CLADE' }        if $cookie->{ 'CLADE' };
         last if $page eq 'clade';
-        push @href, "genome=$cookie->{ 'GENOME' }"     if $cookie->{ 'GENOME' };
+        $href_hash{ "genome" } = $cookie->{ 'GENOME' }      if $cookie->{ 'GENOME' };
         last if $page eq 'genome';
-        push @href, "assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' };
+        $href_hash{ "assembly" } = $cookie->{ 'ASSEMBLY' }  if $cookie->{ 'ASSEMBLY' };
         last if $page eq 'assembly';
-        push @href, "contig=$cookie->{ 'CONTIG' }"     if $cookie->{ 'CONTIG' };
+        $href_hash{ "contig" } = $cookie->{ 'CONTIG' }      if $cookie->{ 'CONTIG' };
         last if $page eq 'contig';
         last;
     }
 
-    return join "&", @href;
+    if ( defined $cookie->{ 'NAV_START' } and defined $cookie->{ 'NAV_END' } ) {
+        $href_hash{ "nav_search" } = "$cookie->{ 'NAV_START' }-$cookie->{ 'NAV_END' }";
+    }
+
+    $href_hash{ "s_beg" }      = $cookie->{ 'S_BEG' }      if defined $cookie->{ 'S_BEG' };
+    $href_hash{ "s_end" }      = $cookie->{ 'S_END' }      if defined $cookie->{ 'S_END' };
+    $href_hash{ "q_id" }       = $cookie->{ 'Q_ID' }       if defined $cookie->{ 'Q_ID' };
+    $href_hash{ "strand" }     = $cookie->{ 'STRAND' }     if defined $cookie->{ 'STRAND' };
+    $href_hash{ "session_id" } = $cookie->{ 'SESSION_ID' } if defined $cookie->{ 'SESSION_ID' };
+
+    push @href_list, "$cookie->{ 'SCRIPT' }?page=$page";
+
+    foreach $href ( keys %href_hash ) {
+        push @href_list, "$href=$href_hash{ $href }";
+    }
+
+    return join "&", @href_list;
 }
 
 
@@ -369,23 +476,50 @@ sub page
 
     my ( @html );
 
-    if ( $cookie->{ 'PAGE' } eq 'export' ) {
-        push @html, page_export( $cookie );
+    if ( $cookie->{ 'PAGE' } eq 'login' ) {
+        push @html, page_login( $cookie );
+    } elsif ( $cookie->{ 'PAGE' } eq 'search' ) {
+        push @html, page_search( $cookie );
     } elsif ( $cookie->{ 'PAGE' } eq 'browse' ) {
         push @html, page_browse( $cookie );
+    } elsif ( $cookie->{ 'PAGE' } eq 'dna' ) {
+        push @html, page_dna( $cookie );
+    } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
+        push @html, page_export( $cookie );
     } else {
         push @html, page_taxonomy( $cookie );
     }
 
+    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => "$cookie->{ 'SESSION_ID' }" ) );
+
     return wantarray ? @html : \@html;
 }
 
 
-sub page_export
+sub page_login
 {
-    # Martin A. Hansen, November 2009.
+    # Martin A. Hansen, December 2009.
 
-    # Renders the export page.
+    # Renders the login page.
+
+    my ( $cookie,
+       ) = @_;
+
+    # Returns a list.
+
+    my ( @html );
+
+    push @html, section_login( $cookie );
+
+    return wantarray ? @html : \@html;
+}
+
+
+sub page_search
+{
+    # Martin A. Hansen, December 2009.
+
+    # Renders the search page.
 
     my ( $cookie,
        ) = @_;
@@ -395,7 +529,7 @@ sub page_export
     my ( @html );
 
     push @html, section_taxonomy_table( $cookie );
-    push @html, section_export( $cookie );
+    push @html, section_search( $cookie );
 
     return wantarray ? @html : \@html;
 }
@@ -422,6 +556,46 @@ sub page_browse
 }
 
 
+sub page_dna
+{
+    # Martin A. Hansen, November 2009.
+    
+    # Renders the DNA page.
+
+    my ( $cookie,
+       ) = @_;
+
+    # Returns a list.
+
+    my ( @html );
+
+    push @html, section_taxonomy_table( $cookie );
+    push @html, section_dna( $cookie );
+
+    return wantarray ? @html : \@html;
+}
+
+
+sub page_export
+{
+    # Martin A. Hansen, November 2009.
+
+    # Renders the export page.
+
+    my ( $cookie,
+       ) = @_;
+
+    # Returns a list.
+
+    my ( @html );
+
+    push @html, section_taxonomy_table( $cookie );
+    push @html, section_export( $cookie );
+
+    return wantarray ? @html : \@html;
+}
+
+
 sub page_taxonomy
 {
     # Martin A. Hansen, November 2009.
@@ -445,6 +619,39 @@ sub page_taxonomy
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SECTIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
+sub section_login
+{
+    # Martin A. Hansen, December 2009.
+   
+    # Returns a HTML section with a login menu.
+
+    my ( $cookie,   # cookie hash
+       ) = @_;
+
+    # Returns a list.
+
+    my ( $user, $password, $login, @html );
+
+    $user     = Maasha::XHTML::text( name => "user", value => "", size => 20 );
+    $password = Maasha::XHTML::password( name => "password", value => "", size => 20 );
+    $login    = Maasha::XHTML::submit( name => "login_submit", value => "Login" );
+
+    push @html, Maasha::XHTML::h2( txt => "Login", class => 'center' );
+
+    push @html, Maasha::XHTML::table_beg( summary => "Login table", align => 'center' );
+    push @html, Maasha::XHTML::table_row_simple( tr => [ "User:", $user ] );
+    push @html, Maasha::XHTML::table_row_simple( tr => [ "Password:", $password ] );
+    push @html, Maasha::XHTML::table_row_simple( tr => [ "", $login ] );
+    push @html, Maasha::XHTML::table_end;
+
+    if ( $cookie->{ 'LOGIN' } and $cookie->{ 'LOGIN' } eq 'ERROR' ) {
+        push @html, Maasha::XHTML::h3( txt => "Bad user or password - please retry", class => 'error' );
+    }
+
+    return wantarray ? @html : \@html;
+}
+
+
 sub section_taxonomy_table
 {
     # Martin A. Hansen, November 2009.
@@ -473,7 +680,7 @@ sub section_taxonomy_table
     }
 
     push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
-    push @html, Maasha::XHTML::table_row_simple( tr => [ join( " ", @row ) ], align => 'center' );
+    push @html, Maasha::XHTML::table_row_simple( tr => [ join( "\n", @row ) ], align => 'center' );
     push @html, Maasha::XHTML::table_end;
 
     return wantarray ? @html : \@html;
@@ -498,7 +705,7 @@ sub section_taxonomy_select
 
     push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
 
-    push @html, Maasha::XHTML::table_beg( summary => "Select table", align => 'center', cellpadding => '5px' );
+    push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center', cellpadding => '5px' );
 
     foreach $item ( @{ $cookie->{ $list } } )
     {
@@ -526,14 +733,14 @@ sub section_navigate
 
     # Returns a list.
 
-    my ( @html );
+    my ( @html, $nav_val );
+
+    $nav_val = Maasha::Calc::commify( $cookie->{ 'NAV_START' } ) . "-" . Maasha::Calc::commify( $cookie->{ 'NAV_END' } );
 
     push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
     push @html, Maasha::XHTML::table_row_simple( tr => [
-        "Start:",
-        Maasha::XHTML::text( name => "nav_start", value => Maasha::Calc::commify( $cookie->{ 'NAV_START' } ), size => 20 ),
-        "End:",
-        Maasha::XHTML::text( name => "nav_end",   value => Maasha::Calc::commify( $cookie->{ 'NAV_END' } ),   size => 20 ), 
+        "Position or search term:",
+        Maasha::XHTML::text( name => "nav_search", value => $nav_val, size => 30 ),
         Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
     ] );
     push @html, Maasha::XHTML::table_end;
@@ -576,7 +783,7 @@ sub section_browse
 
     # Returns a list.
 
-    my ( @tracks, $i, @features, $feat, $elem, $file, $surface, $cr, @html, @img );
+    my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img );
 
     push @features, [ Maasha::BBrowser::Track::track_ruler( $cookie ) ];
     push @features, [ Maasha::BBrowser::Track::track_seq( $cookie ) ];
@@ -590,23 +797,21 @@ sub section_browse
         push @features, [ Maasha::BBrowser::Track::track_feature( $tracks[ $i ], $cookie ) ];
     }
 
-    $file = "fisk.png";   # FIXME
-
     $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
     $cr      = Cairo::Context->create( $surface );
 
-    $cr->rectangle (0, 0, $cookie->{ 'IMG_WIDTH' },  $cookie->{ 'TRACK_OFFSET' } );
-    $cr->set_source_rgb (1, 1, 1);
+    $cr->rectangle ( 0, 0, $cookie->{ 'IMG_WIDTH' },  $cookie->{ 'TRACK_OFFSET' } );
+    $cr->set_source_rgb ( 1, 1, 1 );
     $cr->fill;
 
     foreach $feat ( @features ) {
         Maasha::BBrowser::Draw::draw_feature( $cr, $feat ) if $feat;
     }
 
-    Maasha::BBrowser::Draw::file_png( $surface, $file );
+    $png_data = Maasha::BBrowser::Draw::base64_png( $surface );
 
     push @img, Maasha::XHTML::img(
-        src    => $file,
+        src    => "data:image/png;base64,$png_data",
         alt    => "Browser Tracks",
         height => $cookie->{ 'TRACK_OFFSET' },
         width  => $cookie->{ 'IMG_WIDTH' },
@@ -622,8 +827,16 @@ sub section_browse
         {
             next if $elem->{ 'type' } eq 'text';
 
+            #$elem->{ 'strand' } = '&#43' if $elem->{ 'strand' } eq '+';
+
+            $cookie->{ 'Q_ID' }   = $elem->{ 'q_id' };
+            $cookie->{ 'S_BEG' }  = $elem->{ 's_beg' };
+            $cookie->{ 'S_END' }  = $elem->{ 's_end' };
+            $cookie->{ 'STRAND' } = $elem->{ 'strand' };
+
             push @img, Maasha::XHTML::area(
-                href   => cookie_href( $cookie, "export" ) . "&Q_ID=$elem->{ 'id' }",
+                href   => cookie_href( $cookie, "export" ),
+                # href   => cookie_href( $cookie, "export" ) . "&q_id=$elem->{ 'q_id' }&s_beg=$elem->{ 's_beg' }&s_end=$elem->{ 's_end' }&strand=$elem->{ 'strand' }",
                 shape  => "rect",
                 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }", title => "$elem->{ 'title' }",
             );
@@ -651,9 +864,120 @@ sub section_export
 
     # Returns a list.
 
-    my ( @html );
+    my ( @row_dna_contig, @html );
+
+    push @row_dna_contig, Maasha::XHTML::p( txt => qq(Export Feature: "$cookie->{ 'Q_ID' }" DNA from Contig: ), class => 'inline' );
+    push @row_dna_contig, Maasha::XHTML::p( txt  => "$cookie->{ 'CONTIG' } Start: ", class => 'inline' );
+    push @row_dna_contig, Maasha::XHTML::text( name => "s_beg", value => Maasha::Calc::commify( $cookie->{ 'S_BEG' } ), size => 15 );
+    push @row_dna_contig, Maasha::XHTML::p( txt => "End: ", class => 'inline' );
+    push @row_dna_contig, Maasha::XHTML::text( name => "s_end", value => Maasha::Calc::commify( $cookie->{ 'S_END' } ), size => 15 );
+    push @row_dna_contig, Maasha::XHTML::p( txt => "Strand: ", class => 'inline' );
+    push @row_dna_contig, Maasha::XHTML::menu( name => "strand", options => [ qw( + - ) ], selected => $cookie->{ 'STRAND' } );
+    push @row_dna_contig, Maasha::XHTML::submit( name => "export", value => "Export", title => "Fetch DNA from this region" );
+
+    push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
+    push @html, Maasha::XHTML::table_beg( summary => "Taxonomy select table", align => 'center' );
+    push @html, Maasha::XHTML::table_row_simple( tr => \@row_dna_contig );
+    push @html, Maasha::XHTML::table_end;
+
+    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page", value => "dna" ) );
+    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user",     value => "$cookie->{ 'USER' }" ) );
+    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade",    value => "$cookie->{ 'CLADE' }" ) );
+    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome",   value => "$cookie->{ 'GENOME' }" ) );
+    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => "$cookie->{ 'ASSEMBLY' }" ) );
+    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig",   value => "$cookie->{ 'CONTIG' }" ) );
+
+    return wantarray ? @html : \@html;
+}
+
+
+sub section_search
+{
+    # Martin A. Hansen, November 2009.
+
+    # Returns a HTML section with export table.
+
+    my ( $cookie,   # cookie hash
+       ) = @_;
+
+    # Returns a list.
+
+    my ( $results, $result, $count, @html, $export, $browse );
+
+    $results = Maasha::BBrowser::Track::search_tracks( $cookie );
+
+    $count = scalar @{ $results };
+
+    push @html, Maasha::XHTML::h2( txt => "Search", class => 'center' );
+    push @html, Maasha::XHTML::p( txt => qq(Results for "$cookie->{ 'SEARCH' }": $count), class => 'center' );
+
+    if ( $count > 0 )
+    {
+        push @html, Maasha::XHTML::table_beg( summary => "Search table", align => 'center', cellpadding => '5px' );
+        push @html, Maasha::XHTML::table_row_simple( tr => [ qw( S_ID S_BEG S_END Q_ID SCORE STRAND HITS ALIGN BLOCK_COUNT BLOCK_BEGS BLOCK_LENS BLOCK_TYPE) ] );
+
+        foreach $result ( @{ $results } )
+        {
+            $cookie->{ 'CONTIG' }    = $result->{ 'S_ID' };
+            $cookie->{ 'NAV_START' } = $result->{ 'S_BEG' };
+            $cookie->{ 'NAV_END' }   = $result->{ 'S_END' };
+            $cookie->{ 'S_BEG' }     = $result->{ 'S_BEG' };
+            $cookie->{ 'S_END' }     = $result->{ 'S_END' };
+            $cookie->{ 'STRAND' }    = $result->{ 'STRAND' };
+            $cookie->{ 'Q_ID' }      = $result->{ 'Q_ID' };
+
+            $browse = Maasha::XHTML::ln( txt => "browse", href => cookie_href( $cookie, "browse" ) );
+            $export = Maasha::XHTML::ln( txt => "export", href => cookie_href( $cookie, "export" ) );
+
+            push @html, Maasha::XHTML::table_row_advanced(
+                tr => [ { td => $result->{ 'S_ID' } },
+                        { td => $result->{ 'S_BEG' }, align => 'right' },
+                        { td => $result->{ 'S_END' }, align => 'right' },
+                        { td => $result->{ 'Q_ID' } },
+                        { td => $result->{ 'SCORE' }, align => 'right' },
+                        { td => $result->{ 'STRAND' } },
+                        { td => $result->{ 'HITS' }, align => 'right' },
+                        { td => $result->{ 'ALIGN' } },
+                        { td => $result->{ 'BLOCK_COUNT' }, align => 'right' },
+                        { td => $result->{ 'BLOCK_BEGS' } },
+                        { td => $result->{ 'BLOCK_LENS' } },
+                        { td => $result->{ 'BLOCK_TYPE' } },
+                        { td => $browse },
+                        { td => $export },
+                ], class => "monospace"
+            );
+        }
+
+        push @html, Maasha::XHTML::table_end;
+    }
+
+    return wantarray ? @html : \@html;
+}
+
+
+sub section_dna
+{
+    # Martin A. Hansen, November 2009.
+
+    # Returns a HTML section with extracted DNA.
+
+    my ( $cookie,   # cookie hash
+       ) = @_;
+
+    # Returns a list.
+
+    my ( @html, $beg, $end, $seq );
+    
+    $beg = $cookie->{ 'S_BEG' };
+    $end = $cookie->{ 'S_END' };
+    $beg =~ tr/,//d;
+    $end =~ tr/,//d;
+
+    $seq = ">$cookie->{ 'CONTIG' }_$beg" . "_$end" . "_$cookie->{ 'STRAND' }\n";
+    $seq .= Maasha::BBrowser::Track::dna_get( $cookie );
 
-    push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );   # TODO section_export!
+    push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
+    push @html, Maasha::XHTML::pre( txt => $seq );
 
     return wantarray ? @html : \@html;
 }