Re: R: about DBI
Joel Palmius <[email protected]> Tue, 26 Feb 2008 18:05:15 +0100 (CET)
| Newsgroups | gmane.comp.apache.mod-survey.general |
|---|---|
| Message-ID | <[email protected]> |
This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---481066056-1809763088-1204045113=:19724 Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Content-ID: <[email protected]> I've experimented a bit further. I'm on the edge with versions of perl and= =20 Safe, and I get this error message when trying to use() inside a Safe=20 compartment: Can't load module DBI, dynamic loading not available in this perl. (You=20 may need to build a new perl executable which either supports dynamic=20 loading or has the DBI module statically linked into it.) at=20 /usr/lib/perl5/vendor_perl/5.8.8/i686-linux/DBI.pm line 266 BEGIN=20 failed--compilation aborted at=20 /usr/lib/perl5/vendor_perl/5.8.8/i686-linux/DBI.pm line 266. Compilation=20 failed in require at (eval 88) line 2. BEGIN failed--compilation aborted=20 at (eval 88) line 2. =2E. so obviously it does not work. Maybe you have the same problem in your= =20 Safe, but just don't get the error message. Placing the very same script=20 in an external file and executing it like I mentioned in the other mail=20 works. Survey file: <SURVEY TITLE=3D"test"> <TEXT NAME=3D"test" CAPTION=3D"test" /> <CUSTOM ESCAPED=3D"no"> {\ open(PIPE,"/usr/bin/perl /tmp/db.pl |"); $var =3D join('',<PIPE>); close(PIPE); print $var; \} </CUSTOM> </SURVEY> Contents of /tmp/db.pl: #!/usr/bin/perl use DBI; use DBD::Pg; my $dbh =3D $dbh =3D DBI->connect("dbi:Pg:dbname=3Djoepal", "joepal", ""= ) || print DBI::errstr; $query=3D"SELECT * from hej"; $query_handle =3D $dbh->prepare($query); $crap =3D $query_handle->execute(); while ( @row =3D $query_handle->fetchrow_array ) { print "@row\n"; } $query_handle->finish(); $dbh->disconnect(); So conclusion: Only use Safe for very basic pure perl stuff that doesn't=20 need to include libraries nor do system calls. For everything else, link=20 in an external script. Anyway, I'll make an option in survey.conf for disabling security checking= =20 in Safe for the next releast. You shouldn't have to edit code to do that. // Joel On Tue, 26 Feb 2008, Luca Notari wrote: > I've tried to do $compartment->deny_only(qw(:dangerous)); > > I still have problems in using DBI in perl snippet; as example, I put > here a piece of code that I've used from shell environment with success, > and inside mod_survey perl snippet without success: > > THIS WORKS: > #!/usr/bin/perl > use DBI; > use DBD::mysql; > my $dbh =3D DBI->connect('DBI:mysql:test','root','passwd') > or die "Couldn't connect to database: " . DBI->errstr; > $query=3D"SELECT * from test.test"; > $query_handle =3D $dbh->prepare($query); > $query_handle->execute(); > $query_handle->bind_columns(\$id, \$nome, \$descriz,\$user,\$email); > > while($query_handle->fetch()) { > print "$nome <br />"; > } > > AND THIS DOESN'T WORK: > {\ > use DBD::mysql; > use DBI; > > $dsn=3D"DBI:mysql:test:localhost:3306"; > $dbh =3D DBI->connect("DBI:mysql:test:localhost:3306","root","pwd"); > $query=3D"SELECT * from test.test"; > $query_handle =3D $dbh->prepare($query); > $query_handle->execute(); > $query_handle->bind_columns(\$id, \$nome, \$descriz,\$user,\$email); > > while($query_handle->fetch()) { > print "$nome <br />"; > } > > \} > > It seems that this latter code make use of CPU very higher, and this not > happens launching from shell. > The limit of the IMPORT tag is that the retrieved variable is taken into > the list of submitted variables (I don't want this!) and, above all, > that is not possible to put 2 or more import tags into the same page. > To do these SQL statements: > 1. Select count(*) from tableA where column1=3D'something'; > 2. Select count(*) from tableA where column2=3D'something'; > 3. Select count(*) from tableA where column3=3D'something'; > 4. Select count(*) from tableA where column4=3D'something'; > 5. Select count(*) from tableA where column5=3D'something'; > If I'm right, I need at least 5 pages with IMPORT tag. What if I only > have 4 pages or less? > > Luca Notari > -----Messaggio originale----- > Da: [email protected] > [mailto:[email protected]] Per conto di Joel > Palmius > Inviato: venerd=EC 15 febbraio 2008 14.56 > A: [email protected] > Cc: survey discussion list > Oggetto: Re: survey-discussion-list: about DBI > > > If you want to completely disable security checking, I'd suggest you > change the permit line to: > > $compartment->deny_only(qw(:dangerous)); > > Ie, everything except in principle only dump() and chroot() is allowed. > With this, for example the following is possible: > > <SURVEY TITLE=3D"test"> > > <CUSTOM ESCAPED=3D"no"> > <pre>{& > open(PIPE,"/bin/ls -l /etc |"); > $string =3D join('',<PIPE>); > close(FIL); > print $string; > &}</pre> > </CUSTOM> > > <TEXT NAME=3D"test" CAPTION=3D"test" /> > > </SURVEY> > > To avoid problems with clashes with how mod_survey uses use() and > replaces > things inside the code in the Safe department, I'd suggest making an > external script which prints a value: > > <ROUTE CONTINUE=3D"{& > $someguy =3D $ses->getValue("SUBMITTED_name"); > open(PIPE,"/usr/bin/perl /home/me/myscript.pl $someguy |"); > $allowed =3D <PIPE>; > close(PIPE); > chomp($allowed); > > if($allowed eq "yes") > { > print "continuesurvey.survey"; > } > else > { > print "quotaerror.survey"; > } > &}" /> > > The external script should have no problem with running DBI related > stuff. > > // Joel > > > > On Fri, 15 Feb 2008, Luca Notari wrote: > >> Using IMPORT tag I can access a database via VARIABLE or ARRAY, and >> this variable is included in the list of variables of the survey. >> >> >> But what if I don't want to include the variable? >> >> to do this, I've tried to use DBI in perl snippet but In all cases, >> doesn't work for me(continuous document error or display error; I've >> opened the compartment->permit $compartment->permit(qw(:browse >> :filesys_read :sys_db :filesys_open :filesys_write :subprocess >> :base_core :default :base_io :others require >> caller)) >> both in Display.pm and Document.pm >> >> I've also tried to use open function: open FILE,"myfile.txt", but, >> again nothing works: >> >> >> Document error >> >> Security exception: Undefined subroutine &Carp::longmess_heavy called >> at /usr/lib/perl5/5.8.3/Carp.pm line 166, line 30. >> >> Platform: linux-suse >> Modsurvey version 3.2.4 >> Perl 5.8.3 >> mod_perl 1.99 >> >> >> >> The reason for which I have to fetch data from external is: check >> quotas. If I'm a respondent out of quotas, I have to route to a page >> named i.e. quotafull.survey. To do this, I 1) have to query my DBMS or > >> 2) read a text data or csv data from external >> >> Is there any possibility to fetch data from external source (text >> files, >> databases) and put in a .survey script page with Perl snippets? >> >> >> (I can easy do this with php script, and try to call it via XMLHttp >> using javascript; but, according my knowledge, i have to put variables > >> fetched somewhere in the page, for example using an 'hidden' field; >> but for variables to be available for perl, i think i have to submit >> them ; this is a problem as I need variables available in the same >> page) >> >> thanks, >> >> Luca Notari >> >> > Skickat av Joel Palmius <[email protected]> > till survey-discussion > > > Skickat av "Luca Notari" <[email protected]> > till survey-discussion > ---481066056-1809763088-1204045113=:19724-- Skickat av Joel Palmius <[email protected]> till survey-discussion