{"id":68,"date":"2009-08-23T22:12:15","date_gmt":"2009-08-23T22:12:15","guid":{"rendered":"http:\/\/www.adriangrigoras.com\/blog\/?p=68"},"modified":"2009-08-23T22:12:15","modified_gmt":"2009-08-23T22:12:15","slug":"modify-a-file-from-browser","status":"publish","type":"post","link":"https:\/\/adriangrigoras.com\/blog\/modify-a-file-from-browser\/","title":{"rendered":"Modify a file from browser"},"content":{"rendered":"<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">#! \/usr\/bin\/perl<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">use CGI qw\/:standard\/;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">print &#8220;Content-type: text\/htmlnn&#8221;;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">print &#8220;Modify the file:$file&lt;br\/&gt;&lt;br\/&gt;&#8221;;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$action = param(&#8216;action&#8217;);<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">if($action eq &#8220;&#8221;){<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$file_content=&#8221;&#8221;;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">open (MYFILE, &#8220;&lt;&#8220;, $file);<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">@lines=&lt;MYFILE&gt;;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">foreach $l(@lines){<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$file_content.=$l;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">}<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">close (MYFILE);<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">print&lt;&lt;frm;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">&lt;form action=&#8221;modify.cgi&#8221; method=&#8221;POST&#8221;&gt;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">&lt;textarea name=&#8221;file&#8221; cols=&#8221;150&#8243; rows=&#8221;30&#8243;&gt;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$file_content<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">&lt;\/textarea&gt;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">&lt;input type=&#8221;hidden&#8221; id=&#8221;action&#8221; name=&#8221;action&#8221; value=&#8221;modify&#8221;&gt;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">&lt;br \/&gt;&lt;br \/&gt;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">&lt;input type=&#8221;submit&#8221; value=&#8221;Modify!&#8221;&gt;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">&lt;\/form&gt;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">frm<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">}<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">if($action eq &#8220;modify&#8221;){<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">print &#8220;Done!&#8221;;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$file2=param(&#8216;file&#8217;);<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">#print &#8220;File:$file&#8221;;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">open MYFILE, &#8220;&gt;$file&#8221; or die $!;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">print MYFILE $file2;<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">close (MYFILE);<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">}<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">1;<\/div>\n<p>When you need a fast web development and want to let developers modify directly a config file, you must use the following script:<\/p>\n<blockquote>\n<address>\n<address>#! \/usr\/bin\/perl<\/address>\n<address><\/address>\n<address>use CGI qw\/:standard\/;<\/address>\n<address><\/address>\n<address>print &#8220;Content-type: text\/htmlnn&#8221;;<\/address>\n<address>$file=&#8221;\/etc\/httpd\/conf.d\/my.conf&#8221;;<\/address>\n<address>print &#8220;Modify the file:$file&lt;br\/&gt;&lt;br\/&gt;&#8221;;<\/address>\n<address>$action = param(&#8216;action&#8217;);<\/address>\n<address>if($action eq &#8220;&#8221;){<\/address>\n<address>$file_content=&#8221;&#8221;;<\/address>\n<address>open (MYFILE, &#8220;&lt;&#8220;, $file);<\/address>\n<address>@lines=&lt;MYFILE&gt;;<\/address>\n<address>foreach $l(@lines){<\/address>\n<address> $file_content.=$l;<\/address>\n<address>}<\/address>\n<address>close (MYFILE);<\/address>\n<address>print&lt;&lt;frm;<\/address>\n<address>&lt;form action=&#8221;modify.cgi&#8221; method=&#8221;POST&#8221;&gt;<\/address>\n<address><\/address>\n<address>&lt;textarea name=&#8221;file&#8221; cols=&#8221;150&#8243; rows=&#8221;30&#8243;&gt;<\/address>\n<address>$file_content<\/address>\n<address>&lt;\/textarea&gt;<\/address>\n<address>&lt;input type=&#8221;hidden&#8221; id=&#8221;action&#8221; name=&#8221;action&#8221; value=&#8221;modify&#8221;&gt; <\/address>\n<address>&lt;br \/&gt;&lt;br \/&gt;<\/address>\n<address>&lt;input type=&#8221;submit&#8221; value=&#8221;Modify!&#8221;&gt;<\/address>\n<address><\/address>\n<address>&lt;\/form&gt;<\/address>\n<address>frm<\/address>\n<address>}<\/address>\n<address><\/address>\n<address>if($action eq &#8220;modify&#8221;){<\/address>\n<address>print &#8220;Done!&#8221;;<\/address>\n<address>$file2=param(&#8216;file&#8217;);<\/address>\n<address>#print &#8220;File:$file&#8221;;<\/address>\n<address><\/address>\n<address>open MYFILE, &#8220;&gt;$file&#8221; or die $!;<\/address>\n<address>print MYFILE $file2;<\/address>\n<address>close (MYFILE);<\/address>\n<address><\/address>\n<address>}<\/address>\n<address><\/address>\n<address>1;<\/address>\n<address><\/address>\n<\/p><\/address>\n<\/blockquote>\n<p>Thanks,<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#! \/usr\/bin\/perl use CGI qw\/:standard\/; print &#8220;Content-type: text\/htmlnn&#8221;; print &#8220;Modify the file:$file&lt;br\/&gt;&lt;br\/&gt;&#8221;; $action = param(&#8216;action&#8217;); if($action eq &#8220;&#8221;){ $file_content=&#8221;&#8221;; open (MYFILE, &#8220;&lt;&#8220;, $file); @lines=&lt;MYFILE&gt;; foreach $l(@lines){ $file_content.=$l; } close (MYFILE); print&lt;&lt;frm; &lt;form action=&#8221;modify.cgi&#8221; method=&#8221;POST&#8221;&gt; &lt;textarea name=&#8221;file&#8221; cols=&#8221;150&#8243; rows=&#8221;30&#8243;&gt; $file_content &lt;\/textarea&gt; &lt;input type=&#8221;hidden&#8221; id=&#8221;action&#8221; name=&#8221;action&#8221; value=&#8221;modify&#8221;&gt; &lt;br \/&gt;&lt;br \/&gt; &lt;input type=&#8221;submit&#8221; value=&#8221;Modify!&#8221;&gt; &lt;\/form&gt; frm } if($action\u2026 <span class=\"read-more\"><a href=\"https:\/\/adriangrigoras.com\/blog\/modify-a-file-from-browser\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,11,14],"tags":[],"class_list":["post-68","post","type-post","status-publish","format-standard","hentry","category-apache","category-linux","category-perl"],"_links":{"self":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":0,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"wp:attachment":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}