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