Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/sharedra.../oldrads
File: cmsrainbow.py
#!/opt/imh-python/bin/python3
[0] Fix | Delete
__author__ = 'chases'
[1] Fix | Delete
from glob import glob
[2] Fix | Delete
from pathlib import Path
[3] Fix | Delete
import re
[4] Fix | Delete
import subprocess
[5] Fix | Delete
import sys
[6] Fix | Delete
from typing import Union
[7] Fix | Delete
[8] Fix | Delete
FIND_NAMES = {
[9] Fix | Delete
'version.php': 'versionfiles',
[10] Fix | Delete
'concrete.php': 'concretefiles',
[11] Fix | Delete
'base.php': 'basefiles',
[12] Fix | Delete
'Version.php': 'zf_files',
[13] Fix | Delete
'Kernel.php': 'symfonyfiles',
[14] Fix | Delete
'DefaultSettings.php': 'mediawikifiles',
[15] Fix | Delete
'CHANGELOG.txt': 'drupalfiles',
[16] Fix | Delete
'CHANGELOG': 'magentofiles',
[17] Fix | Delete
'RELEASE_NOTES.txt': 'oldmagefiles',
[18] Fix | Delete
'Mage.php': 'oldmagefiles2',
[19] Fix | Delete
'readme_en.txt': 'prestafiles',
[20] Fix | Delete
'whatsnew_*html': 'whatsnewfiles',
[21] Fix | Delete
'joomla.xml': 'joomlafiles',
[22] Fix | Delete
'CHANGELOG.php': 'oldjoomla',
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
[26] Fix | Delete
def find_target_files() -> list[Path]:
[27] Fix | Delete
# fmt: off
[28] Fix | Delete
cmd = ['find', '/home', '-mindepth', '3']
[29] Fix | Delete
names = list(FIND_NAMES)
[30] Fix | Delete
cmd.extend([
[31] Fix | Delete
'-type', 'f',
[32] Fix | Delete
'-not', '(', '-path', "*cache*", '-prune', ')',
[33] Fix | Delete
'(', '-name', names[0]])
[34] Fix | Delete
for name in names[1:]:
[35] Fix | Delete
cmd.extend(['-o', '-name', name])
[36] Fix | Delete
cmd.extend([')', '-print0'])
[37] Fix | Delete
# fmt: on
[38] Fix | Delete
ret = subprocess.run(
[39] Fix | Delete
cmd, stdout=subprocess.PIPE, encoding='utf-8', check=False
[40] Fix | Delete
)
[41] Fix | Delete
return [Path(x) for x in ret.stdout.split('\0') if x]
[42] Fix | Delete
[43] Fix | Delete
[44] Fix | Delete
def iterlines_path(path: Path):
[45] Fix | Delete
try:
[46] Fix | Delete
with open(path, encoding='utf-8', errors='replace') as infofile:
[47] Fix | Delete
yield from infofile
[48] Fix | Delete
except OSError as exc:
[49] Fix | Delete
print(exc, file=sys.stderr)
[50] Fix | Delete
[51] Fix | Delete
[52] Fix | Delete
def proc_version(path: Path) -> Union[str, None]:
[53] Fix | Delete
str_path = str(path)
[54] Fix | Delete
if 'config' in str_path:
[55] Fix | Delete
for line in iterlines_path(path):
[56] Fix | Delete
if not line.startswith('$APP_VERSION'):
[57] Fix | Delete
continue
[58] Fix | Delete
try:
[59] Fix | Delete
version = line.split(' ')[2].replace("'", '').replace(';', '')
[60] Fix | Delete
return f"Concrete5 {version}"
[61] Fix | Delete
except IndexError:
[62] Fix | Delete
pass
[63] Fix | Delete
return None
[64] Fix | Delete
if 'wp-includes' in str_path:
[65] Fix | Delete
for line in iterlines_path(path):
[66] Fix | Delete
if not line.startswith('$wp_version'):
[67] Fix | Delete
continue
[68] Fix | Delete
try:
[69] Fix | Delete
version = line.split("'")[1]
[70] Fix | Delete
return f'Wordpress {version}'
[71] Fix | Delete
except IndexError:
[72] Fix | Delete
pass
[73] Fix | Delete
return None
[74] Fix | Delete
if 'libraries' in str_path:
[75] Fix | Delete
for line in iterlines_path(path):
[76] Fix | Delete
if not line.lstrip().startswith('const RELEASE'):
[77] Fix | Delete
continue
[78] Fix | Delete
try:
[79] Fix | Delete
version = line.split("'")[1]
[80] Fix | Delete
return f'Joomla {version}'
[81] Fix | Delete
except IndexError:
[82] Fix | Delete
pass
[83] Fix | Delete
return None
[84] Fix | Delete
for line in iterlines_path(path):
[85] Fix | Delete
if not line.startswith('$release'):
[86] Fix | Delete
continue
[87] Fix | Delete
try:
[88] Fix | Delete
version = line.split(' ')[3].replace("'", '')
[89] Fix | Delete
return f'Moodle {version}'
[90] Fix | Delete
except IndexError:
[91] Fix | Delete
pass
[92] Fix | Delete
return None
[93] Fix | Delete
[94] Fix | Delete
[95] Fix | Delete
def concrete_version(path: Path) -> Union[str, None]:
[96] Fix | Delete
if 'config' not in str(path):
[97] Fix | Delete
return None
[98] Fix | Delete
for line in iterlines_path(path):
[99] Fix | Delete
if 'version_installed' not in line:
[100] Fix | Delete
continue
[101] Fix | Delete
try:
[102] Fix | Delete
return line.split("'")[3].strip()
[103] Fix | Delete
except IndexError:
[104] Fix | Delete
pass
[105] Fix | Delete
return None
[106] Fix | Delete
[107] Fix | Delete
[108] Fix | Delete
def oldconcrete_version(path: Path) -> Union[str, None]:
[109] Fix | Delete
if 'config' not in str(path):
[110] Fix | Delete
return None
[111] Fix | Delete
for line in iterlines_path(path):
[112] Fix | Delete
if 'APP_VERSION' not in line:
[113] Fix | Delete
continue
[114] Fix | Delete
if match := re.match(r'.*(\d+\.\d+\.\d+)', line):
[115] Fix | Delete
return match.group(1)
[116] Fix | Delete
return None
[117] Fix | Delete
[118] Fix | Delete
[119] Fix | Delete
def mediawiki_version(path: Path) -> Union[str, None]:
[120] Fix | Delete
if 'includes' not in str(path):
[121] Fix | Delete
return None
[122] Fix | Delete
for line in iterlines_path(path):
[123] Fix | Delete
if not line.startswith('$wgVersion'):
[124] Fix | Delete
continue
[125] Fix | Delete
try:
[126] Fix | Delete
return line.split("'")[1]
[127] Fix | Delete
except IndexError:
[128] Fix | Delete
pass
[129] Fix | Delete
return None
[130] Fix | Delete
[131] Fix | Delete
[132] Fix | Delete
def drupal_version(path: Path) -> Union[str, None]:
[133] Fix | Delete
for line in iterlines_path(path):
[134] Fix | Delete
if not line.lstrip().startswith('Drupal'):
[135] Fix | Delete
continue
[136] Fix | Delete
if match := re.match(r'Drupal (\d+\.\d+)', line):
[137] Fix | Delete
return match.group(1)
[138] Fix | Delete
return None
[139] Fix | Delete
[140] Fix | Delete
[141] Fix | Delete
def prestashop_version(path: Path) -> Union[str, None]:
[142] Fix | Delete
if 'docs' not in str(path):
[143] Fix | Delete
return None
[144] Fix | Delete
for line in iterlines_path(path):
[145] Fix | Delete
if not line.startswith('VERSION'):
[146] Fix | Delete
continue
[147] Fix | Delete
try:
[148] Fix | Delete
return line.split(" ")[1].strip()
[149] Fix | Delete
except IndexError:
[150] Fix | Delete
pass
[151] Fix | Delete
return None
[152] Fix | Delete
[153] Fix | Delete
[154] Fix | Delete
def cur_mage_version(path: Path) -> Union[str, None]:
[155] Fix | Delete
if 'pdepend' not in str(path):
[156] Fix | Delete
return None
[157] Fix | Delete
for line in iterlines_path(path):
[158] Fix | Delete
if not line.startswith('pdepend'):
[159] Fix | Delete
continue
[160] Fix | Delete
try:
[161] Fix | Delete
return line.split("-")[1].strip().split(' ')[0]
[162] Fix | Delete
except IndexError:
[163] Fix | Delete
pass
[164] Fix | Delete
return None
[165] Fix | Delete
[166] Fix | Delete
[167] Fix | Delete
def old_mage_version(path: Path) -> Union[str, None]:
[168] Fix | Delete
for line in iterlines_path(path):
[169] Fix | Delete
if not line.startswith('==='):
[170] Fix | Delete
continue
[171] Fix | Delete
try:
[172] Fix | Delete
return line.split(" ")[1].strip()
[173] Fix | Delete
except IndexError:
[174] Fix | Delete
pass
[175] Fix | Delete
return None
[176] Fix | Delete
[177] Fix | Delete
[178] Fix | Delete
def old_mage_version2(path: Path) -> Union[str, None]:
[179] Fix | Delete
if 'app' not in str(path):
[180] Fix | Delete
return None
[181] Fix | Delete
for line in iterlines_path(path):
[182] Fix | Delete
line = line.strip()
[183] Fix | Delete
if not line.startswith('return'):
[184] Fix | Delete
continue
[185] Fix | Delete
if match := re.match(r"return '(\d+\.\d+\.\d+)", line):
[186] Fix | Delete
return match.group(1)
[187] Fix | Delete
return None
[188] Fix | Delete
[189] Fix | Delete
[190] Fix | Delete
def joomla_version(path: Path) -> Union[str, None]:
[191] Fix | Delete
str_path = str(path)
[192] Fix | Delete
if 'administrator' in str_path or 'plugin' in str_path:
[193] Fix | Delete
return None
[194] Fix | Delete
for line in iterlines_path(path):
[195] Fix | Delete
line = line.strip()
[196] Fix | Delete
if not line.startswith('<version>'):
[197] Fix | Delete
continue
[198] Fix | Delete
if match := re.match(r"<version>(\d+\.\d+\.\d+)", line):
[199] Fix | Delete
return match.group(1)
[200] Fix | Delete
return None
[201] Fix | Delete
[202] Fix | Delete
[203] Fix | Delete
def old_joomla_version(path: Path) -> Union[str, None]:
[204] Fix | Delete
prefix = '--------------------'
[205] Fix | Delete
for line in iterlines_path(path):
[206] Fix | Delete
line = line.strip()
[207] Fix | Delete
if not line.startswith(prefix):
[208] Fix | Delete
continue
[209] Fix | Delete
if match := re.match(rf"{prefix} (\d+\.\d+\.\d+)", line):
[210] Fix | Delete
return match.group(1)
[211] Fix | Delete
return None
[212] Fix | Delete
[213] Fix | Delete
[214] Fix | Delete
def zen_version(zenfolder: Path) -> Union[str, None]:
[215] Fix | Delete
try:
[216] Fix | Delete
return '.'.join(
[217] Fix | Delete
sorted(glob(f'{zenfolder}/whatsnew_*'))[-1]
[218] Fix | Delete
.split('_')[-1]
[219] Fix | Delete
.split('.')[0:3]
[220] Fix | Delete
)
[221] Fix | Delete
except IndexError:
[222] Fix | Delete
return None
[223] Fix | Delete
[224] Fix | Delete
[225] Fix | Delete
def zend_version(path: Path) -> Union[str, None]:
[226] Fix | Delete
if 'Zend' not in str(path):
[227] Fix | Delete
return None
[228] Fix | Delete
for line in iterlines_path(path):
[229] Fix | Delete
if 'const VERSION ' not in line:
[230] Fix | Delete
continue
[231] Fix | Delete
try:
[232] Fix | Delete
return line.split("'")[1]
[233] Fix | Delete
except IndexError:
[234] Fix | Delete
pass
[235] Fix | Delete
return None
[236] Fix | Delete
[237] Fix | Delete
[238] Fix | Delete
def symfony_version(path: Path) -> Union[str, None]:
[239] Fix | Delete
if not str(path).endswith('Symfony/Component/HttpKernel/Kernel.php'):
[240] Fix | Delete
return None
[241] Fix | Delete
for line in iterlines_path(path):
[242] Fix | Delete
if 'const VERSION ' not in line:
[243] Fix | Delete
continue
[244] Fix | Delete
try:
[245] Fix | Delete
return line.split("'")[1]
[246] Fix | Delete
except IndexError:
[247] Fix | Delete
pass
[248] Fix | Delete
return None
[249] Fix | Delete
[250] Fix | Delete
[251] Fix | Delete
def main():
[252] Fix | Delete
paths: dict[str, list[Path]] = {x: [] for x in FIND_NAMES.values()}
[253] Fix | Delete
for path in find_target_files():
[254] Fix | Delete
if 'whatsnew_' in path.name:
[255] Fix | Delete
paths['whatsnewfiles'].append(path)
[256] Fix | Delete
continue
[257] Fix | Delete
try:
[258] Fix | Delete
paths[FIND_NAMES[path.name]].append(path)
[259] Fix | Delete
except KeyError:
[260] Fix | Delete
print("Unexpected file:", path, file=sys.stderr)
[261] Fix | Delete
zenfolder = {path.parent for path in paths['whatsnewfiles']}
[262] Fix | Delete
for folder in zenfolder:
[263] Fix | Delete
if version := zen_version(folder):
[264] Fix | Delete
print('ZenCart', version, folder)
[265] Fix | Delete
for path in paths['joomlafiles']:
[266] Fix | Delete
if version := joomla_version(path):
[267] Fix | Delete
print('Joomla', version, path)
[268] Fix | Delete
for path in paths['oldjoomla']:
[269] Fix | Delete
if version := old_joomla_version(path):
[270] Fix | Delete
print('Joomla', version, path)
[271] Fix | Delete
for path in paths['magentofiles']:
[272] Fix | Delete
if version := cur_mage_version(path):
[273] Fix | Delete
print('Magento', version, path)
[274] Fix | Delete
for path in path['oldmagefiles']:
[275] Fix | Delete
if version := old_mage_version(path):
[276] Fix | Delete
print('Magento', version, path)
[277] Fix | Delete
for path in paths['oldmagefiles2']:
[278] Fix | Delete
if version := old_mage_version2(path):
[279] Fix | Delete
print('Magento', version, path)
[280] Fix | Delete
for path in paths['concretefiles']:
[281] Fix | Delete
if version := concrete_version(path):
[282] Fix | Delete
print('Concrete5', version, path)
[283] Fix | Delete
for path in paths['basefiles']:
[284] Fix | Delete
if version := oldconcrete_version(path):
[285] Fix | Delete
print('Concrete5', version, path)
[286] Fix | Delete
for path in paths['versionfiles']:
[287] Fix | Delete
if found := proc_version(path):
[288] Fix | Delete
print(found, path)
[289] Fix | Delete
for path in paths['mediawikifiles']:
[290] Fix | Delete
if version := mediawiki_version(path):
[291] Fix | Delete
print('MediaWiki', version, path)
[292] Fix | Delete
for path in paths['drupalfiles']:
[293] Fix | Delete
if version := drupal_version(path):
[294] Fix | Delete
print('Drupal', version, path)
[295] Fix | Delete
for path in paths['prestafiles']:
[296] Fix | Delete
if version := prestashop_version(path):
[297] Fix | Delete
print('Prestashop', version, path)
[298] Fix | Delete
for path in paths['zend_files']:
[299] Fix | Delete
if version := zend_version(path):
[300] Fix | Delete
print('ZendFramework', version, path)
[301] Fix | Delete
for path in paths['symfonyfiles']:
[302] Fix | Delete
if version := symfony_version(path):
[303] Fix | Delete
print('Symfony', version, path)
[304] Fix | Delete
[305] Fix | Delete
[306] Fix | Delete
if __name__ == "__main__":
[307] Fix | Delete
main()
[308] Fix | Delete
[309] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function