From 8d815c3eed89242cee1f355ded4ca2a03fee2de3 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@spreadspace.org>
Date: Thu, 1 Oct 2015 19:07:37 +0200
Subject: add sanity chekcs for add show command args


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);
-- 
cgit v0.10.2