Historic archive of defunct list bismark-commits@lists.bufferbloat.net
 help / color / mirror / Atom feed
From: walter@svn.comics.unina.it
To: bismark-commits@lists.bufferbloat.net
Subject: [Bismark-commits] rev 349 - trunk/server/scripts
Date: Thu, 26 May 2011 13:36:22 +0200	[thread overview]
Message-ID: <E1QPYrW-0002pC-3j@svn.comics.unina.it> (raw)

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 <ssh_opts>    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: <dev_id>\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: <dev_id>\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: <dev_id>\n"; help exec; }
 		[ $3 ] || { echo -e "Missing parameter: <command>\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: <dev_id>\n"; help upgrade; }
+		check_device_id $2 || { echo -e "Unknown device $2\n"; help upgrade; }
 		upgrade $2 $3 
 	;;
 	config)
 		[ $2 ] || { echo -e "Missing parameter: <dev_id>\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: <dev_id>\n"; help setuser; }
 		[ $3 ] || { echo -e "Missing parameter: <username>\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: <file>\n"; help copy; }
 		[ $3 ] || { echo -e "Missing parameter: <dev_id>\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


                 reply	other threads:[~2011-05-26 11:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1QPYrW-0002pC-3j@svn.comics.unina.it \
    --to=walter@svn.comics.unina.it \
    --cc=bismark-commits@lists.bufferbloat.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox