Skip to content

Instantly share code, notes, and snippets.

@pocki80
Last active November 2, 2022 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pocki80/e4c2c16c5c1b8886c8320446768a862f to your computer and use it in GitHub Desktop.
Save pocki80/e4c2c16c5c1b8886c8320446768a862f to your computer and use it in GitHub Desktop.
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:
# curl -sS https://gist.githubusercontent.com/pocki80/e4c2c16c5c1b8886c8320446768a862f/raw/0xffedgebanner.sh | sudo 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)'})
serial=$(/usr/sbin/ubnt-hal show-version | grep "HW S/N" | awk '{print $3}' | sed 's/.\{2\}/&:/g' | sed 's/:$//g')
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