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

这里的技术是共享的

You are here

jamf 锁定电脑 使用接口 ,,,和 判断是否 锁定电脑 使用接口 我自己亲自做的 有大用 AG chatgpt 有大用 有大大用

jamf 锁定电脑 使用接口  我自己亲自做的 OK 有大用


function _exec_command_in_computer_from_jamf($command_name,$token, $data)
{
   
$ch = curl_init();
//    curl_setopt($ch, CURLOPT_URL, "https://aaa.bbbbb-ict.com:1234/JSSResource/computers/macaddress/${mac}");

   
if ($_GET['new']) {
       
curl_setopt($ch, CURLOPT_URL, "https://aaa.bbbb-ict.com:1234/JSSResource/computercommands/command/{$command_name}");
   }
else {
       
curl_setopt($ch, CURLOPT_URL, "https://ddd.bbbb-ict.com:1234/JSSResource/computercommands/command/{$command_name}");
   }
//    curl_setopt($ch, CURLOPT_URL, "https://aaa.bbbbb-ict.com:1234/uapi/computers/${mac}");
//    curl_setopt($ch, CURLOPT_URL, "https://aaa.bbbbb-ict.com:1234/JSSResource/computers/macaddress/${mac}/subset/General&groups_accounts");
   
$headers = array('Authorization:Bearer ' . $token, 'Content-Type: application/xml;charset=utf-8', 'Content-Length: ' . strlen($data), 'Accept' => 'application/xml');
   
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');
//    curl_setopt($ch, CURLOPT_PUT, 1);//加上这行 好像有报错,
   
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

   
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);
   
return $response;
}
//$command_name = _removeCnEnSpace($_POST['command_name']);//
$command_name='DeviceLock'//事实上 command_name 就是 DeviceLock


$exec_data = "<computer_command><general><command>{$command_name}</command><passcode>723064</passcode><lock_message>此mac已被组织锁定.</lock_message></general><computers><computer><id>{$computer_id}</id></computer></computers></computer_command>";
$response = _exec_command_in_computer_from_jamf($command_name, $token, $exec_data);
 $xml = simplexml_load_string($response); //$response是个xml的字符串内容,$xml 是一个xml对象
$arr = json_decode(json_encode($xml), true);
// $arr 的一个示例
//        array(1) {
//            ["command"]=>
                   //  array(3) {
                   //     ["name"]=>
                   //    string(10) "DeviceLock"
                   //    ["command_uuid"]=>
                   //    string(36) "39b01c6-e64f-4669-8158-210f180e1822"
                   //    ["computer_id"]=>
                   //    string(4) "4983"
                   //  }
       //}
       




chatgpt  jamf 锁定电脑 使用接口  # 下面的不行,可以不看了

明白 ✅ 你想通过 Jamf 的接口远程锁定电脑。这个功能在 Jamf Pro 里叫 Lock Computer(远程锁定 Mac,类似于 MDM 的远程锁)。我帮你梳理下:


1. Jamf Pro 提供的锁定接口

Jamf Pro REST API 提供了 MDM 命令的下发功能,其中包括 Lock Computer

常用 Endpoint:

POST /JSSResource/computercommands/command/DeviceLock/id/{id}    



  • {id}Jamf Pro 内部的 Computer ID(不是序列号,需要先查)。

  • 返回结果是 JSON,包含下发的命令状态。


2. 典型调用流程

Step 1. 获取 Bearer Token

curl -u "api_user:api_password" \     -X POST "https://your-jamf.example.com/api/v1/auth/token"    



返回:

{  "token": "eyJhbGciOi...",  "expires": "2025-09-24T20:30:00.000Z" }    




Step 2. 查找目标电脑的 ID

比如根据序列号查:

curl -H "Authorization: Bearer eyJhbGciOi..." \     "https://your-jamf.example.com/JSSResource/computers/serialnumber/C02XXXXX"    



返回里会有:

<computer>  <general>    <id>123</id>    <name>MacBook-Pro</name>    ...  </general> </computer>    



这里 123 就是 Computer ID。


Step 3. 下发锁定命令

