Find the answer to your Linux question:
Results 1 to 5 of 5
i want to write to iptables file (where iptables rules saved) through php code. i mean that instead of writing iptables rules on the command line i want to design ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    38

    write into file in php


    i want to write to iptables file (where iptables rules saved) through php code.
    i mean that instead of writing iptables rules on the command line i want to design php interface to allow entering iptables rules through this interface .
    now i try to use fwrite php function to write rules into /etc/sysconfig/iptables but i failed.please help me.

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,769

    Smile

    Quote Originally Posted by shyma View Post
    i want to write to iptables file (where iptables rules saved) through php code.
    i mean that instead of writing iptables rules on the command line i want to design php interface to allow entering iptables rules through this interface .
    now i try to use fwrite php function to write rules into /etc/sysconfig/iptables but i failed.please help me.
    Does the user has write permission to modify the files.
    I believe /etc/sysconfig/iptables are root user files.
    If want to modify it , add your apache/web server user to /etc/sudoers files

    Note : I may be wrong here
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  3. #3
    Just Joined!
    Join Date
    Apr 2008
    Posts
    38
    how i can know apache user?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,769
    I think it's not apache user - just normal user.

    We used a user name called oss and to allow this user to have root access
    we added following line in /etc/sudoers file.

    Code:
    oss     ALL=(ALL)       NOPASSWD:ALL
    Note : I'm just giving some hints ...as i didn't have enough knowledege in web applications

    May be try and execute your php file from command prompt and check it's results ..
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  6. #5
    Just Joined!
    Join Date
    Sep 2007
    Location
    Lafayette, IN
    Posts
    83
    I'd suggest not giving your apache user full sudo access. That leaves you far more exposed to an attack. First of all, I'd make sure your php script can only be run locally (perhaps use an .htaccess file to restrict the web directory in which it resides). Then you could add a line like the following to your sudoers file (might want to double-check my syntax)

    Code:
    apache   ALL = NOPASSWD: /usr/sbin/iptables

Posting Permissions

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