reduce use of CGI.pm
This commit is contained in:
@@ -27,15 +27,13 @@ sub get_user {
|
||||
my $params = shift;
|
||||
my $cgi = shift;
|
||||
|
||||
debug("get_user") if ($debug);
|
||||
debug("get_user") if $debug;
|
||||
|
||||
# login or logout on action
|
||||
if ( defined $params->{action} ) {
|
||||
if ( $params->{action} eq 'login' ) {
|
||||
my $user = login( $config, $params->{user}, $params->{password} );
|
||||
$cgi = new CGI::Simple() unless defined $cgi;
|
||||
|
||||
$cgi->delete( 'user', 'password', 'uri', 'action' );
|
||||
$cgi->delete( 'user', 'password', 'uri', 'action' ) if defined $cgi;
|
||||
return $user;
|
||||
} elsif ( $params->{action} eq 'logout' ) {
|
||||
$cgi = new CGI::Simple() unless defined $cgi;
|
||||
@@ -81,7 +79,7 @@ sub login {
|
||||
my $config = shift;
|
||||
my $user = shift;
|
||||
my $password = shift;
|
||||
debug("login") if ($debug);
|
||||
debug("login") if $debug;
|
||||
|
||||
#print STDERR "login $user $password\n";
|
||||
my $result = authenticate( $config, $user, $password );
|
||||
@@ -103,7 +101,7 @@ sub login {
|
||||
sub logout {
|
||||
my $cgi = shift;
|
||||
my $session_id = read_cookie();
|
||||
debug("logout") if ($debug);
|
||||
debug("logout") if $debug;
|
||||
unless ( delete_session($session_id) ) {
|
||||
return show_login_form( 'Cant delete session', 'logged out' );
|
||||
}
|
||||
@@ -134,14 +132,14 @@ sub create_cookie {
|
||||
}
|
||||
|
||||
sub read_cookie {
|
||||
debug("read_cookie") if ($debug);
|
||||
debug("read_cookie") if $debug;
|
||||
my %cookie = CGI::Cookie->fetch;
|
||||
debug( "cookies: " . Dumper( \%cookie ) ) if ($debug);
|
||||
debug( "cookies: " . Dumper( \%cookie ) ) if $debug;
|
||||
my $cookie = $cookie{'sessionID'};
|
||||
debug( "cookie: " . $cookie ) if ($debug);
|
||||
debug( "cookie: " . $cookie ) if $debug;
|
||||
return undef unless defined $cookie;
|
||||
my $session_id = $cookie->value || undef;
|
||||
debug( "sid: " . $session_id ) if ($debug);
|
||||
debug( "sid: " . $session_id ) if $debug;
|
||||
return $session_id;
|
||||
}
|
||||
|
||||
@@ -149,7 +147,7 @@ sub read_cookie {
|
||||
sub delete_cookie {
|
||||
my $cgi = shift;
|
||||
|
||||
debug("delete_cookie") if ($debug);
|
||||
debug("delete_cookie") if $debug;
|
||||
my $cookie = $cgi->cookie(
|
||||
-name => 'sessionID',
|
||||
-value => '',
|
||||
@@ -165,7 +163,7 @@ sub create_session {
|
||||
my $password = shift;
|
||||
my $expiration = shift;
|
||||
|
||||
debug("create_session") if ($debug);
|
||||
debug("create_session") if $debug;
|
||||
my $session = CGI::Session->new( undef, undef, { Directory => $tmp_dir } );
|
||||
$session->expire($expiration);
|
||||
$session->param( "user", $user );
|
||||
@@ -197,7 +195,7 @@ sub read_session {
|
||||
sub delete_session {
|
||||
my $session_id = shift;
|
||||
|
||||
debug("delete_session") if ($debug);
|
||||
debug("delete_session") if $debug;
|
||||
return undef unless ( defined $session_id );
|
||||
my $session = CGI::Session->new( undef, $session_id, { Directory => $tmp_dir } );
|
||||
$session->delete();
|
||||
@@ -263,7 +261,7 @@ sub show_login_form {
|
||||
};
|
||||
}
|
||||
|
||||
debug("show_login_form") if ($debug);
|
||||
debug("show_login_form") if $debug;
|
||||
print qq{Content-type:text/html
|
||||
|
||||
<!DOCTYPE HTML>
|
||||
|
||||
@@ -17,8 +17,6 @@ sub isJson {
|
||||
}
|
||||
|
||||
sub get {
|
||||
|
||||
#get the Apache2::RequestRec
|
||||
my $r = shift;
|
||||
|
||||
my $tmp_dir = '/var/tmp/';
|
||||
@@ -31,23 +29,13 @@ sub get {
|
||||
$isJson = 0;
|
||||
|
||||
if ( defined $r ) {
|
||||
|
||||
#print STDERR "Apache2::Request\n";
|
||||
#get Apache2::Request
|
||||
my $req = Apache2::Request->new( $r, POST_MAX => $upload_limit, TEMP_DIR => $tmp_dir );
|
||||
|
||||
for my $key ( $req->param ) {
|
||||
$params->{ scalar($key) } = scalar( $req->param($key) );
|
||||
}
|
||||
|
||||
#copy params to hash
|
||||
#my $body=$req->body();
|
||||
#if (defined $body){
|
||||
# for my $key (keys %$body){
|
||||
# $params->{scalar($key)}=scalar($req->param($key));
|
||||
# }
|
||||
#}
|
||||
$status = $req->parse; #parse
|
||||
$status = $req->parse;
|
||||
} else {
|
||||
print STDERR "$0: require CGI\n";
|
||||
require "CGI.pm";
|
||||
@@ -62,14 +50,14 @@ sub get {
|
||||
$isJson = 1 if ( defined $params->{json} ) && ( $params->{json} eq '1' );
|
||||
|
||||
if ( defined $status ) {
|
||||
$status = '' if ( $status eq 'Success' );
|
||||
$status = '' if ( $status eq 'Missing input data' );
|
||||
print $cgi->header . $status . "\n" if ( $status ne '' );
|
||||
$status = '' if $status eq 'Success' ;
|
||||
$status = '' if $status eq 'Missing input data' ;
|
||||
if ($status ne ''){
|
||||
$cgi=new CGI::Simple() unless defined $cgi;
|
||||
print $cgi->header . $status . "\n";
|
||||
} ;
|
||||
}
|
||||
|
||||
#print STDERR Dumper($params);
|
||||
#print $cgi->header.Dumper($params).$status;
|
||||
|
||||
return ( $cgi, $params, $status );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user