#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    82

    Executing a binary on server


    I am trying to execute a binary on a server from a webpage.

    My web page code is as follows:

    Code:
    <html>
    <body>
    <form action="" method="post">
        <button type="submit" name="button">Turn on Front Porch Light</button>
    </form>
    
    <?php 
    $var1 = "14";
    $var2 = "on";
    $var3 = "3m";
    
     if (isset($_POST['button'])) { exec("'./www/var/HAI.pl'. '$var1, $var2, $var3"); print($status);  } 
    
    ?>
    
    </body>
    </html>
    and the server perl script is as follows:

    Code:
    #!/usr/bin/perl -w
    
    my $var1 = '';
    my $var2 = '';
    my $var3 = '';
    $var1 = $ARGV[0];
    $var2 = $ARGV[1];
    $var3 = $ARGV[2];
    print "VAR1: ".$var1."\n";
    print "VAR2: ".$var2."\n";
    print "VAR3: ".$var3."\n";
    system("/bin/hai", $var1, $var2, $var3);
    I am using the Linux Zoneminder CCTV security camera software which provides a web page for viewing the security cameras. What I am trying to do is add buttons to the web page which would allow me to turn exterior floodlights on/off in the vicinity of the cameras.

    I can successfully execute the perl script locally at the server and turn the floodlights on/off but I cannot successfully execute it from the web page.

    I would greatly appreciate any assistance in getting this mod to work.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,115
    Rep Power
    9398
    Could be a variety of things.
    1. exec() is disabled
    2. The path to the script isn't "www/var/HAI.pl."
    3. The shell is complaining about the unclosed quote
    4. The script isn't executable
    5. The script is executing just fine but you can't tell because you're not capturing its output or exit code
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    187
    Rep Power
    82
    I found the source of the problem. It was a malformed exec statement. The statement should look as follows:

    Code:
    if (isset($_POST['ShedFloodLight33'])) 
    { 
    $var1 = "33";
    $var2 = "on";
    $var3 = "3m";
    exec("perl /var/www/HAI.pl $var1 $var2 $var3"); 
    }
    My incorrect statement:


    Code:
     if (isset($_POST['button'])) { exec("'./www/var/HAI.pl'. '$var1, $var2, $var3"); print($status);  }

IMN logo majestic logo threadwatch logo seochat tools logo