Use a php variable to modify a section of a shell script

I have been trying to find a way to find the way to modify a specific portion of a file with a php variable value.

I have created an HTML form which gathers two specific values:

$Unit=_POST[‘Unit’];
$runCmd=_POST[‘runCmd’];

My intention is to open a specific file defined by the $runCmd variable which contains a shell script, modify a section of the script which defines which unit to modify by using the $Unit variable

I have not been able to figure this out for a couple days…

I feel that I have been spinning in the same spot for some time now…

Please help me!!

Thanks!!!

HT

This sounds highly insecure. Post the code for the file you want to edit.

Hello everyone…

I would like to post a quick compendium of how is it that I managed to solve my dilemma…

=-=-=-=-=-=-=-=-
=- HTML FORM =-=-
=-=-=-=-=-=-=-=-

Reboot
Empty Trash

=-=-=-=-=-=-=-=-=
=-= PHP FILE =-=
=-=-=-=-=-=-=-=-=

<?php $Mplayer = $_GET["Mplayer"]; $command = $_GET["radio"]; $selRadio = $command; $subset1 = "sed -e 's/localhost/"; $subset2 = "/g' "; $subset3 = $command." > ".$command."1".".sh"; $final = $subset1.$Mplayer.$subset2.$subset3; $finalLink= "./".$command."1".".sh"; exec($final); shell_exec($finalLink); =-=-=-===-=- With this portion of the code, you may be able to understand the principle. What I did was to gather the DNSNAME($Mplayer) of the unit to access and the predefined command ($command) from the form, once submitted, the php file pulls the information using "GET" (I know that it is not as safe, but at this point, you only have the information you already know). Once I have the first variables set, I now can build a set of variables that will build a command that will perform a "sed" command to a file, which contains a shell script, then, will replace a predefined word in the file for a variable value , then save it on a different file. Once that is done, the script is ready to be used, so you call it. That's it... I hope this makes sense to you guys. I am new to PHP so I am still in the early learning phases, so constructive criticism is welcome I hope this gives you an idea of what is what I did and may help someone in the future. Comments, suggestions and ideas to make this better are welcome.
Sponsor our Newsletter | Privacy Policy | Terms of Service