-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathResponse.php
More file actions
262 lines (224 loc) · 7.86 KB
/
Response.php
File metadata and controls
262 lines (224 loc) · 7.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
declare(strict_types=1);
namespace ClientUpdateServer;
class Response {
/** @var string */
private $oem;
/** @var string */
private $platform;
/** @var string */
private $version;
/** @var string */
private $osRelease;
/** @var string */
private $osVersion;
/** @var string */
private $kernelVersion;
/** @var string */
private $channel;
/** @var bool */
private $isSparkle;
/** @var array */
private $config;
public function __construct(string $oem,
string $platform,
string $version,
string $osRelease,
string $osVersion,
string $kernelVersion,
string $channel,
bool $isSparkle,
array $config) {
$this->oem = $oem;
$this->platform = $platform;
$this->version = $version;
$this->osRelease = $osRelease;
$this->osVersion = $osVersion;
$this->kernelVersion = $kernelVersion;
$this->channel = $channel;
$this->isSparkle = $isSparkle;
$this->config = $config;
}
/**
* Gets the version to update to. Or an empty array if no update is available.
*
* @return array
*/
private function getUpdateVersion() : array {
if(!isset($this->config[$this->oem])) {
if (preg_match('/^[a-zA-Z0-9-_.]+$/', $this->oem) !== 1) {
return [];
}
if (!file_exists(__DIR__ . '/../config/' . $this->oem . '.json')) {
return [];
}
$content = file_get_contents(__DIR__ . '/../config/' . $this->oem . '.json');
if ($content === false) {
return [];
}
$data = json_decode($content, true);
if (!is_array($data)) {
return [];
}
$this->config[$this->oem] = $data;
}
if(!isset($this->config[$this->oem][$this->channel][$this->platform])) {
return [];
}
// if outdated platform, hand out latest stable-qt5, no daily/beta possible
if ($this->checkOldPlatform()) {
$stable = $this->config[$this->oem]['stable-qt5'][$this->platform];
$beta = null;
$daily = null;
$enterprise = null;
} else if (version_compare($this->osVersion, '12.0', '<') &&
version_compare($this->version, '3.14.0', '<') &&
version_compare($this->config[$this->oem]['stable'][$this->platform]['version'], '3.14.0', '==')) {
// Skip 3.14.0 for macOS < 12 when updating as we have an issue with the system requirement settings
// Serve the prior version instead in the meantime (3.13.4)
$stable = $this->config[$this->oem]['stable-qt5'][$this->platform];
$beta = $this->config[$this->oem]['beta'][$this->platform];
$daily = $this->config[$this->oem]['daily'][$this->platform];
$enterprise = null;
} else {
$stable = $this->config[$this->oem]['stable'][$this->platform];
$beta = $this->config[$this->oem]['beta'][$this->platform];
$daily = $this->config[$this->oem]['daily'][$this->platform];
$enterprise = $this->config[$this->oem]['enterprise'][$this->platform];
}
$isMacOs = ($this->platform === 'macos' && $this->isSparkle === true);
if (isset($daily) && $this->channel == 'daily' && (version_compare($this->version, $daily['version']) == -1)) {
return $daily;
}
if (isset($beta) && $this->channel == 'beta' && (version_compare($stable['version'], $beta['version']) == -1 || $isMacOs)) {
return $beta;
}
if (isset($enterprise) && $this->channel == 'enterprise' && (version_compare($this->version, $enterprise['version']) == -1 || $isMacOs)) {
return $enterprise;
}
if (version_compare($this->version, $stable['version']) == -1 || $isMacOs) {
return $stable;
}
return [];
}
private function checkOldPlatform(): bool {
// Outdated platforms:
// - macOS < 11
// - Win < 10
// - Win 10 (build number < 1809)
// - Win 11 (build number < 17764)
// - Ubuntu <22.04
// - openSuse <15.5
// - RHEL <9.2
// Mac < 11
if ($this->platform === "macos" && version_compare($this->osVersion, "11") == -1) {
return true;
}
// Windows <10
if ($this->platform === "win32" && version_compare($this->osVersion, "10") == -1) {
return true;
}
// Windows 10 (build number < 1809)
if ($this->platform === "win32" && version_compare($this->osVersion, "10") == 0 && version_compare($this->kernelVersion, '10.0.1809') == -1) {
return true;
}
// - Win 11 (build number < 17764)
if ($this->platform === "win32" && version_compare($this->osVersion, "11") == 0 && version_compare($this->kernelVersion, '10.0.17764') == -1) {
return true;
}
// - Ubuntu <22.04
if ($this->platform === "linux" && $this->osRelease == "ubuntu" && version_compare($this->osVersion, '22.04') == -1) {
return true;
}
// - RHEL <9.2
if ($this->platform === "linux" && $this->osRelease == "rhel" && version_compare($this->osVersion, '9.2') == -1) {
return true;
}
// - openSuse <15.5
if ($this->platform === "linux" && $this->osRelease == "opensuse-leap" && version_compare($this->osVersion, '15.5') == -1) {
return true;
}
return false;
}
/**
* Returns the current time stamp
* @return string
*/
protected function getCurrentTimeStamp() : string {
return (new \DateTime())->format('D, j F y H:m:s O');
}
/**
* Convenience functions to get specific file provider or standard client update information
*/
private function getSparkleUpdateUrl(array $updateVersion) : string {
$updateUrlKey = 'sparkleDownloadUrl';
return $updateVersion[$updateUrlKey];
}
private function getSparkleUpdateSignature(array $updateVersion) : string {
$updateSignatureKey = 'signature';
return $updateVersion[$updateSignatureKey];
}
private function getSparkleUpdateLength(array $updateVersion) : int {
$updateLengthKey = 'length';
return $updateVersion[$updateLengthKey];
}
private function getSparkleVersionString(array $updateVersion) : string {
$updateLengthKey = 'versionstring';
return $updateVersion[$updateLengthKey];
}
/**
* Builds the response for Sparkle (used by the Mac updater)
*
* @param array $updateVersion
* @return string
*/
private function buildSparkleResponse(array $updateVersion) : string {
$sparkleUrl = $this->getSparkleUpdateUrl($updateVersion);
$versionString = $this->getSparkleVersionString($updateVersion);
$sparkleSignature = $this->getSparkleUpdateSignature($updateVersion);
$sparkleLength = $this->getSparkleUpdateLength($updateVersion);
$item = !empty($updateVersion) ? '
<item>
<title>'.$versionString.'</title>
<pubDate>'.$this->getCurrentTimeStamp().'</pubDate>
<enclosure url="'.$sparkleUrl.'" sparkle:version="'.$updateVersion['version'].'" type="application/octet-stream" sparkle:installationType="package" sparkle:edSignature="'.$sparkleSignature.'" length="'.$sparkleLength.'"/>
<sparkle:minimumSystemVersion>11.0</sparkle:minimumSystemVersion>
</item>' : '';
return '<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Download Channel</title>
<description>Most recent changes with links to updates.</description>
<language>en</language>'.$item.'
</channel>
</rss>';
}
/**
* Builds the generic response for all other OS
*
* @param array $updateVersion
* @return string
*/
private function buildRegularResponse(array $updateVersion) : string {
$xml = new \SimpleXMLElement('<owncloudclient/>');
$updateVersion = array_flip($updateVersion);
array_walk_recursive($updateVersion, [$xml, 'addChild']);
return $xml->asXML();
}
/**
* Builds the response for the update request
*
* @return string
*/
public function buildResponse() : string {
$updateVersion = $this->getUpdateVersion();
if($this->isSparkle && $this->platform === 'macos') {
return $this->buildSparkleResponse($updateVersion);
}
return $this->buildRegularResponse($updateVersion);
}
}