Rev 1434 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | /* |
2 | * OIDplus 2.0 |
||
1426 | daniel-mar | 3 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
635 | daniel-mar | 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 | |||
1434 | daniel-mar | 22 | doUpdateOIDplus: function(cur_rev, next_rev, max_rev) { |
647 | daniel-mar | 23 | $("#update_versioninfo").hide(); |
1434 | daniel-mar | 24 | OIDplusPageAdminSoftwareUpdate._downloadUpdate(cur_rev, next_rev, max_rev); |
647 | daniel-mar | 25 | }, |
26 | |||
1434 | daniel-mar | 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); |
||
1426 | daniel-mar | 29 | $("#update_infobox").html(/*$("#update_infobox").html() +*/ '<span class="severity_2"><strong>' + _L('INFO') + ":</strong></span> "+msg+"\n"); |
797 | daniel-mar | 30 | |
647 | daniel-mar | 31 | //show_waiting_anim(); |
635 | daniel-mar | 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, |
||
1426 | daniel-mar | 45 | next_version: next_rev, |
46 | max_version: max_rev, |
||
47 | update_version: 3, |
||
635 | daniel-mar | 48 | action: "update_now", |
49 | }, |
||
50 | error:function(jqXHR, textStatus, errorThrown) { |
||
651 | daniel-mar | 51 | //hide_waiting_anim(); |
52 | if (errorThrown == "abort") { |
||
53 | $("#update_header").text(_L("Update aborted")); |
||
687 | daniel-mar | 54 | $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">'); |
651 | daniel-mar | 55 | return; |
56 | } else { |
||
57 | $("#update_header").text(_L("Update failed")); |
||
833 | daniel-mar | 58 | //alertError(_L("Error: %1",errorThrown)); |
659 | daniel-mar | 59 | $("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + errorThrown + "\n\n"); |
687 | daniel-mar | 60 | $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">'); |
651 | daniel-mar | 61 | } |
635 | daniel-mar | 62 | }, |
63 | success: function(data) { |
||
1292 | daniel-mar | 64 | // TODO: Use oidplus_ajax_success(), since this checks the existance of "error" in data, and checks if status>=0 |
647 | daniel-mar | 65 | //hide_waiting_anim(); |
1036 | daniel-mar | 66 | if (typeof data === "object" && "error" in data) { |
651 | daniel-mar | 67 | $("#update_header").text(_L("Update failed")); |
833 | daniel-mar | 68 | //alertError(_L("Error: %1",data.error)); |
1036 | daniel-mar | 69 | if (typeof data === "object" && "content" in data) { |
659 | daniel-mar | 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"); |
651 | daniel-mar | 71 | } else { |
659 | daniel-mar | 72 | $("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + data.error + "\n\n"); |
635 | daniel-mar | 73 | } |
687 | daniel-mar | 74 | $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">'); |
1447 | daniel-mar | 75 | } else if (typeof data === "object" && "status" in data && data.status >= 0) { |
807 | daniel-mar | 76 | |
1426 | daniel-mar | 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(); |
||
807 | daniel-mar | 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"); |
||
1426 | daniel-mar | 84 | var cur_rev = data.rev=="HEAD" ? max_rev : data.rev; |
85 | if (cur_rev >= max_rev) { |
||
807 | daniel-mar | 86 | $("#update_header").text(_L("Update finished")); |
1426 | daniel-mar | 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)); |
696 | daniel-mar | 88 | $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">'); |
651 | daniel-mar | 89 | } else { |
807 | daniel-mar | 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 { |
||
1426 | daniel-mar | 94 | // This is an undefined state! (TODO) |
807 | daniel-mar | 95 | } |
651 | daniel-mar | 96 | } |
807 | daniel-mar | 97 | return; |
98 | } else { |
||
1426 | daniel-mar | 99 | // This code is usual for version 3 "manual" update |
100 | OIDplusPageAdminSoftwareUpdate._applyChangescripts(data.update_files); |
||
647 | daniel-mar | 101 | } |
635 | daniel-mar | 102 | return; |
103 | } else { |
||
651 | daniel-mar | 104 | $("#update_header").text(_L("Update failed")); |
833 | daniel-mar | 105 | //alertError(_L("Error: %1",data)); |
1447 | daniel-mar | 106 | if (typeof data === "object" && "content" in data) { |
659 | daniel-mar | 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"); |
651 | daniel-mar | 108 | } else { |
1447 | daniel-mar | 109 | console.error(data); |
659 | daniel-mar | 110 | $("#update_infobox").html($("#update_infobox").html() + "\n\n" + '<span class="severity_4"><strong>' + _L('FATAL ERROR') + ':</strong></span> ' + data + "\n\n"); |
635 | daniel-mar | 111 | } |
687 | daniel-mar | 112 | $("#update_infobox").html($("#update_infobox").html() + '\n\n<input type="button" onclick="location.reload()" value="'+_L('Reload page')+'">'); |
635 | daniel-mar | 113 | } |
114 | }, |
||
115 | timeout:0 // infinite |
||
116 | }); |
||
117 | return false; |
||
1426 | daniel-mar | 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 | |||
635 | daniel-mar | 188 | } |
189 | |||
190 | }; |