|
12 | 12 | use Exception; |
13 | 13 | use GuzzleHttp\Client; |
14 | 14 | use Illuminate\Console\Command; |
| 15 | +use Illuminate\Support\Facades\Config; |
15 | 16 | use Str; |
16 | 17 |
|
17 | 18 | class SitesChecker extends Command |
@@ -58,10 +59,10 @@ public function handle(int $site_id = null, $mode = null) |
58 | 59 | } |
59 | 60 |
|
60 | 61 | if ($site_id === null) { |
61 | | - $sites = Sites::where('enabled', 1)->get(); |
| 62 | + $sites = Sites::where('enabled', 1)->with('checksList')->get(); |
62 | 63 | $tgMessage = 0; |
63 | 64 | } else { |
64 | | - $sites[] = Sites::find($site_id); |
| 65 | + $sites[] = Sites::where('id', $site_id)->with('checksList')->firstOrFail(); |
65 | 66 | $tgMessage = 1; |
66 | 67 | } |
67 | 68 |
|
@@ -119,19 +120,34 @@ private function ckeckSite($site, $cli = false, $debug = false): void |
119 | 120 | Sites::where('id', $site->id)->update(['ip_address' => gethostbyname($site->url)]); |
120 | 121 | try { |
121 | 122 | if ($site->checksList->use_file === 1) { |
122 | | - $httpClient = new Client(); |
123 | | - $url = ($site->https === 1 && $site->checksList->check_https === 1) ? 'https://' . $site->file_url : 'http://' . $site->file_url; |
124 | | - $request = $httpClient->request('GET', $url, ['allow_redirects' => false]); |
125 | | - $response = $request->getBody(); |
126 | | - $responseArray = json_decode($response, true); |
127 | | - $phpVersion = $responseArray['php-version']; |
128 | | - $statusCode = $request->getStatusCode(); |
129 | | - $webServerType = $responseArray['web-server']; |
130 | | - $phpBranch = $responseArray['php-branch']; |
| 123 | + if ($site->file_url === null) { |
| 124 | + $phpVersion = 0; |
| 125 | + $statusCode = 999; |
| 126 | + $webServerType = 0; |
| 127 | + $phpBranch = 0; |
| 128 | + } else { |
| 129 | + $httpClient = new Client(); |
| 130 | + $url = ($site->https === 1) ? 'https://' . $site->url . '/' . $site->file_url : 'http://' . $site->url . '/' . $site->file_url; |
| 131 | + $request = $httpClient->request('GET', $url, ['allow_redirects' => false]); |
| 132 | + if ($request->getStatusCode() === 200) { |
| 133 | + $response = $request->getBody(); |
| 134 | + $responseArray = json_decode($response, true); |
| 135 | + $phpVersion = $responseArray['php-version']; |
| 136 | + $statusCode = $request->getStatusCode(); |
| 137 | + $webServerType = $responseArray['web-server']; |
| 138 | + $phpBranch = $responseArray['php-branch']; |
| 139 | + } else { |
| 140 | + $phpVersion = 0; |
| 141 | + $statusCode = $request->getStatusCode(); |
| 142 | + $webServerType = 0; |
| 143 | + $phpBranch = 0; |
| 144 | + } |
| 145 | + } |
131 | 146 | } else { |
132 | 147 | $url = ($site->https === 1 && $site->checksList->check_https === 1) ? 'https://' . $site->url : 'http://' . $site->url; |
133 | 148 | $ch = curl_init(); |
134 | 149 | curl_setopt($ch, CURLOPT_URL, $url); |
| 150 | + curl_setopt($ch, CURLOPT_USERAGENT, Config::get('moring.userAgent')); |
135 | 151 | curl_setopt($ch, CURLOPT_HEADER, true); |
136 | 152 | curl_setopt($ch, CURLOPT_NOBODY, true); |
137 | 153 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
0 commit comments