mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
Merge pull request #226 from YunoHost/change-version-fetch-method
Remove dependency to GET /version to fetch version
This commit is contained in:
commit
5625be5edf
5 changed files with 79 additions and 87 deletions
|
@ -3,8 +3,6 @@
|
||||||
var app = Sammy.apps['#main'];
|
var app = Sammy.apps['#main'];
|
||||||
var store = app.store;
|
var store = app.store;
|
||||||
|
|
||||||
var initial_checks_already_performed = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Home
|
* Home
|
||||||
*
|
*
|
||||||
|
@ -12,84 +10,11 @@
|
||||||
|
|
||||||
// Home page
|
// Home page
|
||||||
app.get('#/', function (c) {
|
app.get('#/', function (c) {
|
||||||
if (initial_checks_already_performed)
|
c.view("home");
|
||||||
{
|
// N.B : if you need to run stuff at login time,
|
||||||
c.view("home");
|
// see js/events.js instead
|
||||||
}
|
|
||||||
else c.api('/users', function(data) {
|
|
||||||
// Warn admin if no users are created.
|
|
||||||
if (typeof data.users !== 'undefined' && data.users.length === 0) {
|
|
||||||
c.flash('warning', y18n.t('warning_first_user'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get security feed and display new items
|
|
||||||
var securityFeed = 'https://yunohost.org/security.rss';
|
|
||||||
var forumUrl = 'https://forum.yunohost.org';
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: securityFeed,
|
|
||||||
// dataType: (jQuery.browser.msie) ? "text" : "xml",
|
|
||||||
dataType: "xml"
|
|
||||||
})
|
|
||||||
.done(function(xml){
|
|
||||||
// Get viewed security alerts from cookie
|
|
||||||
var viewedItems = Cookies.get('ynhSecurityViewedItems') || [];
|
|
||||||
|
|
||||||
// Get 6 month earlier date
|
|
||||||
var SixMonthEarlier = new Date();
|
|
||||||
SixMonthEarlier.setMonth(SixMonthEarlier.getMonth() - 6);
|
|
||||||
|
|
||||||
// Loop through items in a reverse order (older first)
|
|
||||||
$($('item', xml).get().reverse()).each(function(k, v) {
|
|
||||||
var link = $('link', v).text();
|
|
||||||
if (typeof link == 'string' && link !== '' && link.charAt(0) == '/') {
|
|
||||||
link = forumUrl+link;
|
|
||||||
}
|
|
||||||
|
|
||||||
// var description=$('description', v).text();
|
|
||||||
// description=description.replace('href="/','href="'+forumUrl+'/');
|
|
||||||
|
|
||||||
var item = {
|
|
||||||
guid: $('guid', v).text(),
|
|
||||||
title: $('title', v).text(),
|
|
||||||
url: link,
|
|
||||||
// desc: description,
|
|
||||||
date: new Date($('pubDate', v).text()),
|
|
||||||
};
|
|
||||||
|
|
||||||
// If item is not already viewed and is not older than 6 month
|
|
||||||
if (viewedItems.indexOf(item.guid) === -1 && (item.date.getTime() > SixMonthEarlier.getTime())) {
|
|
||||||
// Show security message to administrator
|
|
||||||
var warning = item.title + ' - ' +
|
|
||||||
item.date.toISOString().substring(0, 10) +
|
|
||||||
' (<a href="'+ item.url +'" class="alert-link" target="_blank">'+y18n.t('read_more')+'</a>)';
|
|
||||||
c.flash('warning', warning);
|
|
||||||
// Store viewed item
|
|
||||||
viewedItems.push(item.guid);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Saved viewed items to cookie
|
|
||||||
Cookies.set('ynhSecurityViewedItems', viewedItems, {
|
|
||||||
expires: 7
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.fail(function() {
|
|
||||||
c.flash('fail', y18n.t('error_retrieve_feed', [securityFeed]));
|
|
||||||
});
|
|
||||||
|
|
||||||
c.api("/diagnosis", function(data) {
|
|
||||||
if (data.security["CVE-2017-5754"].vulnerable) {
|
|
||||||
c.flash('danger', y18n.t('meltdown'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
initial_checks_already_performed = true;
|
|
||||||
c.view('home');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login
|
* Login
|
||||||
*
|
*
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
delete monitorData.network.usage.lo;
|
delete monitorData.network.usage.lo;
|
||||||
|
|
||||||
// Get YunoHost versions too
|
// Get YunoHost versions too
|
||||||
c.api('/version', function(versions) {
|
c.api('/diagnosis', function(diagnosis) {
|
||||||
monitorData.versions = versions;
|
monitorData.versions = diagnosis.packages;
|
||||||
c.view('tools/tools_monitoring', monitorData);
|
c.view('tools/tools_monitoring', monitorData);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -223,8 +223,8 @@
|
||||||
|
|
||||||
// Packages version
|
// Packages version
|
||||||
app.get('#/tools/versions', function (c) {
|
app.get('#/tools/versions', function (c) {
|
||||||
c.api('/version', function(versions) {
|
c.api('/diagnosis', function(diagnosis) {
|
||||||
c.view('tools/tools_versions', {'versions' : versions});
|
c.view('tools/tools_versions', {'versions' : diagnosis.packages });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,75 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
app.bind('login', function(e, data) {
|
app.bind('login', function(e, data) {
|
||||||
this.api('/version', function(versions) {
|
c.api('/users', function(data) {
|
||||||
$('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost.version, versions.yunohost.repo]));
|
// Warn admin if no users are created.
|
||||||
|
if (typeof data.users !== 'undefined' && data.users.length === 0) {
|
||||||
|
c.flash('warning', y18n.t('warning_first_user'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get security feed and display new items
|
||||||
|
var securityFeed = 'https://yunohost.org/security.rss';
|
||||||
|
var forumUrl = 'https://forum.yunohost.org';
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: securityFeed,
|
||||||
|
// dataType: (jQuery.browser.msie) ? "text" : "xml",
|
||||||
|
dataType: "xml"
|
||||||
|
})
|
||||||
|
.done(function(xml){
|
||||||
|
// Get viewed security alerts from cookie
|
||||||
|
var viewedItems = Cookies.get('ynhSecurityViewedItems') || [];
|
||||||
|
|
||||||
|
// Get 6 month earlier date
|
||||||
|
var SixMonthEarlier = new Date();
|
||||||
|
SixMonthEarlier.setMonth(SixMonthEarlier.getMonth() - 6);
|
||||||
|
|
||||||
|
// Loop through items in a reverse order (older first)
|
||||||
|
$($('item', xml).get().reverse()).each(function(k, v) {
|
||||||
|
var link = $('link', v).text();
|
||||||
|
if (typeof link == 'string' && link !== '' && link.charAt(0) == '/') {
|
||||||
|
link = forumUrl+link;
|
||||||
|
}
|
||||||
|
|
||||||
|
// var description=$('description', v).text();
|
||||||
|
// description=description.replace('href="/','href="'+forumUrl+'/');
|
||||||
|
|
||||||
|
var item = {
|
||||||
|
guid: $('guid', v).text(),
|
||||||
|
title: $('title', v).text(),
|
||||||
|
url: link,
|
||||||
|
// desc: description,
|
||||||
|
date: new Date($('pubDate', v).text()),
|
||||||
|
};
|
||||||
|
|
||||||
|
// If item is not already viewed and is not older than 6 month
|
||||||
|
if (viewedItems.indexOf(item.guid) === -1 && (item.date.getTime() > SixMonthEarlier.getTime())) {
|
||||||
|
// Show security message to administrator
|
||||||
|
var warning = item.title + ' - ' +
|
||||||
|
item.date.toISOString().substring(0, 10) +
|
||||||
|
' (<a href="'+ item.url +'" class="alert-link" target="_blank">'+y18n.t('read_more')+'</a>)';
|
||||||
|
c.flash('warning', warning);
|
||||||
|
// Store viewed item
|
||||||
|
viewedItems.push(item.guid);i
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Saved viewed items to cookie
|
||||||
|
Cookies.set('ynhSecurityViewedItems', viewedItems, {
|
||||||
|
expires: 7
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function(stuff) {
|
||||||
|
c.flash('fail', y18n.t('error_retrieve_feed', [securityFeed]));
|
||||||
|
});
|
||||||
|
|
||||||
|
c.api("/diagnosis", function(data) {
|
||||||
|
versions = data.packages;
|
||||||
|
$('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost.version, versions.yunohost.repo]));
|
||||||
|
if (data.security["CVE-2017-5754"].vulnerable) {
|
||||||
|
c.flash('danger', y18n.t('meltdown'));
|
||||||
|
}
|
||||||
|
$('div.loader').remove();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -149,9 +149,9 @@
|
||||||
// Store url
|
// Store url
|
||||||
sam.store.set('url', window.location.hostname + '/yunohost/api');
|
sam.store.set('url', window.location.hostname + '/yunohost/api');
|
||||||
|
|
||||||
// Get YunoHost version
|
|
||||||
if (sam.store.get('connected')) {
|
if (sam.store.get('connected')) {
|
||||||
this.api('/version', function(versions) {
|
this.api('/diagnosis', function(diagnosis) {
|
||||||
|
versions = diagnosis.packages;
|
||||||
$('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost.version, versions.yunohost.repo]));
|
$('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost.version, versions.yunohost.repo]));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue