Skip to content

Commit

Permalink
Add obfuscate strings
Browse files Browse the repository at this point in the history
  • Loading branch information
qaxi committed Apr 24, 2024
1 parent f9a9a24 commit 044c098
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 50 deletions.
47 changes: 0 additions & 47 deletions test/unit/commands.in

This file was deleted.

5 changes: 5 additions & 0 deletions test/unit/fetch_command_output.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ COMMANDS=()
# system info
COMMANDS+=("show version")
COMMANDS+=("show system")
COMMANDS+=("show version")
COMMANDS+=("show inventory")

# config commands
Expand Down Expand Up @@ -45,3 +46,7 @@ COMMANDS+=("show lldp neighbors $LLDPINTERFACE")
# ntp commands
COMMANDS+=("show sntp status")

OBFUSCATE=()
OBFUSCATE+=("sw-cb-&&&switch-")
OBFUSCATE+=("PSZ21221ECM&&&ABC12234XYZ")
OBFUSCATE+=("CZ;Ceske Budejovice;Rudolfovska 83;vr&&&Something;Somewhere;Somestreet;others")
25 changes: 22 additions & 3 deletions test/unit/fetch_command_output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ do

echo "## Fetching '$CMD' to '$CMDSTR.txt'"
# --debug
echo -e "$(napalm --user "$DEVUSERNAME" --password "$DEVPASSWORD" --vendor "$VENDOR" "$DEVICE" call --method-kwargs "command='$CMD'" "$METHOD" | sed 's/^"//;s/"$//;s/\\"/"/g')" > "$CMDFILE"
set -x
echo -e "$(napalm --debug --user "$DEVUSERNAME" --password "$DEVPASSWORD" --vendor "$VENDOR" "$DEVICE" call --method-kwargs "command='$CMD'" "$METHOD" | sed 's/^"//;s/"$//;s/\\"/"/g')" > "$CMDFILE"
set +x
done

echo "#### Preparing obfuscate script"
Expand All @@ -167,6 +169,7 @@ echo $IPs
for a in $IPs
do
oa=${a}
oa=${oa//1/3}
oa=${oa//2/3}
oa=${oa//4/3}
oa=${oa//5/3}
Expand Down Expand Up @@ -208,10 +211,26 @@ do
oMACs="$oMACs$om "
done

echo "## Obfuscate"
echo "## Obfuscate IPs and MACs"
echo oIPS=$oIPs
echo oMACs=$oMACs
sed -ri $oMACs $oIPs "$CODIR/$TYPE/"*.txt
set -x
sed -r -iOBF $oMACs $oIPs "$CODIR/$TYPE/"*.txt
set +x

echo "## Obfuscate strings from OBFUSCATE config variable"

for s in "${OBFUSCATE[@]}"
do
f="${s%%&&&*}"
t="${s##*&&&}"
oSTR="${oSTR}s/$f/$t/g;"
done

echo $oSTR
sed -r -iSTR -e "$oSTR" "$CODIR/$TYPE/"*.txt



echo "###################################################"
echo "## Do not forget obfuscate other output: ##"
Expand Down

0 comments on commit 044c098

Please sign in to comment.