reloadNode.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Jobs\VNet;
  3. use App\Models\Node;
  4. use GuzzleHttp\Client;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Queue\SerializesModels;
  10. class reloadNode implements ShouldQueue {
  11. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  12. private static $host;
  13. private static $secret;
  14. private static $data;
  15. public function __construct(Node $node) {
  16. self::$host = ($node->server?: $node->ip).':'.$node->push_port;
  17. self::$secret = $node->auth->secret;
  18. self::$data = [
  19. 'id' => $node->id,
  20. 'method' => $node->method,
  21. 'protocol' => $node->protocol,
  22. 'obfs' => $node->obfs,
  23. 'obfs_param' => $node->obfs_param?: '',
  24. 'is_udp' => $node->is_udp,
  25. 'speed_limit' => $node->speed_limit,
  26. 'client_limit' => $node->client_limit,
  27. 'single' => $node->single,
  28. 'port' => (string) $node->port,
  29. 'passwd' => $node->passwd?: '',
  30. 'push_port' => $node->push_port,
  31. 'secret' => $node->auth->secret,
  32. 'redirect_url' => sysConfig('redirect_url')
  33. ];
  34. }
  35. public function handle(): void {
  36. $client = new Client([
  37. 'base_uri' => self::$host,
  38. 'timeout' => 15,
  39. 'headers' => [
  40. 'secret' => self::$secret,
  41. 'content-type' => 'application/json'
  42. ]
  43. ]);
  44. $client->post('/api/v2/node/reload', ['body' => json_encode(self::$data)]);
  45. }
  46. }