Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: Get latest software version automatically #163

Open
mattiaskagstrom opened this issue Nov 7, 2019 · 3 comments
Open

Discussion: Get latest software version automatically #163

mattiaskagstrom opened this issue Nov 7, 2019 · 3 comments

Comments

@mattiaskagstrom
Copy link

mattiaskagstrom commented Nov 7, 2019

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
Copy link
Author

not needed if #141 is completed

@the-wondersmith
Copy link

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

@sprocktech
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants