Explorar el Código

Make everything point at /secure/* when logged in

This way we can use a different Location rule in nginx
George Baugh hace 5 meses
padre
commit
9dc222c790

+ 6 - 0
lib/TCMS.pm

@@ -158,6 +158,11 @@ sub _routes ( $data = {} ) {
     # Routes in general are going to override earlier, more default ones.
     # XXX this is probably bad in the case of the specific content-typed routes, they should be mutex
     my %roots = $data->routes();
+
+    # Setup the /secure/... versions for logged in users
+    @roots{ map { "/secure$_" } keys(%roots) } = values(%roots);
+
+    # It is the responsibility of theme authors to setup /secure routes (other than index)
     my %themed = Trog::Themes::routes();
 
     %routes                                      = %Trog::Routes::HTML::routes;
@@ -175,6 +180,7 @@ sub _routes ( $data = {} ) {
     # The Various aliases for directory indices
     foreach my $index (qw{ / /index.html /index.htm}) {
         $routes{$index} = $routes{'/index'} unless exists $routes{$index};
+        $routes{"/secure$index"} = $routes{'/index'} unless exists $routes{"/secure$index"};
     }
 
     return clone( \%routes );

+ 26 - 2
lib/Trog/Routes/HTML.pm

@@ -62,7 +62,6 @@ our %routes = (
     #        method   => 'GET',
     #        callback => \&Trog::Routes::HTML::setup,
     #    },
-
     '/login' => {
         method   => 'GET',
         callback => \&Trog::Routes::HTML::login,
@@ -72,6 +71,7 @@ our %routes = (
         method   => 'GET',
         callback => \&Trog::Routes::HTML::logout,
         noindex  => 1,
+        nocache  => 1,
     },
     '/auth' => {
         method   => 'POST',
@@ -125,15 +125,23 @@ our %routes = (
         callback => \&Trog::Routes::HTML::resetpass,
         noindex  => 1,
     },
+    # When we are logged in, we get a diff ver of the page.
+    '/secure/password_reset' => {
+        method   => 'GET',
+        callback => \&Trog::Routes::HTML::resetpass,
+        auth     => 1,
+    },
     '/request_password_reset' => {
         method   => 'POST',
         callback => \&Trog::Routes::HTML::do_resetpass,
         noindex  => 1,
+        nocache  => 1,
     },
     '/request_totp_clear' => {
         method   => 'POST',
         callback => \&Trog::Routes::HTML::do_totp_clear,
         noindex  => 1,
+        nocache  => 1,
     },
     '/processed' => {
         method   => 'GET',
@@ -930,6 +938,9 @@ Displays identified series, not all series.
 sub series ($query) {
     my $is_admin = grep { $_ eq 'admin' } @{ $query->{user_acls} };
 
+    # rip away /secure if present
+    $query->{route} =~ s|^/secure||;
+
     #we are either viewed one of two ways, /post/$id or /$aclname
     my ( undef, $aclname, $id ) = split( /\//, $query->{route} );
     $query->{aclname} = $aclname if !$id;
@@ -997,6 +1008,9 @@ Implements direct user profile view.
 
 sub users ($query) {
 
+    # rip away /secure if present
+    $query->{route} =~ s|^/secure||;
+
     # Capture the username
     my ( undef, undef, $display_name ) = split( /\//, $query->{route} );
     $display_name = URI::Escape::uri_unescape($display_name);
@@ -1035,6 +1049,10 @@ sub posts ( $query, $direct = 0 ) {
 
     #Process the input URI to capture tag/id
     $query->{route} //= $query->{to};
+
+    # rip away /secure if present
+    $query->{route} =~ s|^/secure||;
+
     my ( undef, undef, $id ) = split( /\//, $query->{route} );
 
     my $tags = Trog::Utils::coerce_array( $query->{tag} );
@@ -1253,7 +1271,7 @@ sub _post_helper ( $query, $tags, $acls ) {
     $query->{page}  ||= 1;
     $query->{limit} ||= 25;
 
-    return $data->get(
+    my @d = $data->get(
         older        => $query->{older},
         newer        => $query->{newer},
         page         => int( $query->{page} ),
@@ -1267,6 +1285,12 @@ sub _post_helper ( $query, $tags, $acls ) {
         id           => $query->{id},
         version      => $query->{version},
     );
+    return map {
+        my $subj = $_;
+        $subj->{local_href} = "/secure$_->{local_href}";
+        $subj
+    } @d if $query->{user};
+    return @d;
 }
 
 =head2 sitemap

+ 4 - 0
www/templates/html/components/categories.tx

@@ -1,5 +1,9 @@
 <span id="categories">
 : for $categories -> $category {
+    : if ($user) {
+<a href="/secure<: $category.local_href :>"   title="<: $category.title :>" class="topbar"><: $category.title :></a>
+    : } else {
 <a href="<: $category.local_href :>"   title="<: $category.title :>" class="topbar"><: $category.title :></a>
+    : }
 : }
 </span>

+ 1 - 1
www/templates/html/sysbar.tx

@@ -1,7 +1,7 @@
 <div id="topkek" style="text-align: center; vertical-align: middle;">
     <button title="Menu" id="clickme">☰</button>
     <span id="configbar">
-        <a href="/"            title="Back home"     class="topbar">Home</a>
+        <a href="/secure/"     title="Back home"     class="topbar">Home</a>
         <a href="/config"      title="Configuration" class="topbar">Settings</a>
         <a href="/manual"      title="Manual"        class="topbar">Manual</a>
         <a href="/metrics?period=hour&num_periods=24"     title="Metrics"       class="topbar">Metrics</a>