Due to the limited implementation methods of Web Server and PHP, it is difficult for us to use PHP in the real environment to call programs that require root permission in Linux, I found another way to bypass this restriction from the Internet. First, write a c program to call the system command, and then use PHP to execute the c program.
C program
First, write a c file, such as/usr/local/ismole/w. c.
- // Note due to the wordpress Editor, remove unnecessary spaces in the header file in this Code.
- # Include <stdio. h>
- # Include <stdlib. h>
- # Include <policypes. h>
- # Include <unistd. h>
-
- Int main ()
- {
- Uid_t uid, euid;
-
- // Note to get the current uid
- Uid = getuid ();
- // Note to obtain the current euid
- Euid = geteuid ();
-
- // Note exchange the two IDs
- If (setreuid (euid, uid ))
- Perror ("setreuid ");
-
- // Note: run the linux Command.
- System ("/usr/bin/w ");
- Return 0;
- }
// Note due to the wordpress Editor, remove unnecessary spaces in the header file in this Code.
Compile the gcc-o EPT-Wall w. c file. The program w is generated in the current directory.
Change the chmod u + s./w owner of this program.
PHP Execution
The file content is as follows. Put it in the web directory, the access will output the current server load.
- <? Php
- // Note key verification process
- If ($ key! = $ Authkey ){
- // Exit (key error );
- }
-
- $ Last_line = exec (/usr/local/ismole/w, $ retval );
-
- $ ReturnArray = explode ("load average:", $ retval [0]);
- $ ReturnString = $ returnArray [1];
-
- Echo $ returnString;
According to the above example, we can use PHP to execute any Linux system commands, SVN updates, server monitoring, backup, recovery, and routine maintenance that we want to execute. For example, use SVN to build a test Server