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