]> git.donarmstrong.com Git - biopieces.git/blobdiff - www/index.cgi
fixed URI::Escape on q_id in BGB
[biopieces.git] / www / index.cgi
index 0da25999dfc111cedc77cec42144471291e40dd1..2009fbf25dc455e356425e7caabdebd16c7210e1 100755 (executable)
@@ -26,6 +26,7 @@ use warnings;
 use lib $ENV{ 'BP_PERL' };
 
 use CGI;
+use URI::Escape;
 use Data::Dumper;
 use Digest::MD5;
 use Maasha::Common;
@@ -33,9 +34,9 @@ use Maasha::Filesys;
 use Maasha::Calc;
 use Maasha::XHTML;
 use Maasha::KISS;
-use Maasha::BBrowser::Session;
-use Maasha::BBrowser::Track;
-use Maasha::BBrowser::Draw;
+use Maasha::BGB::Session;
+use Maasha::BGB::Track;
+use Maasha::BGB::Draw;
 
 my ( $cgi, $cookie, @html );
 
@@ -109,7 +110,7 @@ sub cookie_default
     $cookie->{ 'SESSION_DIR' }     = "Sessions";
     $cookie->{ 'LIST_PAGES' }      = [ qw( clade genome assembly contig browse ) ];
 
-    $cookie->{ 'USER' }            = $cgi->param( 'user' );
+    $cookie->{ 'USER' }            = $cgi->param( 'user' ) || '';
     $cookie->{ 'PASSWORD' }        = $cgi->param( 'password' );
     $cookie->{ 'SESSION_ID' }      = $cgi->param( 'session_id' );
 
@@ -122,6 +123,8 @@ sub cookie_default
     $cookie->{ 'ASSEMBLY' }        = $cgi->param( 'assembly' ) || '';
     $cookie->{ 'CONTIG' }          = $cgi->param( 'contig' )   || '';
     $cookie->{ 'Q_ID' }            = $cgi->param( 'q_id' );
+    $cookie->{ 'NAV_START' }     ||= $cgi->param( 'nav_start' ) || $cgi->param( 's_beg' );  # FIXME this is ugly!
+    $cookie->{ 'NAV_END' }       ||= $cgi->param( 'nav_end' )   || $cgi->param( 's_end' );
     $cookie->{ 'S_BEG' }           = $cgi->param( 's_beg' );
     $cookie->{ 'S_END' }           = $cgi->param( 's_end' );
     $cookie->{ 'STRAND' }          = $cgi->param( 'strand' );
@@ -197,12 +200,37 @@ sub cookie_session
 
     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' };
+    $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
+
+    # if ( $cookie->{ 'SESSION_ID' } )
+    # {
+    #     if ( $cookie->{ 'SESSION_ID' } ne $ENV{ 'SSL_SESSION_ID' } ) {
+    #         $cookie->{ 'PAGE' } = 'login';
+    #         print STDERR "HER1"; # DEBUG
+    #     }
+    # }
+    # else
+    # {
+    #     $cookie->{ 'PAGE' } = 'login';
+    # 
+    #     print STDERR "HER2"; # DEBUG
+    # }
+
+    if ( exists $session->{ $cookie->{ 'USER' } } and $cookie->{ 'SESSION_ID' } )
+    {
+        if ( $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ne $cookie->{ 'SESSION_ID' } ) {
+            $cookie->{ 'PAGE' } = 'login';
+            print STDERR "HER3"; # DEBUG
+        }
+    }
+    else
+    {
+        $cookie->{ 'PAGE' } = 'login';
+        print STDERR "HER4"; # DEBUG
+        print STDERR "NO COOKIE SESSION ID\n" if not $cookie->{ 'SESSION_ID' }; # DEBUG
+        print STDERR "NO COOKIE USER\n" if not $cookie->{ 'USER' }; # DEBUG
+        print STDERR "NO SESSION USER\n"      if not exists $session->{ $cookie->{ 'USER' } }; # DEBUG
+    }
 }
 
 
@@ -220,23 +248,22 @@ sub cookie_login
 
     my ( $session );
 
