[
'REMOTE_ADDR' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '',
'PHPSESSID' => pa_ptp_session_id(),
],
];
$response = ['SESSION' => []];
if ($request['SESSION']['PHPSESSID'] !== '' && function_exists('PAWebAdminSessionInfo')) {
PAWebAdminSessionInfo($request, $response);
}
if (!isset($response['SESSION']['Active']) || (int)$response['SESSION']['Active'] !== 1) {
header('Location: ./index.php');
exit;
}
return $response['SESSION'];
}
function pa_ptp_h($value)
{
return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
}
function pa_ptp_aws_credentials()
{
$helperPath = '/opt/SA/DEV/SERVICE/LIB/PACOMMONLIBRARY/php/AWSS3.php';
if (file_exists($helperPath)) {
require_once $helperPath;
}
if (!class_exists('AWSS3Helper')) {
throw new RuntimeException('AWSS3Helper is not available.');
}
$reflection = new ReflectionClass('AWSS3Helper');
$credentials = [];
foreach (['accessKey' => 'accessKey', 'secretKey' => 'secretKey'] as $propertyName => $credentialName) {
if (!$reflection->hasProperty($propertyName)) {
throw new RuntimeException('AWSS3Helper is missing ' . $propertyName . '.');
}
$property = $reflection->getProperty($propertyName);
$property->setAccessible(true);
$credentials[$credentialName] = $property->getValue();
}
if (empty($credentials['accessKey']) || empty($credentials['secretKey'])) {
throw new RuntimeException('AWS credentials are not configured.');
}
return $credentials;
}
function pa_ptp_s3_uri_encode($value)
{
return str_replace('%2F', '/', rawurlencode($value));
}
function pa_ptp_signing_key($secretKey, $dateStamp, $region)
{
$kDate = hash_hmac('sha256', $dateStamp, 'AWS4' . $secretKey, true);
$kRegion = hash_hmac('sha256', $region, $kDate, true);
$kService = hash_hmac('sha256', 's3', $kRegion, true);
return hash_hmac('sha256', 'aws4_request', $kService, true);
}
function pa_ptp_s3_get_object($bucket, $key, $region)
{
$credentials = pa_ptp_aws_credentials();
$host = $bucket . '.s3.' . $region . '.amazonaws.com';
$canonicalUri = '/' . pa_ptp_s3_uri_encode(ltrim($key, '/'));
$amzDate = gmdate('Ymd\THis\Z');
$dateStamp = gmdate('Ymd');
$payloadHash = hash('sha256', '');
$signedHeaders = 'host;x-amz-content-sha256;x-amz-date';
$canonicalHeaders = "host:" . $host . "\n" .
"x-amz-content-sha256:" . $payloadHash . "\n" .
"x-amz-date:" . $amzDate . "\n";
$canonicalRequest = "GET\n" . $canonicalUri . "\n\n" .
$canonicalHeaders . "\n" .
$signedHeaders . "\n" .
$payloadHash;
$credentialScope = $dateStamp . "/" . $region . "/s3/aws4_request";
$stringToSign = "AWS4-HMAC-SHA256\n" . $amzDate . "\n" .
$credentialScope . "\n" . hash('sha256', $canonicalRequest);
$signature = hash_hmac('sha256', $stringToSign, pa_ptp_signing_key($credentials['secretKey'], $dateStamp, $region));
$authorization = 'AWS4-HMAC-SHA256 Credential=' . $credentials['accessKey'] . '/' . $credentialScope .
', SignedHeaders=' . $signedHeaders .
', Signature=' . $signature;
$curl = curl_init('https://' . $host . $canonicalUri);
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Host: ' . $host,
'x-amz-content-sha256: ' . $payloadHash,
'x-amz-date: ' . $amzDate,
'Authorization: ' . $authorization,
],
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 15,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
]);
$body = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$curlError = curl_error($curl);
curl_close($curl);
if ($body === false || $httpCode < 200 || $httpCode >= 300) {
$message = $curlError !== '' ? $curlError : trim(strip_tags((string)$body));
throw new RuntimeException('Unable to read s3://' . $bucket . '/' . $key . ': HTTP ' . $httpCode . ' ' . $message);
}
return $body;
}
function pa_ptp_s3_read_json($bucket, $key, $region)
{
$output = pa_ptp_s3_get_object($bucket, $key, $region);
$output = preg_replace('/^\xEF\xBB\xBF/', '', $output);
$json = json_decode($output, true);
if (!is_array($json)) {
throw new RuntimeException('Invalid JSON in s3://' . $bucket . '/' . $key);
}
return $json;
}
function pa_ptp_generate_presigned_url($bucket, $key, $region, $expiresSeconds)
{
$credentials = pa_ptp_aws_credentials();
$host = $bucket . '.s3.' . $region . '.amazonaws.com';
$canonicalUri = '/' . pa_ptp_s3_uri_encode(ltrim($key, '/'));
$amzDate = gmdate('Ymd\THis\Z');
$dateStamp = gmdate('Ymd');
$credentialScope = $dateStamp . "/" . $region . "/s3/aws4_request";
$queryParams = [
'X-Amz-Algorithm' => 'AWS4-HMAC-SHA256',
'X-Amz-Credential' => $credentials['accessKey'] . '/' . $credentialScope,
'X-Amz-Date' => $amzDate,
'X-Amz-Expires' => (string)(int)$expiresSeconds,
'X-Amz-SignedHeaders' => 'host',
];
ksort($queryParams);
$canonicalQueryString = '';
foreach ($queryParams as $paramKey => $paramValue) {
if ($canonicalQueryString !== '') {
$canonicalQueryString .= '&';
}
$canonicalQueryString .= rawurlencode($paramKey) . '=' . rawurlencode($paramValue);
}
$canonicalRequest = "GET\n" . $canonicalUri . "\n" . $canonicalQueryString .
"\nhost:" . $host . "\n\nhost\nUNSIGNED-PAYLOAD";
$stringToSign = "AWS4-HMAC-SHA256\n" . $amzDate . "\n" .
$credentialScope . "\n" . hash('sha256', $canonicalRequest);
$signature = hash_hmac('sha256', $stringToSign, pa_ptp_signing_key($credentials['secretKey'], $dateStamp, $region));
return 'https://' . $host . $canonicalUri . '?' . $canonicalQueryString . '&X-Amz-Signature=' . $signature;
}
function pa_ptp_log_download_link($session, $manifest, $installerKey)
{
$logDir = dirname(__DIR__) . '/logs';
if (!is_dir($logDir)) {
@mkdir($logDir, 0770, true);
}
$admin = isset($session['AdminID']) ? $session['AdminID'] : 'unknown';
$adminType = isset($session['AdminType']) ? $session['AdminType'] : 'unknown';
$accessLevel = isset($session['AccessLevel']) ? $session['AccessLevel'] : 'unknown';
$remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown';
$version = isset($manifest['version']) ? $manifest['version'] : 'unknown';
$line = sprintf(
"[%s] admin_id=%s admin_type=%s access_level=%s remote_addr=%s version=%s installer_key=%s\n",
gmdate('c'),
$admin,
$adminType,
$accessLevel,
$remoteAddr,
$version,
$installerKey
);
$logFile = $logDir . '/ptp_download_links.log';
if (!is_writable($logDir) || (is_file($logFile) && !is_writable($logFile)) || @file_put_contents($logFile, $line, FILE_APPEND | LOCK_EX) === false) {
error_log('[PTP_DOWNLOAD_LINK] ' . trim($line));
}
}
$session = pa_ptp_require_admin();
$bucket = 'part-tracker-provision-releases';
$region = 'us-west-2';
$currentKey = 'provision-app/current.json';
$expiresSeconds = 900;
$current = null;
$manifest = null;
$signedUrl = '';
$errorMessage = '';
$generatedAt = '';
try {
$current = pa_ptp_s3_read_json($bucket, $currentKey, $region);
if (empty($current['manifestKey'])) {
throw new RuntimeException('current.json does not contain manifestKey.');
}
$manifest = pa_ptp_s3_read_json($bucket, $current['manifestKey'], $region);
if (empty($manifest['installerKey'])) {
$manifest['installerKey'] = 'provision-app/latest/PART_Tracker_Provision_Installer.exe';
}
$signedUrl = pa_ptp_generate_presigned_url($bucket, $manifest['installerKey'], $region, $expiresSeconds);
$generatedAt = gmdate('Y-m-d H:i:s') . ' UTC';
pa_ptp_log_download_link($session, $manifest, $manifest['installerKey']);
} catch (Throwable $e) {
$errorMessage = $e->getMessage();
}
$displayVersion = $current['currentVersion'] ?? ($manifest['version'] ?? 'Unavailable');
$displayReleased = $manifest['released'] ?? 'Unavailable';
$displayNotes = $manifest['notes'] ?? 'No release notes were provided.';
$displayInstallerKey = $manifest['installerKey'] ?? 'Unavailable';
$displaySha256 = $manifest['sha256'] ?? 'Unavailable';
include_once("./PA_WEB_PAGE_HEADER.php");
?>
- Pink Angels
- Administration
- PART Tracker Provision Download
Unable to load release information.
= pa_ptp_h($errorMessage) ?>
Authorized admin use only
PART Tracker Provision is the Windows factory setup tool used to prepare a new tracker before it is shipped to a customer.
It helps an operator flash firmware, provision cloud credentials, read SIM and device identity information, create the tracker label code, and complete factory/shipping steps.
Current Version
= pa_ptp_h($displayVersion) ?>
Released
= pa_ptp_h($displayReleased) ?>
Download the Factory Setup Tool
What this installer is for
Install this on the Windows provisioning computer used by the factory team. It is not a customer application.
Application Preview
- Flashes approved tracker firmware
- Provisions required cloud credentials
- Reads SIM card and device identity details
- Creates the tracker code for the physical label
- Guides final factory and shipping steps
- Updates itself from approved AWS releases
Latest approved release
= nl2br(pa_ptp_h($displayNotes)) ?>
- Installer File
- PART Tracker Provision Installer for Windows
- Storage Path
= pa_ptp_h($displayInstallerKey) ?>
- SHA-256 Checksum
= pa_ptp_h($displaySha256) ?>
Operator Reminder
Download is ready.
Use the main button on this page to install or update the Windows provisioning computer.
Download unavailable
The current installer link could not be prepared. Check the release information alert above.
- Download the installer on the Windows provisioning computer.
- The secure link expires 15 minutes after this page loads.
- Do not post this link in public chat or customer emails.
- If the link expires, refresh this page to get a new one.