Commit 46851d01 authored by Jos Schellevis's avatar Jos Schellevis

Check for updates, still need ro enable cronjob

parent 5cd1ca75
......@@ -35,6 +35,7 @@
# /tmp/pkg_upgrades.output -> Output of pkg upgrade -n
# /tmp/pkg_updates.available -> File with content the number of upgrades or new installs
# /tmp/pkg_core_update.available -> File with content the new OPNsense version number
# /tmp/pkg_last.check -> Write date of last check to file
pkg_running=""
......@@ -45,7 +46,9 @@ if [ "$pkg_running" == "" ]; then
pkg update -f > /tmp/pkg_updates.output 2>&1 &
pid=$!
# wait for defined number of seconds for connection
sleep 5
sleep 8
# write date time stamp to disk
echo `date` > /tmp/pkg_last.check
# check if pkg is done, if not we have a connection issue
pkg_running=`ps | grep $pid | grep -v "grep"`
if [ "$pkg_running" == "" ]; then
......
......@@ -35,51 +35,45 @@ require_once("functions.inc");
require_once("guiconfig.inc");
require_once('notices.inc');
include_once("includes/functions.inc.php");
require_once("script/load_phalcon.php");
if($_REQUEST['getupdatestatus']) {
if(isset($config['system']['firmware']['disablecheck'])) {
exit;
}
if(isset($config['system']['firmware']['alturl']['enable']))
$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}";
else
$updater_url = $g['update_url'];
/* 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)";
$nanosize = "";
if ($g['platform'] == "nanobsd") {
if (file_exists("/etc/nano_use_vga.txt"))
$nanosize = "-nanobsd-vga-";
else
$nanosize = "-nanobsd-";
$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
}
@unlink("/tmp/{$g['product_name']}_version");
if (download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/tmp/{$g['product_name']}_version", 'read_body', 5, 5) === true)
$remote_version = trim(@file_get_contents("/tmp/{$g['product_name']}_version"));
if($_POST['action'] == 'call_this') {
/* 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
}
}
if(empty($remote_version))
echo "<br /><br />Unable to check for updates.";
else {
$current_installed_buildtime = ''; /* XXX zap */
$current_installed_version = trim(file_get_contents("/usr/local/etc/version"));
if(!$remote_version) {
echo "<br /><br />Unable to check for updates.";
}
else {
$needs_system_upgrade = false;
if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $remote_version) == -1) {
echo "<br /><span class=\"red\" id=\"updatealert\"><b>Update available. </b></span><a href=\"/system_firmware_check.php\">Click Here</a> to view update.";
echo "\n<script type=\"text/javascript\">\n";
echo "//<![CDATA[\n";
echo "jQuery('#updatealert').effect('pulsate',{times: 30},10000);\n";
echo "//]]>\n";
echo "</script>\n";
} else
echo "<br />You are on the latest version.";
}
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>" ;
}
echo $update_text;
exit;
}
......@@ -111,8 +105,6 @@ $filesystems = get_mounted_filesystems();
//]]>
</script>
<table class="table table-striped">
<tbody>
<tr>
......@@ -124,17 +116,24 @@ $filesystems = get_mounted_filesystems();
<td width="75%" class="listr">
<strong><?php readfile("/usr/local/etc/version"); ?></strong>
(<?php echo php_uname("m"); ?>)
<br />
built on <?php readfile("/usr/local/etc/version.buildtime"); ?>
<?php if(!$g['hideuname']): ?>
<br />
<div id="uname"><a href="#" onclick='swapuname(); return false;'><?php echo php_uname("s") . " " . php_uname("r"); ?></a></div>
<?php endif; ?>
</td>
</tr>
<?php if(!isset($config['system']['firmware']['disablecheck'])): ?>
<div id='updatestatus'><br /><?php echo gettext("Obtaining update status"); ?> ...</div>
<?php endif; ?>
<tr>
<td>
Updates
</td>
<td>
<div id='updatestatus'><?php echo $update_text; ?></div>
</td>
</tr>
<?php endif; ?>
<tr>
<td width="25%" class="vncellt"><?=gettext("Platform");?></td>
<td width="75%" class="listr">
......@@ -325,6 +324,17 @@ $filesystems = get_mounted_filesystems();
function swapuname() {
jQuery('#uname').html("<?php echo php_uname("a"); ?>");
}
function checkupdate() {
jQuery.ajax({
type: "POST",
url: '/widgets/widgets/system_information.widget.php',
data:{action:'call_this'},
success:function(html) {
alert(html);
}
});
}
<?php if(!isset($config['system']['firmware']['disablecheck'])): ?>
function getstatus() {
scroll(0,0);
......@@ -343,7 +353,7 @@ $filesystems = get_mounted_filesystems();
// to avoid this we set the innerHTML property
jQuery('#updatestatus').prop('innerHTML',transport.responseText);
}
setTimeout('getstatus()', 4000);
setTimeout('getstatus()', 10000); // Update after 10 seconds
<?php endif; ?>
//]]>
</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