1
|
<?php
|
2
|
/*
|
3
|
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
|
*/
|
28
|
/*
|
29
|
pfSense_MODULE: shell
|
30
|
*/
|
31
|
|
32
|
##|+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
|
##|*MATCH=browser.php*
|
38
|
##|*MATCH=filebrowser/browser.php*
|
39
|
##|-PRIV
|
40
|
|
41
|
$pgtitle = array(gettext("Diagnostics"), gettext("Edit file"));
|
42
|
require("guiconfig.inc");
|
43
|
|
44
|
if($_POST['action']) {
|
45
|
switch($_POST['action']) {
|
46
|
case 'load':
|
47
|
if(strlen($_POST['file']) < 1) {
|
48
|
echo "|5|" . gettext("No file name specified") . ".|";
|
49
|
} elseif(is_dir($_POST['file'])) {
|
50
|
echo "|4|" . gettext("Loading a directory is not supported") . ".|";
|
51
|
} elseif(! is_file($_POST['file'])) {
|
52
|
echo "|3|" . gettext("File does not exist or is not a regular file") . ".|";
|
53
|
} else {
|
54
|
$data = file_get_contents(urldecode($_POST['file']));
|
55
|
if($data === false) {
|
56
|
echo "|1|" . gettext("Failed to read file") . ".|";
|
57
|
} else {
|
58
|
$data = base64_encode($data);
|
59
|
echo "|0|{$_POST['file']}|{$data}|";
|
60
|
}
|
61
|
}
|
62
|
exit;
|
63
|
case 'save':
|
64
|
if(strlen($_POST['file']) < 1) {
|
65
|
echo "|" . gettext("No file name specified") . ".|";
|
66
|
} else {
|
67
|
conf_mount_rw();
|
68
|
$_POST['data'] = str_replace("\r", "", base64_decode($_POST['data']));
|
69
|
$ret = file_put_contents($_POST['file'], $_POST['data']);
|
70
|
conf_mount_ro();
|
71
|
if($_POST['file'] == "/conf/config.xml" || $_POST['file'] == "/cf/conf/config.xml") {
|
72
|
if(file_exists("/tmp/config.cache"))
|
73
|
unlink("/tmp/config.cache");
|
74
|
disable_security_checks();
|
75
|
}
|
76
|
if($ret === false) {
|
77
|
echo "|" . gettext("Failed to write file") . ".|";
|
78
|
} elseif($ret <> strlen($_POST['data'])) {
|
79
|
echo "|" . gettext("Error while writing file") . ".|";
|
80
|
} else {
|
81
|
echo "|" . gettext("File successfully saved") . ".|";
|
82
|
}
|
83
|
}
|
84
|
exit;
|
85
|
}
|
86
|
exit;
|
87
|
}
|
88
|
|
89
|
$closehead = false;
|
90
|
require("head.inc");
|
91
|
outputCSSFileInline("code-syntax-highlighter/SyntaxHighlighter.css");
|
92
|
outputJavaScriptFileInline("filebrowser/browser.js");
|
93
|
outputJavaScriptFileInline("javascript/base64.js");
|
94
|
|
95
|
?>
|
96
|
</head>
|
97
|
<body link="#000000" vlink="#000000" alink="#000000">
|
98
|
<?php include("fbegin.inc"); ?>
|
99
|
|
100
|
<script type="text/javascript">
|
101
|
//<![CDATA[
|
102
|
function loadFile() {
|
103
|
jQuery("#fileStatus").html("<?=gettext("Loading file"); ?> ...");
|
104
|
jQuery("#fileStatusBox").show(500);
|
105
|
|
106
|
jQuery.ajax(
|
107
|
"<?=$_SERVER['SCRIPT_NAME'];?>", {
|
108
|
type: "post",
|
109
|
data: "action=load&file=" + jQuery("#fbTarget").val(),
|
110
|
complete: loadComplete
|
111
|
}
|
112
|
);
|
113
|
}
|
114
|
|
115
|
function loadComplete(req) {
|
116
|
jQuery("#fileContent").show(1000);
|
117
|
var values = req.responseText.split("|");
|
118
|
values.shift(); values.pop();
|
119
|
|
120
|
if(values.shift() == "0") {
|
121
|
var file = values.shift();
|
122
|
var fileContent = Base64.decode(values.join("|"));
|
123
|
jQuery("#fileStatus").html("<?=gettext("File successfully loaded"); ?>.");
|
124
|
jQuery("#fileContent").val(fileContent);
|
125
|
|
126
|
var lang = "none";
|
127
|
if(file.indexOf(".php") > 0) lang = "php";
|
128
|
else if(file.indexOf(".inc") > 0) lang = "php";
|
129
|
else if(file.indexOf(".xml") > 0) lang = "xml";
|
130
|
else if(file.indexOf(".js" ) > 0) lang = "js";
|
131
|
else if(file.indexOf(".css") > 0) lang = "css";
|
132
|
|
133
|
if(jQuery("#highlight").checked && lang != "none") {
|
134
|
jQuery("fileContent").prop("className",lang + ":showcolumns");
|
135
|
dp.SyntaxHighlighter.HighlightAll("fileContent", true, false);
|
136
|
}
|
137
|
}
|
138
|
else {
|
139
|
jQuery("#fileStatus").html(values[0]);
|
140
|
jQuery("#fileContent").val("");
|
141
|
}
|
142
|
jQuery("#fileContent").show(1000);
|
143
|
}
|
144
|
|
145
|
function saveFile(file) {
|
146
|
jQuery("#fileStatus").html("<?=gettext("Saving file"); ?> ...");
|
147
|
jQuery("#fileStatusBox").show(500);
|
148
|
|
149
|
var fileContent = Base64.encode(jQuery("#fileContent").val());
|
150
|
fileContent = fileContent.replace(/\+/g,"%2B");
|
151
|
|
152
|
jQuery.ajax(
|
153
|
"<?=$_SERVER['SCRIPT_NAME'];?>", {
|
154
|
type: "post",
|
155
|
data: "action=save&file=" + jQuery("#fbTarget").val() +
|
156
|
"&data=" + fileContent,
|
157
|
complete: function(req) {
|
158
|
var values = req.responseText.split("|");
|
159
|
jQuery("#fileStatus").html(values[1]);
|
160
|
}
|
161
|
}
|
162
|
);
|
163
|
}
|
164
|
//]]>
|
165
|
</script>
|
166
|
|
167
|
<!-- file status box -->
|
168
|
<div style="display:none; background:#eeeeee;" id="fileStatusBox">
|
169
|
<div class="vexpl" style="padding-left:15px;">
|
170
|
<strong id="fileStatus"></strong>
|
171
|
</div>
|
172
|
</div>
|
173
|
|
174
|
<br />
|
175
|
|
176
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="file editor">
|
177
|
<tr>
|
178
|
<td class="tabcont" align="center">
|
179
|
|
180
|
<!-- controls -->
|
181
|
<table width="100%" cellpadding="9" cellspacing="9" summary="controls">
|
182
|
<tr>
|
183
|
<td align="center" class="list">
|
184
|
<?=gettext("Save / Load from path"); ?>:
|
185
|
<input type="text" class="formfld file" id="fbTarget" size="45" />
|
186
|
<input type="button" class="formbtn" onclick="loadFile();" value="<?=gettext('Load');?>" />
|
187
|
<input type="button" class="formbtn" id="fbOpen" value="<?=gettext('Browse');?>" />
|
188
|
<input type="button" class="formbtn" onclick="saveFile();" value="<?=gettext('Save');?>" />
|
189
|
<br />
|
190
|
<?php
|
191
|
/*
|
192
|
<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
|
193
|
*/
|
194
|
?>
|
195
|
</td>
|
196
|
</tr>
|
197
|
</table>
|
198
|
|
199
|
<!-- filebrowser -->
|
200
|
<div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%;"></div>
|
201
|
|
202
|
<!-- file viewer/editor -->
|
203
|
<table width="100%" summary="file editor">
|
204
|
<tr>
|
205
|
<td valign="top">
|
206
|
<div style="background:#eeeeee;" id="fileOutput">
|
207
|
<script type="text/javascript">
|
208
|
//<![CDATA[
|
209
|
window.onload=function(){
|
210
|
document.getElementById("fileContent").wrap='off';
|
211
|
}
|
212
|
//]]>
|
213
|
</script>
|
214
|
<textarea id="fileContent" name="fileContent" style="width:100%;" rows="30" cols=""></textarea>
|
215
|
</div>
|
216
|
</td>
|
217
|
</tr>
|
218
|
</table>
|
219
|
|
220
|
</td>
|
221
|
</tr>
|
222
|
</table>
|
223
|
|
224
|
<script type="text/javascript" src="/code-syntax-highlighter/shCore.js"></script>
|
225
|
<script type="text/javascript" src="/code-syntax-highlighter/shBrushCss.js"></script>
|
226
|
<script type="text/javascript" src="/code-syntax-highlighter/shBrushJScript.js"></script>
|
227
|
<script type="text/javascript" src="/code-syntax-highlighter/shBrushPhp.js"></script>
|
228
|
<script type="text/javascript" src="/code-syntax-highlighter/shBrushXml.js"></script>
|
229
|
<script type="text/javascript">
|
230
|
//<![CDATA[
|
231
|
jQuery(window).load(
|
232
|
function() {
|
233
|
jQuery("#fbTarget").focus();
|
234
|
|
235
|
NiftyCheck();
|
236
|
Rounded("div#fileStatusBox", "all", "#ffffff", "#eeeeee", "smooth");
|
237
|
}
|
238
|
);
|
239
|
|
240
|
<?php if($_GET['action'] == "load"): ?>
|
241
|
jQuery(window).load(
|
242
|
function() {
|
243
|
jQuery("#fbTarget").val("<?=$_GET['path'];?>");
|
244
|
loadFile();
|
245
|
}
|
246
|
);
|
247
|
<?php endif; ?>
|
248
|
//]]>
|
249
|
</script>
|
250
|
|
251
|
<?php include("fend.inc"); ?>
|
252
|
</body>
|
253
|
</html>
|