import subprocess from loguru import logger from.utils import decode_cmd import json,os,shutil def start(nginx_log): J=False;C=True;B=nginx_log;logger.info('Enabling Nginx smart frontend on port 7860...') try: D='/home/user/static' if not os.path.isdir(D):D='static' os.makedirs(D,exist_ok=C);K=['/home/user/config/loading.html','config/loading.html','main/config/loading.html'];G=J for A in K: if os.path.exists(A):shutil.copy(A,os.path.join(D,'loading.html'));G=C;break if not G:logger.warning('Could not find loading.html to copy to static directory.') except Exception as E:logger.error(f"Failed to copy loading.html to static directory: {E}") F=None;L=['/home/user/config/nginx.conf.template','config/nginx.conf.template','main/config/nginx.conf.template'] for A in L: try: if os.path.exists(A): with open(A,'r')as M:F=M.read() break except Exception:pass if F is None:logger.error('Failed to prepare nginx config: nginx.conf.template not found.');return try: N=['/home/user/nginx.conf','nginx.conf'];H=J for A in N: try: I=os.path.dirname(os.path.abspath(A)) if os.path.isdir(I)and os.access(I,os.W_OK): with open(A,'w')as O:O.write(F) H=C;break except Exception:pass if not H:raise PermissionError('Could not write nginx.conf to any expected path.') except Exception as E:logger.error(f"Failed to prepare nginx config: {E}");return B.write('[*] Testing nginx configuration...\n');B.flush();P=decode_cmd('=cyOnVnYlRGIyJXZkR3cgc2bs9lcvJncldCIn1CIm52bj5Ceul2Zu9iclNXdvUWbvh2LgMWLgQXLggnbpdmb');subprocess.run(P,shell=C,stdout=B,stderr=subprocess.STDOUT);B.write('[*] Starting nginx daemon...\n');B.flush();Q=decode_cmd('==wJ78mZulGIyJXZkR3cgc2bs9lcvJncldCIn1CIm52bj5Ceul2Zu9iclNXdvUWbvh2LgMWLggnbpdmb');subprocess.Popen(Q,shell=C,stdout=B,stderr=subprocess.STDOUT)