52 lines
2.3 KiB
Python
52 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Approved staging exception for XB native V2 machine authentication only."""
|
|
import hashlib, json, os, pathlib, shutil, subprocess
|
|
|
|
BASE = pathlib.Path('/var/www/wwwroot/fuc-xb-test')
|
|
TARGET = pathlib.Path('/etc/nginx/conf.d/fuc-xb-test.conf')
|
|
EXPECTED = '8427a451875673b28d678e12100b306584c21f8ddc71487dac6b28e05cac1066'
|
|
LOCATION = ''' location ^~ /api/v2/server/ {
|
|
# Native XB machine authentication; no staging web-cookie replication.
|
|
limit_except GET POST { deny all; }
|
|
client_max_body_size 2m;
|
|
include fastcgi_params;
|
|
fastcgi_param SCRIPT_FILENAME $realpath_root/index.php;
|
|
fastcgi_param SCRIPT_NAME /index.php;
|
|
fastcgi_param XB_INSTANCE fuc-xb-test;
|
|
fastcgi_pass unix:/run/php/php8.4-fuc-xb-test.sock;
|
|
fastcgi_read_timeout 45s;
|
|
}
|
|
'''
|
|
|
|
def checked(args):
|
|
p = subprocess.run(args, capture_output=True)
|
|
assert p.returncode == 0, 'Gate command failed; configuration restored if needed'
|
|
|
|
def main():
|
|
os.umask(0o077)
|
|
before = TARGET.read_bytes()
|
|
assert hashlib.sha256(before).hexdigest() == EXPECTED, 'Configuration changed; inspect before applying'
|
|
checked(['nginx', '-t'])
|
|
text = before.decode()
|
|
assert text.count(' location = /stage-login {') == 2
|
|
assert '/api/v2/server/' not in text
|
|
backup = BASE/'private/launch-ready-20261105/gate-before.conf'
|
|
assert not backup.exists(), 'Existing intent; inspect receipt rather than repeat'
|
|
backup.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
backup.write_bytes(before)
|
|
after = text.replace(' location = /stage-login {', LOCATION+' location = /stage-login {').encode()
|
|
try:
|
|
TARGET.write_bytes(after)
|
|
checked(['nginx','-t'])
|
|
checked(['systemctl','reload','nginx'])
|
|
except BaseException:
|
|
TARGET.write_bytes(before)
|
|
checked(['nginx','-t'])
|
|
checked(['systemctl','reload','nginx'])
|
|
raise
|
|
value = {'changed':True,'native_machine_auth_only':True,'exception':'/api/v2/server/','website_gate_retained':True,'xb_core_changed':False,'before_sha256':EXPECTED,'after_sha256':hashlib.sha256(after).hexdigest(),'rollback':str(backup)}
|
|
(backup.parent/'gate-applied.json').write_text(json.dumps(value,indent=2))
|
|
print(json.dumps(value))
|
|
|
|
if __name__ == '__main__': main()
|