curl -H "Authorization: Bearer eyJhbGciOi..." \     -X POST "https://your-jamf.example.com/JSSResource/computercommands/command/DeviceLock/id/123"    



可选参数:可以加上 PIN 码(设备解锁需要输入 PIN):

curl -H "Authorization: Bearer eyJhbGciOi..." \     -H "Content-Type: application/xml" \     -d "<computer_command><passcode>1234</passcode></computer_command>" \     -X POST "https://your-jamf.example.com/JSSResource/computercommands/command/DeviceLock/id/123"    




3. 注意事项

  • 设备必须是 受管控 (enrolled) 并启用 MDM,才能收到锁定命令。

  • PIN 码必须保存好,锁定后用户需要输入 PIN 才能解锁设备。

  • API 调用需要具有 Send Computer Remote Lock Command 的权限。




AG  jamf 锁定电脑 使用接口 

在 Jamf 中锁定电脑的接口

Jamf Pro 提供了多种方式来远程锁定 Mac 电脑,您可以通过以下接口实现:

1. Jamf Pro API

使用 Jamf Pro 的 REST API 发送锁定命令:

bash    
curl -X POST -u "username:password" \ https://yourjamfinstance.jamfcloud.com/JSSResource/computercommands/command/DeviceLock/id/{computer_id}    




2. Jamf Pro 管理控制台

图形界面操作方法:

  1. 登录 Jamf Pro 管理控制台

  2. 导航到 Computers > All Computers

  3. 选择目标电脑

  4. 点击 "Management" 选项卡

  5. 点击 "Security" 下的 "Lock Computer" 按钮

3. Jamf Remote 桌面工具

通过 Jamf Remote 桌面工具可以实现:

  • 右键点击计算机 > 安全 > 锁定计算机

4. Jamf Self Service

如果配置了自助服务策略,用户可以通过 Self Service 应用自行锁定电脑。

5. 命令行工具 (jamfHelper)

也可以通过 jamfHelper 工具创建自定义锁定脚本:

bash    
/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper \ -windowType utility -title "Device Lock" -description "This computer will be locked." \ -icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/FileVaultIcon.icns \ -button1 "OK" -defaultButton 1 -lockHUD    




注意:要实现远程锁定功能,目标电脑必须:

  • 已注册到 Jamf

  • 在线且能接收命令

  • 运行 macOS 10.7 或更高版本

  • 当前用户已启用 FileVault(必需)

需要管理员权限才能执行锁定操作。



chatgpt  jamf 判断是否锁定电脑 使用接口 

懂了 ✅ 你想通过 Jamf 的接口 判断某台电脑是否已经被远程锁定

Jamf Pro 本身没有一个直接返回 “锁定状态=是/否” 的字段,但是可以通过以下几种方式判断:


1. 查看电脑的管理命令执行历史

Jamf Pro 里每个下发的命令都会有执行记录,可以通过 Computer Commands API 查询。

Endpoint:

GET /JSSResource/computercommands/id/{computer_id}    



GET /JSSResource/computercommands/command/DeviceLock/id/{computer_id}    



返回结果里会列出 DeviceLock 命令的下发状态:

  • Pending → 命令已下发,未执行

  • Completed → 命令已执行(电脑已锁定)

  • Failed → 命令下发失败


2. 查询具体电脑的命令历史

GET /JSSResource/computers/id/{computer_id}    



返回 XML/JSON 中会包含 <commands> 节点,可以看到所有最近的命令。
如果有 DeviceLock 且状态是 Completed,说明电脑已经锁定。


3. 示例(curl)

获取锁定命令状态

curl -H "Authorization: Bearer eyJhbGciOi..." \     "https://your-jamf.example.com/JSSResource/computercommands/id/123"    



返回(简化):

<computer_command>  <id>456</id>  <command>DeviceLock</command>  <status>Completed</status>  <computer_id>123</computer_id> </computer_command>    




4. 另一种方法:在电脑详情里找 remote_management 信息

某些 Jamf 版本在 computers/id/{id} 里会有 管理状态字段,但通常锁定状态还是要靠 命令执行结果 来判断。



普通分类: