make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); use Illuminate\Support\Facades\{DB,Cache}; use App\Models\{User,Server,ServerGroup}; if(DB::connection()->getDatabaseName()!=='fuc_xb_test')throw new RuntimeException('Wrong database'); $action=$argv[1]??'';$file=$dir.'/node-state.json'; if($action==='setup'){ if(file_exists($file)||Server::count()!==0||User::where('email','qa-node-20261104@fuc-xb.invalid')->exists())throw new RuntimeException('Node fixture collision'); $state=['before'=>['users'=>User::count(),'groups'=>ServerGroup::count(),'nodes'=>0,'wallet'=>(int)User::sum('balance')],'setting_rows'=>DB::table('v2_settings')->whereIn('name',['server_token','server_push_interval','server_pull_interval'])->get()->map(fn($x)=>(array)$x)->all(),'created_at'=>time()]; // Journal intended identity before creating any fixture. file_put_contents($file,json_encode($state));chmod($file,0600); DB::transaction(function()use(&$state,$file){ $g=new ServerGroup();$g->name='FUC-XB isolated QA 20261104';$g->save(); $u=User::create(['email'=>'qa-node-20261104@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'=>$g->id,'balance'=>0,'banned'=>0,'expired_at'=>time()+3600,'transfer_enable'=>100*1024*1024,'u'=>0,'d'=>0,'speed_limit'=>10,'device_limit'=>1]); $n=Server::create(['type'=>'vmess','name'=>'FUC-XB QA JP02 (temporary)','group_ids'=>[(string)$g->id],'route_ids'=>[],'host'=>'193.111.31.52','port'=>25443,'server_port'=>25443,'rate'=>1,'transfer_enable'=>100*1024*1024,'u'=>0,'d'=>0,'show'=>true,'enabled'=>true,'sort'=>9999,'protocol_settings'=>['tls'=>1,'tls_settings'=>['server_name'=>'jp02.gembox-dns.com','allow_insecure'=>false],'network'=>'ws','network_settings'=>['path'=>'/fuc-xb-qa-20261104','headers'=>['Host'=>'jp02.gembox-dns.com']]]]); $state+=['user_id'=>$u->id,'node_id'=>$n->id,'group_id'=>$g->id,'server_token'=>bin2hex(random_bytes(32))]; app(App\Support\Setting::class)->save(['server_token'=>$state['server_token'],'server_push_interval'=>10,'server_pull_interval'=>10]); file_put_contents($file,json_encode($state));chmod($file,0600); }); file_put_contents($file,json_encode($state));chmod($file,0600); $users=App\Services\ServerService::getAvailableUsers(Server::findOrFail($state['node_id'])); if($users->count()!==1||(int)$users[0]->id!==$state['user_id'])throw new RuntimeException('QA isolation failed'); echo json_encode(['created'=>true,'only_qa_user_on_node'=>true,'qa_quota_mib'=>100,'qa_lifetime_seconds'=>3600,'node_type'=>'vmess','port'=>25443,'formal_users_changed'=>false]).PHP_EOL; exit; } $state=json_decode(file_get_contents($file),true,512,JSON_THROW_ON_ERROR);$u=User::findOrFail($state['user_id']);$n=Server::findOrFail($state['node_id']); if($u->email!=='qa-node-20261104@fuc-xb.invalid'||$n->name!=='FUC-XB QA JP02 (temporary)')throw new RuntimeException('Fixture identity changed'); if($action==='work'){ $before=Illuminate\Support\Facades\Queue::size('traffic_fetch')+Illuminate\Support\Facades\Queue::size('stat'); if($before>100)throw new RuntimeException('Unexpected queue backlog'); Illuminate\Support\Facades\Artisan::call('queue:work',['connection'=>'redis','--queue'=>'traffic_fetch,stat','--stop-when-empty'=>true,'--max-time'=>25,'--tries'=>1,'--sleep'=>1]); echo json_encode(['bounded_worker'=>true,'pending_before'=>$before,'traffic_pending'=>Illuminate\Support\Facades\Queue::size('traffic_fetch'),'stat_pending'=>Illuminate\Support\Facades\Queue::size('stat')]).PHP_EOL;exit; } if($action==='probe'){ echo json_encode(['qa_upload'=>$u->u,'qa_download'=>$u->d,'node_upload'=>$n->u,'node_download'=>$n->d,'last_check_at'=>$n->last_check_at,'last_push_at'=>$n->last_push_at,'online'=>$n->online,'available_users'=>App\Services\ServerService::getAvailableUsers($n)->count(),'available_servers'=>count(App\Services\ServerService::getAvailableServers($u))]).PHP_EOL;exit; } if($action==='disable'){ $u->update(['banned'=>1,'expired_at'=>time()-1,'transfer_enable'=>0]); echo json_encode(['disabled'=>true,'users_no_longer_dispatched'=>App\Services\ServerService::getAvailableUsers($n)->count()===0]).PHP_EOL;exit; } if($action==='export'){ // Only SSH consumers receive this; never print to the chat/tool log. $gate=json_decode(file_get_contents('/var/www/wwwroot/fuc-xb-test/private/gate-credentials.json'),true); echo json_encode(['node_id'=>$n->id,'server_token'=>$state['server_token'],'gate_cookie'=>$gate['cookie_token'],'source'=>'https://fuc-xb-test.gemcook.net','alias'=>'https://fuc-xb-test.tomtojapan.online','subscribe_token'=>$u->token,'qa_uuid'=>$u->uuid,'expected_exit'=>'193.111.31.52','expected_country'=>'JP','port'=>25443,'sni'=>'jp02.gembox-dns.com','node_tag'=>$n->name]);exit; } if($action==='cleanup'){ if(!$u->banned)throw new RuntimeException('Disable and verify revoked access before cleanup'); $backup=['user'=>$u->getAttributes(),'node'=>$n->getAttributes(),'traffic'=>DB::table('v2_stat_user')->where('user_id',$u->id)->get()->all()]; file_put_contents($dir.'/node-fixtures-before-cleanup.json',json_encode($backup)); DB::transaction(function()use($state,$u,$n){ foreach(['v2_stat_user','v2_traffic_reset_logs','fuc_vip_entries','fuc_vip_accounts']as$t)DB::table($t)->where('user_id',$u->id)->delete(); DB::table('personal_access_tokens')->where('tokenable_id',$u->id)->delete(); DB::table('v2_stat_server')->where('server_id',$n->id)->where('server_type','vmess')->delete(); app(App\Services\DeviceStateService::class)->removeNodeDevices($n->id,$u->id); Illuminate\Support\Facades\Redis::srem('traffic:pending_check',(string)$u->id); $n->delete();$u->delete();ServerGroup::where('id',$state['group_id'])->where('name','FUC-XB isolated QA 20261104')->delete(); DB::table('v2_settings')->whereIn('name',['server_token','server_push_interval','server_pull_interval'])->delete(); foreach($state['setting_rows']as$row)DB::table('v2_settings')->insert($row); }); Cache::store('redis')->forget(App\Support\Setting::CACHE_KEY); $after=['users'=>User::count(),'groups'=>ServerGroup::count(),'nodes'=>Server::count(),'wallet'=>(int)User::sum('balance')]; echo json_encode(['cleanup'=>true,'baseline_counts_and_wallet_restored'=>$after===$state['before'],'temporary_master_token_removed'=>true,'formal_users_changed'=>false]).PHP_EOL;exit; } throw new RuntimeException('Unknown action');