GitHub integration fails due to missing user agent in GET requests
Created by: c-schmitz
I was wondering why suddenly the GitHub integration does not work anymore. The reason is that GitHub now requires a valid user agent to be sent with any http request (see http://developer.github.com/v3/#user-agent-required )
The problem is that the function function url_get in /mantis/core/url_api.php does not provide a user agent string.
I did a very crude hack that basically enforces CURL and sets a user agent like this:
if( !ini_get_bool( 'allow_url_fopen' ) ) { // disable file_get_contents
return @file_get_contents( $p_url );
}
# Use the PHP cURL extension
if( function_exists( 'curl_init' ) ) {
$t_curl = curl_init( $p_url );
curl_setopt($t_curl,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); // Set a user agent
curl_setopt( $t_curl, CURLOPT_RETURNTRANSFER, true );
$t_data = curl_exec( $t_curl );
curl_close( $t_curl );
return $t_data;
}
I'd recommend to either change the Mantis API or use your own function url_get in the Source plugin.
Thank you for a great plugin.