Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I have a usb temperature stick called TEMPer. I am using a c program I found which returns the current air temperature. What I would like to do is ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2006
    Posts
    14

    apache run server side code via php


    Hi,

    I have a usb temperature stick called TEMPer. I am using a c program I found which returns the current air temperature. What I would like to do is call this binary code from a webpage.

    I put the compiled code in /usr/bin and created the following file "index.php"


    Code:
    <?php
    print("Current Temp:\n\n");
    $thetemp = system('temper');
    echo $thetemp;
    ?>
    I only get "Current Temp:" on my page and an error in my /var/log/httpd/error_log:

    "TemperCreate: Operation not permitted"

    Where TemperCreate is a function in the original C code. I guess this is a good thing as it is stopping apache from running server side code.

    So to my question. Is it possible to allow apache to run compiled C code ?

    Safe mode is turned off and I have tried making apache the owner of the binary, still no joy.

    Any suggestion would be great.

    Thanks,

    Pete.

  2. #2
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,540
    It sounds like it is running the C program. Does the TemperCreate function require another file that Apache doesn't have permission to?
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    The Fifth Continent

  3. #3
    Just Joined!
    Join Date
    May 2006
    Posts
    14

    update

    The C code includes the following.

    #include <usb.h>

    and i think the library function that is casing the problem is:

    usb_control_msg

    which has the following description:

    int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout);

    usb_control_msg performs a control request to the default control pipe on a device. The parameters mirror the types of the same name in the USB specification. Returns number of bytes written/read or < 0 on error.

    Is there a way of allowing the apache user to run this function, i.e. access to usb devices ?

    Thanks,

    Pete.

  4. #4
    Just Joined!
    Join Date
    May 2006
    Posts
    14

    Solved

    I just placed the binary executable in the same directory as my index.php file (instead of in /usr/bin) and I edited the system call to be:
    Code:
    $thetemp = system('./temper');
    note the addition of the "./"

    and all works great now



    Pete.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •