-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathhydra-checks-footer.js
349 lines (314 loc) · 15.6 KB
/
hydra-checks-footer.js
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/*
* (C) Copyright 2017 TheOtherP (theotherp@posteo.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
angular
.module('nzbhydraApp')
.directive('hydraChecksFooter', hydraChecksFooter);
function hydraChecksFooter() {
return {
templateUrl: 'static/html/directives/checks-footer.html',
controller: controller
};
function controller($scope, UpdateService, RequestsErrorHandler, HydraAuthService, $http, $uibModal, ConfigService, GenericStorageService, ModalService, growl, NotificationService, bootstrapped) {
$scope.updateAvailable = false;
$scope.checked = false;
var welcomeIsBeingShown = false;
$scope.mayUpdate = HydraAuthService.getUserInfos().maySeeAdmin;
$scope.$on("user:loggedIn", function () {
if (HydraAuthService.getUserInfos().maySeeAdmin && !$scope.checked) {
retrieveUpdateInfos();
}
});
function checkForOutOfMemoryException() {
GenericStorageService.get("outOfMemoryDetected", false).then(function (response) {
if (response.data !== "" && response.data) {
//headline, message, params, size, textAlign
ModalService.open("Out of memory error detected", 'The log indicates that the process ran out of memory. Please increase the XMX value in the main config and restart.', {
yes: {
text: "OK"
}
}, undefined, "left");
GenericStorageService.put("outOfMemoryDetected", false, false);
}
});
}
function checkForOpenToInternet() {
GenericStorageService.get("showOpenToInternetWithoutAuth", false).then(function (response) {
if (response.data !== "" && response.data) {
//headline, message, params, size, textAlign
ModalService.open("Security issue - open to internet", 'It looks like NZBHydra is exposed to the internet without any authentication enable. Please make sure it cannot be reached from outside your network or enable an authentication method.', {
yes: {
text: "OK"
}
}, undefined, "left");
GenericStorageService.put("showOpenToInternetWithoutAuth", false, false);
}
});
}
console.log("Checking for below Java 17.");
function checkForJavaBelow17() {
GenericStorageService.get("belowJava17", false).then(function (response) {
if (response.data !== "" && response.data) {
console.log("Java below 17");
//headline, message, params, size, textAlign
ModalService.open("Java version below 17", 'You\'re currently running NZBHydra2 with an older java version. A future update will require Java 17. Please install <a href="https://adoptium.net/" target="_blank">Java 17</a> (not higher) from here.', {
yes: {
text: "OK"
}
}, undefined, "left");
GenericStorageService.put("belowJava17", false, false);
}
});
}
console.log("Checking for failed backup.");
function checkForFailedBackup() {
GenericStorageService.get("FAILED_BACKUP", false).then(function (response) {
if (response.data !== "" && response.data && !response.data) {
console.log("Failed backup detected");
//headline, message, params, size, textAlign
ModalService.open("Failed backup", 'The creation of a backup file has failed. Error message: \"' + response.data.message + '."<br> For details please check the log around ' + response.data.time + '.', {
yes: {
text: "OK"
}
}, undefined, "left");
GenericStorageService.put("FAILED_BACKUP", false, null);
}
});
}
function checkForOutdatedWrapper() {
$http.get("internalapi/updates/isDisplayWrapperOutdated").then(function (response) {
var data = response.data;
if (data !== undefined && data !== null && data) {
ModalService.open("Outdated wrappers detected", 'The NZBHydra wrappers (i.e. the executables or python scripts you use to run NZBHydra) seem to be outdated. Please update them.<br><br>\n' +
' Shut down NZBHydra, <a href="https://github.com/theotherp/nzbhydra2/releases/latest">download the latest version</a> and extract all the relevant wrapper files into your main NZBHydra folder.<br>\n' +
' For Windows these files are:\n' +
' <ul>\n' +
' <li>NZBHydra2.exe</li>\n' +
' <li>NZBHydra2 Console.exe</li>\n' +
' </ul>\n' +
' For linux these files are:\n' +
' <ul>\n' +
' <li>nzbhydra2</li>\n' +
' <li>nzbhydra2wrapper.py</li>\n' +
' <li>nzbhydra2wrapperPy3.py</li>\n' +
' </ul>\n' +
' Make sure to overwrite all of these files that already exist - you don\'t need to update any files that aren\'t already present.\n' +
' <br><br>\n' +
' Afterwards start NZBHydra again.', {
yes: {
text: "OK",
onYes: function () {
$http.put("internalapi/updates/setOutdatedWrapperDetectedWarningShown")
}
}
}, undefined, "left");
}
});
}
if ($scope.mayUpdate) {
retrieveUpdateInfos();
checkForOutOfMemoryException();
checkForOutdatedWrapper();
checkForOpenToInternet();
checkForJavaBelow17();
checkForFailedBackup();
}
function retrieveUpdateInfos() {
$scope.checked = true;
UpdateService.getInfos().then(function (response) {
if (response) {
$scope.currentVersion = response.data.currentVersion;
$scope.latestVersion = response.data.latestVersion;
$scope.latestVersionIsBeta = response.data.latestVersionIsBeta;
$scope.updateAvailable = response.data.updateAvailable;
$scope.changelog = response.data.changelog;
$scope.updatedExternally = response.data.updatedExternally;
$scope.showUpdateBannerOnUpdatedExternally = response.data.showUpdateBannerOnUpdatedExternally;
$scope.showWhatsNewBanner = response.data.showWhatsNewBanner;
if ($scope.updatedExternally && !$scope.showUpdateBannerOnUpdatedExternally) {
$scope.updateAvailable = false;
}
$scope.automaticUpdateToNotice = response.data.automaticUpdateToNotice;
$scope.$emit("showUpdateFooter", $scope.updateAvailable);
$scope.$emit("showAutomaticUpdateFooter", $scope.automaticUpdateToNotice);
} else {
$scope.$emit("showUpdateFooter", false);
}
});
}
$scope.update = function () {
UpdateService.update($scope.latestVersion);
};
$scope.ignore = function () {
UpdateService.ignore($scope.latestVersion);
$scope.updateAvailable = false;
$scope.$emit("showUpdateFooter", $scope.updateAvailable);
};
$scope.showChangelog = function () {
UpdateService.showChanges($scope.latestVersion);
};
$scope.showChangesFromAutomaticUpdate = function () {
UpdateService.showChangesFromAutomaticUpdate();
$scope.automaticUpdateToNotice = null;
$scope.$emit("showAutomaticUpdateFooter", false);
};
$scope.dismissChangesFromAutomaticUpdate = function () {
$scope.automaticUpdateToNotice = null;
$scope.$emit("showAutomaticUpdateFooter", false);
console.log("Dismissing showAutomaticUpdateFooter");
return $http.get("internalapi/updates/ackAutomaticUpdateVersionHistory").then(function (response) {
});
};
function checkAndShowNews() {
RequestsErrorHandler.specificallyHandled(function () {
if (ConfigService.getSafe().showNews) {
$http.get("internalapi/news/forcurrentversion").then(function (response) {
var data = response.data;
if (data && data.length > 0) {
$uibModal.open({
templateUrl: 'static/html/news-modal.html',
controller: NewsModalInstanceCtrl,
size: "lg",
resolve: {
news: function () {
return data;
}
}
});
$http.put("internalapi/news/saveshown");
}
});
}
});
}
function checkExpiredIndexers() {
_.each(ConfigService.getSafe().indexers, function (indexer) {
if (indexer.vipExpirationDate != null && indexer.vipExpirationDate !== "Lifetime") {
var expiryWarning;
var expiryDate = moment(indexer.vipExpirationDate, "YYYY-MM-DD");
var messagePrefix = "VIP access for indexer " + indexer.name;
if (expiryDate < moment()) {
expiryWarning = messagePrefix + " expired on " + indexer.vipExpirationDate;
} else if (expiryDate.subtract(7, 'days') < moment()) {
expiryWarning = messagePrefix + " will expire on " + indexer.vipExpirationDate;
}
if (expiryWarning) {
console.log(expiryWarning);
growl.warning(expiryWarning);
}
}
});
}
function checkAndShowWelcome() {
RequestsErrorHandler.specificallyHandled(function () {
$http.get("internalapi/welcomeshown").then(function (response) {
if (!response.data) {
$http.put("internalapi/welcomeshown");
var promise = $uibModal.open({
templateUrl: 'static/html/welcome-modal.html',
controller: WelcomeModalInstanceCtrl,
size: "md"
});
promise.opened.then(function () {
welcomeIsBeingShown = true;
});
promise.closed.then(function () {
welcomeIsBeingShown = false;
});
} else {
if (HydraAuthService.getUserInfos().maySeeAdmin) {
_.defer(checkAndShowNews);
_.defer(checkExpiredIndexers);
}
}
}, function () {
console.log("Error while checking for welcome")
});
});
}
checkAndShowWelcome();
function showUnreadNotifications(unreadNotifications, stompClient) {
if (unreadNotifications.length > ConfigService.getSafe().notificationConfig.displayNotificationsMax) {
growl.info(unreadNotifications.length + ' notifications have piled up. <a href=stats/notifications>Go to the notification history to view them.</a>', {disableCountDown: true});
for (var i = 0; i < unreadNotifications.length; i++) {
if (unreadNotifications[i].id === undefined) {
console.log("Undefined ID found for notification " + unreadNotifications[i]);
continue;
}
stompClient.send("/app/markNotificationRead", {}, unreadNotifications[i].id);
}
return;
}
for (var j = 0; j < unreadNotifications.length; j++) {
var notification = unreadNotifications[j];
var body = notification.body.replace("\n", "<br>");
switch (notification.messageType) {
case "INFO":
growl.info(body);
break;
case "SUCCESS":
growl.success(body);
break;
case "WARNING":
growl.warning(body);
break;
case "FAILURE":
growl.danger(body);
break;
}
if (notification.id === undefined) {
console.log("Undefined ID found for notification " + unreadNotifications[i]);
continue;
}
stompClient.send("/app/markNotificationRead", {}, notification.id);
}
}
if (ConfigService.getSafe().notificationConfig.displayNotifications && HydraAuthService.getUserInfos().maySeeAdmin) {
var socket = new SockJS(bootstrapped.baseUrl + 'websocket');
var stompClient = Stomp.over(socket);
stompClient.debug = null;
stompClient.connect({}, function (frame) {
stompClient.subscribe('/topic/notifications', function (message) {
showUnreadNotifications(JSON.parse(message.body), stompClient);
});
});
}
}
}
angular
.module('nzbhydraApp')
.controller('NewsModalInstanceCtrl', NewsModalInstanceCtrl);
function NewsModalInstanceCtrl($scope, $uibModalInstance, news) {
$scope.news = news;
$scope.close = function () {
$uibModalInstance.dismiss();
};
}
angular
.module('nzbhydraApp')
.controller('WelcomeModalInstanceCtrl', WelcomeModalInstanceCtrl);
function WelcomeModalInstanceCtrl($scope, $uibModalInstance, $state, MigrationService) {
$scope.close = function () {
$uibModalInstance.dismiss();
};
$scope.startMigration = function () {
$uibModalInstance.dismiss();
MigrationService.migrate();
};
$scope.goToConfig = function () {
$uibModalInstance.dismiss();
$state.go("root.config.main");
}
}