Index: chey/start.sh =================================================================== --- chey.orig/start.sh +++ chey/start.sh @@ -1,4 +1,7 @@ #!/bin/bash +# May I suggest Ruby? It has awesome date & time string processing, and features +# regular expressions a la Perl. +# Python has crap for date & time processing, as far as I remember. userfile=users.list groupfile=groups.list @@ -12,6 +15,7 @@ function runip() { if [ `echo $gline | awk '{print $2}'` = "ALL" ] ; then echo $iptables -A $ipgroup -p ALL -i $GREEN -s `echo $userline | awk '{print $2}'` -j ACCEPT else + # instead of this... { z=1 portnumb=`echo $gline | awk '{print $2}' | sed /,/s//"\n"/g | wc -l` if [ $portnumb -gt 1 ] ; then @@ -23,12 +27,27 @@ function runip() { else echo $iptables -A $ipgroup -p ALL -i $GREEN -s `echo $userline | awk '{print $2}'` --dport `echo $gline | awk '{print $2}'` -j ACCEPT fi + # } + + # Do this: { + portlist=$(echo $gline | awk '{print $2}' | sed -e 's:,: :g') + ipaddress=$(echo $userline | awk '{print $2}') + for port in $portlist; do + echo $iptables -A $ipgroup -p udp -i $GREEN -s $ipaddress --dport $port -j ACCEPT + echo $iptables -A $ipgroup -p tcp -i $GREEN -s $ipaddress --dport $port -j ACCEPT + done + # } fi # echo $iptables -A $ipgroup -p ALL -I $GREEN -s `echo $userline | awk '{print $2}'` --dport `echo $gline | awk '{print $2 # echo bla } +function hourmin2min() { + hour="$1"; min="$2"; + expr $min '+' $hour '*' 60 +} + # See how many lines are in the userfile usernumb=`wc -l $userfile | awk '{print $1}'` @@ -78,11 +97,23 @@ do fi if [ $starthour -eq $currhour ]; then if [ $startmin -lt $currmin ] ; then + # Wouldn't you need to check end minutes here if endhour -eq currhour? runip fi fi fi + # Better idea: convert everything to minutes + currmin2=$(hourmin2min $currhour $currmin) + startmin2=$(hourmin2min $starthour $startmin) + endmin2=$(hourmin2min $endhour $endmin) + + if [ $startmin2 -gte $currmin2 ]; then + if [ $endmin2 -lte $currmin2 ]; then + runip + fi + fi + let x+=1 done