use entry::set_numbers and setbools for parameters

This commit is contained in:
Milan
2020-03-08 14:43:01 +01:00
parent 07219ad3ee
commit 5c73484638
24 changed files with 46 additions and 223 deletions

View File

@@ -11,19 +11,31 @@ sub from_valid($$) {
sub set_numbers($$$) {
my ( $entry, $params, $fields ) = @_;
for my $field (@$fields) {
next unless defined $params->{$field};
if ( $params->{$field} =~ /([\-\d]+)/ ){
my $value = $params->{$field};
next unless defined $value;
if ( $value =~ /([\-\d]+)/ ){
$entry->{$field} = $1;
}
}
}
sub set_bools($$$) {
my ( $entry, $params, $fields ) = @_;
for my $field (@$fields) {
my $value = $params->{$field};
next unless defined $value;
if ($value=~/([01])/){
$entry->{$field} = $1;
}
}
}
sub set_strings($$$) {
my ( $entry, $params, $attrs ) = @_;
for my $field (@$attrs) {
next unless defined $params->{$field};
$entry->{$field} = $params->{$field};
my $value = $params->{$field};
next unless defined $value;
$entry->{$field} = $value;
$entry->{$field} =~ s/^\s+//g;
$entry->{$field} =~ s/\s+$//g;
}
@@ -31,7 +43,8 @@ sub set_strings($$$) {
sub element_of($$) {
my ( $value, $attrs ) = @_;
return { map { $_ => $_ } @$attrs }->{$value};
return unless $value;
return { map { $_ => $_ } @$attrs }->{$value} //'';
}
# do not delete last line

View File

@@ -35,7 +35,6 @@ my $debug = $config->{system}->{debug};
my ( $user, $expires ) = auth::get_user( $config, $params, $cgi );
return if ( !defined $user ) || ( $user eq '' );
#print STDERR $params->{project_id}."\n";
my $user_presets = uac::get_user_presets(
$config,
{
@@ -48,7 +47,6 @@ $params->{default_studio_id} = $user_presets->{studio_id};
$params = uac::setDefaultStudio( $params, $user_presets );
$params = uac::setDefaultProject( $params, $user_presets );
#print STDERR $params->{project_id}."\n";
my $request = {
url => $ENV{QUERY_STRING} || '',
params => {
@@ -206,12 +204,6 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
#actions and roles
$checked->{action} = '';
if ( defined $params->{action} ) {
@@ -236,11 +228,3 @@ sub check_params {
return $checked;
}
__DATA__
SELECT ps.project_id, ps.studio_id, ps.series_id,p.name,s.name,se.series_name,se.title
FROM calcms_project_series ps ,calcms_projects p,calcms_studios s,calcms_series se
where ps.project_id=p.project_id and ps.studio_id=s.id and ps.series_id=se.id
order by se.series_name,p.name,s.name

View File

@@ -352,12 +352,6 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
#actions and roles
$checked->{action} = '';
if ( defined $params->{action} ) {

View File

@@ -554,19 +554,8 @@ sub check_params {
$checked->{studio_id} = -1;
}
#word
for my $param ( 'debug', 'name', 'description' ) {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\s*(.+?)\s*$/ ) ) {
$checked->{$param} = $1;
}
}
# words
for my $attr ( 'action', 'path' ) {
if ( ( defined $params->{$attr} ) && ( $params->{$attr} =~ /(\S+)/ ) ) {
$checked->{$attr} = $params->{$attr};
}
}
entry::set_strings( $checked, $params, [
'name', 'description', 'action', 'path' ]);
$checked->{upload} = $params->{upload};
return $checked;

View File

@@ -288,9 +288,6 @@ sub check_params {
my $event_id = $params->{event_id} || '';
if ( $event_id =~ /^(\d+)$/ ) {
$comment->{event_id} = $1;
} else {
# error('invalid event_id');
}
$comment->{event_id} = '' unless defined $comment->{event_id};

View File

@@ -202,12 +202,6 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
#actions and roles
$checked->{action} = '';
if ( defined $params->{action} ) {

View File

@@ -247,12 +247,6 @@ sub check_params {
my $template = '';
$checked->{template} = template::check( $config, $params->{template}, 'event-history' );
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
#numeric values
entry::set_numbers( $checked, $params, [
'id', 'project_id', 'studio_id', 'default_studio_id', 'user_id', 'series_id', 'event_id', 'v1', 'v2' )

View File

@@ -802,12 +802,6 @@ sub check_params {
my $template = '';
$checked->{template} = template::check( $config, $params->{template}, 'series' );
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
entry::set_numbers( $checked, $params, [
'id', 'project_id', 'studio_id', 'default_studio_id',
'user_id', 'series_id', 'event_id', 'source_event_id',
@@ -825,23 +819,13 @@ sub check_params {
'studio', 'search', 'from', 'till', 'hide_series'
]);
#numbers
for my $param ( 'duration', 'recurrence' ) {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /(\d+)/ ) ) {
$checked->{$param} = $1;
}
}
entry::set_numbers( $checked, $params, [
'duration', 'recurrence' ]);
#checkboxes
for my $param (
entry::set_bools( $checked, $params, [
'live', 'published', 'playout', 'archived',
'rerun', 'draft', 'disable_event_sync', 'get_rerun'
)
{
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /([01])/ ) ) {
$checked->{$param} = $1;
}
}
]);
entry::set_strings( $checked, $params, [
'series_name', 'title', 'excerpt', 'content',

View File

@@ -620,13 +620,6 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
#numeric values
$checked->{exclude} = 0;
entry::set_numbers( $checked, $params, [
'id', 'project_id', 'studio_id', 'default_studio_id' ]);

View File

@@ -381,26 +381,10 @@ sub check_params {
$checked->{studio_id} = -1;
}
#string
for my $param ( 'debug', 'name', 'description', 'licence' ) {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\s*(.+?)\s*$/ ) ) {
$checked->{$param} = $1;
}
}
#Words
for my $attr ('action') {
if ( ( defined $params->{$attr} ) && ( $params->{$attr} =~ /(\S+)/ ) ) {
$checked->{$attr} = $params->{$attr};
}
}
entry::set_strings( $checked, $params, [ 'action', 'name', 'description', 'licence' ]);
#checkboxes
for my $param ('public') {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /([01])/ ) ) {
$checked->{$param} = $1;
}
}
entry::set_bools( $checked, $params, [ 'public' ] );
return $checked;
}

View File

@@ -416,7 +416,6 @@ sub check_params {
my $checked = { template => template::check( $config, $params->{template}, 'image.html' ) };
#numeric values
$checked->{limit} = 100;
entry::set_numbers( $checked, $params, [
'project_id', 'studio_id', 'series_id', 'event_id', 'pid', 'default_studio_id', 'limit'
@@ -431,35 +430,15 @@ sub check_params {
$checked->{limit} = 100 unless defined $checked->{limit};
$checked->{limit} = 100 if ( $checked->{limit} > 100 );
#string
$checked->{search} = '';
if ( ( defined $params->{search} ) && ( $params->{search} =~ /^\s*(.+?)\s*$/ ) ) {
$checked->{search} = $1;
}
for my $attr ( 'update_name', 'update_description', 'licence' ) {
$checked->{$attr} = '';
if ( ( defined $params->{$attr} ) && ( $params->{$attr} =~ /^\s*(.+?)\s*$/ ) ) {
$checked->{$attr} = $params->{$attr};
}
}
#Words
$checked->{delete_image} = '';
$checked->{save_image} = '';
for my $attr ( 'save_image', 'delete_image', 'show', 'filename', 'target' ) {
$checked->{$attr} = '';
if ( ( defined $params->{$attr} ) && ( $params->{$attr} =~ /(\S+)/ ) ) {
$checked->{$attr} = $params->{$attr};
}
}
entry::set_strings( $checked, $params, [
'search',
'update_name', 'update_description', 'licence',
'save_image', 'delete_image', 'show', 'filename', 'target' ]);
#checkboxes
for my $param ('public') {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /([01])/ ) ) {
$checked->{$param} = $1;
}
}
entry::set_bools( $checked, $params, [ 'public ']);
#map show to filename, but overwrite if filename given
if ( $checked->{show} ne '' ) {

View File

@@ -252,11 +252,8 @@ sub check_params {
'event_id', 'project_id', 'studio_id', 'default_studio_id', 'user_id', 'series_id', 'duration'
]);
for my $param ( 'subject', 'to', 'cc', 'content' ) {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /\S/ ) ) {
$checked->{$param} = $params->{$param};
}
}
entry::set_strings( $checked, $params, [
'subject', 'to', 'cc', 'content']);
if ( defined $checked->{studio_id} ) {
$checked->{default_studio_id} = $checked->{studio_id};

View File

@@ -115,13 +115,6 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
#actions and roles
$checked->{action} = '';
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(delete)$/ ) {

View File

@@ -285,11 +285,8 @@ sub check_params {
}
}
for my $param ( 'name', 'title', 'subtitle', 'start_date', 'end_date', 'image', 'email', 'setImage' ) {
if ( defined $params->{$param} ) {
$checked->{$param} = $params->{$param};
}
}
entry::set_strings( $checked, $params, [
'name', 'title', 'subtitle', 'start_date', 'end_date', 'image', 'email', 'setImage' ]);
entry::set_numbers( $checked, $params, [
'project_id', 'studio_id', 'default_studio_id', 'pid', 'sid']);

View File

@@ -142,20 +142,8 @@ sub check_params {
my $checked = {};
#my $template = '';
#$checked->{template} = template::check($config, $params->{template}, 'request-password' );
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
for my $param ( 'user', 'token', 'user_password', 'user_password2' ) {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /\S/ ) ) {
$checked->{$param} = $params->{$param};
}
}
entry::set_strings( $checked, $params, [
'user', 'token', 'user_password', 'user_password2']);
$checked->{action} = '';
if ( defined $params->{action} ) {

View File

@@ -125,21 +125,13 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
entry::set_numbers( $checked, $params, [
'id', 'project_id', 'studio_id', 'series_id', 'event_id', 'p_id', 's_id'
]);
for my $param ( 'selectProjectStudio', 'selectSeries', 'selectRange' ) {
if ( ( defined $params->{$param} ) && ( $params->{$param} eq '1' ) ) {
$checked->{$param} = $params->{$param};
}
}
entry::set_bools( $checked, $params,
[ 'selectProjectStudio', 'selectSeries', 'selectRange' ]
);
for my $param ('resultElemId') {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^[a-zA-ZöäüÖÄÜß_\d]+$/ ) ) {

View File

@@ -115,21 +115,12 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
entry::set_numbers( $checked, $params, [
'id', 'project_id', 'studio_id', 'series_id', 'p_id', 's_id'
]);
for my $param ( 'selectProjectStudio', 'selectSeries', 'selectRange' ) {
if ( ( defined $params->{$param} ) && ( $params->{$param} eq '1' ) ) {
$checked->{$param} = $params->{$param};
}
}
entry::set_bools( $checked, $params, [
'selectProjectStudio', 'selectSeries', 'selectRange' ]);
for my $param ('resultElemId') {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^[a-zA-ZöäüÖÄÜß_\d]+$/ ) ) {

View File

@@ -1411,12 +1411,6 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
#actions
$checked->{action} = '';
if ( defined $params->{action} ) {

View File

@@ -100,12 +100,6 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
#numeric values
for my $param ('filename') {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^[A-Za-z\_\-\.\d\/]+$/ ) ) {

View File

@@ -17,6 +17,7 @@ use series;
use template;
use playout;
use audio;
use entry;
binmode STDOUT, ":utf8";
@@ -149,13 +150,6 @@ sub check_params {
$checked->{studio_id} = -1;
}
#word
for my $param ('debug') {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\s*(.+?)\s*$/ ) ) {
$checked->{$param} = $1;
}
}
return $checked;
}

View File

@@ -358,12 +358,6 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
#actions and roles
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(show|save_schedule|delete_schedule|show_dates)$/ ) {
@@ -371,7 +365,6 @@ sub check_params {
}
}
#numeric values
$checked->{exclude} = 0;
entry::set_numbers( $checked, $params, [
'id', 'project_id', 'studio_id', 'default_studio_id', 'schedule_id', 'schedule_studio_id'
@@ -392,11 +385,7 @@ sub check_params {
$checked->{template} = template::check( $config, $params->{template}, 'studio-timeslots' );
for my $param ('frequency') {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /(\d+)/ ) ) {
$checked->{$param} = $1;
}
}
entry::set_numbers( $checked, $params, ['frequency'] );
for my $attr ( 'start', 'end' ) {
if ( ( defined $params->{$attr} ) && ( $params->{$attr} =~ /(\d\d\d\d\-\d\d\-\d\d[ T]\d\d\:\d\d)/ ) ) {

View File

@@ -229,11 +229,8 @@ sub check_params {
}
}
for my $param ( 'name', 'description', 'location', 'stream', 'google_calendar', 'image', 'setImage' ) {
if ( defined $params->{$param} ) {
$checked->{$param} = $params->{$param};
}
}
entry::set_strings( $checked, $params, [
'name', 'description', 'location', 'stream', 'google_calendar', 'image', 'setImage' ]);
entry::set_numbers( $checked, $params, [
'project_id', 'studio_id', 'default_studio_id', 'id'

View File

@@ -394,7 +394,6 @@ sub check_params {
my $checked = {};
#template
my $template = '';
$template = template::check( $config, $params->{template}, 'users' );
$checked->{template} = $template;

View File

@@ -264,12 +264,6 @@ sub check_params {
my $checked = {};
my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1;
}
$checked->{debug} = $debug;
#actions and roles
$checked->{action} = '';
if ( defined $params->{action} ) {
@@ -278,7 +272,6 @@ sub check_params {
}
}
#numeric values
$checked->{exclude} = 0;
entry::set_numbers( $checked, $params, [
'project_id', 'studio_id', 'default_studio_id', 'schedule_id',