version check

This commit is contained in:
Jokob-sk
2023-01-03 23:58:35 +11:00
parent 2aabae6faa
commit 8490540384
12 changed files with 333 additions and 27 deletions

View File

@@ -666,10 +666,10 @@ height: 50px;
width:46%;
}
/* .setting_input
.myhidden
{
width:35%;
} */
display:none;
}
.center
{
@@ -702,4 +702,13 @@ height: 50px;
.drp-edit
{
cursor: pointer;
}
.new-version
{
top: -6px;
position: absolute;
z-index: 1;
left: 0px;
font-size: large;
}

View File

@@ -0,0 +1,60 @@
function handleVersion(){
release_timestamp = getCookie("release_timestamp")
if(release_timestamp != "")
{
build_timestamp = parseInt($('#version').attr("data-build-time").match( /\d+/g ).join(''))
// if the release_timestamp is older by 10 min or more as the build timestamp then there is a new release available
if(release_timestamp > build_timestamp + 600 )
{
console.log("New release!")
$('#version').attr("class", $('#version').attr("class").replace("myhidden", ""))
$('#new-version-text').attr("class", $('#new-version-text').attr("class").replace("myhidden", ""))
}
else{
console.log("All up-to-date!")
$('#current-version-text').attr("class", $('#current-version-text').attr("class").replace("myhidden", ""))
}
}
}
//--------------------------------------------------------------
function getVersion()
{
release_timestamp = getCookie("release_timestamp")
// no cached value available
if(release_timestamp == "")
{
// get parameter value
$.get('https://api.github.com/repos/jokob-sk/Pi.Alert/releases', function(data) {
var releases = data;
if(releases.length > 0)
{
release_datetime = releases[0].published_at;
release_timestamp = new Date(release_datetime).getTime() / 1000;
// cache value
setCookie("release_timestamp", release_timestamp, 5);
handleVersion();
}
});
} else
{
// cache is available, just call the handler
handleVersion()
}
}
// handle the dispaly of the NEW icon
getVersion()

View File

@@ -34,11 +34,70 @@ function setCache(key, data)
// -----------------------------------------------------------------------------
function setCookie (cookie, value, expirationHours='') {
function handleVersion(){
release_timestamp = getCookie("release_timestamp")
if(release_timestamp != "")
{
build_timestamp = parseInt($('#version').attr("data-build-time").match( /\d+/g ).join(''))
// if the release_timestamp is older by 10 min or more as the build timestamp then there is a new release available
if(release_timestamp > build_timestamp + 600 )
{
console.log("New release!")
$('#version').attr("class", $('#version').attr("class").replace("myhidden", ""))
}
else{
console.log("All up-to-date!")
$('#current-version-text').attr("class", $('#current-version-text').attr("class").replace("myhidden", ""))
// new-version-text current-version-text
}
}
}
//--------------------------------------------------------------
function getVersion()
{
release_timestamp = getCookie("release_timestamp")
// no cached value available
if(release_timestamp == "")
{
// get parameter value
$.get('https://api.github.com/repos/jokob-sk/Pi.Alert/releases', function(data) {
var releases = data;
if(releases.length > 0)
{
release_datetime = releases[0].published_at;
release_timestamp = new Date(release_datetime).getTime() / 1000;
// cache value
setCookie("release_timestamp", release_timestamp ,5);
handleVersion();
}
});
} else
{
// cache is available, just call the handler
handleVersion()
}
}
// -----------------------------------------------------------------------------
function setCookie (cookie, value, expirationMinutes='') {
// Calc expiration date
var expires = '';
if (typeof expirationHours === 'number') {
expires = ';expires=' + new Date(Date.now() + expirationHours *60*60*1000).toUTCString();
if (typeof expirationMinutes === 'number') {
expires = ';expires=' + new Date(Date.now() + expirationMinutes *60*1000).toUTCString();
}
// Save Cookie

View File

@@ -154,6 +154,12 @@ if (isset($_POST['submit']) && submit && isset($_POST['skinselector_set'])) {
</div>
<div class="box-body" style="padding-bottom: 5px;">
<div class="db_info_table">
<div class="db_info_table_row">
<div class="db_info_table_cell" style="min-width: 140px"><?php echo lang('Maintenance_version');?></div>
<div class="db_info_table_cell">
<div class="version" id="version" data-build-time="<?php echo file_get_contents( "buildtimestamp.txt");?>"><?php echo '<span id="new-version-text" class="myhidden">' .lang('Maintenance_new_version').'</span>'.'<span id="current-version-text" class="myhidden">' .lang('Maintenance_current_version').'</span>';?></div>
</div>
</div>
<div class="db_info_table_row">
<div class="db_info_table_cell" style="min-width: 140px"><?php echo lang('Maintenance_database_path');?></div>
<div class="db_info_table_cell">
@@ -811,3 +817,4 @@ window.onload = function asyncFooter()
</script>

View File

@@ -51,6 +51,7 @@
<!-- Pi.Alert -------------------------------------------------------------- -->
<script src="js/pialert_common.js"></script>
<script src="js/handle_version.js"></script>
</body>
</html>

View File

@@ -223,6 +223,7 @@ if ($ENABLED_DARKMODE === True) {
</li>
<li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('maintenance.php') ) ){ echo 'active'; } ?>">
<div class="new-version myhidden" id="version" data-build-time="<?php echo file_get_contents( "buildtimestamp.txt");?>">🆕</div>
<a href="maintenance.php"><i class="fa fa-wrench "></i> <span><?php echo lang('Navigation_Maintenance');?></span></a>
</li>
<li class=" <?php if (in_array (basename($_SERVER['SCRIPT_NAME']), array('settings.php') ) ){ echo 'active'; } ?>">
@@ -239,31 +240,40 @@ if ($ENABLED_DARKMODE === True) {
<!-- /.sidebar -->
</aside>
<script src="js/pialert_common.js"></script>
<script defer>
function getParam(targetId, key, skipCache = false) {
//--------------------------------------------------------------
skipCacheQuery = "";
//--------------------------------------------------------------
function getParam(targetId, key, skipCache = false) {
if(skipCache)
{
skipCacheQuery = "&skipcache";
skipCacheQuery = "";
if(skipCache)
{
skipCacheQuery = "&skipcache";
}
// get parameter value
$.get('php/server/parameters.php?action=get&parameter='+ key + skipCacheQuery, function(data) {
var result = data;
document.getElementById(targetId).innerHTML = result.replaceAll('"', '');
});
}
// get parameter value
$.get('php/server/parameters.php?action=get&parameter='+ key + skipCacheQuery, function(data) {
var result = data;
//--------------------------------------------------------------
document.getElementById(targetId).innerHTML = result.replaceAll('"', '');
// Update server time in the header
show_pia_servertime()
});
}
// Update server state in the header
updateState()
// Update server time in the header
show_pia_servertime()
// Update server state in the header
updateState()
</script>

View File

@@ -216,6 +216,9 @@ $lang['en_us'] = array(
//////////////////////////////////////////////////////////////////
'Maintenance_Title' => 'Maintenance tools',
'Maintenance_version' => 'Application updates',
'Maintenance_new_version' => '🆕 A new version is available. Check out the <a href="https://github.com/jokob-sk/Pi.Alert/releases" target="_blank">release notes</a>.',
'Maintenance_current_version' => 'You are up-to-date. Check out what <a href="https://github.com/jokob-sk/Pi.Alert/issues/138" target="_blank">I\'m working on</a>.',
'Maintenance_database_path' => 'Database-Path',
'Maintenance_database_size' => 'Database-Size',
'Maintenance_database_lastmod' => 'Last Modification',
@@ -432,6 +435,7 @@ $lang['en_us'] = array(
'settings_missing' => 'Not all settings loaded, refresh the page! This is probably caused by a high load on the database.',
'settings_missing_block' => 'You can\'t save your settings without specifying all setting keys. Refresh the page. This is probably caused by a high load on the database.',
'settings_old' => 'The settings in the DB (shown on this page) are outdated. This is probably caused by a running scan. The settings were saved in the <code>pialert.conf</code> file, but the background process didn\'t have time to import it yet to the DB. You can wait until the settings get refreshed so you don\'t overwrite your old values. Feel free to save your settings either way if you don\'t mind losing the settings between the last save and now. There are also backup files created if you need to compare your settings later.',
'settings_imported' => 'Last time settings were imported from the pialert.conf file:',
//General
'SCAN_SUBNETS_name' => 'Subnets to scan',

View File

@@ -51,7 +51,7 @@ CommitDB();
<h1 id="pageTitle">
<?php echo lang('Navigation_Settings');?>
</h1>
Last time imported from the pialert.conf file: <span id="lastImportedTime"></span>
<div class="settingsImported"><?php echo lang("settings_imported");?> <span id="lastImportedTime"></span></div>
</section>
<div class="content">
<?php