chiark / gitweb /
wip, finish path handling, seems to work well now
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 11 Jan 2013 16:47:39 +0000 (16:47 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 11 Jan 2013 16:47:39 +0000 (16:47 +0000)
cgi-auth-flexible.pm

index 00b766aec90bf5a416ecdbe73ff640efc6777173..af4c30b48b2c7938412f6208172fe218da46305d 100644 (file)
@@ -54,6 +54,7 @@ sub flatten_params ($) {
     my ($p) = @_;
     my @p;
     foreach my $k (keys %$p) {
+        next if $k eq '';
        foreach my $v (@{ $p->{$k} }) {
            push @p, $k, $v;
        }
@@ -113,10 +114,13 @@ sub gen_some_form ($$) {
     # Calls $bodyfn->($c,$r) which returns @formbits
     my $c = $r->{Cgi};
     my @form;
+    my $pathinfo = '';
+    $pathinfo .= $params->{''}[0] if $params->{''};
     push @form, ('<form method="POST" action="'.
-                escapeHTML($r->_ch('get_url')).'">');
+                escapeHTML($r->_ch('get_url').$pathinfo).'">');
     push @form, $bodyfn->($c,$r);
     foreach my $n (keys %$params) {
+        next if $n eq '';
         foreach my $val (@{ $params->{$n} }) {
             push @form, ('<input type="hidden"'.
                          ' name="'.escapeHTML($n).'"'.
@@ -199,6 +203,7 @@ sub new_verifier {
            promise_check_mutate => 0,
            get_param => sub { $_[0]->param($_[2]) },
            get_params => sub { $_[1]->get_params() },
+           get_path_info => sub { $_[0]->path_info() },
            get_cookie => sub { $_[0]->cookie($_[1]->{S}{cookie_name}) },
            get_method => sub { $_[0]->request_method() },
            get_url => sub { $_[0]->url(); },
@@ -619,6 +624,8 @@ sub chain_params ($) {
     foreach my $name (grep /^$dummy_prefix/, keys %p) {
         delete $p{$name};
     }
+    die if exists $p{''};
+    $p{''} = [ $r->_ch('get_path_info') ];
     return \%p;
 }
 
@@ -722,6 +729,7 @@ sub url_with_query_params ($$) {
     my ($r, $params) = @_;
 print STDERR "PARAMS ",Dumper($params);
     my $uri = URI->new($r->_ch('get_url'));
+    $uri->path($uri->path() . $params->{''}[0]) if $params->{''};
     $uri->query_form(flatten_params($params));
     return $uri->as_string();
 }
@@ -748,10 +756,6 @@ sub check_ok ($) {
     my $params = $divert->{Params};
     my $cookie = $r->construct_cookie($cookiesecret);
 
-    if (defined $cookiesecret) {
-        $params->{$r->{S}{assoc_param_name}} = [ $r->hash($cookiesecret) ];
-    }
-
     if ($kind =~ m/^REDIRECT-/) {
        # for redirects, we honour stored NextParams and SetCookie,
        # as we would for non-divert
@@ -768,6 +772,10 @@ sub check_ok ($) {
        return 0;
     }
 
+    if (defined $cookiesecret) {
+        $params->{$r->{S}{assoc_param_name}} = [ $r->hash($cookiesecret) ];
+    }
+
     my ($title, @body);
     if ($kind =~ m/^LOGIN-/) {
        $title = $r->_gt('Login');