Re: question about perl functions
Joel Palmius <[email protected]> Wed, 15 Mar 2006 13:10:34 +0100 (CET)
| Newsgroups | gmane.comp.apache.mod-survey.general |
|---|---|
| Message-ID | <[email protected]> |
The security settings on the perl snippets are pretty restrictive, since
otherwise they could allow untrusted users to do dangerous stuff. I think
rand and shuffle possibly fall into a category which are deemed to be
dangerous because of being able to load the server with work.
All these security settings are performed with Safe, a standard perl
module.
If you are making a pre-parse snippet, you can find the security settings
on line 451 in Survey::Document:
$compartment->permit(qw(:browse));
If you have no untrusted users on your system, you could change this to a
more permissive approach. See "perldoc Safe" and "man 3 Opcode". My guess
is you want to change the line to:
$compartment->permit(qw(:browse :base_math));
(in order to get rand).
Otherwise you could remove the Safe thing altogether and run eval()
straight off in the same place in the code. It'd be functionally
equivalent.
There is no way to permit rand() and shuffle() in snippets without
changing the mod_survey code.
// Joel
On Wed, 15 Mar 2006, Luca Notari wrote:
> Hi all,
>
> I have to do a particular randomized survey, multipage, in which each page
> must contain only 1 question (with images, and with a particular layout);
>
> I must randomize a block of 20 questions, and then continue the survey. All
> these questions must be answered.
>
> So, I think that instructions as RANDOMROUTE, RANDOM(survey tag),
> SUBSET(survey tag) are not useful because:
>
> RANDOMROUTE: I suppose that I cant control which page i come from, and count
> the index of my page to learn if I finished my 20 question block or not;
> RANDOM: This (I think) works only if I split for example the 20 questions
> with 5 questions per page: but this is not my goal;
>
> So, following an example by Joel (Interesting use of snippets, 2006/3/2),
> I've tried to use perl snippet.
> I've created an array with 20 elements, with the idea of using <ROUTE
> CONTINUE={&... perl snippet
> in which I want to assign an array index element to tell where to go :
>
> <ROUTE CONTINUE="{& print ("page".$myarray[0].".survey")&}"/>
>
> Obiouvsly, I have to randomize such array.......
>
> And this is my problem: using shuffle or rand() I experienced this message:
>
> Document error
>
> Security exception: 'rand' trapped by operation mask at (eval 83) line 7,
> line 16.
>
> How can I solve problem?
>
>
> thanks all,
> Luca Notari
> Le informazioni contenute in questa e-mail sono riservate e destinate
> esclusivamente alla/e persona/e o allente/i sopra indicati. È vietato a
> soggetti diversi da destinatari qualsiasi uso, copia, diffusione di quanto
> in esso contenuto sia ai sensi dellart.616 c.p., sia ai sensi della legge
> 196/03. Se questa comunicazione vi è pervenuta per errore, Vi preghiamo di
> rinviarla al mittente e successivamente di cancellarla dal vostro sistema.
>
> This e-mail (and any attachment/s) contains confidential and/or privileged
> information. If you are not the intended recipient (or have received this
> e-mail in error) please notify the sender immediately and destroy this
> e-mail. Any unauthorized copying, disclosure or distribution of the material
> in this e-mail is strictly forbidden.
>
>
>