-1

I've already setup SSH usage in PHP and most of the things work.

Now what I want to do is that I'm looking to edit a line in a file and replace it back. It works directly on the server but can't seem to get it working with PHP files. Here is what I'm trying.

$new_line1 = 'Line $I want to add - The $I has to go into the file as it is';
$new_line2 = 'Ending $text of the line - $text again goes into file;
$query = "Addition to line";
$exec1= 'cd /root; perl -pe "s/.*/' ;
$exec2=  '/ if $. == 37" Edit.sh > Edited.sh';
$new="$exec1$new_line1$query$new_line2$exec2";
$edit="cd /root/mp; cp Edited.sh Edit.sh";
echo $ssh->exec($new);
echo $ssh->exec($edit);

Now the thing is that running the perl command directly in SSH works without any errors but when I run this through PHP I get the error: Substitution replacement not terminated at -e line 1. I want to know why would it work this way and not that?

Asad Moeen
  • 437
  • 3
  • 11
  • 22
  • I've thanked people before in my questions whenever their knowledge has helped me. EDIT : Oh well I'm sorry - I didn't notice their was an accept button as well. I'll do that – Asad Moeen Jul 09 '12 at 13:44

1 Answers1

3

Oh this looks like a security and reliability disaster waiting to happen.

Short answer: there is an opening quote in $exec1 but I can't find the matching closing quote.

More generally, if anyone manages to sneak a quote into line1 or line2, this is going to go wrong. This basically provides a web interface for anyone with access to it to run arbitary code on your computer ...

pjc50
  • 1,720
  • 10
  • 12
  • The matching code I actually put into $exec2. This was actually a single line command but I had to split it up because some $cmds had to go exactly and some needed values parsed. – Asad Moeen Jul 09 '12 at 09:14