diff --git a/web-lib.pl b/web-lib.pl index 3171f7c28..5a8db9a67 100755 --- a/web-lib.pl +++ b/web-lib.pl @@ -34,5 +34,12 @@ if (!$done_web_lib_funcs) { $remote_error_handler ||= \&error; $main::remote_error_handler ||= \&error; +# Die handler that stores the error from +# eval message in a global variable +$SIG{__DIE__} = sub { + # Don't meddle with the natural functioning of eval. + $main::error_last_eval = $_[0] if (!$^S); +}; + 1; diff --git a/webmin/twofactor-funcs-lib.pl b/webmin/twofactor-funcs-lib.pl index 923464f64..58399b6a8 100644 --- a/webmin/twofactor-funcs-lib.pl +++ b/webmin/twofactor-funcs-lib.pl @@ -162,8 +162,7 @@ sub validate_twofactor_apikey_totp { my ($miniserv, $in) = @_; eval "use Authen::OATH"; -$main::error_last_eval = $@; -if ($main::error_last_eval) { +if ($@) { return &text('twofactor_etotpmodule', 'Authen::OATH', "../cpan/download.cgi?source=3&cpan=Authen::OATH&mode=2&". "return=/$module_name/&returndesc=".&urlize($text{'index_return'})); @@ -249,8 +248,7 @@ $id =~ /^[A-Z0-9=]+$/i || return $text{'twofactor_etotpid'}; $token =~ /^\d+$/ || return $text{'twofactor_etotptoken'}; eval "use lib (\"$root_directory/vendor_perl\")"; eval "use Authen::OATH"; -$main::error_last_eval = $@; -if ($main::error_last_eval) { +if ($@) { return &text('twofactor_etotpmodule2', 'Authen::OATH'); } my $secret = &decode_base32($id);