Commit d9dec434 authored by Franco Fichtner's avatar Franco Fichtner

widgets: finally zap the redirect file

parent 42230362
...@@ -35,36 +35,22 @@ require_once('notices.inc'); ...@@ -35,36 +35,22 @@ require_once('notices.inc');
include_once("includes/functions.inc.php"); include_once("includes/functions.inc.php");
require_once("script/load_phalcon.php"); require_once("script/load_phalcon.php");
/* XXX keep redirect through file because we know it works, but zap this later */ if ($_REQUEST['getupdatestatus']) {
$file_pkg_status = '/tmp/pkg_status.json';
if ($_POST['action'] == 'pkg_update') {
$pkg_json = trim(configd_run('firmware pkgstatus')); $pkg_json = trim(configd_run('firmware pkgstatus'));
if ($pkg_json != '') { if ($pkg_json != '') {
file_put_contents($file_pkg_status, $pkg_json); $pkg_status = json_decode($pkg_json, true);
} }
}
if ($_REQUEST['getupdatestatus']) { if (!isset($pkg_status) || $pkg_status["connection"]=="error") {
if (file_exists($file_pkg_status)) { echo "<span class='text-danger'>".gettext("Connection Error")."</span><br/><span class='btn-link' onclick='checkupdate()'>".gettext("Click to retry")."</span>";
$json = file_get_contents($file_pkg_status); } elseif ($pkg_status["repository"]=="error") {
$pkg_status = json_decode($json, true); echo "<span class='text-danger'>".gettext("Repository Problem")."</span><br/><span class='btn-link' onclick='checkupdate()'>".gettext("Click to retry")."</span>";
unlink($file_pkg_status); } elseif ($pkg_status["updates"]=="0") {
} echo "<span class='text-info'>".gettext("Your system is up to date.")."</span><br/><span class='btn-link' onclick='checkupdate()'>Click to check for updates</span>";
if (isset($pkg_status)) {
if ($pkg_status["connection"]=="error") {
echo "<span class='text-danger'>".gettext("Connection Error")."</span><br/><span class='btn-link' onclick='checkupdate()'>".gettext("Click to retry")."</span>";
} elseif ($pkg_status["repository"]=="error") {
echo "<span class='text-danger'>".gettext("Repository Problem")."</span><br/><span class='btn-link' onclick='checkupdate()'>".gettext("Click to retry")."</span>";
} elseif ($pkg_status["updates"]=="0") {
echo "<span class='text-info'>".gettext("At")." <small>".$pkg_status["last_check"]."</small>".gettext(" no updates found.")."<br/><span class='btn-link' onclick='checkupdate()'>Click to check for updates</span>";
} else {
echo "<span class='text-danger'>".gettext("There are ").$pkg_status["updates"].gettext(" update(s) available.")."<br/><span class='text-info'><small>(When last checked at: ".$pkg_status["last_check"]." )</small></span>"."</span><br/><a href='/ui/core/firmware/'>".gettext("Click to upgrade")."</a> | <span class='btn-link' onclick='checkupdate()'>Re-check now</span>";
}
} else { } else {
echo "<span class='btn-link' onclick='checkupdate()'>".gettext("Click to check for updates")."</span>"; echo "<span class='text-info'>".gettext("There are ").$pkg_status["updates"].gettext(" update(s) available.")."</span><br/><a href='/ui/core/firmware/'>".gettext("Click to upgrade")."</a> | <span class='btn-link' onclick='checkupdate()'>Re-check now</span>";
} }
exit; exit;
} }
...@@ -118,18 +104,14 @@ endif; ?> ...@@ -118,18 +104,14 @@ endif; ?>
</td> </td>
</tr> </tr>
<?php if (!isset($config['system']['firmware']['disablecheck'])) :
?>
<tr> <tr>
<td> <td>
Updates Updates
</td> </td>
<td> <td>
<div id='updatestatus'><span class="text-info">Fetching status</span></div> <div id='updatestatus'><span class='btn-link' onclick='checkupdate()'><?=gettext("Click to check for updates");?></span></div>
</td> </td>
</tr> </tr>
<?php
endif; ?>
<tr> <tr>
<td width="25%" class="vncellt"><?=gettext("CPU Type");?></td> <td width="25%" class="vncellt"><?=gettext("CPU Type");?></td>
<td width="75%" class="listr"> <td width="75%" class="listr">
...@@ -315,30 +297,24 @@ endforeach; ?> ...@@ -315,30 +297,24 @@ endforeach; ?>
} }
}); });
} }
window.onload = function(){
getstatus();
}
<?php if (!isset($config['system']['firmware']['disablecheck'])) : function getstatus() {
?> scroll(0,0);
function getstatus() { var url = "/widgets/widgets/system_information.widget.php";
scroll(0,0); var pars = 'getupdatestatus=yes';
var url = "/widgets/widgets/system_information.widget.php"; jQuery.ajax(
var pars = 'getupdatestatus=yes'; url,
jQuery.ajax( {
url,
{
type: 'get', type: 'get',
data: pars, data: pars,
complete: activitycallback complete: activitycallback
}); });
} }
function activitycallback(transport) {
// .html() method process all script tags contained in responseText, function activitycallback(transport) {
// to avoid this we set the innerHTML property // .html() method process all script tags contained in responseText,
jQuery('#updatestatus').prop('innerHTML',transport.responseText); // to avoid this we set the innerHTML property
} jQuery('#updatestatus').prop('innerHTML',transport.responseText);
<?php }
endif; ?>
//]]> //]]>
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment