@@ -480,6 +480,8 @@ public static function sendLineItemResult($user_id, $grade, $scoreMaximum, $comm
480480 if ( is_array ($ debug_log ) ) $ debug_log [] = $ headers ;
481481 if ( is_array ($ debug_log ) ) $ debug_log [] = $ grade_call ;
482482
483+ self ::setUserAgentCurl ($ ch ); // Set the User-Agent header
484+
483485 $ line_item = curl_exec ($ ch );
484486 if ( $ line_item === false ) return self ::handle_curl_error ($ ch , $ debug_log );
485487
@@ -537,6 +539,8 @@ public static function loadNRPS($membership_url, $access_token, &$debug_log=fals
537539 if ( is_array ($ debug_log ) ) $ debug_log [] = $ membership_url ;
538540 if ( is_array ($ debug_log ) ) $ debug_log [] = $ headers ;
539541
542+ self ::setUserAgentCurl ($ ch ); // Set the User-Agent header
543+
540544 $ membership = curl_exec ($ ch );
541545 if ( $ membership === false ) return self ::handle_curl_error ($ ch , $ debug_log );
542546
@@ -637,6 +641,8 @@ public static function loadGroups($context_groups_url, $access_token, &$debug_lo
637641 if ( is_array ($ debug_log ) ) $ debug_log [] = $ context_groups_url ;
638642 if ( is_array ($ debug_log ) ) $ debug_log [] = $ headers ;
639643
644+ self ::setUserAgentCurl ($ ch ); // Set the User-Agent header
645+
640646 $ lti_groups = curl_exec ($ ch );
641647 if ( $ lti_groups === false ) return self ::handle_curl_error ($ ch , $ debug_log );
642648
@@ -727,6 +733,8 @@ public static function loadLineItems($lineitems_url, $access_token, &$debug_log=
727733 if (is_array ($ debug_log ) ) $ debug_log [] = 'Line Items URL: ' .$ lineitems_url ;
728734 if (is_array ($ debug_log ) ) $ debug_log [] = $ headers ;
729735
736+ self ::setUserAgentCurl ($ ch ); // Set the User-Agent header
737+
730738 $ lineitems = curl_exec ($ ch );
731739 if ( $ lineitems === false ) return self ::handle_curl_error ($ ch , $ debug_log );
732740
@@ -779,6 +787,8 @@ public static function loadLineItem($lineitem_url, $access_token, &$debug_log=fa
779787 if (is_array ($ debug_log ) ) $ debug_log [] = 'Line Items URL: ' .$ lineitem_url ;
780788 if (is_array ($ debug_log ) ) $ debug_log [] = $ headers ;
781789
790+ self ::setUserAgentCurl ($ ch ); // Set the User-Agent header
791+
782792 $ lineitem = curl_exec ($ ch );
783793 if ( $ lineitem === false ) return self ::handle_curl_error ($ ch , $ debug_log );
784794
@@ -836,6 +846,8 @@ public static function loadResults($lineitem_url, $access_token, &$debug_log=fal
836846 if (is_array ($ debug_log ) ) $ debug_log [] = 'Line Items URL: ' .$ actual_url ;
837847 if (is_array ($ debug_log ) ) $ debug_log [] = $ headers ;
838848
849+ self ::setUserAgentCurl ($ ch ); // Set the User-Agent header
850+
839851 $ results = curl_exec ($ ch );
840852 if ( $ results === false ) return self ::handle_curl_error ($ ch , $ debug_log );
841853
@@ -897,6 +909,8 @@ public static function deleteLineItem($lineitem_url, $access_token, &$debug_log=
897909 if (is_array ($ debug_log ) ) $ debug_log [] = 'Line Item URL: ' .$ lineitem_url ;
898910 if (is_array ($ debug_log ) ) $ debug_log [] = $ headers ;
899911
912+ self ::setUserAgentCurl ($ ch ); // Set the User-Agent header
913+
900914 $ response = curl_exec ($ ch );
901915 if ( $ response === false ) return self ::handle_curl_error ($ ch , $ debug_log );
902916
@@ -969,6 +983,8 @@ public static function createLineItem($lineitems_url, $access_token, $lineitem,
969983 if (is_array ($ debug_log ) ) $ debug_log [] = 'Line Items URL: ' .$ lineitems_url ;
970984 if (is_array ($ debug_log ) ) $ debug_log [] = $ headers ;
971985
986+ self ::setUserAgentCurl ($ ch ); // Set the User-Agent header
987+
972988 $ line_item = curl_exec ($ ch );
973989 if ( $ line_item === false ) return self ::handle_curl_error ($ ch , $ debug_log );
974990
@@ -1038,6 +1054,8 @@ public static function updateLineItem($lineitem_url, $access_token, $lineitem, &
10381054 if (is_array ($ debug_log ) ) $ debug_log [] = 'Line Item URL: ' .$ lineitem_url ;
10391055 if (is_array ($ debug_log ) ) $ debug_log [] = $ headers ;
10401056
1057+ self ::setUserAgentCurl ($ ch ); // Set the User-Agent header
1058+
10411059 $ line_item = curl_exec ($ ch );
10421060 if ( $ line_item === false ) return self ::handle_curl_error ($ ch , $ debug_log );
10431061
@@ -1121,6 +1139,8 @@ public static function get_access_token($scope, $subject, $lti13_token_url, $lti
11211139 if ( is_array ($ debug_log ) ) $ debug_log [] = "Post Data: " ;
11221140 if ( is_array ($ debug_log ) ) $ debug_log [] = $ query ;
11231141
1142+ self ::setUserAgentCurl ($ ch ); // Set the User-Agent header
1143+
11241144 $ token_str = curl_exec ($ ch );
11251145 if ( $ token_str === false ) {
11261146 self ::handle_curl_error ($ ch , $ debug_log );
@@ -1478,4 +1498,19 @@ public static function extractKeyFromKeySet($keyset_str, $kid)
14781498 return null ;
14791499 }
14801500
1501+ public static function setUserAgentCurl ($ ch )
1502+ {
1503+ global $ CFG ;
1504+
1505+ // Construct a robust default User-Agent
1506+ $ default_agent = 'Tsugi/ ' .
1507+ (defined ('TSUGI_VERSION ' ) ? TSUGI_VERSION : 'dev ' ) .
1508+ ' ( ' . (isset ($ CFG ->wwwroot ) ? $ CFG ->wwwroot : 'https://www.tsugi.org ' ) . ') ' .
1509+ ' PHP/ ' . phpversion ();
1510+
1511+ // Allow overrides via extension mechanism
1512+ $ user_agent = $ CFG ->getExtension ('user_agent ' , $ default_agent );
1513+
1514+ curl_setopt ($ ch , CURLOPT_USERAGENT , $ user_agent );
1515+ }
14811516}
0 commit comments