Subversion Repositories oidplus

Rev

Rev 1434 | View as "text/javascript" | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.  * OIDplus 2.0
  3.  * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17.  
  18. var OIDplusPageAdminSoftwareUpdate = {
  19.  
  20.         oid: "1.3.6.1.4.1.37476.2.5.2.4.3.900",
  21.  
  22.         doUpdateOIDplus: function(cur_rev, next_rev, max_rev) {
  23.                 $("#update_versioninfo").hide();
  24.                 OIDplusPageAdminSoftwareUpdate._downloadUpdate(cur_rev, next_rev, max_rev);
  25.         },
  26.  
  27.         _downloadUpdate: function(cur_rev, next_rev, max_rev) {
  28.                 var msg = _L("Downloading update beginning from version %1 up to %2...",cur_rev,max_rev);
  29.                 $("#update_infobox").html(/*$("#update_infobox").html() +*/ '<span class="severity_2"><strong>' + _L('INFO') + ":</strong></span> "+msg+"\n");
  30.  
  31.                 //show_waiting_anim();
  32.                 $.ajax({
  33.                         url: "ajax.php",
  34.                         type: "POST",
  35.                         beforeSend: function(jqXHR, settings) {
  36.                                 $.xhrPool.abortAll();
  37.                                 $.xhrPool.add(jqXHR);
  38.                         },
  39.                         complete: function(jqXHR, text) {
  40.                                 $.xhrPool.remove(jqXHR);
  41.                         },
  42.                         data: {
  43.                                 csrf_token:csrf_token,
  44.                                 plugin: OIDplusPageAdminSoftwareUpdate.oid,
  45.                                 next_version: next_rev,
  46.                                 max_version: max_rev,
  47.                                 update_version: 3,
  48.                                 action: "update_now",
  49.                         },
  50.                         error:function(jqXHR, textStatus, errorThrown) {
  51.                                 //hide_waiting_anim();
  52.                                 if (errorThrown == "abort") {
  53.                                         $("#update_header").text(_L("Update aborted"));
  54.                                         $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
  55.                                         return;
  56.                                 } else {
  57.                                         $("#update_header").text(_L("Update failed"));
  58.                                         //alertError(_L("Error: %1",errorThrown));
  59.                                         $("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + errorThrown + "\n\n");
  60.                                         $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
  61.                                 }
  62.                         },
  63.                         success: function(data) {
  64.                                 // TODO: Use oidplus_ajax_success(), since this checks the existance of "error" in data, and checks if status>=0
  65.                                 //hide_waiting_anim();
  66.                                 if (typeof data === "object" && "error" in data) {
  67.                                         $("#update_header").text(_L("Update failed"));
  68.                                         //alertError(_L("Error: %1",data.error));
  69.                                         if (typeof data === "object" && "content" in data) {
  70.                                                 $("#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");
  71.                                         } else {
  72.                                                 $("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + data.error + "\n\n");
  73.                                         }
  74.                                         $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
  75.                                 } else if (typeof data === "object" && "status" in data && data.status >= 0) {
  76.  
  77.                                         if (!(typeof data === "object" && "update_files" in data)) {
  78.                                                 // This code is usual for svn-wc and git-wc update
  79.                                                 var output = data.content.trim();
  80.                                                 output = output.replace(/INFO:/g, '<span class="severity_2"><strong>' + _L('INFO') + ':</strong></span>');
  81.                                                 output = output.replace(/WARNING:/g, '<span class="severity_3"><strong>' + _L('WARNING') + ':</strong></span>');
  82.                                                 output = output.replace(/FATAL ERROR:/g, '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span>');
  83.                                                 $("#update_infobox").html($("#update_infobox").html() + output + "\n");
  84.                                                 var cur_rev = data.rev=="HEAD" ? max_rev : data.rev;
  85.                                                 if (cur_rev >= max_rev) {
  86.                                                         $("#update_header").text(_L("Update finished"));
  87.                                                         $("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_1"><strong> ' + _L('UPDATE FINISHED') + ':</strong></span> ' + _L('You are now at version %1', cur_rev));
  88.                                                         $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
  89.                                                 } else {
  90.                                                         if (output.includes("FATAL ERROR:")) {
  91.                                                                 $("#update_header").text(_L("Update failed"));
  92.                                                                 $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
  93.                                                         } else {
  94.                                                                 // This is an undefined state! (TODO)
  95.                                                         }
  96.                                                 }
  97.                                                 return;
  98.                                         } else {
  99.                                                 // This code is usual for version 3 "manual" update
  100.                                                 OIDplusPageAdminSoftwareUpdate._applyChangescripts(data.update_files);
  101.                                         }
  102.                                         return;
  103.                                 } else {
  104.                                         $("#update_header").text(_L("Update failed"));
  105.                                         //alertError(_L("Error: %1",data));
  106.                                         if (typeof data === "object" && "content" in data) {
  107.                                                 $("#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");
  108.                                         } else {
  109.                                                 console.error(data);
  110.                                                 $("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + data + "\n\n");
  111.                                         }
  112.                                         $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
  113.                                 }
  114.                         },
  115.                         timeout:0 // infinite
  116.                 });
  117.                 return false;
  118.         },
  119.  
  120.         _applyChangescripts: function(leftscripts) {
  121.  
  122.                 if (leftscripts.length == 0) {
  123.                         $("#update_header").text(_L("Update successful"));
  124.                         $("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_1"><strong> ' + _L('UPDATE FINISHED') + '</strong></span>');
  125.                         $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
  126.                         return;
  127.                 }
  128.  
  129.                 var tmp = leftscripts.shift();
  130.                 var version = tmp[0];
  131.                 var scripturl = tmp[1];
  132.  
  133.                 console.log("Execute update file " + scripturl);
  134.                 $("#update_header").text(_L("Updating to version %1 ...",version)+"\n");
  135.                 var msg = _L("Update to OIDplus version %1 is running...",version);
  136.                 $("#update_infobox").html($("#update_infobox").html() + '<span class="severity_2"><strong>' + _L('INFO') + ":</strong></span> "+msg+"\n");
  137.  
  138.                 $.ajax({
  139.                         url: scripturl,
  140.                         type: "GET",
  141.                         beforeSend: function(jqXHR, settings) {
  142.                                 $.xhrPool.abortAll();
  143.                                 $.xhrPool.add(jqXHR);
  144.                         },
  145.                         complete: function(jqXHR, text) {
  146.                                 $.xhrPool.remove(jqXHR);
  147.                         },
  148.                         data: {
  149.                         },
  150.                         error:function(jqXHR, textStatus, errorThrown) {
  151.                                 //hide_waiting_anim();
  152.                                 if (errorThrown == "abort") {
  153.                                         $("#update_header").text(_L("Update aborted"));
  154.                                         $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
  155.                                         return;
  156.                                 } else {
  157.                                         $("#update_header").text(_L("Update failed"));
  158.                                         //alertError(_L("Error: %1",errorThrown));
  159.                                         $("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + errorThrown + "\n\n");
  160.                                         $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
  161.                                 }
  162.                         },
  163.                         success: function(data2) {
  164.                                 //hide_waiting_anim();
  165.                                 var output2 = data2.trim();
  166.                                 output2 = output2.replace(/INFO:/g, '<span class="severity_2"><strong>' + _L('INFO') + ':</strong></span>');
  167.                                 output2 = output2.replace(/WARNING:/g, '<span class="severity_3"><strong>' + _L('WARNING') + ':</strong></span>');
  168.                                 output2 = output2.replace(/FATAL ERROR:/g, '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span>');
  169.  
  170.                                 if (output2 == "DONE") { // DO NOT TRANSLATE
  171.                                         var msg = _L("Update to OIDplus version %1 was successful!",version);
  172.                                         $("#update_infobox").html($("#update_infobox").html() + '<span class="severity_2"><strong>' + _L('INFO') + ":</strong></span> "+msg+"\n");
  173.                                 } else {
  174.                                         $("#update_infobox").html($("#update_infobox").html() + output2 + "\n");
  175.                                 }
  176.  
  177.                                 if (output2.includes("FATAL ERROR:")) {
  178.                                         $("#update_header").text(_L("Update failed"));
  179.                                         $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">');
  180.                                 } else {
  181.                                         OIDplusPageAdminSoftwareUpdate._applyChangescripts(leftscripts);
  182.                                 }
  183.                                 return;
  184.                         },
  185.                         timeout:0 // infinite
  186.                 });
  187.  
  188.         }
  189.  
  190. };
  191.