diff --git a/getKey.sh b/getKey.sh deleted file mode 100755 index 4767768..0000000 --- a/getKey.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# This script is used to get the API key from a palo alto firewall - -FW_MGMT_IP=$1 -USERNAME=$2 -PASSWD=$3 - -# Check parameters -if [ $# -ne 3 ]; then - echo "Usage: $0 " - exit 1 -fi - -URL="https://$FW_MGMT_IP/api/?type=keygen&user=$USERNAME&password=$PASSWD" - -# Get the key from firewall -curl -k -s -X POST "$URL" | grep -oP '(?<=)[^<]+' diff --git a/get_key.sh b/get_key.sh new file mode 100755 index 0000000..ca33c84 --- /dev/null +++ b/get_key.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Configuration +FW_MGMT_IP=$1 +USER=$2 +PASSWD=$3 + +[ $# -eq 0 ] && { + echo "ERRO - Uso: $0 Exemplo: 192.168.1.1 admin password" + exit 1 +} + +wget --output-document=/tmp/getkey.txt "https://$FW_MGMT_IP/api/?type=keygen&user=$USER&password=$PASSWD" --no-check-certificate + +KEY=$(cat /tmp/getkey.txt | awk '{print $4}' | grep -o '.*' | sed 's/\(\|<\/key>\)//g') + +echo "Valor da variavel KEY do PaloAlto >>> $KEY" diff --git a/smb-pan.sh b/smb-pan.sh old mode 100644 new mode 100755 index 6b43b62..699315d --- a/smb-pan.sh +++ b/smb-pan.sh @@ -20,6 +20,15 @@ LOGGED_USERS=$(sudo smbstatus -b | tail -n +5) # Count logged in users LOGGED_USERS_COUNT=$(echo "$LOGGED_USERS" | wc -l) +# If no users are logged in, exit +if [ $LOGGED_USERS_COUNT -eq 0 ]; then + echo "No users logged in, exiting" + exit 0 +fi + +# Build XML command +ENTRIES="" + while read -r line; do USER=$(echo $line | awk '{print $2}') IP=$(echo $line | awk '{print $5}') @@ -40,21 +49,15 @@ while read -r line; do ENTRIES="$ENTRIES" done <<<"$LOGGED_USERS" -# Check if ENTRIES is empty -if [ -z "$ENTRIES" ]; then - echo "No users logged in, skipping" - exit 0 -fi - COMMAND="1.0update$ENTRIES" -URL="https://$FW_MGMT_IP/api/?type=user-id&key=$FW_KEY&cmd=$COMMAND" +URL="https://$FW_MGMT_IP/api/?type=user-id&key=$FW_KEY" echo --- -$CURL -k -H "Content-Type: application/xml" -X POST "$URL" +$CURL -k -H "Content-Type: application/x-www-form-urlencoded" -d "cmd=$COMMAND" -X POST "$URL" # Get current datetime NOW=$(date +"%Y-%m-%d %H:%M:%S") -echo $NOW " - $LOGGED_USERS_COUNT users mapped to firewall" >/var/log/smb-pan.log +echo $NOW " - $LOGGED_USERS_COUNT users mapped to firewall" >>/var/log/smb-pan.log