From e1424fa99483e7d5944dcd729f96ee43f7b6c10d Mon Sep 17 00:00:00 2001 From: Mitch Jackson Date: Fri, 29 Jun 2018 14:01:36 -0500 Subject: RT# 31208 Fix Browse Discounts sorting error --- httemplate/browse/discount.html | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/httemplate/browse/discount.html b/httemplate/browse/discount.html index d3cf873d0..5ed43cf0e 100644 --- a/httemplate/browse/discount.html +++ b/httemplate/browse/discount.html @@ -1,10 +1,9 @@ <% include( 'elements/browse.html', 'title' => 'Discounts', 'name' => 'discounts', - 'menubar' => [ 'Add a new discount' => - $p.'edit/discount.html', - ], - 'query' => { 'table' => 'discount', }, + 'menubar' => \@menubar, + 'query' => \%query, + 'order_by_sql' => { description => 'discountnum' }, 'count_query' => 'SELECT COUNT(*) FROM discount', 'disableable' => 1, 'disabled_statuspos' => 1, @@ -13,9 +12,7 @@ 'classname', 'description', ], - 'links' => [ $link, - $link, - ], + 'links' => \@links ) %> <%init> @@ -23,6 +20,24 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); -my $link = [ "${p}edit/discount.html?", 'discountnum' ]; +my @links = ( + [ "${p}edit/discount.html?", 'discountnum' ], + [ "${p}edit/discount_class.html?", 'classnum' ], +); + +# Fixes disableable, because discount and discount_class tables +# both contain a 'disabled' column +local $FS::Record::qsearch_qualify_columns = 1; + +my %query = ( + select => 'discount.*, discount_class.*', + table => 'discount', + addl_from => 'LEFT JOIN discount_class USING(classnum)', +); + +my @menubar = ( + 'Add a new discount' => $p.'edit/discount.html', + 'Discount classes' => $p.'browse/discount_class.html', +); -- cgit v1.2.1 From 62b18c75989a1b00a25079f8f110992aaad81bba Mon Sep 17 00:00:00 2001 From: Mitch Jackson Date: Fri, 19 Oct 2018 17:54:48 -0400 Subject: RT# 31208 Docs $FS::Record::qsearch_qualify_columns --- FS/FS/Record.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 89957cb47..12e2d318f 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -289,6 +289,11 @@ the individual PARAMS_HASHREF queries #regular FS::TABLE methods #on it. +C<$FS::Record::qsearch_qualify_columns> package global is disabled by default. +When enabled, the WHERE clause generated from the 'hashref' parameter has +the table name prepended to each column name. WHERE column = 'value' becomes +WHERE table.coumn = 'value' + =cut my %TYPE = (); #for debugging -- cgit v1.2.1 From 3e6f3fa1610939bbc35a181966e38ec9d97940f7 Mon Sep 17 00:00:00 2001 From: Mitch Jackson Date: Mon, 22 Oct 2018 15:57:05 -0400 Subject: RT# 80555 Sanitize leading 0's from ip addr input --- FS/FS/IP_Mixin.pm | 4 ++++ FS/FS/Record.pm | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/FS/FS/IP_Mixin.pm b/FS/FS/IP_Mixin.pm index 3ec769313..8920cebc5 100644 --- a/FS/FS/IP_Mixin.pm +++ b/FS/FS/IP_Mixin.pm @@ -94,6 +94,10 @@ sub ip_check { $self->ip_addr(''); } + # Will strip extraneous leading zeros from ip adddresses + # e.g. 10.0.022.220 corrected to 10.0.22.220 + $self->ut_ip46n('ip_addr'); + if ( $self->ip_addr and !$self->router and $self->conf->exists('auto_router') ) { diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 12e2d318f..fe8fad969 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -2676,7 +2676,7 @@ sub ut_ip { $self->getfield($field) =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ or return "Illegal (IP address) $field: ". $self->getfield($field); for ( $1, $2, $3, $4 ) { return "Illegal (IP address) $field" if $_ > 255; } - $self->setfield($field, "$1.$2.$3.$4"); + $self->setfield( $field, $self->_ut_ip_strip_leading_zeros( "$1.$2.$3.$4" )); ''; } @@ -2705,8 +2705,9 @@ Check/untaint IPv4 or IPv6 address. sub ut_ip46 { my( $self, $field ) = @_; - my $ip = NetAddr::IP->new($self->getfield($field)) - or return "Illegal (IP address) $field: ".$self->getfield($field); + my $ip = NetAddr::IP->new( + $self->_ut_ip_strip_leading_zeros( $self->getfield($field) ) + ) or return "Illegal (IP address) $field: ".$self->getfield($field); $self->setfield($field, lc($ip->addr)); return ''; } @@ -2726,6 +2727,20 @@ sub ut_ip46n { $self->ut_ip46($field); } +sub _ut_ip_strip_leading_zeros { + # strip user-entered leading 0's from IP addresses + # so parsers like NetAddr::IP don't mangle the address + # e.g. NetAddr::IP converts 10.0.022.220 into 10.0.18.220 + + my ( $self, $ip ) = @_; + + return join '.', map int, split /\./, $ip + if $ip + && $ip =~ /\./ + && $ip =~ /[\.^]0/; + $ip; +} + =item ut_coord COLUMN [ LOWER [ UPPER ] ] Check/untaint coordinates. -- cgit v1.2.1 From 3a62fa3cc84424ebf528ee2f67b64ea00b363921 Mon Sep 17 00:00:00 2001 From: Mitch Jackson Date: Tue, 23 Oct 2018 00:51:51 -0400 Subject: RT# 38217 Fix JS bug when creating an email notice --- httemplate/browse/log_email.html | 45 ++++++++++++++++------------------- httemplate/misc/delete-log_email.html | 14 ++++++----- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/httemplate/browse/log_email.html b/httemplate/browse/log_email.html index 007ea6f74..6c2bce571 100644 --- a/httemplate/browse/log_email.html +++ b/httemplate/browse/log_email.html @@ -6,10 +6,7 @@ . $add_condition_link . ' | ' . $system_log_link - . '

