83 lines
2.4 KiB
Perl
83 lines
2.4 KiB
Perl
# Selima Website Content Management System
|
|
# ScptPriv.pm: The script privilege form checker.
|
|
|
|
# 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-14
|
|
|
|
package Selima::Checker::ScptPriv;
|
|
use 5.008;
|
|
use strict;
|
|
use warnings;
|
|
use base qw(Selima::Checker);
|
|
|
|
use Selima::DataVars qw($DBH);
|
|
use Selima::ShortCut;
|
|
|
|
# new: Initialize the checker
|
|
sub new : method {
|
|
local ($_, %_);
|
|
my $class;
|
|
($class, @_) = @_;
|
|
$_[1] = "scptpriv" if scalar(@_) < 2 || !defined $_[1];
|
|
return $class->SUPER::new(@_);
|
|
}
|
|
|
|
# check: Run a list of checks
|
|
sub check : method {
|
|
local ($_, %_);
|
|
my ($self, $error, @cols);
|
|
($self, @cols) = @_;
|
|
# Run the parent method first
|
|
$error = $self->SUPER::check(@cols);
|
|
return $error if defined $error;
|
|
# See if we need to check the duplicates. Check it in the end.
|
|
%_ = map { $_ => 1 } @cols;
|
|
if (exists $_{"grp"} && exists $_{"member"}) {
|
|
$error = $self->__check_dup();
|
|
return $error if defined $error;
|
|
}
|
|
return;
|
|
}
|
|
|
|
# _check_script: Check the script
|
|
# Use the default script checker
|
|
|
|
# _check_grp: Check the group
|
|
# Use the default group checker
|
|
|
|
# __check_dup: Check if this item is duplicated
|
|
sub __check_dup : method {
|
|
local ($_, %_);
|
|
my ($self, $form, $error, $sth, $sql);
|
|
$self = $_[0];
|
|
$form = $self->{"form"};
|
|
@_ = qw();
|
|
push @_, "script=" . $form->param("script");
|
|
push @_, "grp=" . $form->param("grp");
|
|
push @_, "sn!=" . $self->{"sn"}
|
|
if $self->{"iscur"};
|
|
$sql = "SELECT * FROM " . $DBH->quote_identifier($self->{"table"})
|
|
. " WHERE " . join(" AND ", @_) . ";\n";
|
|
$sth = $DBH->prepare($sql);
|
|
$sth->execute;
|
|
return {"msg"=>N_("This script privilege record already exists. You cannot create a duplicated one.")}
|
|
if $sth->rows > 0;
|
|
return;
|
|
}
|
|
|
|
return 1;
|