/*
* OIDplus 2.0
* Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var OIDplusPageAdminSoftwareUpdate = {
oid: "1.3.6.1.4.1.37476.2.5.2.4.3.900",
doUpdateOIDplus: function(rev, max) {
$("#update_versioninfo").hide();
$("#update_infobox").html(_L("Started update from %1 to %2",rev,max)+"\n");
OIDplusPageAdminSoftwareUpdate._doUpdateOIDplus(rev, max);
},
_doUpdateOIDplus: function(rev, max) {
$("#update_header").text(_L("Updating to Revision %1 ...",rev)+"\n");
var msg = "Update to OIDplus version svn-"+rev+" is running..."; // TODO: If we would translate this to German, then we would also need to generate the serverside scripts to German. So we keep this in English.
$("#update_infobox").html($("#update_infobox").html() + '<span class="severity_2"><strong>' + _L('INFO') + ":</strong></span> "+msg+"\n");
//show_waiting_anim();
$.ajax({
url: "ajax.php",
type: "POST",
beforeSend: function(jqXHR, settings) {
$.xhrPool.abortAll();
$.xhrPool.add(jqXHR);
},
complete: function(jqXHR, text) {
$.xhrPool.remove(jqXHR);
},
data: {
csrf_token:csrf_token,
plugin: OIDplusPageAdminSoftwareUpdate.oid,
rev: rev,
update_version: 2,
action: "update_now",
},
error:function(jqXHR, textStatus, errorThrown) {
//hide_waiting_anim();
if (errorThrown == "abort") {
$("#update_header").text(_L("Update aborted"));
$("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
return;
} else {
$("#update_header").text(_L("Update failed"));
//alertError(_L("Error: %1",errorThrown));
$("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + errorThrown + "\n\n");
$("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
}
},
success: function(data) {
// TODO: Use oidplus_ajax_success(), since this checks the existance of "error" in data, and checks if status>=0
//hide_waiting_anim();
if (typeof data === "object" && "error" in data) {
$("#update_header").text(_L("Update failed"));
//alertError(_L("Error: %1",data.error));
if (typeof data === "object" && "content" in data) {
$("#update_infobox").html($("#update_infobox").html() + "\n\n" + data.content + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + data.error + "\n\n");
} else {
$("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + data.error + "\n\n");
}
$("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
} else if (typeof data === "object" && data.status >= 0) {
if (!(typeof data === "object" && "update_file" in data)) {
output = data.content.trim();
output = output.replace(/INFO:/g, '<span class="severity_2"><strong>' + _L('INFO') + ':</strong></span>');
output = output.replace(/WARNING:/g, '<span class="severity_3"><strong>' + _L('WARNING') + ':</strong></span>');
output = output.replace(/FATAL ERROR:/g, '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span>');
$("#update_infobox").html($("#update_infobox").html() + output + "\n");
rev = data.rev=="HEAD" ? max : data.rev;
if (rev >= max) {
$("#update_header").text(_L("Update finished"));
$("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_1"><strong> ' + _L('UPDATE FINISHED') + ':</strong></span> ' + _L('You are now at SVN revision %1', rev));
$("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
} else {
if (output.includes("FATAL ERROR:")) {
$("#update_header").text(_L("Update failed"));
$("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
} else {
OIDplusPageAdminSoftwareUpdate._doUpdateOIDplus(parseInt(rev)+1, max);
}
}
return;
} else {
console.log("Execute update file " + data.update_file);
$.ajax({
url: data.update_file,
type: "GET",
beforeSend: function(jqXHR, settings) {
$.xhrPool.abortAll();
$.xhrPool.add(jqXHR);
},
complete: function(jqXHR, text) {
$.xhrPool.remove(jqXHR);
},
data: {
},
error:function(jqXHR, textStatus, errorThrown) {
//hide_waiting_anim();
if (errorThrown == "abort") {
$("#update_header").text(_L("Update aborted"));
$("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
return;
} else {
$("#update_header").text(_L("Update failed"));
//alertError(_L("Error: %1",errorThrown));
$("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + errorThrown + "\n\n");
$("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
}
},
success: function(data2) {
//hide_waiting_anim();
output2 = data2.trim();
output2 = output2.replace(/INFO:/g, '<span class="severity_2"><strong>' + _L('INFO') + ':</strong></span>');
output2 = output2.replace(/WARNING:/g, '<span class="severity_3"><strong>' + _L('WARNING') + ':</strong></span>');
output2 = output2.replace(/FATAL ERROR:/g, '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span>');
$("#update_infobox").html($("#update_infobox").html() + output2 + "\n");
rev = data.rev=="HEAD" ? max : data.rev;
if (rev >= max) {
$("#update_header").text(_L("Update finished"));
$("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_1"><strong> ' + _L('UPDATE FINISHED') + ':</strong></span> ' + _L('You are now at SVN revision %1', rev));
$("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
} else {
if (output2.includes("FATAL ERROR:")) {
$("#update_header").text(_L("Update failed"));
$("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
} else {
OIDplusPageAdminSoftwareUpdate._doUpdateOIDplus(parseInt(rev)+1, max);
}
}
return;
},
timeout:0 // infinite
});
}
return;
} else {
$("#update_header").text(_L("Update failed"));
//alertError(_L("Error: %1",data));
if ("content" in data) {
$("#update_infobox").html($("#update_infobox").html() + "\n\n" + data.content + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + data + "\n\n");
} else {
$("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + data + "\n\n");
}
$("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
}
},
timeout:0 // infinite
});
return false;
}
};