diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/diagnost.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/diagnost.js index 66c7d54..2931339 100644 --- a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/diagnost.js +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/diagnost.js @@ -49,7 +49,7 @@ return baseclass.extend({ log: '/tmp/'+tools.appName+'_dwc.log', logArea: this.logArea, callback: this.execAndReadCallback, - cbarg: this, // wnd + ctx: this, }); }, @@ -70,27 +70,27 @@ return baseclass.extend({ log: '/tmp/'+tools.appName+'_dwc.log', logArea: this.logArea, callback: this.execAndReadCallback, - cbarg: this, // wnd + ctx: this, }); }, - execAndReadCallback: function(wnd, rc, txt = '') + execAndReadCallback: function(rc, txt = '') { - wnd.setBtnMode(1, 1, 1); + this.setBtnMode(1, 1, 1); if (rc == 0 && txt) { - wnd.appendLog('========================================================='); + this.appendLog('========================================================='); return; } if (rc >= 500) { if (txt) { - wnd.appendLog(txt.startsWith('ERROR') ? txt : 'ERROR: ' + txt); + this.appendLog(txt.startsWith('ERROR') ? txt : 'ERROR: ' + txt); } else { - wnd.appendLog('ERROR: ' + wnd._action + ': Terminated with error code = ' + rc); + this.appendLog('ERROR: ' + this._action + ': Terminated with error code = ' + rc); } } else { - wnd.appendLog('ERROR: Process finished with retcode = ' + rc); + this.appendLog('ERROR: Process finished with retcode = ' + rc); } - wnd.appendLog('========================================================='); + this.appendLog('========================================================='); }, openDiagnostDialog: function(pkg_arch) diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js index a7954fe..b7b205e 100644 --- a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js @@ -740,7 +740,7 @@ return baseclass.extend({ }, }), - execAndRead: async function({ cmd = [ ], log = '', logArea = null, callback = null, cbarg = null, hiderow = [ ], rpc_timeout = 5, rpc_root = false } = {}) + execAndRead: async function({ cmd = [ ], log = '', logArea = null, callback = null, ctx = null, hiderow = [ ], rpc_timeout = 5, rpc_root = false } = {}) { function appendLog(msg, end = '\n') { @@ -764,23 +764,23 @@ return baseclass.extend({ await fs.exec('/bin/busybox', [ 'rm', '-f', logFile + '*' ], null, rpc_opt); appendLog('Output file cleared!'); } catch (e) { - return callback(cbarg, 500, 'ERROR: Failed to clear output file'); + return callback.call(ctx, 500, 'ERROR: Failed to clear output file'); } try { let opt_list = [ logFile ]; opt_list.push(...cmd); let res = await fs.exec(this.appDir+'/script-exec.sh', opt_list, null, rpc_opt); if (res.code != 0) { - return callback(cbarg, 525, 'ERROR: cannot run "' + cmd[0] + '" script! (error = ' + res.code + ')'); + return callback.call(ctx, 525, 'ERROR: cannot run "' + cmd[0] + '" script! (error = ' + res.code + ')'); } appendLog('Process started...'); } catch (e) { - return callback(cbarg, 520, 'ERROR: Failed on execute process: ' + e.message); + return callback.call(ctx, 520, 'ERROR: Failed on execute process: ' + e.message); } let lastLen = 0; let retCode = -1; return await new Promise(async (resolve, reject) => { - async function poll() + async function epoll() { try { let res = await fs.exec('/bin/cat', [ logFile ], null, rpc_opt); @@ -796,7 +796,7 @@ return baseclass.extend({ let rc = await fs.exec('/bin/cat', [ rcFile ], null, rpc_opt); if (rc.code != 0) { fixLogEnd(); - resolve(callback(cbarg, 545, 'ERROR: cannot read file "' + rcFile + '"')); + resolve(callback.call(ctx, 545, 'ERROR: cannot read file "' + rcFile + '"')); return; } if (rc.stdout) { @@ -806,13 +806,13 @@ return baseclass.extend({ if (retCode >= 0) { fixLogEnd(); if (retCode == 0 && res.stdout) { - resolve(callback(cbarg, 0, res.stdout)); + resolve(callback.call(ctx, 0, res.stdout)); return; } - resolve(callback(cbarg, retCode, 'ERROR: Process failed with error ' + retCode)); + resolve(callback.call(ctx, retCode, 'ERROR: Process failed with error ' + retCode)); return; } - setTimeout(poll, 500); + setTimeout(epoll, 500); } catch (e) { let skip_err = false; if (e.message?.includes('RPC call to file/exec failed with error -32000: Object not found')) { @@ -823,17 +823,17 @@ return baseclass.extend({ } if (skip_err) { console.warn('WARN: execAndRead: ' + e.message); - setTimeout(poll, 500); - return; // goto next poll iteration + setTimeout(epoll, 500); + return; // goto next epoll iteration } fixLogEnd(); let errtxt = 'ERROR: execAndRead: ' + e.message; errtxt += 'ERROR: execAndRead: ' + e.stack?.trim().split('\n')[0]; - callback(cbarg, 540, errtxt); + callback.call(ctx, 540, errtxt); reject(e); } } - poll(); + epoll(); }); }, diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/updater.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/updater.js index 096a922..a8a57c1 100644 --- a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/updater.js +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/updater.js @@ -59,7 +59,7 @@ return baseclass.extend({ log: '/tmp/'+tools.appName+'_pkg_check.log', logArea: this.logArea, callback: this.execAndReadCallback, - cbarg: this, // wnd + ctx: this, }); }, @@ -84,54 +84,54 @@ return baseclass.extend({ logArea: this.logArea, hiderow: /^ \* resolve_conffiles.*(?:\r?\n|$)/gm, callback: this.execAndReadCallback, - cbarg: this, // wnd + ctx: this, }); }, - execAndReadCallback: function(wnd, rc, txt = '') + execAndReadCallback: function(rc, txt = '') { - //console.log('execAndReadCallback = ' + rc + '; _action = ' + wnd._action); + //console.log('execAndReadCallback = ' + rc + '; _action = ' + this._action); if (rc == 0 && txt) { let code = txt.match(/^RESULT:\s*\(([^)]+)\)\s+.+$/m); - if (wnd._action == 'checkUpdates') { - wnd.appendLog('========================================================='); + if (this._action == 'checkUpdates') { + this.appendLog('========================================================='); if (code && code[1] == 'E') { - wnd.btn_install.textContent = _('Reinstall'); + this.btn_install.textContent = _('Reinstall'); } else { - wnd.btn_install.textContent = _('Install'); + this.btn_install.textContent = _('Install'); } let pkg_url = txt.match(/^ZAP_PKG_URL\s*=\s*(.+)$/m); if (code && pkg_url) { - if (!wnd.forced_reinstall) { + if (!this.forced_reinstall) { if (code[1] == 'E' || code[1] == 'G') { - wnd.setStage(0); // install not needed + this.setStage(0); // install not needed return; } } - wnd.pkg_url = pkg_url[1]; - wnd.setStage(2); // enable all buttons + this.pkg_url = pkg_url[1]; + this.setStage(2); // enable all buttons return; // install allowed } } - if (wnd._action == 'installUpdates') { - if (wnd._test || (code && code[1] == '+')) { - wnd.setStage(9); - wnd.appendLog('Please update WEB-page (press F5)'); + if (this._action == 'installUpdates') { + if (this._test || (code && code[1] == '+')) { + this.setStage(9); + this.appendLog('Please update WEB-page (press F5)'); return; } } } - wnd.setStage(0); + this.setStage(0); if (rc >= 500) { if (txt) { - wnd.appendLog(txt.startsWith('ERROR') ? txt : 'ERROR: ' + txt); + this.appendLog(txt.startsWith('ERROR') ? txt : 'ERROR: ' + txt); } else { - wnd.appendLog('ERROR: ' + wnd._action + ': Terminated with error code = ' + rc); + this.appendLog('ERROR: ' + this._action + ': Terminated with error code = ' + rc); } } else { - wnd.appendLog('ERROR: Process finished with retcode = ' + rc); + this.appendLog('ERROR: Process finished with retcode = ' + rc); } - wnd.appendLog('========================================================='); + this.appendLog('========================================================='); }, openUpdateDialog: function(pkg_arch)