' - . '', + . '

', 'query' => $query, 'count_query' => $count_query, 'header' => [ '#', @@ -43,6 +40,24 @@ ) %> + + <%init> my $curuser = $FS::CurrentUser::CurrentUser; @@ -50,11 +65,7 @@ my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" unless $curuser->access_right([ 'View system logs', 'Configuration' ]); -my $add_condition_link = include('/elements/popup_link.html', - 'action' => $p.'edit/log_email.html?popup=1', - 'label' => 'Add log email condition', - 'actionlabel' => 'Add log email condition', -); +my $add_condition_link = qq( Add log email condition ); my $system_log_link = qq(System Log); @@ -68,24 +79,10 @@ my $query = { my $count_query = "SELECT COUNT(*) FROM log_email"; my $actions = sub { - my $log_email = shift; - my $logemailnum = $log_email->logemailnum; + my $logemailnum = shift->logemailnum; qq!(delete)!; }; -my $areyousure_onclick = include('/elements/popup_link_onclick.html', - 'js_action' => q(') . $p . q(misc/delete-log_email.html?logemailnum=' + logemailnum), - 'actionlabel' => 'Delete log email condition', -); - -my $areyousure = < diff --git a/httemplate/misc/delete-log_email.html b/httemplate/misc/delete-log_email.html index cc17b15a0..5a6bdc083 100644 --- a/httemplate/misc/delete-log_email.html +++ b/httemplate/misc/delete-log_email.html @@ -3,7 +3,7 @@ % } else {

Log email condition deleted

% } @@ -11,10 +11,12 @@ window.top.location.reload(); die "access denied" unless $FS::CurrentUser::CurrentUser->access_right([ 'View system logs', 'Configuration' ]); -my $logemailnum = $cgi->param('logemailnum'); -$logemailnum =~ /^\d+$/ or die "bad logemailnum '$logemailnum'"; -my $log_email = FS::log_email->by_key($logemailnum) - or die "logemailnum '$logemailnum' not found"; -my $error = $log_email->delete; + my $error; + my $logemailnum = $cgi->param('logemailnum'); + if ( $logemailnum && $logemailnum =~ /^\d+$/ ) { + if ( my $log_email = FS::log_email->by_key( $logemailnum ) ) { + $error = $log_email->delete; + } + } -- cgit v1.2.1 From d5357a8ed89d3bfb9f861cd073a472a88768f9a1 Mon Sep 17 00:00:00 2001 From: Mitch Jackson Date: Tue, 23 Oct 2018 00:55:42 -0400 Subject: RT# 38217 Remove debugging --- httemplate/browse/log_email.html | 1 - 1 file changed, 1 deletion(-) diff --git a/httemplate/browse/log_email.html b/httemplate/browse/log_email.html index 6c2bce571..fe583dc62 100644 --- a/httemplate/browse/log_email.html +++ b/httemplate/browse/log_email.html @@ -43,7 +43,6 @@