LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   how do i use php to pass commands onto a server? (https://www.linuxquestions.org/questions/linux-software-2/how-do-i-use-php-to-pass-commands-onto-a-server-709257/)

steve51184 03-04-2009 09:57 PM

how do i use php to pass commands onto a server?
 
hi all how do i use php to pass commands onto a server?

like i want to be able to:

1. delete the content of a file (or just delete the file and make a new one if it's easier)

2. read the content from a file

3. write new data to a file via an input box

4. run a command on the server

any help would be really appreciated

frieza 03-04-2009 11:27 PM

a tutorial on forms with php
http://www.phpf1.com/tutorial/php-form.html

php file i/o
http://www.felixgers.de/teaching/php/fileIO.html

as for running a command on the server perhaps the system() function, however that is a security hole

steve51184 03-05-2009 12:02 AM

the tutorial on forms with php and the php file i/o looks like what i need and about a security hole only i will have access to this php script so it'll be "safe" imo but please feel free to correct me (p.s. i have a dedicated server so only i have access to it)

will post here later with what i have to ether ask for more help or for others to use if needed

thank you

frieza 03-05-2009 12:50 AM

if the script can be accessed via internet then it is possible that it could be potentially exploited, on second thought, what kind of 'dedicated server' is it and do you have root access to it?

steve51184 03-05-2009 01:00 AM

it's an amd 2.5ghz dual core, 4gb ram 320gb x2 VERY nice server and yes root access

also i'll be using a .htaccess like below:

Quote:

Order deny,allow
Deny from all
Allow from myip
so as you can see only i will be able to use it :)

T74marcell 03-05-2009 02:32 AM

1. delete the content of a file (or just delete the file and make a new one if it's easier)
unlink ($filename);
system ("echo \"\" > filename");

2. read the content from a file
$fp = fopen($filename, "r");
$string = fgets ($fp);

3. write new data to a file via an input box
the contents of the input box are passed via the POST or GET mechanism of the HTTP transfer
get the passed values like $_REQUEST['idname']
fwrite ($fp, $_REQUEST['idname'], strlen($_REQUEST['idname']));

4. run a command on the server
system ("echo \"\" > filename");


----------
T74marcell

Arch Linux

steve51184 03-05-2009 02:46 AM

wow thanks T74marcell for answers 1,2,3 but if i wanted them in a php file with an option to select/do each one how would i do that without making them in there own script?

and for answer 4 can i do that with any command like system ("wget http://domain.com/file.zip");

steve51184 04-29-2009 02:24 AM

bump?


All times are GMT -5. The time now is 09:48 AM.