| |||||||
|
|
Click here to download plain text source code.
# subroutine name: evaluate # Evaluates perl code. If execution status is successful, returns result # of execution. If execution status is error, makes process to die with error # "demo" edition allows usage of pre-defined strings only # Usage example: evaluate("2+2"); # Result: "4" sub evaluate { my ($perl_code,$ignore)= @_; if ($ignore ne "ignore") { if ( ! %ALLOWED_EVALUATE_STRINGS && -f "approved_demo_evals.dat") { %ALLOWED_EVALUATE_STRINGS = map {&unsafe($_) => 1} split(/\n/, ${&sysreaddata("approved_demo_evals.dat")}); }; unless ($ALLOWED_EVALUATE_STRINGS{$perl_code}) { if ($debug) { $ALLOWED_EVALUATE_STRINGS{$perl_code} = 1; my $enc = $perl_code; $enc=~s/([%\x00-\x08\x0A-\x1F])/uc sprintf("%%%02x",ord($1))/seg; &appenddata("approved_demo_evals.dat", $enc); } else { die "Security restriction: Perl code you are trying to execute is not approved for DEMO version. In full version of software you will be able to execute any code. Disallowed Perl code follows: $perl_code"; } } } my $res=eval ($perl_code); if ($@) { #Error occured die("Error: $@ ; During execution of: $perl_code; Result: $res"); } else { # NO fatal errors return $res; } } |
|||||||||||||||||||||
| Copyright © 1999-2007 Atomicsoft Ltd. All Rights Reserved. | ||