userData['bridge'])) { $this->returnEntryPage(); return; } $bridgeName = $this->userData['bridge']; $this->reportBridgeConnectivity($bridgeName); } /** * 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 string $bridgeName Name of the bridge to generate the report for * @return void */ private function reportBridgeConnectivity($bridgeName) { $bridgeFac = new \BridgeFactory(); $bridgeFac->setWorkingDir(PATH_LIB_BRIDGES); if(!$bridgeFac->isWhitelisted($bridgeName)) { header('Content-Type: text/html'); returnServerError('Bridge is not whitelisted!'); } header('Content-Type: text/json'); $retVal = array( 'bridge' => $bridgeName, 'successful' => false, 'http_code' => 200, ); $bridge = $bridgeFac->create($bridgeName); if($bridge === false) { echo json_encode($retVal); return; } $curl_opts = array( CURLOPT_CONNECTTIMEOUT => 5 ); try { $reply = getContents($bridge::URI, array(), $curl_opts, true); if($reply) { $retVal['successful'] = true; if (isset($reply['header'])) { if (strpos($reply['header'], 'HTTP/1.1 301 Moved Permanently') !== false) { $retVal['http_code'] = 301; } } } } catch(Exception $e) { $retVal['successful'] = false; } echo json_encode($retVal); } private function returnEntryPage() { echo <<
EOD; } }