X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=cgi-auth-hybrid.pm;h=422d7a31b357e6d18cd2052d128501a5a3b7aa39;hb=a3eb016136dc3782b103c06fca9762012469d711;hp=3388b85cdf793730da2d8a65d8b4ef0cb3155c88;hpb=8be9bfceabd19dfb7474de5707ec9ccb9dcea2d9;p=cgi-auth-flexible.git diff --git a/cgi-auth-hybrid.pm b/cgi-auth-hybrid.pm index 3388b85..422d7a3 100644 --- a/cgi-auth-hybrid.pm +++ b/cgi-auth-hybrid.pm @@ -31,17 +31,73 @@ our @EXPORT_OK; use DBI; use CGI; +use Locale::Gettext; #---------- default callbacks ---------- -sub _def_is_logout ($$) { - my ($c,$r) = @_; - foreach my $pn (@{ $r->{S}{logout_param_names} }) { +sub has_a_param ($$) { + my ($c,$cn) = @_; + foreach my $pn (@{ $r->{S}{$cn} }) { return 1 if $r->_cm('get_param')($pn); } return 0; } +sub get_param_list ($$) { + my ($c) = @_; + my @p = ( ); + foreach my $name ($c->param()) { + foreach my $val ($c->param($name)) { + push @p, $name, $val; + } + } + return @p; +} + +sub get_cookie_domain ($$$) { + my ($c,$r) = @_; + my $uri = new URI $r->_ch('get_url'); + return $uri->host(); +} + +sub construct_cookie ($$$) { + my ($c, $r, $cookv) = @_; + return $c->cookie(-name => $r->{S}{cookie_name}, + -value => $cookv, + -path => $r->{S}{cookie_path}, + -domain => $r->_ch('get_cookie_domain'), + -expires => '+'.$r->{S}{login_timeout}.'s', + -secure => $r->{S}{encrypted_only}); +} + +sub do_redirect_cgi ($$$$) { + my ($c, $r, $new_url, $cookie) = @_; + my @ha = ('text/html', + -status => '303 See other', + -location => $new_url); + push @ha, (-cookie => $cookie) if defined $cookie; + $r->_print($c->header(@ha), + $r->_ch('gen_start_html')($r->__('Redirection')), + '', + $r->__("If you aren't redirected, click to continue."), + "", + $c->_ch('gen_end_html')); +} + +sub gen_plain_login_form ($$) { + my ($c,$r) = @_; + my @form; + push @form, ('