Skip to content

Instantly share code, notes, and snippets.

@jackfischer
Created May 30, 2017 21:46
Show Gist options
  • Save jackfischer/010ca1427d53f7e8e13b09a3a4a6c116 to your computer and use it in GitHub Desktop.
Save jackfischer/010ca1427d53f7e8e13b09a3a4a6c116 to your computer and use it in GitHub Desktop.
#Python 3
import fileinput
import os
TARGET_EXTENSION = ".php"
FIND = "REMOTE_ADDR"
REPLACE = "HTTP_CF_CONNECTING_IP"
def replace(f):
print(f"handling {f}")
with fileinput.FileInput(f, inplace=True, backup='.backup') as f:
for line in f:
print(line.replace(FIND, REPLACE), end='')
for root, dirs, files in os.walk('.'):
for f in files:
if f.endswith(TARGET_EXTENSION):
replace( os.path.join(root,f) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment