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

Check for updates, still need ro enable cronjob

parent 5cd1ca75
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
# /tmp/pkg_upgrades.output -> Output of pkg upgrade -n # /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_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_core_update.available -> File with content the new OPNsense version number
# /tmp/pkg_last.check -> Write date of last check to file
pkg_running="" pkg_running=""
...@@ -45,7 +46,9 @@ if [ "$pkg_running" == "" ]; then ...@@ -45,7 +46,9 @@ if [ "$pkg_running" == "" ]; then
pkg update -f > /tmp/pkg_updates.output 2>&1 & pkg update -f > /tmp/pkg_updates.output 2>&1 &
pid=$! pid=$!
# wait for defined number of seconds for connection # 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 # check if pkg is done, if not we have a connection issue
pkg_running=`ps | grep $pid | grep -v "grep"` pkg_running=`ps | grep $pid | grep -v "grep"`
if [ "$pkg_running" == "" ]; then if [ "$pkg_running" == "" ]; then
......
...@@ -35,53 +35,47 @@ require_once("functions.inc"); ...@@ -35,53 +35,47 @@ require_once("functions.inc");
require_once("guiconfig.inc"); require_once("guiconfig.inc");
require_once('notices.inc'); require_once('notices.inc');
include_once("includes/functions.inc.php"); include_once("includes/functions.inc.php");
require_once("script/load_phalcon.php");
if($_REQUEST['getupdatestatus']) { /* Check for updates on /tmp/pkg_* files, generated by */
if(isset($config['system']['firmware']['disablecheck'])) { $file_connection="/tmp/pkg_connection_issue";
exit; $file_repository="/tmp/pkg_repository.error";
} $file_updates="/tmp/pkg_updates.available";
if(isset($config['system']['firmware']['alturl']['enable'])) $file_newcore_version="/tmp/pkg_core_update.available";
$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}"; $file_last_check="/tmp/pkg_last.check";
else $update_text="(update in 10 seconds)";
$updater_url = $g['update_url'];
$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($_POST['action'] == 'call_this') {
if (download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/tmp/{$g['product_name']}_version", 'read_body', 5, 5) === true) /* Setup Shell variables */
$remote_version = trim(@file_get_contents("/tmp/{$g['product_name']}_version")); $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) { if($_REQUEST['getupdatestatus']) {
echo "<br /><br />Unable to check for updates."; if (file_exists($file_connection)) {
} /* There is an connection issue, repository can not be reached */
else { $update_text="<div class='text-danger'>Connection error</div><a href='' onclick='checkupdate()'>Click to retry now</a>";
$needs_system_upgrade = false; } elseif (file_exists($file_repository)) {
if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $remote_version) == -1) { /* The repository is not corect */
echo "<br /><span class=\"red\" id=\"updatealert\"><b>Update available. </b></span><a href=\"/system_firmware_check.php\">Click Here</a> to view update."; $update_text="<div class='text-danger'>Repository error</div><a href='' onclick='checkupdate()'>Click to retry now</a>";
echo "\n<script type=\"text/javascript\">\n"; } elseif (file_exists($file_updates)) {
echo "//<![CDATA[\n"; /* There are updates available */
echo "jQuery('#updatealert').effect('pulsate',{times: 30},10000);\n"; $updates=file_get_contents($file_updates);
echo "//]]>\n"; $update_text="<div class='text-info'>There are <b>".$updates."</b> update(s) available</div><a href='/system_firmware.php'> Click to update </a>";
echo "</script>\n"; } elseif (file_exists($file_last_check)) {
} else $last_check=file_get_contents($file_last_check);
echo "<br />You are on the latest version."; $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; exit;
} }
$curcfg = $config['system']['firmware']; $curcfg = $config['system']['firmware'];
...@@ -111,8 +105,6 @@ $filesystems = get_mounted_filesystems(); ...@@ -111,8 +105,6 @@ $filesystems = get_mounted_filesystems();
//]]> //]]>
</script> </script>
<table class="table table-striped"> <table class="table table-striped">
<tbody> <tbody>
<tr> <tr>
...@@ -124,17 +116,24 @@ $filesystems = get_mounted_filesystems(); ...@@ -124,17 +116,24 @@ $filesystems = get_mounted_filesystems();
<td width="75%" class="listr"> <td width="75%" class="listr">
<strong><?php readfile("/usr/local/etc/version"); ?></strong> <strong><?php readfile("/usr/local/etc/version"); ?></strong>
(<?php echo php_uname("m"); ?>) (<?php echo php_uname("m"); ?>)
<br />
built on <?php readfile("/usr/local/etc/version.buildtime"); ?>
<?php if(!$g['hideuname']): ?> <?php if(!$g['hideuname']): ?>
<br /> <br />
<div id="uname"><a href="#" onclick='swapuname(); return false;'><?php echo php_uname("s") . " " . php_uname("r"); ?></a></div> <div id="uname"><a href="#" onclick='swapuname(); return false;'><?php echo php_uname("s") . " " . php_uname("r"); ?></a></div>
<?php endif; ?>
<?php if(!isset($config['system']['firmware']['disablecheck'])): ?>
<div id='updatestatus'><br /><?php echo gettext("Obtaining update status"); ?> ...</div>
<?php endif; ?> <?php endif; ?>
</td> </td>
</tr> </tr>
<?php if(!isset($config['system']['firmware']['disablecheck'])): ?>
<tr>
<td>
Updates
</td>
<td>
<div id='updatestatus'><?php echo $update_text; ?></div>
</td>
</tr>
<?php endif; ?>
<tr> <tr>
<td width="25%" class="vncellt"><?=gettext("Platform");?></td> <td width="25%" class="vncellt"><?=gettext("Platform");?></td>
<td width="75%" class="listr"> <td width="75%" class="listr">
...@@ -325,25 +324,36 @@ $filesystems = get_mounted_filesystems(); ...@@ -325,25 +324,36 @@ $filesystems = get_mounted_filesystems();
function swapuname() { function swapuname() {
jQuery('#uname').html("<?php echo php_uname("a"); ?>"); 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'])): ?> <?php if(!isset($config['system']['firmware']['disablecheck'])): ?>
function getstatus() { function getstatus() {
scroll(0,0); scroll(0,0);
var url = "/widgets/widgets/system_information.widget.php"; var url = "/widgets/widgets/system_information.widget.php";
var pars = 'getupdatestatus=yes'; var pars = 'getupdatestatus=yes';
jQuery.ajax( jQuery.ajax(
url, url,
{ {
type: 'get', type: 'get',
data: pars, data: pars,
complete: activitycallback complete: activitycallback
}); });
} }
function activitycallback(transport) { function activitycallback(transport) {
// .html() method process all script tags contained in responseText, // .html() method process all script tags contained in responseText,
// to avoid this we set the innerHTML property // to avoid this we set the innerHTML property
jQuery('#updatestatus').prop('innerHTML',transport.responseText); jQuery('#updatestatus').prop('innerHTML',transport.responseText);
} }
setTimeout('getstatus()', 4000); setTimeout('getstatus()', 10000); // Update after 10 seconds
<?php endif; ?> <?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