Commit 51758409 authored by Jos Schellevis's avatar Jos Schellevis

WIP cleanup system information widget and us json with ajax calls... so much nicer

parent 84684f08
......@@ -26,7 +26,7 @@
# USAGE:
# Add this file to a CRON job to check for pakcage updates regularly
# Add this file to a CRON job to check for package updates regularly
#
# This script generates a json structured file with the following content:
# connection: error|ok
......@@ -80,8 +80,7 @@ if [ "$pkg_running" == "" ]; then
repository="ok"
# Now check if there are upgrades
pkg upgrade -n > $tmp_pkg_output_file
updates=`cat $tmp_pkg_output_file | grep 'The following' | awk -F '[ ]' '{print $3}'` # > /tmp/pkg_upgrades.output
#updates=`cat /tmp/pkg_upgrades.output | grep 'The following' | awk -F '[ ]' '{print $3}'`
updates=`cat $tmp_pkg_output_file | grep 'The following' | awk -F '[ ]' '{print $3}'`
if [ "$updates" == "" ]; then
# There are no updates
updates="0"
......@@ -148,7 +147,7 @@ if [ "$pkg_running" == "" ]; then
itemcount=`echo $linecount + 4 | bc`
fi
done
if [ "$opnsense_core_update" == "" ]; then
if [ "$core_version" == "" ]; then
core_version="current"
fi
fi
......@@ -158,7 +157,7 @@ if [ "$pkg_running" == "" ]; then
killall pkg
fi
last_check=`date`
echo "{\"connection\":\"$connection\"},{\"repository\":\"$repository\"},{\"last_check\":,\"$last_check\"},{\"updates\":\"$updates\"},{\"core_version\":\"$core_version\"},{\"download_size\":\"$download_size\"},{\"extra_space_required\":\"$required_space\"},{\"new_packages\":[$packages_new]},{\"upgrade_packages\":[$packages_upgraded]}" > $package_json_output
echo "{\"connection\":\"$connection\",\"repository\":\"$repository\",\"last_check\":\"$last_check\",\"updates\":\"$updates\",\"core_version\":\"$core_version\",\"download_size\":\"$download_size\",\"extra_space_required\":\"$required_space\",\"new_packages\":[$packages_new],\"upgrade_packages\":[$packages_upgraded]}" > $package_json_output
else
# pkg is already running, quitting
fi
......@@ -37,45 +37,31 @@ require_once('notices.inc');
include_once("includes/functions.inc.php");
require_once("script/load_phalcon.php");
/* Check for updates on /tmp/pkg_* files, generated by */
$file_connection="/tmp/pkg_connection_issue";
$file_repository="/tmp/pkg_repository.error";
$file_updates="/tmp/pkg_updates.available";
$file_newcore_version="/tmp/pkg_core_update.available";
$file_last_check="/tmp/pkg_last.check";
$update_text="(update in 10 seconds)";
$file_pkg_status="/tmp/pkg_status.json";
if($_POST['action'] == 'call_this') {
if($_POST['action'] == 'pkg_update') {
/* Setup Shell variables */
$shell_output = array();
$shell = new Core\Shell();
// execute shell command and collect (only valid) info into named array
if ($shell->exec("/usr/local/opnsense/scripts/pkg_updates.sh&",false,false,$shell_output) == 0 )
{
// Aplication done
}
$shell->exec("/usr/local/opnsense/scripts/pkg_updatecheck.sh",false,false,$shell_output);
}
if($_REQUEST['getupdatestatus']) {
if (file_exists($file_connection)) {
/* There is an connection issue, repository can not be reached */
$update_text="<div class='text-danger'>Connection error</div><a href='' onclick='checkupdate()'>Click to retry now</a>";
} elseif (file_exists($file_repository)) {
/* The repository is not corect */
$update_text="<div class='text-danger'>Repository error</div><a href='' onclick='checkupdate()'>Click to retry now</a>";
} elseif (file_exists($file_updates)) {
/* There are updates available */
$updates=file_get_contents($file_updates);
$update_text="<div class='text-info'>There are <b>".$updates."</b> update(s) available</div><a href='/system_firmware.php'> Click to update </a>";
} elseif (file_exists($file_last_check)) {
$last_check=file_get_contents($file_last_check);
$update_text="<div class='text-info'>No updates found (checked once a day) </div><div class='text-info'>last time on: ".$last_check."</div><a href='' onclick='checkupdate()'>Click to check now</a>" ;
if (file_exists($file_pkg_status)) {
$json = file_get_contents($file_pkg_status);
$pkg_status = json_decode($json,true);
if ($pkg_status["updates"]=="0") {
echo "Last check at (".$pkg_status["last_check"]."), you where up to date";
} else {
echo "<span class='text-danger'>A total of ".$pkg_status["updates"]." update(s) are available.</span>";
}
} else {
$update_text="<div class='text-info'>Daily cron has not yet run</div><a href='' onclick='checkupdate()'>Click here to try now</a>";
echo "Unknown<span class='btn-link' onclick='checkupdate()'>Click to check now</span>";
}
echo $update_text;
exit;
}
......@@ -130,9 +116,8 @@ $filesystems = get_mounted_filesystems();
<td>
Updates
</td>
<td>
<div id='updatestatus'><?php echo $update_text; ?></div>
<td>
<div id='updatestatus'><span class="text-info">Fetching status</span></div>
</td>
</tr>
<?php endif; ?>
......@@ -327,16 +312,22 @@ $filesystems = get_mounted_filesystems();
jQuery('#uname').html("<?php echo php_uname("a"); ?>");
}
function checkupdate() {
jQuery('#updatestatus').html('<span class="text-info">Updating.... (takes about 10 seconds) </span>');
jQuery.ajax({
type: "POST",
url: '/widgets/widgets/system_information.widget.php',
data:{action:'call_this'},
data:{action:'pkg_update'},
success:function(html) {
alert(html);
//alert(html);
getstatus();
}
});
}
window.onload = function(){
getstatus();
}
<?php if(!isset($config['system']['firmware']['disablecheck'])): ?>
function getstatus() {
scroll(0,0);
......@@ -355,7 +346,6 @@ $filesystems = get_mounted_filesystems();
// to avoid this we set the innerHTML property
jQuery('#updatestatus').prop('innerHTML',transport.responseText);
}
setTimeout('getstatus()', 10000); // Update after 10 seconds
<?php endif; ?>
//]]>
</script>
This diff is collapsed.
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