mirror of
https://github.com/RaspAP/raspap-webgui.git
synced 2024-11-21 23:20:22 +00:00
Patch applied + modified from RaspAP/raspap-insiders#242
This commit is contained in:
parent
2151a44729
commit
ba45daad19
10 changed files with 220 additions and 4 deletions
26
ajax/system/sys_chk_update.php
Normal file
26
ajax/system/sys_chk_update.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
require '../../includes/csrf.php';
|
||||
require_once '../../includes/config.php';
|
||||
require_once '../../includes/defaults.php';
|
||||
|
||||
if (isset($_POST['csrf_token'])) {
|
||||
if (csrfValidateRequest() && !CSRFValidate()) {
|
||||
handleInvalidCSRFToken();
|
||||
}
|
||||
$uri = RASPI_API_ENDPOINT;
|
||||
preg_match('/(\d+(\.\d+)+)/', RASPI_VERSION, $matches);
|
||||
$thisRelease = $matches[0];
|
||||
|
||||
$json = shell_exec("wget --timeout=5 --tries=1 $uri -qO -");
|
||||
$data = json_decode($json, true);
|
||||
$tagName = $data['tag_name'];
|
||||
$updateAvailable = checkReleaseVersion($thisRelease, $tagName);
|
||||
|
||||
$response['tag'] = $tagName;
|
||||
$response['update'] = $updateAvailable;
|
||||
echo json_encode($response);
|
||||
|
||||
} else {
|
||||
handleInvalidCSRFToken();
|
||||
}
|
18
ajax/system/sys_perform_update.php
Normal file
18
ajax/system/sys_perform_update.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
require '../../includes/csrf.php';
|
||||
|
||||
if (isset($_POST['csrf_token'])) {
|
||||
if (csrfValidateRequest() && !CSRFValidate()) {
|
||||
handleInvalidCSRFToken();
|
||||
}
|
||||
// set installer path + options
|
||||
$path = getenv("DOCUMENT_ROOT");
|
||||
$opts = " --update --path $path --yes";
|
||||
$installer = "curl -sL https://install.raspap.com | bash -s -- ";
|
||||
$execUpdate = $installer.$opts;
|
||||
echo json_encode($execUpdate);
|
||||
|
||||
} else {
|
||||
handleInvalidCSRFToken();
|
||||
}
|
|
@ -262,3 +262,7 @@ button > i.fas {
|
|||
border-bottom-right-radius: 0.35rem;
|
||||
}
|
||||
|
||||
.cmd-copy {
|
||||
width: 95%;
|
||||
height: 6rem;
|
||||
}
|
||||
|
|
|
@ -276,6 +276,63 @@ $('#debugModal').on('shown.bs.modal', function (e) {
|
|||
});
|
||||
});
|
||||
|
||||
$('#chkupdateModal').on('shown.bs.modal', function (e) {
|
||||
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
||||
$.post('ajax/system/sys_chk_update.php',{'csrf_token': csrfToken},function(data){
|
||||
var response = JSON.parse(data);
|
||||
var tag = response.tag;
|
||||
var update = response.update;
|
||||
var msg;
|
||||
var msgUpdate = $('#msgUpdate').data('message');
|
||||
var msgLatest = $('#msgLatest').data('message');
|
||||
var msgInstall = $('#msgInstall').data('message');
|
||||
var msgDismiss = $('#js-check-dismiss').data('message');
|
||||
var faCheck = '<i class="fas fa-check ml-2"></i><br />';
|
||||
$(".fas.fa-sync-alt").removeClass("fa-spin");
|
||||
if (update === true) {
|
||||
msg = msgUpdate +' '+tag;
|
||||
$("#msg-check-update").html(msg);
|
||||
$("#msg-check-update").append(faCheck);
|
||||
$("#msg-check-update").append("<p>"+msgInstall+"</p>");
|
||||
$("#js-sys-check-update").removeClass("collapse");
|
||||
} else {
|
||||
msg = msgLatest;
|
||||
dismiss = $("#js-check-dismiss");
|
||||
$("#msg-check-update").html(msg);
|
||||
$("#msg-check-update").append(faCheck);
|
||||
$("#js-sys-check-update").remove();
|
||||
dismiss.text(msgDismiss);
|
||||
dismiss.removeClass("btn-outline-secondary");
|
||||
dismiss.addClass("btn-primary");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#js-sys-check-update').click(function() {
|
||||
$('#chkupdateModal').modal('hide');
|
||||
$('#cmdupdateModal').modal('show');
|
||||
});
|
||||
|
||||
$('#cmdupdateModal').on('shown.bs.modal', function (e) {
|
||||
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
||||
$.post('ajax/system/sys_perform_update.php',{
|
||||
'csrf_token': csrfToken
|
||||
},function(data){
|
||||
var response = JSON.parse(data);
|
||||
$('#shellCmd').val(response);
|
||||
});
|
||||
});
|
||||
|
||||
$('#js-cmd-copy').click(function() {
|
||||
$('#shellCmd').select();
|
||||
document.execCommand('copy');
|
||||
var btnCancel = $('#cmdupdateCancel');
|
||||
var btnText = btnCancel.data('message');
|
||||
btnCancel.text(btnText);
|
||||
btnCancel.removeClass("btn-outline-secondary");
|
||||
btnCancel.addClass("btn-primary");
|
||||
});
|
||||
|
||||
$('#hostapdModal').on('shown.bs.modal', function (e) {
|
||||
var seconds = 3;
|
||||
var pct = 0;
|
||||
|
|
|
@ -31,6 +31,9 @@ define('RASPI_LIGHTTPD_CONFIG', '/etc/lighttpd/lighttpd.conf');
|
|||
define('RASPI_ACCESS_CHECK_IP', '1.1.1.1');
|
||||
define('RASPI_ACCESS_CHECK_DNS', 'one.one.one.one');
|
||||
|
||||
// Constant for the GitHub API latest release endpoint
|
||||
define('RASPI_API_ENDPOINT', 'https://api.github.com/repos/RaspAP/raspap-webgui/releases/latest');
|
||||
|
||||
// Constant for the 5GHz wireless regulatory domain
|
||||
define("RASPI_5GHZ_CHANNEL_MIN", 100);
|
||||
define("RASPI_5GHZ_CHANNEL_MAX", 192);
|
||||
|
|
|
@ -6,7 +6,7 @@ if (!defined('RASPI_CONFIG')) {
|
|||
|
||||
$defaults = [
|
||||
'RASPI_BRAND_TEXT' => 'RaspAP',
|
||||
'RASPI_VERSION' => '3.0.1',
|
||||
'RASPI_VERSION' => '2.9.9',
|
||||
'RASPI_CONFIG_NETWORK' => RASPI_CONFIG.'/networking/defaults.json',
|
||||
'RASPI_CONFIG_PROVIDERS' => 'config/vpn-providers.json',
|
||||
'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth',
|
||||
|
|
|
@ -899,3 +899,28 @@ function getCountryCodes($locale = 'en', $flag = true) {
|
|||
return $countryData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the current release with the latest available release
|
||||
*
|
||||
* @param string $installed
|
||||
* @param string $latest
|
||||
* @return boolean
|
||||
*/
|
||||
function checkReleaseVersion($installed, $latest) {
|
||||
$installedArray = explode('.', $installed);
|
||||
$latestArray = explode('.', $latest);
|
||||
|
||||
// compare segments of the version number
|
||||
for ($i = 0; $i < max(count($installedArray), count($latestArray)); $i++) {
|
||||
$installedSegment = (int)($installedArray[$i] ?? 0);
|
||||
$latestSegment = (int)($latestArray[$i] ?? 0);
|
||||
|
||||
if ($installedSegment < $latestSegment) {
|
||||
return true;
|
||||
} elseif ($installedSegment > $latestSegment) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1457,3 +1457,36 @@ msgstr "Insiders"
|
|||
msgid "Contributing"
|
||||
msgstr "Contributing"
|
||||
|
||||
msgid "Check for update"
|
||||
msgstr "Check for update"
|
||||
|
||||
msgid "New release check in progress..."
|
||||
msgstr "New release check in progress..."
|
||||
|
||||
msgid "A new release is available: Version"
|
||||
msgstr "A new release is available: Version"
|
||||
|
||||
msgid "GitHub authentication"
|
||||
msgstr "GitHub authentication"
|
||||
|
||||
msgid "Updating Insiders requires GitHub authentication."
|
||||
msgstr "Updating Insiders requires GitHub authentication."
|
||||
|
||||
msgid "Your credentials will be sent to GitHub securely with SSL. However, use caution if your RaspAP install is on a WLAN shared by untrusted users."
|
||||
msgstr "Your credentials will be sent to GitHub securely with SSL. However, use caution if your RaspAP install is on a WLAN shared by untrusted users."
|
||||
|
||||
msgid "Personal Access Token"
|
||||
msgstr "Personal Access Token"
|
||||
|
||||
msgid "Please provide a valid token."
|
||||
msgstr "Please provide a valid token."
|
||||
|
||||
msgid "Get update command"
|
||||
msgstr "Get update command"
|
||||
|
||||
msgid "Copy the following and execute it in the terminal:"
|
||||
msgstr "Copy the following and execute it in the terminal:"
|
||||
|
||||
msgid "Copy"
|
||||
msgstr "Copy"
|
||||
|
||||
|
|
|
@ -36,3 +36,43 @@ require_once 'app/lib/Parsedown.php';
|
|||
</div><!-- /.card -->
|
||||
</div><!-- /.col-lg-12 -->
|
||||
</div><!-- /.row -->
|
||||
|
||||
<!-- modal check-update-->
|
||||
<div class="modal fade" id="chkupdateModal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<div class="modal-title" id="ModalLabel"><i class="fas fa-sync-alt fa-spin mr-2"></i><?php echo _("Check for update"); ?></div>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="col-md-12 mb-3 mt-1" id="msg-check-update"><?php echo _("New release check in progress..."); ?></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div id="msgUpdate" data-message="<?php echo _("A new release is available: Version"); ?>"></div>
|
||||
<div id="msgLatest" data-message="<?php echo _("Installed version is the latest release."); ?>"></div>
|
||||
<div id="msgInstall" data-message="<?php echo _("Install this update now?"); ?>"></div>
|
||||
<button type="button" data-message="<?php echo _("OK"); ?>" id="js-check-dismiss" class="btn btn-outline-secondary" data-dismiss="modal"><?php echo _("Cancel"); ?></button>
|
||||
<button type="button" data-message="<?php echo _("OK"); ?>" id="js-sys-check-update" class="btn btn-outline btn-primary collapse"><?php echo _("OK"); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- modal update-cmd -->
|
||||
<div class="modal fade" id="cmdupdateModal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<div class="modal-title" id="ModalLabel"><i class="fas fa-terminal mr-2"></i><?php echo _("Update command"); ?></div>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="col-md-12 mb-3 mt-1" id="msg-check-update"><?php echo _("Copy the following and execute it in the terminal:"); ?></div>
|
||||
<textarea class="logoutput ml-2 cmd-copy" id="shellCmd"></textarea>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" data-message="<?php echo _("Done"); ?>" class="btn btn-outline-secondary" id="cmdupdateCancel" data-dismiss="modal"><?php echo _("Cancel"); ?></button>
|
||||
<button type="button" class="btn btn-warning" id="js-cmd-copy" /><i class="far fa-copy ml-1 mr-2"></i><?php echo _("Copy"); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,9 +1,19 @@
|
|||
<!-- about general tab -->
|
||||
<div class="tab-pane active" id="aboutgeneral">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mt-3">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="ml-5 mt-2"><img class="about-logo" src="app/img/raspAP-logo.php" style="width: 175px; height:175px"></div>
|
||||
<h2 class="mt-3 ml-4"><?php echo _("RaspAP") ." v".RASPI_VERSION; ?></h2>
|
||||
<button type="button" class="btn btn-warning ml-4 mt-2" name="check-update" data-toggle="modal" data-target="#chkupdateModal" />
|
||||
<i class="fas fa-sync-alt ml-1 mr-2"></i><?php echo _("Check for update"); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<h2 class="mt-3"><?php echo _("RaspAP") ." v".RASPI_VERSION; ?></h2>
|
||||
<div class="ml-5 mt-3"><img class="about-logo" src="app/img/raspAP-logo.php" style="width: 175px; height:175px"></div>
|
||||
|
||||
<div class="mt-3">RaspAP is a co-creation of <a href="https://github.com/billz">billz</a> and <a href="https://github.com/sirlagz">SirLagz</a>
|
||||
with the contributions of our <a href="https://github.com/raspap/raspap-webgui/graphs/contributors">developer community</a>
|
||||
and <a href="https://crowdin.com/project/raspap">language translators</a>.
|
||||
|
|
Loading…
Reference in a new issue