/** * Use Curl to send the request to the Alfresco repository. * * @see elis_files_utils_invoke_service */ function elis_files_utils_http_request($serviceurl, $auth = 'ticket', $headers = array(), $method = 'GET', $data = NULL, $username = '', $retry = 3) { global $CFG; switch ($auth) { case 'ticket': case 'refresh': $url = elis_files_utils_get_wc_url($serviceurl, $auth, $username); break; case 'basic': $url = elis_files_utils_get_url($serviceurl); $hauth = elis_files_utils_get_auth_headers($username); $headers = array_merge($hauth, $headers); break; default: return false; } /// Prepare curl sessiontoge $session = curl_init($url); if (ELIS_FILES_DEBUG_TRACE) { curl_setopt($session, CURLOPT_VERBOSE, true); } /// Add additonal headers curl_setopt($session, CURLOPT_HTTPHEADER, $headers); /// Don't return HTTP headers. Do return the contents of the call curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); if ($auth == 'basic') { $user = elis::$config->elisfiles->server_username; $pass = elis::$config->elisfiles->server_password; curl_setopt($session, CURLOPT_USERPWD, "$user:$pass"); } if ($method == 'CUSTOM-POST') { curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'POST' ); curl_setopt($session, CURLOPT_POSTFIELDS, $data); } if ($method == 'CUSTOM-PUT') { curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'PUT' ); curl_setopt($session, CURLOPT_POSTFIELDS, $data); } if ($method == 'CUSTOM-DELETE') { curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($session, CURLOPT_POSTFIELDS, $data); //curl_setopt($session, CURLOPT_ERRORBUFFER, 1); } elis_files_set_curl_timeouts($session); /// Make the call $return_data = curl_exec($session); /// Get return http status code $httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE); /// Close HTTP session curl_close($session); // Prepare return $result = new stdClass(); $result->code = $httpcode; $result->data = $return_data; return $result; }
/** * Detect whether or not the remove Alfreco repository is currently running. * * @param none * @return bool True if the remote system is running, False otherwise. */ function is_running() { // TODO: This means that if Alfresco comes up during a user's login session, this won't be refelcted until they // log back into Moodle again. We probably want to add somethign here that will check after a certain amount of // time since the last check for an individual user. // Don't check if Alfresco is running if we have already checked once. if ($this->isrunning !== null) { return $this->isrunning; } if (empty(elis::$config->elisfiles->server_host)) { $this->isrunning = false; return false; } $repourl = elis::$config->elisfiles->server_host; if ($repourl[strlen($repourl) - 1] == '/') { $repourl = substr($repourl, 0, strlen($repourl) - 1); } if (!empty(elis::$config->elisfiles->server_port)) { $repourl .= ':' . elis::$config->elisfiles->server_port; } $repourl .= '/alfresco'; // A list of valid HTTP response codes $validresponse = array( 200, 201, 204, 302, 401, 505 ); // Initialize the cURL session $session = curl_init($repourl); elis_files_set_curl_timeouts($session); // Execute the cURL call curl_exec($session); // Get the HTTP response code from our request $httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE); curl_close($session); // Make sure the code is in the list of valid, acceptible codes if (array_search($httpcode, $validresponse)) { $this->isrunning = true; return true; } $this->isrunning = false; return false; }