欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal7 d7 drupal 7 登录用户能打开,,未登录用户不能打开,,原因为是网站里请求了一个url 网址

# 在页面的访问权限里 有  _can_operation_jamf_or_from_self_service  和  operation jamf


function custom_twenty_three_jamf_menu()
{
     $items['ajax_qiyong_jingyong_computer_in_policy'] = array(
   
'page callback' => 'custom_twenty_three_jamf_ajax_qiyong_jingyong_computer_in_policy',//启用禁用策略
  // 'access arguments' => array('operation jamf'),  // 'access arguments' => true 是不对的,只能用'access callback'=>true
   
'access callback' => '_can_operation_jamf_or_from_self_service',
   
'access arguments' => array('operation jamf'),  // 'access arguments' => true 是不对的,只能用'access callback'=>true
   );
}




function _can_operation_jamf_or_from_self_service($string)
{

   
$return = user_access($string);

   
if($return){
       
return true;
   }
//    global $from_self_service;
//    $from_self_service = 1;
   //从 self service 上的脚本来的
   
$http_x_real_ip  =  $_SERVER['HTTP_X_REAL_IP'];

   
$serial = _removeCnEnSpace($_POST['serial']);
   
$computer_id =  _removeCnEnSpace($_POST['computer_id']);
   
$_GET['new'] = 1;
   
$token_expires = get_jamf_token(); // 未登录用户会执行到这里
   
$token_expires = json_decode($token_expires, true);
   
$token = $token_expires['token'];

   
$a_computer_info_xml_from_jamf = _get_groups_account_by_id_from_jamf($computer_id, $token,'General');
   
$a_computer_info = _get_a_computer_info_from_jamf_xml($a_computer_info_xml_from_jamf);
   
//从 self service 上的脚本来的 computer_id 得到的 序列号,与从  self service 上的脚本来的 序列号相等,
   //并且 从 self service 上的脚本来的 ip 与从  self service 上的脚本来的 ip   相等,与  此时,才允许执行
   
if(($a_computer_info['serial_number'] == $serial ) &&  ($a_computer_info['last_reported_ip'] == $http_x_real_ip))
   {
       
return true;
   }
   
//其它情况就为 false 吧
   
return false;
}




//得到 登录 jamf 的 token
function get_jamf_token()
{
   
$ch = curl_init();

   
if ($_GET['new']) {
//        curl_setopt($ch, CURLOPT_URL, "https://jsjamf.luxshare-ict.com:8443/uapi/auth/tokens");
       
curl_setopt($ch, CURLOPT_URL, "https://aaaa.bbbbb-ict.com:8443/api/v1/auth/token");  //这里网址可能无法访问,所以会导致整个网页无法打开
   }
else {
//        curl_setopt($ch, CURLOPT_URL, "https://jamfsrv.luxshare-ict.com:8443/uapi/auth/tokens");
       
curl_setopt($ch, CURLOPT_URL, "https://cccc.bbbbb-ict.com:8443/api/v1/auth/token");  //这里网址可能无法访问,所以会导致整个网页无法打开
   }
   
$headers = array('Authorization:Basic ' . _my_jamf_get_base64_encode(), 'Content-Type: application/json');
   
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
   
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // to resolve your current error
   
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
   
if (!empty($data_arr)) {
       
curl_setopt($ch, CURLOPT_POSTFIELDS, drupal_json_encode($data_arr));
   }
   
$response = curl_exec($ch);
   
if (curl_error($ch)) {
       
$response = curl_error($ch);
   }
   
curl_close($ch);
   
//var_dump($response);
   //var_dump("AAA");exit;
   
return $response;
}


普通分类: