summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-10-01 17:07:37 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-10-01 17:07:37 (GMT)
commit8d815c3eed89242cee1f355ded4ca2a03fee2de3 (patch)
treebe986be75236d19a4d197a4e1ada6ca91a605911 /utils
parent6f1943313a0e503189dd9685483a9ecd1bd7cc6e (diff)
add sanity chekcs for add show command args
Diffstat (limited to 'utils')
-rwxr-xr-xutils/rd-group9
-rwxr-xr-xutils/rd-show44
2 files changed, 49 insertions, 4 deletions
diff --git a/utils/rd-group b/utils/rd-group
index 3898b5e..246d450 100755
--- a/utils/rd-group
+++ b/utils/rd-group
@@ -21,13 +21,14 @@
#
use strict;
+use lib "../lib/";
use RHRD::rddb;
# this is ridiculous but makes it a little harder to create/remove users...
-if ($> != 0 ) {
- print STDERR "this must be run as root!\n";
- exit 1;
-}
+# if ($> != 0 ) {
+# print STDERR "this must be run as root!\n";
+# exit 1;
+# }
sub print_usage
{
diff --git a/utils/rd-show b/utils/rd-show
index 0e53e05..c9a71c9 100755
--- a/utils/rd-show
+++ b/utils/rd-show
@@ -135,10 +135,54 @@ sub add__get_group_carts
return $low_cart;
}
+sub add__check_arguments
+{
+ my ($name, $title, $num_carts, $rhythm, $dow, $starttime, $len) = @_;
+
+ if($name !~ m/^[a-zA-Z0-9_]{1,10}$/) {
+ print STDERR "name '" . $name . "' contains illegal characters or is too long/short\n";
+ print STDERR " only a-z, A-Z, 0-9 and _ are allowed and the length must be between 1 and 10\n";
+ return 1;
+ }
+
+ if($num_carts <= 0) {
+ print STDERR "num-carts '" . $num_carts . "' must be > 0\n";
+ return 1;
+ }
+
+ if($rhythm !~ m/^[01]{4}$/ || $rhythm eq '0000') {
+ print STDERR "rhythm '" . $rhythm . "' contains illegal characters or is too long/short\n";
+ print STDERR " only 0 or 1 are allowed and, length must be exactly 4 and it must not be '0000'\n";
+ return 1;
+ }
+
+ if($dow < 1 || $dow > 7) {
+ print STDERR "dow '" . $dow . "' is out of range, must be between 1 and 7 (1=Monday, ..., 7=Sunday)\n";
+ return 1;
+ }
+
+ if($starttime !~ m/^[0-2][0-9][0-5][0-9]$/ || $starttime > 2359) {
+ print STDERR "starttime '" . $starttime . "' is not a valid time must be HHMM\n";
+ return 1;
+ }
+
+ if($len <= 0) {
+ print STDERR "len '" . $len . "' must be > 0\n";
+ return 1;
+ }
+
+ return 0;
+}
+
sub add
{
my ($ctx, $groupname, $name, $title, $num_carts, $rhythm, $dow, $starttime, $len) = @_;
+ my $ret = add__check_arguments($name, $title, $num_carts, $rhythm, $dow, $starttime, $len);
+ if($ret) {
+ return $ret;
+ }
+
print " * creating show: " . $title . " (" . $name . ") for group '" . $groupname . "'\n";
my $low_cart = add__get_group_carts($ctx, $groupname, $num_carts);