in reply to Re^6: INSERT file contents inside a table
in thread INSERT file contents inside a table

Try this and post the result. Be aware of the security risk of user provided data, see Calling External Commands More Safely for better solutions.

#!/usr/bin/perl use strict; use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser' ; # only for test my $id = param('release'); my $cmd = "sudo /usr/bin/amavisd-release $id 2"; my $result; if ($id =~ /^spam-[a-zA-Z0-9-]+\.gz$/) { $result = qx/ $cmd /; } else { $result = "ERROR : Invalid id '$id'"; } print "Content-type: text/plain\n\n"; print "$cmd\n\n$result";
poj

Replies are listed 'Best First'.
Re^8: INSERT file contents inside a table
by theravadamonk (Scribe) on Jun 07, 2018 at 05:07 UTC

    Thanks once again for your effort to rewrite the code.

    Anyway, Why I need below line. NOW, I DON'T want to use front end HTML release.html code ANYMORE. Instead, I want to release directly by clicking.

    my $id = param('release');

    This is the ERROR

    sudo /usr/bin/amavisd-release 2 ERROR : Invalid id ''

    the above error does NOT show the ID. Hope to hear from you. Meanwhile I am also trying to resolve the issue.

      If you mean by clicking this link

      <td><a href=/cgi-bin/release.pl>$id</a></td>

      then you need to add the id as parameter

      <td><a href=/cgi-bin/release.pl?release=$id>$id</a></td>
      poj

        yeah, U r right.below code is OK. it's what I mean. But, I need YES and NO option after clicking for safety purpose. Anyway, It's my NEXT TASK.

        <td><a href=/cgi-bin/release.pl?release=$id>$id</a></td>

        My IDs r in below formats

        spam-IUiA-_bUe0eN.gz

        badh-Xh-Vzy9BSsHN

        banned-8KuHlZuzBCaA

        virus-gUS5QeJ_ayqZ

        So, I had to changed the below code. It has UNDERSCORE as well

        if ($id =~ /^spam-[a-zA-Z0-9-]+\.gz$/) {
        to
        if ($id =~ /^spam-[a-zA-Z0-9-_]+\.gz$|^badh-[a-zA-Z0-9-_]+|^banned-[a- +zA-Z0-9-_]+|^virus-[a-zA-Z0-9-_]+/) {
        also changed
        my $cmd = "sudo /usr/bin/amavisd-release $id 2"; <code> to <code> my $cmd = "sudo /usr/bin/amavisd-release $id";

        Now, code WORKS well. Many thanks once again. UNLESS u helped me, I may NOT achive what I expect. hope to hear from you