26 lines
2.0 KiB
Python
26 lines
2.0 KiB
Python
import os,subprocess,json,http.client,ssl,time,glob,re
|
|
result={'time':time.strftime('%Y-%m-%d %H:%M:%S')}
|
|
for name,args in [('uptime',['uptime']),('memory',['free','-m']),('listener',['ss','-ltnp','sport = :8686']),('bt_status',['/etc/init.d/bt','status'])]:
|
|
try:
|
|
p=subprocess.run(args,stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True,timeout=5)
|
|
result[name]=(p.stdout+p.stderr)[:1600]
|
|
except Exception as e:result[name]=type(e).__name__+': '+str(e)
|
|
print(json.dumps(result),flush=True)
|
|
for protocol in ['https','http']:
|
|
started=time.monotonic()
|
|
try:
|
|
c=http.client.HTTPSConnection('127.0.0.1',8686,timeout=5,context=ssl._create_unverified_context()) if protocol=='https' else http.client.HTTPConnection('127.0.0.1',8686,timeout=5)
|
|
c.request('GET','/gaorui',headers={'Host':'47.106.181.28:8686','User-Agent':'Codex-Panel-Diagnostic/1.0'})
|
|
r=c.getresponse();body=r.read(500)
|
|
print(json.dumps({'local_protocol':protocol,'status':r.status,'location':r.getheader('Location'),'prefix':body[:180].decode('utf-8','replace'),'seconds':round(time.monotonic()-started,2)}),flush=True)
|
|
c.close()
|
|
except Exception as e:print(json.dumps({'local_protocol':protocol,'error':type(e).__name__+': '+str(e),'seconds':round(time.monotonic()-started,2)}),flush=True)
|
|
print('PANEL_LOG_METADATA',flush=True)
|
|
for p in ['/www/server/panel/logs/error.log','/www/server/panel/logs/requests.log','/www/server/panel/logs/task.log','/www/server/panel/logs/panel.log']:
|
|
if os.path.exists(p):print(json.dumps({'path':p,'size':os.path.getsize(p),'modified':time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(os.path.getmtime(p)))}),flush=True)
|
|
for p in ['/www/server/panel/logs/error.log','/www/server/panel/logs/panel.log']:
|
|
if os.path.exists(p):
|
|
text=subprocess.check_output(['tail','-n','25',p]).decode('utf-8','replace')
|
|
text=re.sub(r'(?i)((?:password|passwd|token|secret|cookie|authorization)\s*[=:]\s*)[^\s,;]+',r'\1<redacted>',text)
|
|
print(json.dumps({'log':p,'tail':text[-4000:]}),flush=True)
|