cavac has asked for the wisdom of the Perl Monks concerning the following question:
Hi!
I need a little help for my Maplat webserver project: To automate some processes i like to give the user the opportunity to write simple embedded script code. This scripts should be able to do math, string matching and change some given data structures - but nothing more. No file access, no access to the host script (written in perl).
This interpreter would be run within a perl script, get the data structures defined by that script and after the interpreter finished (or timed out) the results would be used in the perl script.
Here's a (rather stupid, i admit) example pseudo code how it could be used in a webmail system:
I looked into Lua::API, but i'm not sure how to safely sandbox that. I read some Lua documentation, but i'm none the wiser...
Any ideas how to do that?
Rene
UPDATE
Managed to translate http://lua-users.org/wiki/SimpleLuaApiExample into a simple Lua::API script.
test.lua:
test.pl:
I need a little help for my Maplat webserver project: To automate some processes i like to give the user the opportunity to write simple embedded script code. This scripts should be able to do math, string matching and change some given data structures - but nothing more. No file access, no access to the host script (written in perl).
This interpreter would be run within a perl script, get the data structures defined by that script and after the interpreter finished (or timed out) the results would be used in the perl script.
Here's a (rather stupid, i admit) example pseudo code how it could be used in a webmail system:
// Forward mail to private account on weekend if weekday > 5 then email.reciever = "private@example.com" exit; end if email.subject has "TEST" then email.mailbox = "testmails" else if email.sender == "boss@example.com" email.mailbox = "bigboss" else email.mailbox = "trash" end
I looked into Lua::API, but i'm not sure how to safely sandbox that. I read some Lua documentation, but i'm none the wiser...
Any ideas how to do that?
Rene
UPDATE
Managed to translate http://lua-users.org/wiki/SimpleLuaApiExample into a simple Lua::API script.
test.lua:
x = 0 for i = 1, #foo do x = x + foo[i] end return x
test.pl:
This still needs a lot of work though, but i see a (very dim) light at the end of the (very long) tunnel.use strict; use warnings; use Lua::API; my $L = Lua::API::State->new; my $status = $L->loadfile("test.lua"); if($status) { die "Failed to load file: " . $L->tostring(-1); } $L->newtable; for(my $i = 1; $i <= 5; $i++) { $L->pushnumber($i); $L->pushnumber($i*2); $L->rawset(-3); } $L->setglobal("foo"); my $result = $L->pcall(0, Lua::API::MULTRET, 0); if($result) { die "Failed to execute file: " . $L->tostring(-1); } my $sum = $L->tonumber(-1); print "Script returned $sum\n"; $L->pop(1); $L->close;
Don't use '#ff0000':
use Acme::AutoColor; my $redcolor = RED();
All colors subject to change without notice.
use Acme::AutoColor; my $redcolor = RED();
All colors subject to change without notice.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Embedded scripting sandbox? Lua?
by afoken (Chancellor) on Oct 03, 2011 at 18:52 UTC | |
by cavac (Parson) on Oct 04, 2011 at 05:45 UTC | |
Re: Embedded scripting sandbox? Lua?
by perlfan (Vicar) on Oct 03, 2011 at 20:04 UTC | |
by cavac (Parson) on Oct 04, 2011 at 05:36 UTC | |
by perlfan (Vicar) on Oct 04, 2011 at 13:28 UTC | |
by cavac (Parson) on Oct 10, 2011 at 17:29 UTC | |
Re: Embedded scripting sandbox? Lua?
by Anonymous Monk on Oct 04, 2011 at 06:43 UTC | |
by cavac (Parson) on Oct 04, 2011 at 08:00 UTC | |
by Anonymous Monk on Oct 04, 2011 at 09:26 UTC | |
by cavac (Parson) on Oct 10, 2011 at 17:08 UTC |
Back to
Seekers of Perl Wisdom