Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 994999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:39:14+00:00 2026-05-16T06:39:14+00:00

I am attempting to create a very simple web interface for changing some system

  • 0

I am attempting to create a very simple web interface for changing some system settings on a network appliance. I am fairly new to PHP and becoming painfully aware of how easy it is to do things in hacky ways, so I am trying to write everything with the best practices in mind.

That said, what would the best practice be for editing files owned by root/some other admin account? Would it be to create a protected shell/perl/whatever script that gets executed by PHP? Using setuid was another option that came up, but that doesnt appear to have any way of restricting users.

I hope that wasn’t too vague, let me know if you need any more details and I’ll be glad to share.

Further Detail: Just to clarify – by edit system files I mean specifically ifcfg’s and some proprietary licensing information. So for simplicity’s sake, lets just say a simple web interface to change the ip/subnet/gateway/dns settings on a linux-based network appliance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:39:15+00:00Added an answer on May 16, 2026 at 6:39 am

    A few things. Take a backup first. Write to a temporary file next. Then validate that file (re-read it to make sure it’s syntatically valid, and means what you think it does). Only then, MOVE (mv or rename()) the file over the top of the original. That way, you can never get stuck in a position where another process tries to read while you’re still writing, or a write failure causes a syntax error, etc…

    Edit:

    There are a few things that you can do for the escalated permissions.

    One would be to write a script (shell) to validate the file and do the move. You can then setuid that file. So then, you write the temporary file using PHP, validate it in PHP (after all, you can never validate too much). Then call the script to move the temporary file into position (with the escalated privileges).

    Another would be to add an account with permission to write to those files only (either via sudo or normally). Then, use PHP to su newuser -c "mv tmpfile finalfile". You’d have to bang out authentication, but it’s better than running PHP as escilated…

    The other option, would be to use the SSH extension to ssh back into the box (using a private key), upload the file and copy it to the final destination.

    But either way you do it, if PHP is hacked, they have access to those files since PHP has a way to…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to create a simple web application for some personal development, but I've
I'm attempting to create a very simple CMS with PHP and MYSQL. The problem
I'm attempting to create an iOS 5 app with some very basic FTP functionality
I'm attempting to create a DataGrid with some data retrieved from a Web Service.
I am attempting to create a very simplistic particle system for an Android application
I'm very new to WPF and I'm attempting to create a treelist navigation within
Im attempting to create a new operator :? on lists, which operates the same
I'm attempting to build a very simple wxPython GUI that monitors and displays external
I am attempting to write a very simple rake task (and merge it into
thank you for you time in advance. Very new to MFC and attempting to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.