Skip to content

Discussion: Get latest software version automatically #163

@mattiaskagstrom

Description

@mattiaskagstrom

I made a PHP script that fetches the latest version from the unify download site.
(Related to #151 )

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://www.ui.com/download/?group=unifi-ap');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

$headers = array();
$headers[] = 'Authority: www.ui.com';
$headers[] = 'Pragma: no-cache';
$headers[] = 'Cache-Control: no-cache';
$headers[] = 'Accept: application/json, text/javascript, */*; q=0.01';
$headers[] = 'X-Requested-With: XMLHttpRequest';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36';
$headers[] = 'Sec-Fetch-Site: same-origin';
$headers[] = 'Sec-Fetch-Mode: cors';
$headers[] = 'Referer: https://www.ui.com/download/unifi/unifi-ap';
$headers[] = 'Accept-Encoding: gzip, deflate, br';
$headers[] = 'Accept-Language: en-US,en;q=0.9,sv-SE;q=0.8,sv;q=0.7,en-SE;q=0.6,en-GB;q=0.5';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

$workingvar = json_decode($result, true)["downloads"];
$workingvar = array_filter($workingvar, function ($node){
	return $node["category__slug"] == "software";
});
$workingvar = array_filter($workingvar, function ($node){
	return strpos($node["description"],"inux") !== false;
});
usort($workingvar, function ($item1, $item2) {
    return str_replace(".", "", $item2['version']) <=> str_replace(".", "", $item1['version']);
});
$latest = $workingvar[0];

$latest = $latest["version"];
curl_close($ch);
var_dump($latest);
?>

it currently outputs the versionnumber, but the object has multiple properties you could output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions