Skip to content

Instantly share code, notes, and snippets.

@pocki80 pocki80/0xffedgebanner.sh Secret
Last active Oct 1, 2018

Embed
What would you like to do?
SSH Pre-Login Banner for 0xFF Funkfeuer EdgeRouter Logins
#!/bin/bash
# check if exists:
# grep -A 4 banner /config/config.boot | grep pre-login | grep ",---.,---.,---.,---.." | wc -l
#
# INSTALL/UPDATE via CLI:
# sudo curl -sS https://gist.githubusercontent.com/pocki80/e4c2c16c5c1b8886c8320446768a862f/raw/0xffedgebanner.sh | bash
location=$(echo -n $(grep -A 8 snmp /config/config.boot | grep location | sed "s/location//g" | sed "s/\"//g"))
contact=$(echo -n $(grep -A 8 snmp /config/config.boot | grep contact | sed "s/contact//g" | sed "s/\"//g"))
serial=$(ip -6 link show eth0 | grep link/ether | awk {'print toupper($2)'})
hostname=$(hostname)
# apply banner if missing or wrong snmp data inside
if [ $(grep -A 4 banner /config/config.boot | grep pre-login | grep ",---.,---.,---.,---.." | wc -l) -eq 0 ] ||
[ $(grep -A 4 banner /config/config.boot | grep pre-login | grep ":: $hostname ::" | wc -l) -eq 0 ] ||
[ $(grep -A 4 banner /config/config.boot | grep pre-login | grep "Location: $location" | wc -l) -eq 0 ] ||
[ $(grep -A 4 banner /config/config.boot | grep pre-login | grep "SerialNo: $serial" | wc -l) -eq 0 ] ||
[ $(grep -A 4 banner /config/config.boot | grep pre-login | grep "Contact : $contact" | wc -l) -eq 0 ]; then
cmd="/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper"
bannertext="Welcome to EdgeOS\n"
bannertext=$bannertext" | |\n"
bannertext=$bannertext" ,---.,---|,---.,---.,---.,---.. .|--- ,---.,---.\n"
bannertext=$bannertext" |---\`| || ||---\`| | || || |---\`|\n"
bannertext=$bannertext" \`---\`\`---\`\`---|\`---\`\` \`---\`\`---\`\`--- \`---\`\`\n"
bannertext=$bannertext" \`---\` :: "$hostname" ::\n"
[ "$location" ] && bannertext=$bannertext" Location: "$location"\n"
[ "$contact" ] && bannertext=$bannertext" Contact : "$contact"\n"
[ "$serial" ] && bannertext=$bannertext" SerialNo: "$serial"\n"
bannertext=$bannertext"\n\n\n"
tfile=$(mktemp)
(
$cmd begin
ret=0
if [ $ret == 0 ]; then
$cmd delete system login banner pre-login || ret=1
fi
if [ $ret == 0 ]; then
$cmd set system login banner pre-login "$bannertext" || ret=1
fi
if [ $ret == 0 ]; then
$cmd commit || ret=1
fi
if [ $ret == 0 ]; then
$cmd save || ret=1
fi
$cmd end
exit $ret
) >$tfile 2>&1
ret=$?
output=$(cat $tfile)
rm -f $tfile
echo "Banner updated."
echo $output
else
echo "Banner was already fine."
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.