update client ip retrieval

This commit is contained in:
Micky 2024-12-26 12:48:46 +11:00
parent 5f517e39e0
commit 333a4403e6
2 changed files with 11 additions and 2 deletions

View File

@ -64,6 +64,14 @@ def send_webhook(webhook_url, text_data):
response.raise_for_status()
# Get client IP address
@exception_handler
def get_client_ip(request):
if not request.headers.getlist("X-Forwarded-For"):
return request.remote_addr
return request.headers.getlist("X-Forwarded-For")[0]
# Establish connection to network device
def establish_connection(device_config):
try:

View File

@ -3,7 +3,7 @@ from flask import (
)
import logging
from app.functions.utils import exception_handler, load_yaml, execute_command, send_webhook
from app.functions.utils import exception_handler, load_yaml, send_webhook, get_client_ip, execute_command,
logger = logging.getLogger(__name__)
@ -58,6 +58,7 @@ def execute():
# Send a webhook notification with client IP and command output
if not result['error'] and webhook:
send_webhook(webhook['url'], f"Client IP: `{request.remote_addr}`\nDevice: `{input_device}`\nCommand: `{input_command} -{ip_version} {input_target}`")
client_ip = get_client_ip(request)
send_webhook(webhook['url'], f"Client IP: `{client_ip}`\nDevice: `{input_device}`\nCommand: `{input_command} -{ip_version} {input_target}`")
return result