Askozia Forums
May 21, 2012, 09:10:28 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: r422 diag_editor appends characters  (Read 666 times)
devon
Guest
« on: February 24, 2008, 03:24:58 am »

To reproduce this, go to diag_exec.php and execute the following  command to create a two-line file called 'test'.

# echo "foo1" > /etc/test && echo "foo2" >> test

Download and view the resulting file '/etc/test' in hex:

000000: 66 6f 6f 31 0a 66 6f 6f 32 0a |foo1.foo2.|

Now go to diag_editor.php and open /etc/test. Don't make any changes, just click 'Save'.
Download and view the saved file '/etc/test' in hex:

000000: 66 6f 6f 31 0d 0a 66 6f 6f 32 0d 0a |foo1..foo2..|

I know the 'diag' pages are unsupported but I just wanted to let those who use the editor for testing purposes know that some programs (cron sees ^M) don't know how to handle files edited this way, and may do strange things.


Logged
devon
Guest
« Reply #1 on: February 24, 2008, 07:16:40 am »

Well, it turns out that this is just a result of 'file_get_contents' adding \r\n linefeeds. One way I found to fix this in diag_editor.php is to use 'str_replace' (shown in red) to remove the unwanted "\r" linefeeds.

<-snip->
} else if (isset($pconfig['save'])) {
      conf_mount_rw();
      $f = fopen($pconfig['file'], "w");
      $pconfig['contents'] = str_replace("\r", "", $pconfig['contents']);
      fwrite($f, $pconfig['contents']);
      fclose($f);
      conf_mount_ro();
      $savemsg = "File contents ({$pconfig['file']}) saved.";
   }
<-snip->

In this example, the 'conf_mount' functions (in green) would allow configuration files in /conf to be edited and saved.
Logged
Michael
Askozia Staff
Hero Member
*

Karma: 49
Posts: 1020


View Profile
« Reply #2 on: February 24, 2008, 06:43:41 pm »

Nice find. I've committed your changes with a small modification here:
 - http://lists.askozia.com/pbx-commits/showmsg.php?id=0/47

Thanks!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.09 seconds with 19 queries.