mirror of
https://github.com/mrvasil/ctf-ad-mirror-tool-rust.git
synced 2026-10-23 14:31:02 +00:00
46 lines
2.4 KiB
Python
46 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Render legacy templates using public loopback data; never import legacy config.
|
|
|
|
Development-only: pip install jinja2
|
|
Usage: python scripts/legacy_ui_reference.py ../ad_scripts/mirror_tool
|
|
Then serve test-results/legacy-reference on loopback for visual comparison.
|
|
"""
|
|
import argparse
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('legacy', type=Path)
|
|
parser.add_argument('--output', type=Path, default=Path('test-results/legacy-reference'))
|
|
args = parser.parse_args()
|
|
template_dir = args.legacy / 'templates'
|
|
base = (template_dir / 'base.html').read_text()
|
|
original_css = base.split('<style>', 1)[1].split('</style>', 1)[0]
|
|
current_css = Path('web/app.css').read_text()
|
|
normalized_css = '\n'.join(line.rstrip() for line in original_css.splitlines())
|
|
assert normalized_css in current_css, 'Original CSS rules were changed or removed'
|
|
env = Environment(loader=FileSystemLoader(template_dir), autoescape=select_autoescape(['html']))
|
|
env.globals.update(get_flashed_messages=lambda **_: [], url_for=lambda _: '#')
|
|
data = dict(session={'authenticated': True}, tasks={'Echo': 18081},
|
|
teams={'Loopback A': '127.0.0.1', 'Loopback B': '::1'},
|
|
custom_proxies={}, port_monitoring_enabled=True, main_team_ip='127.0.0.1')
|
|
args.output.mkdir(parents=True, exist_ok=True)
|
|
for template in ('index.html', 'login.html'):
|
|
html = env.get_template(template).render(**data)
|
|
html = re.sub(r'<script\b[^>]*>.*?</script>', '', html, flags=re.S)
|
|
html = html.replace('https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css', '/vendor/bootstrap.min.css')
|
|
html = html.replace('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css', '/vendor/fontawesome.min.css')
|
|
(args.output / template).write_text(html)
|
|
shutil.copytree('web/vendor', args.output / 'vendor', dirs_exist_ok=True)
|
|
(args.output / 'webfonts').mkdir(exist_ok=True)
|
|
shutil.copyfile('web/vendor/fa-solid-900.woff2', args.output / 'webfonts/fa-solid-900.woff2')
|
|
print(f'Original CSS preserved (trailing whitespace normalized) ({len(original_css)} characters); reference at {args.output}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|