Skip to content

Commit

Permalink
luci-app-attendedsysupgrade: rename uci options
Browse files Browse the repository at this point in the history
remove leading "upgrade" from uci options
also rename server_url to url

cleaning

use new api/ urls

wait for successfull reboot

Signed-off-by: Paul Spooren <paul@spooren.de>
  • Loading branch information
aparcar committed Nov 2, 2017
1 parent 9e1728c commit e8259af
Showing 1 changed file with 61 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,40 @@
%>
<%+header%>
<h2 name="content"><%:Attended Sysupgrade%></h2>
<div class="container">
<p>
<div class="cbi-map-descr">
Easily search and install new releases and package upgrades. Sysupgrade images are created on demand based on locally installed packages.
</p>
<div style="display: none" id="upgrade_info" class="alert-message info"></div>
<div style="display: none" id="upgrade_error" class="alert-message danger"></div>
</div>
<p>
<textarea style="display: none; width: 100%;" id="edit_packages" rows="15"></textarea>
</P>
<div style="display: none" id="upgrade_info" class="alert-message info"></div>
<div style="display: none" id="upgrade_error" class="alert-message danger"></div>
<div style="display: none" id="packages" class="alert-message success"></div>
<fieldset class="cbi-section">
<form method="post" action="">
<div class="cbi-selection-node">
<div class="cbi-value" id="keep_container" style="display: none">
<div class="cbi-section-descr">Check "Keep settings" to retain the current configuration (requires a compatible firmware image).</div>
<label class="cbi-value-title" for="keep">Keep settings:</label>
<div class="cbi-value-field">
<input name="keep" id="keep" checked="checked" type="checkbox">
</div>
</div>
<div class="cbi-value" id="edit_button" style="display: none">
<div class="cbi-value-field">
<input class="cbi-button" value="edit installed packages" onclick="edit_packages()" type="button">
</div>
</div>
<div class="cbi-value cbi-value-last">
<div class="cbi-value-field">
<input class="cbi-button cbi-input-apply" value="Search for upgrades" style="display: none" onclick="upgrade_request()" type="button" id="upgrade_button">
</div>
</div>
</div>
</form>
</fieldset>
<p>
<textarea style="display: none; width: 100%;" id="edit_packages" rows="15"></textarea>
</p>
<fieldset class="cbi-section">
<form method="post" action="">
<div class="cbi-selection-node">
<div class="cbi-value" id="keep_container" style="display: none">
<div class="cbi-section-descr">
Check "Keep settings" to retain the current configuration (requires a compatible firmware image).
</div>
<label class="cbi-value-title" for="keep">Keep settings:</label>
<div class="cbi-value-field">
<input name="keep" id="keep" checked="checked" type="checkbox">
</div>
</div>
<div class="cbi-value" id="edit_button" style="display: none">
<div class="cbi-value-field">
<input class="cbi-button" value="edit installed packages" onclick="edit_packages()" type="button">
</div>
</div>
<div class="cbi-value cbi-value-last">
<div class="cbi-value-field">
<input class="cbi-button cbi-input-apply" value="Search for upgrades" style="display: none" onclick="upgrade_check()" type="button" id="upgrade_button">
</div>
</div>
</div>
</form>
</fieldset>
<script type="text/javascript">
latest_version = "";
data = {};
Expand All @@ -130,7 +128,7 @@ <h2 name="content"><%:Attended Sysupgrade%></h2>
request_dict.target = data.release.target.split("\/")[0];
request_dict.subtarget = data.release.target.split("\/")[1];
var request = new XMLHttpRequest();
request.open("POST", data.server_url + "/" + path, true);
request.open("POST", data.url + "/" + path, true);
request.setRequestHeader("Content-type", "application/json");
request.send(JSON.stringify(request_dict));
request.onerror = function(e) {
Expand All @@ -148,19 +146,19 @@ <h2 name="content"><%:Attended Sysupgrade%></h2>
ubus_call("system", "board", {}, "release");
ubus_call("system", "board", {}, "board_name");
ubus_call("system", "board", {}, "model");
uci_call({ "config": "attendedsysupgrade", "section": "upgradeserver", "option": "server_url" })
uci_call({ "config": "attendedsysupgrade", "section": "upgradeclient", "option": "upgrade_packages" })
uci_call({ "config": "attendedsysupgrade", "section": "upgradeclient", "option": "advanced_mode" })
uci_call({ "config": "attendedsysupgrade", "section": "upgradeclient", "option": "auto_search" })
uci_call({ "config": "attendedsysupgrade", "section": "server", "option": "url" })
uci_call({ "config": "attendedsysupgrade", "section": "client", "option": "upgrade_packages" })
uci_call({ "config": "attendedsysupgrade", "section": "client", "option": "advanced_mode" })
uci_call({ "config": "attendedsysupgrade", "section": "client", "option": "auto_search" })
setup_ready();
}

function setup_ready() {
if(ubus_counter != ubus_closed) {
setTimeout(setup_ready, 500)
setTimeout(setup_ready, 300)
} else {
if(data.auto_search == 1) {
upgrade_request();
upgrade_check();
} else {
document.getElementById("upgrade_button").style.display = "block";
}
Expand Down Expand Up @@ -195,7 +193,6 @@ <h2 name="content"><%:Attended Sysupgrade%></h2>
data[variable] = request_json[variable]
}
ubus_closed++;
console.log(ubus_closed)
}
});
request.send(JSON.stringify(request_data));
Expand All @@ -219,19 +216,19 @@ <h2 name="content"><%:Attended Sysupgrade%></h2>
}

