ios 从 .mobileconfig 获取设备 UDID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5781314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:42:49  来源:igfitidea点击:

Getting a device UDID from .mobileconfig

iosconfigurationutilityudid

提问by joseym

I'm trying to write function similar to http://whatismyudid.com/that, then approved, will return the users UDID and store it to a database for future reference with that user.

我正在尝试编写类似于http://whatismyudid.com/ 的函数,然后批准,将返回用户 UDID 并将其存储到数据库中以供该用户将来参考。

I have written a .mobileconfig xml doc that opens in the Profile Installer just fine but when I tell it to install the profile it responds with [alert] Invalid Profilebut no alert body. No description, no code, no help.

我写了一个 .mobileconfig xml 文档,它在配置文件安装程序中打开就好了,但是当我告诉它安装配置文件时,它响应[alert] Invalid Profile但没有警报正文。没有描述,没有代码,没有帮助。

I'm new to the mobile configuration game so any help would thrill me.

我是新来的移动配置游戏,所以任何帮助会令我激动。

Here is my configuration file:

这是我的配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>PayloadContent</key>
    <dict>
        <key>URL</key>
        <string>http://apps.mortlabs.com/device/retrieve.php</string>
        <key>DeviceAttributes</key>
        <array>
            <string>UDID</string>
            <string>IMEI</string>
            <string>ICCID</string>
            <string>VERSION</string>
            <string>PRODUCT</string>
        </array>
    </dict>
    <key>PayloadOrganization</key>
    <string>MortLabs.com</string>
    <key>PayloadDisplayName</key>
    <string>Profile Service</string>
    <key>PayloadVersion</key>
    <integer>1</integer>
    <key>PayloadUUID</key>
    <string>B958E359-34C2-42F4-BD0C-C985E6D5376B</string>
    <key>PayloadIdentifier</key>
    <string>com.mortlabs.profile-service</string>
    <key>PayloadDescription</key>
    <string>This temporary profile will be used to find and display your current device's UDID.</string>
    <key>PayloadType</key>
    <string>Profile Service</string>
</dict>
</plist>

The profile is initialized by navigating to http://apps.mortlabs.com/device/enroll.phpwith mobile safari

通过使用移动 safari导航到http://apps.mortlabs.com/device/enroll.php来初始化配置文件

采纳答案by Kev

I found that by using the above that Apache was being talked to by the Ipad/Iphone - The post by Kyle2011 at https://discussions.apple.com/thread/3089948?start=0&tstart=0filled in the rest of the solution.

我发现通过使用上面的内容,Ipad/Iphone 正在与 Apache 对话 - Kyle2011 在https://discussions.apple.com/thread/3089948?start=0&tstart=0 上的帖子填写了解决方案的其余部分.

Basically at the bottom of the retrieve.php page you need to redirect the browser to a directory by using a line similar to the following:-

基本上在retrieve.php 页面的底部,您需要使用类似于以下内容的行将浏览器重定向到一个目录:-

header("Location: https://www.example.com/enrolment?params={$params}");

Where enrolment is a directory - this then calls the DirectoryIndex (typically index.php) which can then display stuff to your user.

注册是一个目录 - 然后调用 DirectoryIndex(通常是 index.php),然后它可以向您的用户显示内容。

To populate the $params variable you need the following line at the top of your retrieve.php script

要填充 $params 变量,您需要在retrieve.php 脚本的顶部添加以下行

$data = file_get_contents('php://input');

You can then parse the $data string to get what you need (try file_put_contents("data.txt", $data);or Kyle2011's example)

然后您可以解析 $data 字符串以获得您需要的内容(尝试file_put_contents("data.txt", $data);或 Kyle2011 的示例)

I also changed the Payload UDID to something different by using udidgenin a terminal on a Mac rather than just using whatismyudid.com's.

我还通过udidgen在 Mac 上的终端中使用而不是仅使用 whatismyudid.com将有效负载 UDID 更改为不同的内容。

Update: From iOS 7.1 some of the files (the .plist IIRC) need to be served over https:// - they will fail to install if everything is served over http:// - probably best to serve everything including the .ipa over https:// to ensure future changes on Apple's side don't cause a problem.

更新:从 iOS 7.1 开始,一些文件(.plist IIRC)需要通过 https:// 提供 - 如果所有内容都通过 http:// 提供,它们将无法安装 - 可能最好提供包括 .ipa 在内的所有内容https:// 以确保 Apple 方面的未来更改不会引起问题。

回答by Pixman

Note about the last page ( FOLDER ).

请注意最后一页 ( FOLDER )。

If you want to use a page script for final redirection in place of a folder.

如果要使用页面脚本代替文件夹进行最终重定向。

you can change this :

你可以改变这个:

header("Location: https://www.example.com/enrolment?params={$params}");

header("位置:https: //www.example.com/enrolment?params ={$params}");

by

经过

header("Location: https://www.example.com/enrolment.php?params={$params}", true, 301);

header("位置:https: //www.example.com/enrolment.php?params ={$params}", true, 301);

Source : header function on php.net manual

来源:php.net 手册上的标头函数

it's work !

这是工作 !

回答by Calrion

The error you're getting is because iOS expects your profile service URL (the one it sends its UDID to) to return a configuration profile (i.e. a .mobileconfigfile). I currently capture device UDIDs without returning this profile; my devices generate the alert you describe but the data is on my server.

您收到的错误是因为 iOS 期望您的配置文件服务 URL(它将其 UDID 发送到的那个)返回配置文件(即.mobileconfig文件)。我目前在不返回此配置文件的情况下捕获设备 UDID;我的设备生成您描述的警报,但数据在我的服务器上。

For reference, here's the (very) simple PHP file I use to capture the data:

作为参考,这是我用来捕获数据的(非常)简单的 PHP 文件:

<?php
// set file to write
$file = 'device_data/data.p7s';

$fp = fopen($file, 'w') or die('Could not open file!');
fwrite($fp, $HTTP_RAW_POST_DATA) or die('Could not write to file');
fclose($fp);
?>

The key here is the use of the $HTTP_RAW_POST_DATAvariable to capture the HTTP request body exactly as sent, without attempting to parse it into the usual name/value pairs. I'd suggest reading the documentationat this point, but it really doesn't tell you much.

这里的关键是使用$HTTP_RAW_POST_DATA变量准确地捕获发送的 HTTP 请求正文,而不尝试将其解析为通常的名称/值对。我建议此时阅读文档,但它实际上并没有告诉你太多。

Security tip: whatever the user sends in the request body, you're writing to a file on your server. If the user decides to send a shell script, PHP file, or other executable content, then visits the URL of the file you create, they can execute the code the just uploaded on your web server. So, make sure the file you write to can't be accessed via HTTP! (A .htaccessfile would do the trick, or write to somewhere outside the web root.)

安全提示:无论用户在请求正文中发送什么,您都在写入服务器上的文件。如果用户决定发送 shell 脚本、PHP 文件或其他可执行内容,然后访问您创建的文件的 URL,他们就可以执行刚刚上传到您的 Web 服务器上的代码。因此,请确保您写入的文件无法通过 HTTP 访问!(.htaccess文件可以解决问题,或者写入 Web 根目录之外的某个地方。)

回答by steffenborup

Try setting the URL to an address without .php extension. This solved the problem for me. Now my only problem is that I can't find out how to retrieve the data sent from the iOS device to my server. It does not seem to be in the $_POST variable.

尝试将 URL 设置为不带 .php 扩展名的地址。这为我解决了这个问题。现在我唯一的问题是我不知道如何检索从 iOS 设备发送到我的服务器的数据。它似乎不在 $_POST 变量中。