use
vars
qw($VERSION @ISA %EXPORT_TAGS @EXPORT @EXPORT_OK)
;
$VERSION
=
'5.32'
;
@ISA
=
qw(Exporter)
;
%EXPORT_TAGS
= (
'vars'
=> [
qw(
PUBLIC USER EDITOR PUBLISHER ADMIN MASTER
$dbi %cgiparams %tvars %settings $cgi
)
],
'subs'
=> [
qw(
CGIArray ParamsCheck SetError SetCommand
)
],
'all'
=> [
qw(
PUBLIC USER EDITOR PUBLISHER ADMIN MASTER
$dbi %cgiparams %tvars %settings $cgi
CGIArray ParamsCheck SetError SetCommand
LoadProfiles LoadAccess
)
],
);
@EXPORT_OK
= ( @{
$EXPORT_TAGS
{
'all'
}} );
@EXPORT
= ( @{
$EXPORT_TAGS
{
'all'
}} );
our
%cgiparams
;
our
%tvars
;
our
%settings
;
our
$dbi
;
our
$cgi
;
sub
init {
my
$prot
=
qr{(?:http|https|ftp|afs|news|nntp|mid|cid|mailto|wais|prospero|telnet|gopher|git|file)://}
;
my
$atom
=
qr{[a-z\d]}
i;
my
$host
=
qr{(?:$atom(?:(?:$atom|-)*$atom)?)}
;
my
$domain
=
qr{(?:(?:(?:$host(?:\.$host)*))*(?:\.[a-zA-Z](?:$atom)*$atom)+)}
;
my
$ip
=
qr{(?:(?:\d+)(?:\.(?:\d+)){3}
)(?::(?:\d+))?};
my
$enc
=
qr{%[a-fA-F\d]{2}
};
my
$legal1
=
qr{[a-zA-Z\d\$_.+!*\'(),~\#-]}
;
my
$legal2
=
qr{[\/;:@&=]}
;
my
$legal3
=
qr{(?:(?:$legal1|$enc)+(?:(?:$legal2)+(?:$legal1|$enc)+)*)}
;
my
$path
=
qr{\/(?:$legal3)+}
;
my
$query
=
qr{(?:\?$legal3)+}
;
my
$local
=
qr{[-\w\'=.]+}
;
my
$url1
=
qr{(?: ($prot)? ($domain|$ip|\/$|$path) ($path)* ($query)? ) (\#[-\w.]+)?}
x;
my
$url2
=
qr{(?: (?:$prot) (?:$domain|$ip|\/$|$path) (?:$path)* (?:$query)? ) (?:\#[-\w.]+)?}
x;
my
$email
=
qr{$local\@(?:$domain|$ip)}
;
$settings
{protregex} =
$prot
;
$settings
{urlregex} =
$url1
;
$settings
{urlstrict} =
$url2
;
$settings
{emailregex} =
$email
;
$settings
{crawler} = 0;
if
(
$settings
{crawlers}) {
my
$ra
= Regexp::Assemble->new;
$ra
->add(
'\b'
.
quotemeta
(
$_
) .
'\b'
)
for
(@{
$settings
{crawlers} });
my
$re
=
$ra
->re;
$settings
{crawler} = 1
if
(
$ENV
{
'HTTP_USER_AGENT'
} =~
$re
);
}
$settings
{
'query-parser'
} ||=
'CGI'
;
my
$class
=
'Labyrinth::Query::'
.
$settings
{
'query-parser'
};
eval
{
eval
"CORE::require $class"
;
$cgi
=
$class
->new();
};
die
"Cannot load Query package for '$settings{'query-parser'}': $@"
if
($@);
}
sub
CGIArray {
my
$name
=
shift
;
return
()
unless
(
defined
$cgiparams
{
$name
} &&
$cgiparams
{
$name
});
return
(
$cgiparams
{
$name
})
unless
(
ref
$cgiparams
{
$name
} eq
'ARRAY'
);
return
@{
$cgiparams
{
$name
}};
}
sub
ParamsCheck {
for
my
$field
(
@_
) {
next
if
(
$cgiparams
{
$field
});
$tvars
{errcode} =
'MESSAGE'
;
$tvars
{errmess} =
"Missing parameter ($field)"
;
return
0;
}
return
1;
}
sub
SetError {
$tvars
{errcode} =
shift
;
$tvars
{errmess} =
shift
if
(
@_
);
}
sub
SetCommand {
$tvars
{errcode} =
'NEXT'
;
$tvars
{command} =
shift
;
}
sub
LoadProfiles {
return
if
(
defined
$settings
{profiles});
if
(!
$settings
{profile} || !-f
$settings
{profile} || !-r
$settings
{profile}) {
LogError(
"Cannot read profile file [$settings{profile}]"
);
$tvars
{errcode} =
'ERROR'
;
return
;
}
my
$cfg
= Config::IniFiles->new(
-file
=>
$settings
{profile} );
unless
(
defined
$cfg
) {
LogError(
"Unable to load profile file [$settings{profile}]: @Config::IniFiles::errors"
);
$tvars
{errcode} =
'ERROR'
;
return
;
}
my
$value
=
$cfg
->val(
'MAIN'
,
'default'
);
my
@value
=
$cfg
->val(
'MAIN'
,
'profiles'
);
$settings
{profiles}{
default
} =
$value
;
for
my
$profile
(
@value
) {
for
my
$name
(
$cfg
->Parameters(
$profile
)) {
$value
=
$cfg
->val(
$profile
,
$name
);
$settings
{profiles}{profiles}{
$profile
}{
$name
} =
$value
;
}
}
}
sub
LoadAccess {
return
if
(
defined
$settings
{access});
my
@rows
=
$dbi
->GetQuery(
'hash'
,
'AllAccess'
,9);
for
my
$row
(
@rows
) {
$settings
{access}{names}{
$row
->{accessname}} =
$row
->{accessid};
$settings
{access}{ids}{
$row
->{accessid}} =
$row
->{accessname};
}
}
1;