1 |
447611c4
|
Scott Ullrich
|
<?php
|
2 |
a7f908db
|
Scott Ullrich
|
/*
|
3 |
0d6a185a
|
Scott Ullrich
|
edit.php
|
4 |
|
|
Copyright (C) 2004, 2005 Scott Ullrich
|
5 |
|
|
All rights reserved.
|
6 |
|
|
|
7 |
|
|
Redistribution and use in source and binary forms, with or without
|
8 |
|
|
modification, are permitted provided that the following conditions are met:
|
9 |
|
|
|
10 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
11 |
|
|
this list of conditions and the following disclaimer.
|
12 |
|
|
|
13 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
14 |
|
|
notice, this list of conditions and the following disclaimer in the
|
15 |
|
|
documentation and/or other materials provided with the distribution.
|
16 |
|
|
|
17 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
18 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
19 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
20 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
21 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
27 |
a7f908db
|
Scott Ullrich
|
*/
|
28 |
7ac5a4cb
|
Scott Ullrich
|
/*
|
29 |
|
|
pfSense_MODULE: shell
|
30 |
|
|
*/
|
31 |
a7f908db
|
Scott Ullrich
|
|
32 |
9fbb3599
|
Ermal
|
##|+PRIV
|
33 |
|
|
##|*IDENT=page-diagnostics-edit
|
34 |
|
|
##|*NAME=Diagnostics: Edit FIle
|
35 |
|
|
##|*DESCR=Allow access to the 'Diagnostics: Edit File' page.
|
36 |
|
|
##|*MATCH=edit.php*
|
37 |
c0f613e2
|
Ermal
|
##|*MATCH=browser.php*
|
38 |
|
|
##|*MATCH=filebrowser/browser.php*
|
39 |
9fbb3599
|
Ermal
|
##|-PRIV
|
40 |
|
|
|
41 |
fdb38c10
|
Scott Ullrich
|
$pgtitle = array(gettext("Diagnostics"), gettext("Edit file"));
|
42 |
859329c8
|
Scott Ullrich
|
require("guiconfig.inc");
|
43 |
|
|
|
44 |
55344e2c
|
Ermal
|
if($_POST['action']) {
|
45 |
|
|
switch($_POST['action']) {
|
46 |
0d6a185a
|
Scott Ullrich
|
case 'load':
|
47 |
55344e2c
|
Ermal
|
if(strlen($_POST['file']) < 1) {
|
48 |
a1c2ef43
|
Carlos Eduardo Ramos
|
echo "|5|" . gettext("No file name specified") . ".|";
|
49 |
55344e2c
|
Ermal
|
} elseif(is_dir($_POST['file'])) {
|
50 |
a1c2ef43
|
Carlos Eduardo Ramos
|
echo "|4|" . gettext("Loading a directory is not supported") . ".|";
|
51 |
55344e2c
|
Ermal
|
} elseif(! is_file($_POST['file'])) {
|
52 |
a1c2ef43
|
Carlos Eduardo Ramos
|
echo "|3|" . gettext("File does not exist or is not a regular file") . ".|";
|
53 |
0d6a185a
|
Scott Ullrich
|
} else {
|
54 |
55344e2c
|
Ermal
|
$data = file_get_contents(urldecode($_POST['file']));
|
55 |
0d6a185a
|
Scott Ullrich
|
if($data === false) {
|
56 |
a1c2ef43
|
Carlos Eduardo Ramos
|
echo "|1|" . gettext("Failed to read file") . ".|";
|
57 |
0d6a185a
|
Scott Ullrich
|
} else {
|
58 |
b71f0cbb
|
Ermal
|
$data = base64_encode($data);
|
59 |
55344e2c
|
Ermal
|
echo "|0|{$_POST['file']}|{$data}|";
|
60 |
0d6a185a
|
Scott Ullrich
|
}
|
61 |
|
|
}
|
62 |
|
|
exit;
|
63 |
|
|
case 'save':
|
64 |
55344e2c
|
Ermal
|
if(strlen($_POST['file']) < 1) {
|
65 |
a1c2ef43
|
Carlos Eduardo Ramos
|
echo "|" . gettext("No file name specified") . ".|";
|
66 |
0d6a185a
|
Scott Ullrich
|
} else {
|
67 |
5a557f44
|
jim-p
|
conf_mount_rw();
|
68 |
55344e2c
|
Ermal
|
$_POST['data'] = str_replace("\r", "", base64_decode($_POST['data']));
|
69 |
|
|
$ret = file_put_contents($_POST['file'], $_POST['data']);
|
70 |
5a557f44
|
jim-p
|
conf_mount_ro();
|
71 |
55344e2c
|
Ermal
|
if($_POST['file'] == "/conf/config.xml" || $_POST['file'] == "/cf/conf/config.xml") {
|
72 |
5f05c1e8
|
Scott Ullrich
|
if(file_exists("/tmp/config.cache"))
|
73 |
|
|
unlink("/tmp/config.cache");
|
74 |
0f806eca
|
Erik Fonnesbeck
|
disable_security_checks();
|
75 |
|
|
}
|
76 |
0d6a185a
|
Scott Ullrich
|
if($ret === false) {
|
77 |
a1c2ef43
|
Carlos Eduardo Ramos
|
echo "|" . gettext("Failed to write file") . ".|";
|
78 |
55344e2c
|
Ermal
|
} elseif($ret <> strlen($_POST['data'])) {
|
79 |
a1c2ef43
|
Carlos Eduardo Ramos
|
echo "|" . gettext("Error while writing file") . ".|";
|
80 |
0d6a185a
|
Scott Ullrich
|
} else {
|
81 |
a1c2ef43
|
Carlos Eduardo Ramos
|
echo "|" . gettext("File successfully saved") . ".|";
|
82 |
0d6a185a
|
Scott Ullrich
|
}
|
83 |
|
|
}
|
84 |
|
|
exit;
|
85 |
5124d619
|
Scott Ullrich
|
}
|
86 |
0d6a185a
|
Scott Ullrich
|
exit;
|
87 |
5124d619
|
Scott Ullrich
|
}
|
88 |
|
|
|
89 |
0d6a185a
|
Scott Ullrich
|
require("head.inc");
|
90 |
|
|
outputCSSFileInline("code-syntax-highlighter/SyntaxHighlighter.css");
|
91 |
|
|
outputJavaScriptFileInline("filebrowser/browser.js");
|
92 |
c13b0b31
|
Ermal
|
outputJavaScriptFileInline("javascript/base64.js");
|
93 |
5b237745
|
Scott Ullrich
|
|
94 |
|
|
?>
|
95 |
|
|
|
96 |
0d6a185a
|
Scott Ullrich
|
<body link="#000000" vlink="#000000" alink="#000000">
|
97 |
|
|
<?php include("fbegin.inc"); ?>
|
98 |
5b237745
|
Scott Ullrich
|
|
99 |
0d6a185a
|
Scott Ullrich
|
<script type="text/javascript">
|
100 |
|
|
function loadFile() {
|
101 |
e3c1ea9b
|
Vinicius Coque
|
jQuery("#fileStatus").html("<?=gettext("Loading file"); ?> ...");
|
102 |
|
|
jQuery("#fileStatusBox").show(500);
|
103 |
0d6a185a
|
Scott Ullrich
|
|
104 |
e3c1ea9b
|
Vinicius Coque
|
jQuery.ajax(
|
105 |
0d6a185a
|
Scott Ullrich
|
"<?=$_SERVER['SCRIPT_NAME'];?>", {
|
106 |
e3c1ea9b
|
Vinicius Coque
|
type: "post",
|
107 |
|
|
data: "action=load&file=" + jQuery("#fbTarget").val(),
|
108 |
|
|
complete: loadComplete
|
109 |
0d6a185a
|
Scott Ullrich
|
}
|
110 |
|
|
);
|
111 |
|
|
}
|
112 |
5b237745
|
Scott Ullrich
|
|
113 |
0d6a185a
|
Scott Ullrich
|
function loadComplete(req) {
|
114 |
e3c1ea9b
|
Vinicius Coque
|
jQuery("#fileContent").show(1000);
|
115 |
0d6a185a
|
Scott Ullrich
|
var values = req.responseText.split("|");
|
116 |
|
|
values.shift(); values.pop();
|
117 |
|
|
|
118 |
|
|
if(values.shift() == "0") {
|
119 |
|
|
var file = values.shift();
|
120 |
b71f0cbb
|
Ermal
|
var fileContent = Base64.decode(values.join("|"));
|
121 |
e3c1ea9b
|
Vinicius Coque
|
jQuery("#fileStatus").html("<?=gettext("File successfully loaded"); ?>.");
|
122 |
b71f0cbb
|
Ermal
|
jQuery("#fileContent").val(fileContent);
|
123 |
0d6a185a
|
Scott Ullrich
|
|
124 |
|
|
var lang = "none";
|
125 |
|
|
if(file.indexOf(".php") > 0) lang = "php";
|
126 |
|
|
else if(file.indexOf(".inc") > 0) lang = "php";
|
127 |
|
|
else if(file.indexOf(".xml") > 0) lang = "xml";
|
128 |
|
|
else if(file.indexOf(".js" ) > 0) lang = "js";
|
129 |
|
|
else if(file.indexOf(".css") > 0) lang = "css";
|
130 |
|
|
|
131 |
e3c1ea9b
|
Vinicius Coque
|
if(jQuery("#highlight").checked && lang != "none") {
|
132 |
|
|
jQuery("fileContent").prop("className",lang + ":showcolumns");
|
133 |
0d6a185a
|
Scott Ullrich
|
dp.SyntaxHighlighter.HighlightAll("fileContent", true, false);
|
134 |
|
|
}
|
135 |
|
|
}
|
136 |
|
|
else {
|
137 |
e3c1ea9b
|
Vinicius Coque
|
jQuery("#fileStatus").html(values[0]);
|
138 |
|
|
jQuery("#fileContent").val("");
|
139 |
0d6a185a
|
Scott Ullrich
|
}
|
140 |
e3c1ea9b
|
Vinicius Coque
|
jQuery("#fileContent").show(1000);
|
141 |
0d6a185a
|
Scott Ullrich
|
}
|
142 |
5b237745
|
Scott Ullrich
|
|
143 |
0d6a185a
|
Scott Ullrich
|
function saveFile(file) {
|
144 |
e3c1ea9b
|
Vinicius Coque
|
jQuery("#fileStatus").html("<?=gettext("Saving file"); ?> ...");
|
145 |
|
|
jQuery("#fileStatusBox").show(500);
|
146 |
df61b7b4
|
mcrane
|
|
147 |
e3c1ea9b
|
Vinicius Coque
|
var fileContent = Base64.encode(jQuery("#fileContent").val());
|
148 |
df61b7b4
|
mcrane
|
fileContent = fileContent.replace(/\+/g,"%2B");
|
149 |
|
|
|
150 |
e3c1ea9b
|
Vinicius Coque
|
jQuery.ajax(
|
151 |
0d6a185a
|
Scott Ullrich
|
"<?=$_SERVER['SCRIPT_NAME'];?>", {
|
152 |
e3c1ea9b
|
Vinicius Coque
|
type: "post",
|
153 |
|
|
data: "action=save&file=" + jQuery("#fbTarget").val() +
|
154 |
ee650539
|
Scott Ullrich
|
"&data=" + fileContent,
|
155 |
e3c1ea9b
|
Vinicius Coque
|
complete: function(req) {
|
156 |
0d6a185a
|
Scott Ullrich
|
var values = req.responseText.split("|");
|
157 |
e3c1ea9b
|
Vinicius Coque
|
jQuery("#fileStatus").html(values[1]);
|
158 |
0d6a185a
|
Scott Ullrich
|
}
|
159 |
|
|
}
|
160 |
|
|
);
|
161 |
|
|
}
|
162 |
|
|
</script>
|
163 |
5b237745
|
Scott Ullrich
|
|
164 |
0d6a185a
|
Scott Ullrich
|
<!-- file status box -->
|
165 |
|
|
<div style="display:none; background:#eeeeee;" id="fileStatusBox">
|
166 |
|
|
<div class="vexpl" style="padding-left:15px;">
|
167 |
|
|
<strong id="fileStatus"></strong>
|
168 |
|
|
</div>
|
169 |
|
|
</div>
|
170 |
48581bb7
|
Scott Ullrich
|
|
171 |
0d6a185a
|
Scott Ullrich
|
<br />
|
172 |
|
|
|
173 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
174 |
|
|
<tr>
|
175 |
|
|
<td class="tabcont" align="center">
|
176 |
|
|
|
177 |
|
|
<!-- controls -->
|
178 |
|
|
<table width="100%" cellpadding="9" cellspacing="9">
|
179 |
|
|
<tr>
|
180 |
|
|
<td align="center" class="list">
|
181 |
a1c2ef43
|
Carlos Eduardo Ramos
|
<?=gettext("Save / Load from path"); ?>:
|
182 |
0d6a185a
|
Scott Ullrich
|
<input type="text" class="formfld file" id="fbTarget" size="45" />
|
183 |
|
|
<input type="button" class="formbtn" onclick="loadFile();" value="<?=gettext('Load');?>" />
|
184 |
|
|
<input type="button" class="formbtn" id="fbOpen" value="<?=gettext('Browse');?>" />
|
185 |
|
|
<input type="button" class="formbtn" onclick="saveFile();" value="<?=gettext('Save');?>" />
|
186 |
|
|
<br />
|
187 |
fae0b511
|
Scott Ullrich
|
<?php
|
188 |
|
|
/*
|
189 |
|
|
<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
|
190 |
|
|
*/
|
191 |
|
|
?>
|
192 |
0d6a185a
|
Scott Ullrich
|
</td>
|
193 |
|
|
</tr>
|
194 |
|
|
</table>
|
195 |
2e8eada0
|
Scott Ullrich
|
|
196 |
0d6a185a
|
Scott Ullrich
|
<!-- filebrowser -->
|
197 |
|
|
<div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%;"></div>
|
198 |
|
|
|
199 |
|
|
<!-- file viewer/editor -->
|
200 |
|
|
<table width="100%">
|
201 |
|
|
<tr>
|
202 |
|
|
<td valign="top" class="label">
|
203 |
|
|
<div style="background:#eeeeee;" id="fileOutput">
|
204 |
|
|
<textarea id="fileContent" name="fileContent" style="width:100%;" rows="30" wrap="off"></textarea>
|
205 |
|
|
</div>
|
206 |
|
|
</td>
|
207 |
|
|
</tr>
|
208 |
|
|
</table>
|
209 |
2e8eada0
|
Scott Ullrich
|
|
210 |
0d6a185a
|
Scott Ullrich
|
</td>
|
211 |
|
|
</tr>
|
212 |
5124d619
|
Scott Ullrich
|
</table>
|
213 |
|
|
|
214 |
0d6a185a
|
Scott Ullrich
|
<script type="text/javascript" src="/code-syntax-highlighter/shCore.js"></script>
|
215 |
|
|
<script type="text/javascript" src="/code-syntax-highlighter/shBrushCss.js"></script>
|
216 |
|
|
<script type="text/javascript" src="/code-syntax-highlighter/shBrushJScript.js"></script>
|
217 |
|
|
<script type="text/javascript" src="/code-syntax-highlighter/shBrushPhp.js"></script>
|
218 |
|
|
<script type="text/javascript" src="/code-syntax-highlighter/shBrushXml.js"></script>
|
219 |
|
|
<script type="text/javascript">
|
220 |
e3c1ea9b
|
Vinicius Coque
|
jQuery(window).load(
|
221 |
0d6a185a
|
Scott Ullrich
|
function() {
|
222 |
e3c1ea9b
|
Vinicius Coque
|
jQuery("#fbTarget").focus();
|
223 |
0d6a185a
|
Scott Ullrich
|
|
224 |
|
|
NiftyCheck();
|
225 |
|
|
Rounded("div#fileStatusBox", "all", "#ffffff", "#eeeeee", "smooth");
|
226 |
|
|
}
|
227 |
|
|
);
|
228 |
|
|
|
229 |
|
|
<?php if($_GET['action'] == "load"): ?>
|
230 |
e3c1ea9b
|
Vinicius Coque
|
jQuery(window).load(
|
231 |
0d6a185a
|
Scott Ullrich
|
function() {
|
232 |
e3c1ea9b
|
Vinicius Coque
|
jQuery("#fbTarget").val("<?=$_GET['path'];?>");
|
233 |
0d6a185a
|
Scott Ullrich
|
loadFile();
|
234 |
|
|
}
|
235 |
|
|
);
|
236 |
|
|
<?php endif; ?>
|
237 |
|
|
</script>
|
238 |
ab541dbb
|
Scott Ullrich
|
|
239 |
2900e518
|
Scott Ullrich
|
<?php include("fend.inc"); ?>
|
240 |
5b237745
|
Scott Ullrich
|
</body>
|
241 |
|
|
</html>
|