Skip to content

Commit 862012b

Browse files
committed
improved integer validator
1 parent 01b51dd commit 862012b

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

bin/v-add-user-package

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ is_package_new() {
2929

3030
is_package_consistent() {
3131
source $pkg_dir/$package.pkg
32-
validate_format_int $WEB_DOMAINS
33-
validate_format_int $WEB_ALIASES
34-
validate_format_int $DNS_DOMAINS
35-
validate_format_int $DNS_RECORDS
36-
validate_format_int $MAIL_DOMAINS
37-
validate_format_int $MAIL_ACCOUNTS
38-
validate_format_int $DATABASES
39-
validate_format_int $CRON_JOBS
40-
validate_format_int $DISK_QUOTA
41-
validate_format_int $BACKUPS
32+
validate_format_int $WEB_DOMAINS 'WEB_DOMAINS'
33+
validate_format_int $WEB_ALIASES 'WEB_ALIASES'
34+
validate_format_int $DNS_DOMAINS 'DNS_DOMAINS'
35+
validate_format_int $DNS_RECORDS 'DNS_RECORDS'
36+
validate_format_int $MAIL_DOMAINS 'MAIL_DOMAINS'
37+
validate_format_int $MAIL_ACCOUNTS 'MAIL_ACCOUNTS'
38+
validate_format_int $DATABASES 'DATABASES'
39+
validate_format_int $CRON_JOBS 'CRON_JOBS'
40+
validate_format_int $DISK_QUOTA 'DISK_QUOTA'
41+
validate_format_int $BACKUPS 'BACKUPS'
4242
validate_format_shell $SHELL
4343
}
4444

func/main.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ validate_format_password() {
510510
# Integer
511511
validate_format_int() {
512512
if ! [[ "$1" =~ ^[0-9]+$ ]] ; then
513-
echo "Error: int $1 is not valid"
513+
echo "Error: $2 $1 is not valid"
514514
log_event "$E_INVALID" "$EVENT"
515515
exit $E_INVALID
516516
fi
@@ -700,7 +700,7 @@ validate_format_dvalue() {
700700
fi
701701
if [ "$rtype" = 'MX' ]; then
702702
validate_format_domain "$1" 'mx_record'
703-
validate_format_int "$priority"
703+
validate_format_int "$priority" 'priority_record'
704704
fi
705705

706706
}
@@ -760,17 +760,17 @@ validate_format(){
760760
ftp_user) validate_format_username "$arg" "$arg_name" ;;
761761
host) validate_format_domain "$arg" "$arg_name" 'host';;
762762
hour) validate_format_mhdmw "$arg" $arg_name ;;
763-
id) validate_format_int "$arg" ;;
763+
id) validate_format_int "$arg" 'id' ;;
764764
interface) validate_format_interface "$arg" ;;
765765
ip) validate_format_ip "$arg" ;;
766766
ip_name) validate_format_domain "$arg" 'domain';;
767767
ip_status) validate_format_ip_status "$arg" ;;
768-
job) validate_format_int "$arg" ;;
768+
job) validate_format_int "$arg" 'job' ;;
769769
key) validate_format_username "$arg" "$arg_name" ;;
770770
lname) validate_format_name "$arg" "$arg_name" ;;
771771
malias) validate_format_username "$arg" "$arg_name" ;;
772772
mask) validate_format_ip "$arg" ;;
773-
max_db) validate_format_int "$arg" ;;
773+
max_db) validate_format_int "$arg" 'max db';;
774774
min) validate_format_mhdmw "$arg" $arg_name ;;
775775
month) validate_format_mhdmw "$arg" $arg_name ;;
776776
nat_ip) validate_format_ip "$arg" ;;
@@ -780,8 +780,8 @@ validate_format(){
780780
ns4) validate_format_domain "$arg" 'name_server';;
781781
package) validate_format_name "$arg" "$arg_name" ;;
782782
password) validate_format_password "$arg" ;;
783-
port) validate_format_int "$arg" ;;
784-
quota) validate_format_int "$arg" ;;
783+
port) validate_format_int "$arg" 'port' ;;
784+
quota) validate_format_int "$arg" 'quota' ;;
785785
restart) validate_format_boolean "$arg" 'restart' ;;
786786
record) validate_format_common "$arg" 'record';;
787787
rtype) validate_format_dns_type "$arg" ;;
@@ -790,7 +790,7 @@ validate_format(){
790790
stats_pass) validate_format_password "$arg" ;;
791791
stats_user) validate_format_username "$arg" "$arg_name" ;;
792792
template) validate_format_name "$arg" "$arg_name" ;;
793-
ttl) validate_format_int "$arg" ;;
793+
ttl) validate_format_int "$arg" 'ttl';;
794794
user) validate_format_username "$arg" "$arg_name" ;;
795795
wday) validate_format_mhdmw "$arg" $arg_name ;;
796796
esac

0 commit comments

Comments
 (0)