// asks server for news upgrades, actually only based on relesae not packages
function upgrade_request() {
function upgrade_check() {
upgrade_info("Searching for upgrades", true);
request_dict = {}
request_dict.version = data.release.version;
request_dict.packages = data.packagelist;
// not only search for new release, but for new package versions as well
request_dict.upgrade_packages = data.upgrade_packages
server_request(request_dict, "update-request", upgrade_request_callback)
server_request(request_dict, "api/upgrade-check", upgrade_check_callback)
}

// request the image, need merge with upgrade_request
function image_request() {
console.log("image_request")
function upgrade_request() {
console.log("upgrade_request")
document.getElementById("upgrade_button").disabled = true;
document.getElementById("edit_packages").style.display = "none";
document.getElementById("edit_button").style.display = "none";
Expand All @@ -246,10 +243,10 @@ <h2 name="content"><%:Attended Sysupgrade%></h2>
request_dict.packages = data.packages;
}
request_dict.model = data.model
server_request(request_dict, "image-request", image_request_handler)
server_request(request_dict, "api/upgrade-request", upgrade_request_callback)
}

function image_request_handler(response) {
function upgrade_request_callback(response) {
if (response.status === 400) {
response_content = JSON.parse(response.responseText)
upgrade_error(response_content.error)
Expand All @@ -262,7 +259,7 @@ <h2 name="content"><%:Attended Sysupgrade%></h2>
} else if (response.status === 503) {
upgrade_error("please wait. server overloaded")
// handle overload
setTimeout(image_request, 30000)
setTimeout(upgrade_request, 30000)
} else if (response.status === 201) {
response_content = JSON.parse(response.responseText)
if(response_content.queue != undefined) {
Expand All @@ -273,21 +270,23 @@ <h2 name="content"><%:Attended Sysupgrade%></h2>
upgrade_info("imagebuilder not ready, please wait", true)
console.log("setting up imagebuilder")
}
setTimeout(image_request, 5000)
setTimeout(upgrade_request, 5000)
} else if (response.status === 206) {
// building
console.log("building")
upgrade_info("building image", true)
setTimeout(image_request, 5000)
setTimeout(upgrade_request, 5000)
} else if (response.status === 200) {
// ready to download
response_content = JSON.parse(response.responseText);
data.sysupgrade_url = response_content.sysupgrade;

info_output = "Image created"
if(data.advanced_mode == 1) {
build_log = '</br><a target="_blank" href="' + data.sysupgrade_url + '.log">Build log</a>'
upgrade_info("Image created" + build_log);
info_output += build_log
}
upgrade_info(info_output);

document.getElementById("keep_container").style.display = "block";
document.getElementById("upgrade_button").disabled = false;
Expand All @@ -313,35 +312,37 @@ <h2 name="content"><%:Attended Sysupgrade%></h2>
ubus_call("attendedsysupgrade", "sysupgrade", { "keep_settings": document.getElementById("keep").checked }, 'message');
setTimeout(ping_ubus, 5000)
console.log(data.message);
});
});

upload_request.addEventListener('error', function(event) {
upload_request.addEventListener('error', function(event) {
upgrade_info("uploading failed, please retry")
});
});

upload_request.open('POST', origin + '/cgi-bin/cgi-upload');
upload_request.send(form_data);
upload_request.open('POST', origin + '/cgi-bin/cgi-upload');
upload_request.send(form_data);
}

function ping_ubus() {
var request = new XMLHttpRequest();
request.open("GET", ubus_url, true);
request.addEventListener('error', function(event) {
request.addEventListener('error', function(event) {
upgrade_info("Rebooting", true);
setTimeout(ping_ubus, 1000)
});
});
request.addEventListener('load', function(event) {
upgrade_info("Success! Please reload web interface");
document.getElementById("upgrade_button").value = "reload page";
document.getElementById("upgrade_button").style.display = "block";
document.getElementById("upgrade_button").disabled = false;
document.getElementById("upgrade_button").onclick = function() { location.reload(); }
});
request.send();
}

// download image from server once the url was received by image_request
// download image from server once the url was received by upgrade_request
function download_image() {
console.log("download_image")
document.getElementById("keep_container").style.display = "none";
document.getElementById("upgrade_button").style.display = "none";
var download_request = new XMLHttpRequest();
download_request.open("GET", data.sysupgrade_url);
Expand All @@ -357,7 +358,7 @@ <h2 name="content"><%:Attended Sysupgrade%></h2>
download_request.send();
}

function upgrade_request_callback(response_object) {
function upgrade_check_callback(response_object) {
if (response_object.status === 500) {
// python crashed
upgrade_error("internal server error, please try again later")
Expand Down Expand Up @@ -409,9 +410,9 @@ <h2 name="content"><%:Attended Sysupgrade%></h2>
document.getElementById("upgrade_button").value = "request image";
document.getElementById("upgrade_button").style.display = "block";
document.getElementById("upgrade_button").disabled = false;
document.getElementById("upgrade_button").onclick = image_request;
document.getElementById("upgrade_button").onclick = upgrade_request;
} else {
image_request();
upgrade_request();
}
}
}
Expand Down

0 comments on commit e8259af

Please sign in to comment.