-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config changes, bugfix 15.1.1 release
- Loading branch information
Showing
6 changed files
with
151 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,78 @@ | ||
#!/bin/bash | ||
|
||
# This file is part of IXP Watch | ||
# | ||
# IXP Watch is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License as published by the | ||
# Free Software Foundation, version v2.0 of the License. | ||
# | ||
# IXP Watch is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
# for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License v2.0 | ||
# along with IXP Watch If not, see: | ||
# | ||
# http://www.gnu.org/licenses/gpl-2.0.html | ||
# | ||
# <[email protected]> - 2020-08-24 | ||
# Script to update /etc/ethers with member details to make | ||
# IXP-Watch reports and tcpdump more useful. | ||
# Set this up as a cron task to periodically update /etc/ethers e.g: | ||
# | ||
# 15 */2 * * * root /usr/local/bin/update_ethers.sh | ||
|
||
|
||
# Where is config vars file: | ||
CONFIG=/etc/ixpwatch/config.sh | ||
|
||
# default ethers file (set in CONFIG if different) | ||
ETHERSFILE=/etc/ethers | ||
|
||
# Config file can also be specified from the command line with -c <filename>: | ||
optstring=":c:" | ||
|
||
while getopts ${optstring} arg; do | ||
case "${arg}" in | ||
c) | ||
# Set config file: | ||
CONFIG=${OPTARG} | ||
;; | ||
esac | ||
done | ||
|
||
|
||
if [ ! -f $CONFIG ] ; then | ||
echo "Could not open config file $CONFIG!" | ||
exit 1 | ||
fi | ||
|
||
source $CONFIG | ||
|
||
DESTFILE=/etc/ethers | ||
TMPFILE=/tmp/ethers.$$ | ||
|
||
umask 002 | ||
|
||
if [ ! -f "${DESTFILE}" ] ; then | ||
touch ${DESTFILE} || echo "ERROR: could not write to ${DESTFILE}" >&2 ; exit 1 | ||
if [ ! -f "${ETHERSFILE}" ] ; then | ||
touch ${ETHERSFILE} || echo "ERROR: could not write to ${ETHERSFILE}" >&2 ; exit 1 | ||
fi | ||
|
||
# get updated ethers from IXP Manager: | ||
/usr/bin/wget -qO - https://portal.lonap.net/cgi-bin/json_ethers?vlanid=1 | jq -r '.ethers[] | [.mac,.ethersdesc] | @tsv' > ${TMPFILE} | ||
$WGET $WGET_OPTS $URL_ETHERS | $JQ -r '.ethers[] | [.mac,.ethersdesc] | @tsv' > ${TMPFILE} | ||
|
||
COUNTLINES=`grep -c "__" ${TMPFILE}` | ||
|
||
if [ $COUNTLINES -lt 20 ] ; then | ||
echo "Hmm. file for ${DESTFILE} seems a bit short to me. Not using." >&2 | ||
echo "Hmm. file for ${ETHERSFILE} seems a bit short to me. Not using." >&2 | ||
mv ${TMPFILE} ${TMPFILE}.err | ||
|
||
else | ||
|
||
cat ${TMPFILE} > ${DESTFILE} | ||
cat ${TMPFILE} > ${ETHERSFILE} | ||
|
||
fi | ||
|
||
# clean up tmp file: | ||
if [ -f "${TMPFILE}" ] ; then | ||
rm ${TMPFILE} | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.