diff --git a/src/js/yunohost/controllers/home.js b/src/js/yunohost/controllers/home.js index fb3159fc..ac315c21 100644 --- a/src/js/yunohost/controllers/home.js +++ b/src/js/yunohost/controllers/home.js @@ -3,8 +3,6 @@ var app = Sammy.apps['#main']; var store = app.store; - var initial_checks_already_performed = false; - /** * Home * @@ -12,84 +10,11 @@ // Home page app.get('#/', function (c) { - if (initial_checks_already_performed) - { - c.view("home"); - } - 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) + - ' ('+y18n.t('read_more')+')'; - 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'); - }); + c.view("home"); + // N.B : if you need to run stuff at login time, + // see js/events.js instead }); - - /** * Login * diff --git a/src/js/yunohost/controllers/monitor.js b/src/js/yunohost/controllers/monitor.js index a7e8c664..527e466c 100644 --- a/src/js/yunohost/controllers/monitor.js +++ b/src/js/yunohost/controllers/monitor.js @@ -30,8 +30,8 @@ delete monitorData.network.usage.lo; // Get YunoHost versions too - c.api('/version', function(versions) { - monitorData.versions = versions; + c.api('/diagnosis', function(diagnosis) { + monitorData.versions = diagnosis.packages; c.view('tools/tools_monitoring', monitorData); }); }); @@ -47,4 +47,4 @@ }, 'GET'); }); -})(); \ No newline at end of file +})(); diff --git a/src/js/yunohost/controllers/tools.js b/src/js/yunohost/controllers/tools.js index 07b65c8b..30b73e10 100644 --- a/src/js/yunohost/controllers/tools.js +++ b/src/js/yunohost/controllers/tools.js @@ -223,8 +223,8 @@ // Packages version app.get('#/tools/versions', function (c) { - c.api('/version', function(versions) { - c.view('tools/tools_versions', {'versions' : versions}); + c.api('/diagnosis', function(diagnosis) { + c.view('tools/tools_versions', {'versions' : diagnosis.packages }); }); }); diff --git a/src/js/yunohost/events.js b/src/js/yunohost/events.js index cde91e94..478edecc 100644 --- a/src/js/yunohost/events.js +++ b/src/js/yunohost/events.js @@ -8,8 +8,75 @@ * */ app.bind('login', function(e, data) { - this.api('/version', function(versions) { - $('#yunohost-version').html(y18n.t('footer_version', [versions.yunohost.version, versions.yunohost.repo])); + 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) + + ' ('+y18n.t('read_more')+')'; + 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(); + }); }); }); diff --git a/src/js/yunohost/main.js b/src/js/yunohost/main.js index 8ca70af2..ea00fe6c 100644 --- a/src/js/yunohost/main.js +++ b/src/js/yunohost/main.js @@ -149,9 +149,9 @@ // Store url sam.store.set('url', window.location.hostname + '/yunohost/api'); - // Get YunoHost version 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])); }); }