PDA

View Full Version : CBQ offline editor


oscarBravo
07-03-2007, 04:56 PM
Here's something I just hacked together this evening. It only works for v2, since v3 doesn't support the script upload and download functions - something to look forward to.

Basically I'm a vi kinda guy, and editing CBQ scripts without vi seems like a lot of hard work, so I threw this together to download a CBQ script, edit it, and upload it again. #!/bin/bash

if [ -z $2 ]; then
stty -echo
read -p "Password: " PASSWORD; echo
stty echo
else
PASSWORD=$2
fi

TEMP=`tempfile`

RESULT=`starutil $1 $PASSWORD -dscr cbq $TEMP`
if echo "$RESULT" | grep -q success; then
vi $TEMP
read -p "Upload changes? " UPLOAD
if [ $UPLOAD = 'y' ]; then
read -p "Activate after upload? " ACTIVATE
if [ $ACTIVATE = 'y' ]; then
FLAGS="-a"
fi
starutil $1 $PASSWORD -uscr cbq $TEMP $FLAGS &> /dev/null
echo "Success!"
else
echo "Aborted."
fi
else
echo "$RESULT"
fi

rm $TEMP To use it, you type "editcbq <router address> [password]" - if no password is provided it prompts for one.

I'm pretty crap at bash scripting, so any feedback is welcome.

Question: does the -a flag cause a "save" on the router? In other words, does it write to flash?

Edit: mod to remove the temporary file when finished.

tog
07-03-2007, 05:16 PM
I'm pretty sure UtiliStar and StarCom also do that if you don't mind Windows.

Also, isn't 1.3.0 getting starutil script upload/download support? I forget if it made it in time or not.

oscarBravo
07-03-2007, 05:18 PM
Some examples of this in operation: paul@orac:~$ editcbq 10.60.2.129
Password:
Upload changes? y
Activate after upload? y
Success!
paul@orac:~$ editcbq 10.60.2.129
Password:
Upload changes? n
Aborted.
paul@orac:~$ editcbq 10.60.2.129 wrongpassword
Invalid password
paul@orac:~$ editcbq 10.60.8.129
Password:
Server reported an error: Command not supported
paul@orac:~$ 10.60.8.129 is a WAR2.

tog
07-03-2007, 05:19 PM
Also, that is a cool bit of scripting, thanks.

oscarBravo
07-03-2007, 05:20 PM
I'm pretty sure UtiliStar and StarCom also do that if you don't mind Windows. Don't use Windows, won't use Windows. ;) This is aimed squarely at fellow Linux-heads. Also, isn't 1.3.0 getting starutil script upload/download support? I forget if it made it in time or not. It would be pretty cool if it did.

tony
07-03-2007, 05:22 PM
Yes, the individual script upload / download support made it into release 1.2.1b

lonnie
07-03-2007, 06:58 PM
What version is that WAR2? The new betas have support.

Some examples of this in operation: paul@orac:~$ editcbq 10.60.2.129
Password:
Upload changes? y
Activate after upload? y
Success!
paul@orac:~$ editcbq 10.60.2.129
Password:
Upload changes? n
Aborted.
paul@orac:~$ editcbq 10.60.2.129 wrongpassword
Invalid password
paul@orac:~$ editcbq 10.60.8.129
Password:
Server reported an error: Command not supported
paul@orac:~$ 10.60.8.129 is a WAR2.

oscarBravo
07-04-2007, 05:58 AM
It's 1.1.13, as most of our WARs are. I've been trying to find time to bench-test the betas before I do a field test, but things have been utterly crazy here lately.

As soon as I get a beta release on a router I'll be testing this (among many other things, obviously).

oscarBravo
07-04-2007, 06:01 AM
Oh yeah - any answer on whether "-a" saves the changes to flash? I could test by rebooting a router after applying changes and checking if the edits survived, but it would be nice to know without doing that.

tony
07-04-2007, 07:35 AM
When you upload a script, it is automatically saved to flash with or without the -a (activate) flag.

oscarBravo
07-04-2007, 07:40 AM
Super, thanks Tony.