unifi-pfsense icon indicating copy to clipboard operation
unifi-pfsense copied to clipboard

Discussion: Get latest software version automatically

Open mattiaskagstrom opened this issue 6 years ago • 3 comments

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.

mattiaskagstrom avatar Nov 07 '19 21:11 mattiaskagstrom

not needed if #141 is completed

mattiaskagstrom avatar Feb 10 '20 12:02 mattiaskagstrom

Made an extremely minor improvement to #141, opened a PR for it - #294

the-wondersmith avatar Aug 06 '22 20:08 the-wondersmith

@the-wondersmith Note that if the controller is already installed and the admin account is registered for EA releases, you can pull their API bearer token from the Mongo DB and use that to download EA releases.

I have all but abandoned this project, but here is a link showing you how I'm using it: https://github.com/sprockteam/ubi-tools/blob/3cdeb5197f543532f0e8df472f967a5f90b1aaf0/easy-ubnt.sh#L1381

sprocktech avatar Aug 07 '22 02:08 sprocktech