Initial commit.
This commit is contained in:
90
lib/perl5/Selima/LogOut.pm
Normal file
90
lib/perl5/Selima/LogOut.pm
Normal file
@@ -0,0 +1,90 @@
|
||||
# Selima Website Content Management System
|
||||
# LogOut.pm: The log-out subroutines.
|
||||
|
||||
# Copyright (c) 2004-2018 imacat.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Author: imacat <imacat@mail.imacat.idv.tw>
|
||||
# First written: 2004-10-16
|
||||
|
||||
package Selima::LogOut;
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(Exporter);
|
||||
use vars qw(@EXPORT @EXPORT_OK);
|
||||
BEGIN {
|
||||
@EXPORT = qw(logout);
|
||||
@EXPORT_OK = @EXPORT;
|
||||
# Prototype declaration
|
||||
sub logout();
|
||||
sub new_logoutid();
|
||||
}
|
||||
|
||||
use File::Spec::Functions qw(catfile);
|
||||
|
||||
use Selima::AddGet;
|
||||
use Selima::DataVars qw($SESSION $AUTHINFO :env);
|
||||
use Selima::HTTP;
|
||||
use Selima::Session;
|
||||
use Selima::XFileIO;
|
||||
|
||||
# logout: Log out
|
||||
sub logout() {
|
||||
local ($_, %_);
|
||||
delete $$SESSION{"usersn"};
|
||||
delete $$SESSION{"userid"};
|
||||
delete $$SESSION{"username"};
|
||||
delete $$SESSION{"userpref"};
|
||||
delete $$SESSION{"groups"};
|
||||
delete $$SESSION{"admin"};
|
||||
delete $$SESSION{"guest"};
|
||||
# Logged-in from Apache/mod_perl HTTP Authentication
|
||||
if (defined $AUTHINFO) {
|
||||
my ($id, $file, $r, $uri, $method);
|
||||
($id, $file) = new_logoutid;
|
||||
# Tag the log out file
|
||||
xfwrite($file, "");
|
||||
|
||||
# Get back to the referer
|
||||
$r = $IS_MP2? Apache2::RequestUtil->request:
|
||||
Apache->request;
|
||||
$uri = $r->headers_in->get("Referer");
|
||||
# Default to the home if referer is not available
|
||||
$uri = "/magicat/" if !defined $uri;
|
||||
# Append the logout ID.
|
||||
$uri = add_get_arg $uri, "logout", $id;
|
||||
|
||||
# Back to the referer
|
||||
if ($r->method eq "POST") {
|
||||
http_303 $uri;
|
||||
} else {
|
||||
http_307 $uri;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
# new_logoutid: Generate a new random logout ID number
|
||||
sub new_logoutid() {
|
||||
local ($_, %_);
|
||||
my ($id, $file);
|
||||
do {
|
||||
$id = 100000000 + int rand 900000000;
|
||||
$file = catfile($Selima::Session::DIR, "logout_$id");
|
||||
} until !-e $file;
|
||||
return ($id, $file);
|
||||
}
|
||||
|
||||
return 1;
|
||||
Reference in New Issue
Block a user