soynatan / django-easy-audit

Yet another Django audit log app, hopefully the simplest one.
GNU General Public License v3.0
735 stars 182 forks source link

can we add this automatically I have to run a script to make changes, else I get 127.0.0.1 #273

Open 6abc opened 8 months ago

6abc commented 8 months ago

Find the path to auth_signals.py

AUTH_SIGNALS_PATH=$(find . -type f -name auth_signals.py)

Check if the file was found

if [ -z "$AUTH_SIGNALS_PATH" ]; then echo "Error: auth_signals.py not found." exit 1 fi

Use sed to replace the lines in auth_signals.py

sed -i "s/'remote_ip': request.META[REMOTE_ADDR_HEADER]/'remote_ip': request.META.get('HTTP_X_FORWARDED_FOR', request.META['REMOTE_ADDR']).split(',')[0],/" "$AUTH_SIGNALS_PATH"

Find the path to request_signals.py

REQUEST_SIGNALS_PATH=$(find . -type f -name request_signals.py)

Check if the file was found

if [ -z "$REQUEST_SIGNALS_PATH" ]; then echo "Error: request_signals.py not found." exit 1 fi

Use sed to replace the lines in request_signals.py

sed -i "s/remote_ip = environ.get(REMOTE_ADDR_HEADER, None)/remote_ip = environ.get('HTTP_X_FORWARDED_FOR', environ.get(REMOTE_ADDR_HEADER, '0.0.0.0')).split(',')[0]/" "$REQUEST_SIGNALS_PATH" sed -i "s/remote_ip = list(scope.get('client', ('0.0.0.0', 0)))[0]/remote_ip = headers.get(b'x-forwarded-for', b'0.0.0.0').decode(\"utf-8\").split(',')[0]/" "$REQUEST_SIGNALS_PATH"

image