bridgeFactory = new \BridgeFactory(); } public function execute() { if (!Debug::isEnabled()) { returnError('This action is only available in debug mode!', 400); } if (!isset($this->userData['bridge'])) { $this->returnEntryPage(); return; } $bridgeName = $this->userData['bridge']; $bridgeClassName = $this->bridgeFactory->sanitizeBridgeName($bridgeName); if ($bridgeClassName === null) { throw new \InvalidArgumentException('Bridge name invalid!'); } $this->reportBridgeConnectivity($bridgeClassName); } /** * Generates a report about the bridge connectivity status and sends it back * to the user. * * The report is generated as Json-formatted string in the format * { * "bridge": "", * "successful": true/false * } * * @param class-string $bridgeClassName Name of the bridge to generate the report for * @return void */ private function reportBridgeConnectivity($bridgeClassName) { if (!$this->bridgeFactory->isWhitelisted($bridgeClassName)) { header('Content-Type: text/html'); returnServerError('Bridge is not whitelisted!'); } header('Content-Type: text/json'); $retVal = [ 'bridge' => $bridgeClassName, 'successful' => false, 'http_code' => 200, ]; $bridge = $this->bridgeFactory->create($bridgeClassName); if ($bridge === false) { echo json_encode($retVal); return; } $curl_opts = [ CURLOPT_CONNECTTIMEOUT => 5 ]; try { $reply = getContents($bridge::URI, [], $curl_opts, true); if ($reply['code'] === 200) { $retVal['successful'] = true; if (strpos(implode('', $reply['status_lines']), '301 Moved Permanently')) { $retVal['http_code'] = 301; } } } catch (Exception $e) { $retVal['successful'] = false; } echo json_encode($retVal); } private function returnEntryPage() { echo <<
EOD; } }