From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from svn.comics.unina.it (unknown [143.225.229.147]) by huchra.bufferbloat.net (Postfix) with ESMTP id D8E6B20090F for ; Thu, 26 May 2011 04:22:04 -0700 (PDT) Received: from www-data by svn.comics.unina.it with local (Exim 4.69) (envelope-from ) id 1QPYrW-0002pC-3j for bismark-commits@lists.bufferbloat.net; Thu, 26 May 2011 13:36:22 +0200 To: bismark-commits@lists.bufferbloat.net From: walter@svn.comics.unina.it Message-Id: Date: Thu, 26 May 2011 13:36:22 +0200 X-Mailman-Approved-At: Fri, 27 May 2011 09:25:59 -0700 Subject: [Bismark-commits] rev 349 - trunk/server/scripts X-BeenThere: bismark-commits@lists.bufferbloat.net X-Mailman-Version: 2.1.13 Precedence: list List-Id: Commit log for the bismark source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2011 11:22:05 -0000 Author: walter Date: 2011-05-26 13:36:22 +0200 (Thu, 26 May 2011) New Revision: 349 Modified: trunk/server/scripts/bdm Log: bdm: added check on device id added cleardev command Modified: trunk/server/scripts/bdm =================================================================== --- trunk/server/scripts/bdm 2011-05-26 08:22:51 UTC (rev 348) +++ trunk/server/scripts/bdm 2011-05-26 11:36:22 UTC (rev 349) @@ -52,6 +52,8 @@ clearmsg [id] Delete pending messages + cleardev [id] Delete device from list + Options: -o Additional SSH options @@ -104,6 +106,7 @@ done fi else + check_device_id $2 || { echo -e "Unknown device $2\n"; help tunnel; } [ $3 == "on" ] && start_tunnel $2 $4 [ $3 == "off" ] && stop_tunnel $2 $4 fi @@ -111,11 +114,13 @@ gtunnel) [ $2 ] || { echo -e "Missing parameter: \n"; help gtunnel; } [ $2 == ALL ] && { echo -e "ALL not allowed\n"; help gtunnel; } + check_device_id $2 || { echo -e "Unknown device $2\n"; help gtunnel; } start_gtunnel $2 $3 ;; console) [ $2 ] || { echo -e "Missing parameter: \n"; help console; } [ $2 == ALL ] && { echo -e "ALL not allowed\n"; help console; } + check_device_id $2 || { echo -e "Unknown device $2\n"; help console; } echo "Connecting to $2" console $2 ;; @@ -123,6 +128,7 @@ [ $2 ] || { echo -e "Missing parameter: \n"; help exec; } [ $3 ] || { echo -e "Missing parameter: \n"; help exec; } [ $2 == ALL ] && { echo -e "ALL not allowed\n"; help exec; } + check_device_id $2 || { echo -e "Unknown device $2\n"; help exec; } echo "Executing \"${p#* * }\" on $2" console $2 ${p#* * } ;; @@ -138,16 +144,19 @@ ;; upgrade) [ $2 ] || { echo -e "Missing parameter: \n"; help upgrade; } + check_device_id $2 || { echo -e "Unknown device $2\n"; help upgrade; } upgrade $2 $3 ;; config) [ $2 ] || { echo -e "Missing parameter: \n"; help config; } - [ $2 == ALL ] && echo $* | grep -q DEVICE_ID && { echo -e "ALL not allowed for DEVICE_ID\n"; help console; } + [ $2 == ALL ] && echo $* | grep -q DEVICE_ID && { echo -e "ALL not allowed for DEVICE_ID\n"; help config; } + check_device_id $2 || { echo -e "Unknown device $2\n"; help config; } $* ;; setuser) [ $2 ] || { echo -e "Missing parameter: \n"; help setuser; } [ $3 ] || { echo -e "Missing parameter: \n"; help setuser; } + check_device_id $2 || { echo -e "Unknown device $2\n"; help setuser; } setuser $2 $3 ;; settunnel) @@ -161,11 +170,15 @@ copy) [ $2 ] || { echo -e "Missing parameter: \n"; help copy; } [ $3 ] || { echo -e "Missing parameter: \n"; help copy; } + check_device_id $2 || { echo -e "Unknown device $2\n"; help copy; } copy $2 $3 ;; clearmsg) clearmsg $2 ;; + cleardev) + cleardev $2 + ;; *) [ $1 ] && echo "Unknown command: $1" help @@ -224,6 +237,18 @@ done } +# Check device ID +# $1 = device id +function check_device_id() +{ + if [ $(query $BDM_DB "SELECT id FROM devices WHERE \"id\"='$1';") ]; then + return 0 + else + return 1 + fi +} + + # Check forwarding port # $1 = port number function check_fwd_port() @@ -665,6 +690,19 @@ fi } +# Clear pending messages +# $1 = id +function cleardev() +{ + if [ $1 ]; then + query $BDM_DB "DELETE FROM devices WHERE id=$1;" + else + echo "Delete all devices (yes/no)?" + read a + [ $a == "yes" ] && query $BDM_DB "DELETE FROM devices;" + fi +} + ## Main ## # Set random seed