diff --git a/scripts/fuc-xb-launch/client-context.php b/scripts/fuc-xb-launch/client-context.php index fdd11980..6f9c87d7 100644 --- a/scripts/fuc-xb-launch/client-context.php +++ b/scripts/fuc-xb-launch/client-context.php @@ -9,4 +9,4 @@ $state=json_decode(file_get_contents($dir.'/panel-state.json'),true,512,JSON_THR $u=App\Models\User::findOrFail($state['current_user_id']);if($u->group_id!==$state['qa_group_id']||!str_ends_with($u->email,'@fuc-xb.invalid'))throw new RuntimeException('Not restricted QA'); $gate=json_decode(file_get_contents('/var/www/wwwroot/fuc-xb-test/private/gate-credentials.json'),true,512,JSON_THROW_ON_ERROR);$nodes=[]; foreach($state['nodes']as$key=>$row){$n=App\Models\Server::findOrFail($row['node_id']);$m=App\Models\ServerMachine::findOrFail($row['machine_id']);if($m->name!=='fuc-xb-'.$key)throw new RuntimeException('Machine owner changed');$nodes[$key]=['node_id'=>$n->id,'machine_id'=>$m->id,'machine_token'=>$m->token,'spec'=>$row['spec'],'available_users'=>App\Services\ServerService::getAvailableUsers($n)->count(),'u'=>(int)$n->u,'d'=>(int)$n->d];} -echo json_encode(['owner'=>$state['owner'],'phase'=>$state['qa_phase'],'source'=>'https://fuc-xb-test.gemcook.net','alias'=>'https://fuc-xb-test.tomtojapan.online','gate_cookie'=>$gate['cookie_token'],'qa_uuid'=>$u->uuid,'subscribe_token'=>$u->token,'user_id'=>$u->id,'u'=>(int)$u->u,'d'=>(int)$u->d,'nodes'=>$nodes],JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR); +echo json_encode(['owner'=>$state['owner'],'manifest_sha256'=>$state['manifest_sha256'],'phase'=>$state['qa_phase'],'source'=>'https://fuc-xb-test.gemcook.net','alias'=>'https://fuc-xb-test.tomtojapan.online','gate_cookie'=>$gate['cookie_token'],'qa_uuid'=>$u->uuid,'subscribe_token'=>$u->token,'user_id'=>$u->id,'u'=>(int)$u->u,'d'=>(int)$u->d,'nodes'=>$nodes,'pending_traffic'=>Illuminate\Support\Facades\Queue::size('traffic_fetch'),'pending_stat'=>Illuminate\Support\Facades\Queue::size('stat')],JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR); diff --git a/scripts/fuc-xb-launch/client.py b/scripts/fuc-xb-launch/client.py index c486341d..d47967b8 100644 --- a/scripts/fuc-xb-launch/client.py +++ b/scripts/fuc-xb-launch/client.py @@ -1,10 +1,17 @@ #!/usr/bin/env python3 """Real native subscriptions, each relay/exit, and saved-client revocation.""" -import argparse,gzip,hashlib,json,os,pathlib,secrets,socket,ssl,subprocess,time,urllib.error,urllib.parse,urllib.request +import argparse,fcntl,gzip,hashlib,json,os,pathlib,secrets,socket,ssl,subprocess,time,urllib.error,urllib.parse,urllib.request BASE=pathlib.Path('/var/www/wwwroot/fuc-xb-test/private/launch-ready-20261105/client') BIN=pathlib.Path('/var/www/wwwroot/fuc-xb-test/private/live-acceptance-20261104/bin/sing-box') SHA='768d31fa7f68debc067bb4626539498a1e8751d36a7b99e1a54bee6a23815f93' SOCKS=19876;CONTROL=29090;UNIT='fuc-xb-launch-client' +STARTED=False +def digest(value):return hashlib.sha256(json.dumps(value,sort_keys=True,ensure_ascii=False,separators=(',',':')).encode()).hexdigest() +def identity(c):return {'user_id':c['user_id'],'uuid_sha256':hashlib.sha256(c['qa_uuid'].encode()).hexdigest(),'phase':c['phase'],'manifest_sha256':c['manifest_sha256'],'nodes_sha256':digest({k:{'node_id':n['node_id'],'machine_id':n['machine_id'],'token_sha256':hashlib.sha256(n['machine_token'].encode()).hexdigest(),'spec':n['spec']}for k,n in c['nodes'].items()}),'binary_sha256':SHA} +def binding(c,d): + b=json.loads((d/'binding.json').read_text());assert b['identity']==identity(c)and time.time()-b['created_at']<3600,'Stale/foreign QA progress' + assert hashlib.sha256((d/'client-full.json').read_bytes()).hexdigest()==b['config_sha256']and hashlib.sha256((d/'controller.json').read_bytes()).hexdigest()==b['controller_sha256'],'Saved client configuration changed' + return b def run(args,timeout=45):return subprocess.run(args,capture_output=True,timeout=timeout) def context(): p=run(['php',str(pathlib.Path(__file__).with_name('client-context.php'))]);assert p.returncode==0,'Client context unavailable' @@ -50,22 +57,40 @@ def prepare(c,d): found[key]=p['tag'] (d/'subscription-singbox.json').write_bytes(raw) code,clash=fetch(c,'meta');assert code==200 and b'anytls'in clash and c['qa_uuid'].encode()in clash,'Native Clash subscription failed';(d/'subscription-clash.yaml').write_bytes(clash) + php=r"require '/var/www/wwwroot/fuc-xb-test/current/vendor/autoload.php';echo json_encode(Symfony\Component\Yaml\Yaml::parse(stream_get_contents(STDIN)));" + parsed=subprocess.run(['php','-r',php],input=clash,capture_output=True,timeout=20);assert parsed.returncode==0,'Native Clash YAML parse failed' + meta=json.loads(parsed.stdout);meta_nodes=[p for p in meta['proxies']if p.get('type')=='anytls'];assert len(meta_nodes)==22,'Clash Meta node count mismatch' + for key,n in c['nodes'].items(): + spec=n['spec'];matches=[p for p in meta_nodes if p['server']==spec['relay_host']and p['port']==spec['relay_port']];assert len(matches)==1,'Clash route mismatch: '+key + p=matches[0];assert p['password']==c['qa_uuid']and p.get('skip-cert-verify',False)is False and p.get('sni')==spec['sni'],'Clash TLS/identity mismatch: '+key assert fetch(c,'sing-box','deliberately-invalid-subscription')[0]==403 + if(d/'binding.json').exists(): + old=binding(c,d);assert old['native_sha256']==hashlib.sha256(raw).hexdigest(),'Native subscription changed during resumed test' + return {'native_full_config_checked':True,'binding':old,'resumed_same_configuration':True,'clash_meta_nodes_checked':22} cfg['inbounds']=[{'type':'mixed','tag':'qa-local','listen':'127.0.0.1','listen_port':SOCKS}] control_secret=secrets.token_hex(24);cfg.setdefault('experimental',{})['clash_api']={'external_controller':'127.0.0.1:'+str(CONTROL),'secret':control_secret,'default_mode':'global'} (d/'client-full.json').write_text(json.dumps(cfg,ensure_ascii=False));(d/'controller.json').write_text(json.dumps({'secret':control_secret,'tags':found})) checked=run([str(BIN),'check','-c',str(d/'client-full.json')]);(d/'config-check.stderr').write_bytes(checked.stderr) assert checked.returncode==0,'Native config rejected by real client; diagnostic private' - return {'native_full_config_checked':True,'native_anytls_nodes':22,'all_tls_strict':True,'native_outbounds_dns_rules_retained':True,'only_inbounds_and_loopback_controller_changed':True,'invalid_subscription_rejected':True,'clash_meta_downloaded':True} + b={'identity':identity(c),'created_at':int(time.time()),'native_sha256':hashlib.sha256(raw).hexdigest(),'config_sha256':hashlib.sha256((d/'client-full.json').read_bytes()).hexdigest(),'controller_sha256':hashlib.sha256((d/'controller.json').read_bytes()).hexdigest()};(d/'binding.json').write_text(json.dumps(b,indent=2)) + return {'native_full_config_checked':True,'native_anytls_nodes':22,'all_tls_strict':True,'native_outbounds_dns_rules_retained':True,'only_inbounds_and_loopback_controller_changed':True,'invalid_subscription_rejected':True,'clash_meta_nodes_checked':22,'binding':b} def start(d): + global STARTED + STARTED=False for port in [SOCKS,CONTROL]:assert not run(['ss','-H','-ltn','sport = :'+str(port)]).stdout.strip(),'QA listener collision' - p=run(['systemd-run','--quiet','--collect','--unit='+UNIT,'--property=RuntimeMaxSec=1200','--property=MemoryMax=384M','--property=CPUQuota=40%','--working-directory='+str(d),str(BIN),'run','-D',str(d),'-c',str(d/'client-full.json')]);assert p.returncode==0,'QA client did not start' + p=run(['systemd-run','--quiet','--collect','--unit='+UNIT,'--description=FUC-XB launch restricted QA client','--property=RuntimeMaxSec=1200','--property=MemoryMax=384M','--property=CPUQuota=40%','--working-directory='+str(d),str(BIN),'run','-D',str(d),'-c',str(d/'client-full.json')]);assert p.returncode==0,'QA client did not start';STARTED=True for _ in range(50): try: with socket.create_connection(('127.0.0.1',CONTROL),timeout=.3):return except OSError:time.sleep(.2) raise RuntimeError('QA controller unavailable') -def stop():assert run(['systemctl','stop',UNIT]).returncode==0,'QA client stop failed' +def stop(): + global STARTED + if not STARTED:return + assert run(['systemctl','show',UNIT,'-p','Description','--value']).stdout.decode().strip()=='FUC-XB launch restricted QA client','QA unit ownership changed' + assert run(['systemctl','stop',UNIT]).returncode==0,'QA client stop failed' + assert not run(['ss','-H','-ltn','sport = :'+str(SOCKS)]).stdout.strip(),'QA listener remains active' + STARTED=False def select(d,key): c=json.loads((d/'controller.json').read_text());request=urllib.request.Request('http://127.0.0.1:'+str(CONTROL)+'/proxies/'+urllib.parse.quote('节点选择',safe=''),data=json.dumps({'name':c['tags'][key]},ensure_ascii=False).encode(),headers={'Authorization':'Bearer '+c['secret'],'Content-Type':'application/json'},method='PUT') with urllib.request.urlopen(request,timeout=10)as r:assert r.status in [200,204],'Client selector failed' @@ -73,38 +98,58 @@ def tls_alive(spec): with socket.create_connection((spec['relay_host'],spec['relay_port']),timeout=8)as raw: with ssl.create_default_context().wrap_socket(raw,server_hostname=spec['sni'])as tls:return tls.version() def network(c,d,revoked=False): + b=binding(c,d) progress=d/('revoked-progress.json'if revoked else'network-progress.json') - result=json.loads(progress.read_text())if progress.exists()else{} + old=json.loads(progress.read_text())if progress.exists()else{'binding':b,'nodes':{}};assert old['binding']==b,'Progress belongs to another client';result=old['nodes'] assert set(result).issubset(c['nodes']),'Foreign progress' - start(d) try: + start(d) + if revoked: + with urllib.request.urlopen('https://api.ipify.org?format=json',timeout=12)as r:assert r.status==200 and json.loads(r.read()).get('ip'),'Public target health unavailable' for key,n in c['nodes'].items(): if key in result:continue select(d,key);spec=n['spec'];tls=tls_alive(spec) base=['curl','-sS','--proxy','socks5h://127.0.0.1:'+str(SOCKS),'--connect-timeout','5','--max-time','12'if revoked else'25'] ip=run(base+['https://api.ipify.org?format=json'],35) if revoked: - assert ip.returncode!=0 and not ip.stdout,'Saved revoked identity still connected: '+key - row={'saved_config_rejected':True,'node_tls_still_alive':tls} + (d/('rejected-'+key+'.stderr')).write_bytes(ip.stderr) + assert ip.returncode in [35,52,56,97] and not ip.stdout,'No definite saved-client rejection: '+key + row={'saved_config_rejected':True,'curl_exit':ip.returncode,'node_tls_still_alive':tls,'target_health_confirmed':True,'stderr_sha256':hashlib.sha256(ip.stderr).hexdigest()} else: assert ip.returncode==0 and json.loads(ip.stdout)['ip']==spec['expected_exit'],'Real exit mismatch: '+key down=run(base+['https://speed.cloudflare.com/__down?bytes=65536'],35);assert down.returncode==0 and len(down.stdout)==65536,'Download failed: '+key body=b'FUC-XB-QA-ONLY\n'*2048;(d/'upload.bin').write_bytes(body) up=run(base+['-H','Content-Type: application/octet-stream','--data-binary','@'+str(d/'upload.bin'),'https://httpbin.org/post'],35);assert up.returncode==0 and json.loads(up.stdout).get('data','').encode()==body,'Upload echo failed: '+key row={'actual_exit':spec['expected_exit'],'tls':tls,'download_bytes':len(down.stdout),'upload_bytes':len(body),'native_selector_used':True} - result[key]=row;progress.write_text(json.dumps(result,indent=2));print(json.dumps({'phase':c['phase'],'key':key,**row}),flush=True) + result[key]=row;progress.write_text(json.dumps({'binding':b,'nodes':result},indent=2));print(json.dumps({'phase':c['phase'],'key':key,**row}),flush=True) finally:stop() return result +def traffic(c,before): + for _ in range(25): + after=context();assert identity(after)==identity(c),'QA identity changed while waiting for reports' + delta={k:{s:after['nodes'][k][s]-before['nodes'][k][s]for s in ['u','d']}for k in c['nodes']} + user={s:after[s]-before[s]for s in ['u','d']};raw={s:sum(n[s]for n in delta.values())for s in ['u','d']} + if not after['pending_traffic']and not after['pending_stat']and all(n['u']>0 and n['d']>0 for n in delta.values())and all(user[s]==2*raw[s]for s in ['u','d']): + return {'all_22_nodes_reported_upload_download':True,'rate':2,'raw_bytes':raw,'rated_user_bytes':user,'native_user_and_server_counts_exact':True,'per_node_delta':delta} + time.sleep(2) + raise RuntimeError('Native traffic reports/rate not reconciled') def main(): - os.umask(0o077);p=argparse.ArgumentParser();p.add_argument('action',choices=['prepare','run','revoked','api']);args=p.parse_args();c=context();d=BASE/c['phase'];d.mkdir(mode=0o700,parents=True,exist_ok=True) + os.umask(0o077);BASE.mkdir(mode=0o700,parents=True,exist_ok=True);lock=(BASE/'operation.lock').open('a');fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB) + p=argparse.ArgumentParser();p.add_argument('action',choices=['prepare','run','revoked','api']);args=p.parse_args();c=context();d=BASE/c['phase'];d.mkdir(mode=0o700,parents=True,exist_ok=True) if args.action=='api':result={'phase':c['phase'],'authentication':auth_matrix(c,any(n['available_users']==0 for n in c['nodes'].values()))} elif args.action=='revoked': assert(d/'network-result.json').is_file(),'Positive test missing' + positive=json.loads((d/'network-result.json').read_text());assert positive['binding']==binding(c,d),'Revocation configuration differs from positive test' code,_=fetch(c,'sing-box');assert code==(200 if c['phase']=='exhausted'else 403),'Unexpected native subscription status' - result={'phase':c['phase'],'subscription_status':code,'authentication':auth_matrix(c,True),'nodes':network(c,d,True),'temporary_client_stopped':True};(d/'revocation-result.json').write_text(json.dumps(result,indent=2)) + result={'phase':c['phase'],'binding':binding(c,d),'subscription_status':code,'authentication':auth_matrix(c,True),'nodes':network(c,d,True),'temporary_client_stopped':True};(d/'revocation-result.json').write_text(json.dumps(result,indent=2)) else: assert not(d/'network-result.json').exists(),'Existing completed test; inspect rather than repeat' result=prepare(c,d);result['authentication']=auth_matrix(c) - if args.action=='run':result.update(phase=c['phase'],nodes=network(c,d),temporary_client_stopped=True);(d/'network-result.json').write_text(json.dumps(result,indent=2)) + if args.action=='run': + before_file=d/'traffic-before.json' + if before_file.exists():before=json.loads(before_file.read_text());assert before['binding']==binding(c,d),'Traffic baseline changed' + else: + before={'binding':binding(c,d),'user_id':c['user_id'],'u':c['u'],'d':c['d'],'nodes':{k:{'u':n['u'],'d':n['d']}for k,n in c['nodes'].items()}};before_file.write_text(json.dumps(before,indent=2)) + result.update(phase=c['phase'],nodes=network(c,d),temporary_client_stopped=True);result['traffic']=traffic(c,before);(d/'network-result.json').write_text(json.dumps(result,indent=2)) print(json.dumps({'passed':True,'phase':c['phase'],'action':args.action,'nodes_checked':len(result.get('nodes',result.get('authentication',[])))})) if __name__=='__main__':main() diff --git a/scripts/fuc-xb-launch/horizon-php.py b/scripts/fuc-xb-launch/horizon-php.py index c532e423..c98fe5c9 100644 --- a/scripts/fuc-xb-launch/horizon-php.py +++ b/scripts/fuc-xb-launch/horizon-php.py @@ -13,17 +13,28 @@ def run(args,env=None): return p.stdout.strip() def main(): os.umask(0o077);assert hashlib.sha256(UNIT.read_bytes()).hexdigest()==EXPECTED - assert not DIR.exists()and not SCAN.exists(),'Existing FUC CLI override; inspect' settings=json.loads(run(['php','-r',"echo json_encode(['scan'=>PHP_CONFIG_FILE_SCAN_DIR,'disabled'=>ini_get('disable_functions'),'ini'=>php_ini_loaded_file()]);"])) source=pathlib.Path(settings['scan']);assert source.is_dir() and source.is_absolute()and ':'not in str(source) disabled={x.strip()for x in settings['disabled'].split(',')if x.strip()};restored=sorted(disabled&REQUIRED) assert 'proc_open'in restored,'Unexpected CLI hardening; inspect rather than changing' - before=UNIT.read_bytes();DIR.mkdir(mode=0o700);(DIR/'unit-before').write_bytes(before) - SCAN.mkdir(mode=0o750);group=pwd.getpwnam('fucxbtest').pw_gid;os.chown(SCAN,0,group) + before=UNIT.read_bytes();group=pwd.getpwnam('fucxbtest').pw_gid + if DIR.exists()or SCAN.exists(): + assert DIR.is_dir()and SCAN.is_dir()and not DIR.is_symlink()and not SCAN.is_symlink() + assert not(DIR/'receipt.json').exists()and (DIR/'unit-before').read_bytes()==before,'Foreign/completed override' + assert {p.name for p in SCAN.iterdir()}=={p.name for p in source.glob('*.ini')}|{'zz-fuc-horizon-process.ini'},'Partial override changed' + else: + DIR.mkdir(mode=0o700);(DIR/'unit-before').write_bytes(before);SCAN.mkdir(mode=0o750) + SCAN.chmod(0o750);os.chown(SCAN,0,group) sources={} for f in sorted(source.glob('*.ini')): - assert f.is_file();(SCAN/f.name).symlink_to(f);sources[str(f.resolve())]=hashlib.sha256(f.read_bytes()).hexdigest() - override=SCAN/'zz-fuc-horizon-process.ini';assert not override.exists();override.write_text('disable_functions='+','.join(sorted(disabled-REQUIRED))+'\n');override.chmod(0o640);os.chown(override,0,group) + assert f.is_file();target=SCAN/f.name + if os.path.lexists(target):assert target.is_symlink()and target.resolve()==f.resolve(),'INI source changed' + else:target.symlink_to(f) + sources[str(f.resolve())]=hashlib.sha256(f.read_bytes()).hexdigest() + override=SCAN/'zz-fuc-horizon-process.ini';content='disable_functions='+','.join(sorted(disabled-REQUIRED))+'\n' + if override.exists():assert override.is_file()and not override.is_symlink()and override.read_text()==content,'INI override changed' + else:override.write_text(content) + override.chmod(0o640);os.chown(override,0,group) env={**os.environ,'PHP_INI_SCAN_DIR':str(SCAN),'XB_INSTANCE':'fuc-xb-test'} probe=json.loads(run(['runuser','-u','fucxbtest','--','env','PHP_INI_SCAN_DIR='+str(SCAN),'php','-r',"echo json_encode(array_combine(['proc_open','proc_get_status','proc_close','proc_terminate'],array_map('function_exists',['proc_open','proc_get_status','proc_close','proc_terminate'])));"],env)) assert all(probe.values()),'Required FUC worker process functions unavailable' @@ -34,7 +45,7 @@ def main(): assert run(['systemctl','is-active','fuc-xb-test-horizon'])=='active' assert all(hashlib.sha256(pathlib.Path(p).read_bytes()).hexdigest()==sha for p,sha in sources.items()),'Global PHP sources changed' except BaseException: - UNIT.write_bytes(before);run(['systemctl','daemon-reload']);raise + UNIT.write_bytes(before);run(['systemctl','daemon-reload']);run(['systemctl','restart','fuc-xb-test-horizon']);raise receipt={'configured':True,'scope':'FUC-XB CLI Horizon and its children only','restored_process_functions':restored,'global_php_and_fpm_unchanged':True,'other_disabled_functions_retained':True,'unit_sha256':hashlib.sha256(UNIT.read_bytes()).hexdigest(),'scan_directory':str(SCAN),'source_ini_sha256':sources} (DIR/'receipt.json').write_text(json.dumps(receipt,indent=2));print(json.dumps({k:v for k,v in receipt.items()if k!='source_ini_sha256'})) if __name__=='__main__':main() diff --git a/scripts/fuc-xb-launch/panel.php b/scripts/fuc-xb-launch/panel.php index 9077709c..ccc866ae 100644 --- a/scripts/fuc-xb-launch/panel.php +++ b/scripts/fuc-xb-launch/panel.php @@ -9,7 +9,7 @@ if(DB::connection()->getDatabaseName()!=='fuc_xb_test'||!is_link('/var/www/wwwro $lock=fopen($dir.'/panel.lock','c');if(!flock($lock,LOCK_EX|LOCK_NB))throw new RuntimeException('Another FUC preparation is running'); $action=$argv[1]??''; function saveState(array $s):void{global $stateFile;$p=$stateFile.'.tmp';file_put_contents($p,json_encode($s,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));chmod($p,0600);rename($p,$stateFile);} -function newQA(int $gid,string $phase):User{return User::create(['email'=>'qa-launch-'.$phase.'-20261105@fuc-xb.invalid','password'=>password_hash(bin2hex(random_bytes(20)),PASSWORD_BCRYPT),'uuid'=>(string)Illuminate\Support\Str::uuid(),'token'=>bin2hex(random_bytes(16)),'group_id'=>$gid,'transfer_enable'=>1073741824,'expired_at'=>time()+86400,'balance'=>0,'banned'=>0,'u'=>0,'d'=>0,'speed_limit'=>30,'device_limit'=>2,'remind_expire'=>0,'remind_traffic'=>0]);} +function newQA(int $gid,string $phase):User{return User::create(['email'=>'qa-launch-'.$phase.'-20261105@fuc-xb.invalid','password'=>password_hash(bin2hex(random_bytes(20)),PASSWORD_BCRYPT),'uuid'=>(string)Illuminate\Support\Str::uuid(),'token'=>bin2hex(random_bytes(16)),'group_id'=>$gid,'transfer_enable'=>104857600,'expired_at'=>time()+3600,'balance'=>0,'banned'=>0,'u'=>0,'d'=>0,'speed_limit'=>30,'device_limit'=>2,'remind_expire'=>0,'remind_traffic'=>0]);} if($action==='prepare'){ if(is_file($stateFile)||Server::count()||ServerMachine::count())throw new RuntimeException('Existing preparation; inspect before retry'); $manifest=json_decode(file_get_contents($manifestFile),true,512,JSON_THROW_ON_ERROR); @@ -52,6 +52,10 @@ if($action==='qa-revoke'){ if($state['qa_phase']==='banned')$u->update(['banned'=>1]);elseif($state['qa_phase']==='expired')$u->update(['expired_at'=>time()-1]);elseif($state['qa_phase']==='exhausted')$u->update(['u'=>$u->transfer_enable]);else throw new RuntimeException('Invalid phase'); echo json_encode(['revoked'=>true,'phase'=>$state['qa_phase']]);exit; } +if($action==='qa-bound'){ + $u=User::findOrFail($state['current_user_id']);if($u->group_id!==$state['qa_group_id']||!str_ends_with($u->email,'@fuc-xb.invalid')||$u->balance!==0)throw new RuntimeException('Not this QA'); + $u->update(['transfer_enable'=>104857600,'expired_at'=>min((int)$u->expired_at,time()+3600)]);echo json_encode(['restricted'=>true,'quota_bytes'=>104857600,'maximum_seconds'=>3600]);exit; +} if($action==='qa-next'){ $u=User::findOrFail($state['current_user_id']);foreach($state['nodes']as$row)if(App\Services\ServerService::getAvailableUsers(Server::findOrFail($row['node_id']))->count())throw new RuntimeException('Revoke all QA access first'); $phase=match($state['qa_phase']){'banned'=>'expired','expired'=>'exhausted',default=>throw new RuntimeException('No remaining phase')};