Created
May 30, 2017 21:46
-
-
Save jackfischer/010ca1427d53f7e8e13b09a3a4a6c116 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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