diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/ServiceController.php b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/ServiceController.php index 57dd576e5..d964396a7 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/ServiceController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/ServiceController.php @@ -48,12 +48,16 @@ class ServiceController extends ApiMutableServiceControllerBase if ($response !== null) { $response['status'] = "OK"; $response['status_msg'] = sprintf( - gettext("Added %d and removed %d resource records."), + gettext("Added %d and removed %d resource records."), $response['additions'], $response['removals'] ); return $response; } - return array('message' => 'unable to run configd action'); + + return array( + 'status' => 'ERR', + 'status_msg' => gettext('An error occurred during script execution. Check the logs for details'), + ); } } diff --git a/src/opnsense/mvc/app/views/OPNsense/Unbound/dnsbl.volt b/src/opnsense/mvc/app/views/OPNsense/Unbound/dnsbl.volt index 33244b352..ccaaa7b1a 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Unbound/dnsbl.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Unbound/dnsbl.volt @@ -42,7 +42,9 @@ return dfObj; }, onAction: function(data, status) { - $("#responseMsg").removeClass("hidden").html(data['status_msg']); + if (data['status'].toLowerCase().trim() == 'ok') { + $("#responseMsg").removeClass("hidden").html(data['status_msg']); + } } }); diff --git a/src/opnsense/scripts/unbound/wrapper.py b/src/opnsense/scripts/unbound/wrapper.py index 5c0f899dd..c59da43c7 100755 --- a/src/opnsense/scripts/unbound/wrapper.py +++ b/src/opnsense/scripts/unbound/wrapper.py @@ -48,7 +48,9 @@ def unbound_control_do(action, bulk_input): for input in bulk_input: p.stdin.write("%s\n" % input) - return p.communicate()[0] + result = p.communicate()[0] + # return code is only available after communicate() + return (result, p.returncode) # parse arguments parser = argparse.ArgumentParser() @@ -87,10 +89,14 @@ if args.dnsbl: # RR removals only accept domain names, so strip it again (xxx.xx 0.0.0.0 --> xxx.xx) removals = {line.split(' ')[0].strip() for line in removals} uc = unbound_control_do('local_datas_remove', removals) - syslog.syslog(syslog.LOG_NOTICE, 'unbound-control returned: %s' % uc) + syslog.syslog(syslog.LOG_NOTICE, 'unbound-control returned: %s' % uc[0]) + if uc[1] is not 0: + sys.exit(1) if additions: uc = unbound_control_do('local_datas', additions) - syslog.syslog(syslog.LOG_NOTICE, 'unbound-control returned: %s' % uc) + syslog.syslog(syslog.LOG_NOTICE, 'unbound-control returned: %s' % uc[0]) + if uc[1] is not 0: + sys.exit(1) output = {'additions': len(additions), 'removals': len(removals)} diff --git a/src/opnsense/www/js/opnsense_ui.js b/src/opnsense/www/js/opnsense_ui.js index a54dd2129..fbbc4b9b1 100644 --- a/src/opnsense/www/js/opnsense_ui.js +++ b/src/opnsense/www/js/opnsense_ui.js @@ -575,7 +575,7 @@ $.fn.SimpleActionButton = function (params) { BootstrapDialog.show({ type: BootstrapDialog.TYPE_WARNING, title: this_button.data('error-title'), - message: data['status'], + message: data['status_msg'] ? data['status_msg'] : data['status'], draggable: true }); }