-    $session = Maasha::BBrowser::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
-    
     if ( $cookie->{ 'USER' } and $cookie->{ 'PASSWORD' } )
     {
+        $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
+    
         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' } }->{ 'SESSION_ID' } ||= Maasha::BGB::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 );
+            Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/sessions.txt", $session );
         }
         else
         {
@@ -285,7 +312,7 @@ sub cookie_end
 
     my ( $max );
     
-    $max = Maasha::Filesys::file_size( Maasha::BBrowser::Track::path_seq( $cookie ) );
+    $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
 
     if ( defined $cookie->{ 'NAV_END' } )
     {
@@ -313,7 +340,7 @@ sub cookie_zoom
 
     my ( $max, $dist, $new_dist, $dist_diff );
 
-    $max = Maasha::Filesys::file_size( Maasha::BBrowser::Track::path_seq( $cookie ) );
+    $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
 
     $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
 
@@ -356,7 +383,7 @@ sub cookie_move
 
     my ( $max, $dist, $shift, $new_start, $new_end );
 
-    $max = Maasha::Filesys::file_size( Maasha::BBrowser::Track::path_seq( $cookie ) );
+    $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
 
     $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
 
@@ -418,13 +445,13 @@ sub cookie_href
         last;
     }
 
-    if ( defined $cookie->{ 'NAV_START' } and defined $cookie->{ 'NAV_END' } ) {
+    if ( defined $cookie->{ 'NAV_START' } and defined $cookie->{ 'NAV_END' } and $page !~ /clade|genome|assembly|contig|browse/ ) {
         $href_hash{ "nav_search" } = "$cookie->{ 'NAV_START' }-$cookie->{ 'NAV_END' }";
     }
 
+    $href_hash{ "q_id" }       = URI::Escape::uri_escape( $cookie->{ 'Q_ID' } ) if defined $cookie->{ 'Q_ID' };
     $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' };
 
@@ -490,7 +517,9 @@ sub page
         push @html, page_taxonomy( $cookie );
     }
 
-    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => "$cookie->{ 'SESSION_ID' }" ) );
+    if ( $cookie->{ 'SESSION_ID' } ) {
+        push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => $cookie->{ 'SESSION_ID' } ) );
+    }
 
     return wantarray ? @html : \@html;
 }
@@ -766,11 +795,11 @@ sub section_navigate
     push @html, Maasha::XHTML::table_end;
 
     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page",     value => "browse" ) );
-    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' }" ) );
+    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;
 }
@@ -785,16 +814,16 @@ sub section_browse
 
     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 ) ];
+    push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
+    push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
 
-    @tracks = Maasha::BBrowser::Track::path_tracks( $cookie );
+    @tracks = Maasha::BGB::Track::path_tracks( $cookie );
 
     for ( $i = 0; $i < @tracks; $i++ )
     {
-        $cookie->{ 'FEAT_COLOR' } = Maasha::BBrowser::Draw::palette( $i );
+        $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
 
-        push @features, [ Maasha::BBrowser::Track::track_feature( $tracks[ $i ], $cookie ) ];
+        push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
     }
 
     $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
@@ -805,10 +834,10 @@ sub section_browse
     $cr->fill;
 
     foreach $feat ( @features ) {
-        Maasha::BBrowser::Draw::draw_feature( $cr, $feat ) if $feat;
+        Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
     }
 
-    $png_data = Maasha::BBrowser::Draw::base64_png( $surface );
+    $png_data = Maasha::BGB::Draw::base64_png( $surface );
 
     push @img, Maasha::XHTML::img(
         src    => "data:image/png;base64,$png_data",
@@ -880,12 +909,12 @@ sub section_export
     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' }" ) );
+    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;
 }
@@ -904,7 +933,7 @@ sub section_search
 
     my ( $results, $result, $count, @html, $export, $browse );
 
-    $results = Maasha::BBrowser::Track::search_tracks( $cookie );
+    $results = Maasha::BGB::Track::search_tracks( $cookie );
 
     $count = scalar @{ $results };
 
@@ -973,8 +1002,8 @@ sub section_dna
     $beg =~ tr/,//d;
     $end =~ tr/,//d;
 
-    $seq = ">$cookie->{ 'CONTIG' }_$beg" . "_$end" . "_$cookie->{ 'STRAND' }\n";
-    $seq .= Maasha::BBrowser::Track::dna_get( $cookie );
+    $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
+    $seq .= Maasha::BGB::Track::dna_get( $cookie );
 
     push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
     push @html, Maasha::XHTML::pre( txt => $seq );