开发者

Modify system configuration files and use system commands through web interface

开发者 https://www.devze.com 2023-02-03 20:51 出处:网络
I received a project recently and I am wondering how to do something in a correct and secure manner. The situation is the following:

I received a project recently and I am wondering how to do something in a correct and secure manner.

The situation is the following:

There are classes to manage linux users, mysql users and databases and apache virtual hosts. They're used to automate the addition of users in a small shared-hosting environnement. These classes are then used in command-line scripts to offer a nice interface for the system administrator.

I am now asked to build a simple web interface to offer a GUI to the administrator and then offer some features directly to the users (change their unix password and other daily procedures).

I don't know how to implement the web application. It will run in Apache (with the apache user) but the classes need to access files and com开发者_开发技巧mands that are only usable by the root user to do the necessary changes (e.g useradd and virtual hosts configuration files). When using the command-line scripts, it is not a problem as they are run under the correct user. Giving permissions to the apache user would probably be dangerous.

What would be the best technique to allow this through the web application ? I would like to use the classes directly if possible (it would be handier than calling the command line scripts like external processes and parsing output) but I can't see how to do this in a secure manner.

I saw existing products doing similar things (webmin, eBox, ...) but I don't know how it works.

PS: The classes I received are simple but really badly programmed and barely commented. They are actually in PHP but I'm planning to port them to python. Then I'd like to use the Django framework to build the web admin interface.

Thanks and sorry if the question is not clear enough.

EDIT: I read a little bit about webmin and saw that it uses its own mini web server (called miniserv.pl). It seems like a good solution. The user running this server should then have permissions to modify the files and use the commands. How could I do something similar with Django? Use the development server? Would it be better to use something like CherryPy?


Hello You can easily create web applications in Python using WSGI-compliant web frameworks such as CherryPy2 and templating engines such as Genshi. You can use the 'subprocess' module to manadge external commands...


You can use sudo to give the apache user root permission for only the commands/scripts you need for your web app.

0

精彩评论

暂无评论...
验证码 换一张
取 消