Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate URLs via JavaScript #448

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions index.web.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ public function isAuthenticated() {

$updater->log('[info] show HTML page');
$updater->logVersion();
$updaterUrl = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
if (strpos($updaterUrl, 'index.php') === false) {
$updaterUrl = rtrim($updaterUrl, '/') . '/index.php';
}
?>

<html>
Expand Down Expand Up @@ -545,7 +541,6 @@ public function isAuthenticated() {
<h1 class="header-appname">Updater</h1>
</div>
<input type="hidden" id="updater-access-key" value="<?php echo htmlentities($password) ?>"/>
<input type="hidden" id="updater-endpoint" value="<?php echo htmlentities($updaterUrl) ?>"/>
<input type="hidden" id="updater-step-start" value="<?php echo $stepNumber ?>" />
<div id="content-wrapper">
<div id="content">
Expand Down Expand Up @@ -644,7 +639,7 @@ public function isAuthenticated() {
}?>">
<h2>Done</h2>
<div class="output hidden">
<a class="button" href="<?php echo htmlspecialchars(str_replace('/index.php', '/../', $updaterUrl), ENT_QUOTES); ?>">Go back to your Nextcloud instance to finish the update</a>
<a id="back-to-nextcloud" class="button">Go back to your Nextcloud instance to finish the update</a>
</div>
</li>
</ul>
Expand Down Expand Up @@ -675,6 +670,13 @@ public function isAuthenticated() {
</body>
<?php if ($auth->isAuthenticated()): ?>
<script>
var nextcloudUrl = window.location.href.replace('updater/', '').replace('index.php', '');

var backToButton = document.getElementById('back-to-nextcloud');
if (backToButton) {
backToButton.href = nextcloudUrl;
}

function escapeHTML(s) {
return s.toString().split('&').join('&amp;').split('<').join('&lt;').split('>').join('&gt;').split('"').join('&quot;').split('\'').join('&#039;');
}
Expand Down Expand Up @@ -742,7 +744,7 @@ function waitingStep(id) {
function performStep(number, callback) {
started = true;
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', document.getElementById('updater-endpoint').value);
httpRequest.open('POST', window.location.href);
httpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
httpRequest.setRequestHeader('X-Updater-Auth', document.getElementById('updater-access-key').value);
httpRequest.onreadystatechange = function () {
Expand Down Expand Up @@ -983,7 +985,7 @@ function performStep(number, callback) {
el.classList.remove('hidden');

// above is the fallback if the Javascript redirect doesn't work
window.location.href = "<?php echo htmlspecialchars(str_replace('/index.php', '/../', $updaterUrl), ENT_QUOTES); ?>";
window.location.href = nextcloudUrl;
} else {
errorStep('step-done', 12);
var text = escapeHTML(response.response);
Expand Down