Project

General

Profile

Download (7.69 KB) Statistics
| Branch: | Tag: | Revision:
1 447611c4 Scott Ullrich
<?php
2 a7f908db Scott Ullrich
/*
3 0d6a185a Scott Ullrich
	edit.php
4
	Copyright (C) 2004, 2005 Scott Ullrich
5 ed2d1343 Renato Botelho
        Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6 0d6a185a Scott Ullrich
	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 a7f908db Scott Ullrich
*/
29 7ac5a4cb Scott Ullrich
/*
30
	pfSense_MODULE:	shell
31
*/
32 a7f908db Scott Ullrich
33 9fbb3599 Ermal
##|+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 c0f613e2 Ermal
##|*MATCH=browser.php*
39
##|*MATCH=filebrowser/browser.php*
40 9fbb3599 Ermal
##|-PRIV
41
42 fdb38c10 Scott Ullrich
$pgtitle = array(gettext("Diagnostics"), gettext("Edit file"));
43 859329c8 Scott Ullrich
require("guiconfig.inc");
44
45 55344e2c Ermal
if($_POST['action']) {
46
	switch($_POST['action']) {
47 0d6a185a Scott Ullrich
		case 'load':
48 55344e2c Ermal
			if(strlen($_POST['file']) < 1) {
49 a1c2ef43 Carlos Eduardo Ramos
				echo "|5|" . gettext("No file name specified") . ".|";
50 55344e2c Ermal
			} elseif(is_dir($_POST['file'])) {
51 a1c2ef43 Carlos Eduardo Ramos
				echo "|4|" . gettext("Loading a directory is not supported") . ".|";
52 55344e2c Ermal
			} elseif(! is_file($_POST['file'])) {
53 a1c2ef43 Carlos Eduardo Ramos
				echo "|3|" . gettext("File does not exist or is not a regular file") . ".|";
54 0d6a185a Scott Ullrich
			} else {
55 55344e2c Ermal
				$data = file_get_contents(urldecode($_POST['file']));
56 0d6a185a Scott Ullrich
				if($data === false) {
57 a1c2ef43 Carlos Eduardo Ramos
					echo "|1|" . gettext("Failed to read file") . ".|";
58 0d6a185a Scott Ullrich
				} else {
59 b71f0cbb Ermal
					$data = base64_encode($data);
60 55344e2c Ermal
					echo "|0|{$_POST['file']}|{$data}|";	
61 0d6a185a Scott Ullrich
				}
62
			}
63
			exit;
64
		case 'save':
65 55344e2c Ermal
			if(strlen($_POST['file']) < 1) {
66 a1c2ef43 Carlos Eduardo Ramos
				echo "|" . gettext("No file name specified") . ".|";
67 0d6a185a Scott Ullrich
			} else {
68 5a557f44 jim-p
				conf_mount_rw();
69 55344e2c Ermal
				$_POST['data'] = str_replace("\r", "", base64_decode($_POST['data']));
70
				$ret = file_put_contents($_POST['file'], $_POST['data']);
71 5a557f44 jim-p
				conf_mount_ro();
72 55344e2c Ermal
				if($_POST['file'] == "/conf/config.xml" || $_POST['file'] == "/cf/conf/config.xml") {
73 5f05c1e8 Scott Ullrich
					if(file_exists("/tmp/config.cache"))
74
						unlink("/tmp/config.cache");
75 0f806eca Erik Fonnesbeck
					disable_security_checks();
76
				}
77 0d6a185a Scott Ullrich
				if($ret === false) {
78 a1c2ef43 Carlos Eduardo Ramos
					echo "|" . gettext("Failed to write file") . ".|";
79 55344e2c Ermal
				} elseif($ret <> strlen($_POST['data'])) {
80 a1c2ef43 Carlos Eduardo Ramos
					echo "|" . gettext("Error while writing file") . ".|";
81 0d6a185a Scott Ullrich
				} else {
82 a1c2ef43 Carlos Eduardo Ramos
					echo "|" . gettext("File successfully saved") . ".|";
83 0d6a185a Scott Ullrich
				}
84
			}
85
			exit;
86 5124d619 Scott Ullrich
	}
87 0d6a185a Scott Ullrich
	exit;
88 5124d619 Scott Ullrich
}
89
90 74286b9e Colin Fleming
$closehead = false;
91 0d6a185a Scott Ullrich
require("head.inc");
92
outputCSSFileInline("code-syntax-highlighter/SyntaxHighlighter.css");
93
outputJavaScriptFileInline("filebrowser/browser.js");
94 c13b0b31 Ermal
outputJavaScriptFileInline("javascript/base64.js");
95 5b237745 Scott Ullrich
96
?>
97 74286b9e Colin Fleming
</head>
98 0d6a185a Scott Ullrich
<body link="#000000" vlink="#000000" alink="#000000">
99
<?php include("fbegin.inc"); ?>
100 5b237745 Scott Ullrich
101 0d6a185a Scott Ullrich
<script type="text/javascript">	
102 74286b9e Colin Fleming
//<![CDATA[
103 0d6a185a Scott Ullrich
	function loadFile() {
104 e3c1ea9b Vinicius Coque
		jQuery("#fileStatus").html("<?=gettext("Loading file"); ?> ...");
105
		jQuery("#fileStatusBox").show(500);
106 0d6a185a Scott Ullrich
107 e3c1ea9b Vinicius Coque
		jQuery.ajax(
108 0d6a185a Scott Ullrich
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
109 e3c1ea9b Vinicius Coque
				type: "post",
110
				data: "action=load&file=" + jQuery("#fbTarget").val(),
111
				complete: loadComplete
112 0d6a185a Scott Ullrich
			}
113
		);
114
	}
115 5b237745 Scott Ullrich
116 0d6a185a Scott Ullrich
	function loadComplete(req) {
117 e3c1ea9b Vinicius Coque
		jQuery("#fileContent").show(1000);
118 0d6a185a Scott Ullrich
		var values = req.responseText.split("|");
119
		values.shift(); values.pop();
120
121
		if(values.shift() == "0") {
122
			var file = values.shift();
123 b71f0cbb Ermal
			var fileContent = Base64.decode(values.join("|"));
124 e3c1ea9b Vinicius Coque
			jQuery("#fileStatus").html("<?=gettext("File successfully loaded"); ?>.");
125 b71f0cbb Ermal
			jQuery("#fileContent").val(fileContent);
126 0d6a185a Scott Ullrich
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 e3c1ea9b Vinicius Coque
			if(jQuery("#highlight").checked && lang != "none") {
135
				jQuery("fileContent").prop("className",lang + ":showcolumns");
136 0d6a185a Scott Ullrich
				dp.SyntaxHighlighter.HighlightAll("fileContent", true, false);
137
			}
138
		}
139
		else {
140 e3c1ea9b Vinicius Coque
			jQuery("#fileStatus").html(values[0]);
141
			jQuery("#fileContent").val("");
142 0d6a185a Scott Ullrich
		}
143 e3c1ea9b Vinicius Coque
		jQuery("#fileContent").show(1000);
144 0d6a185a Scott Ullrich
	}
145 5b237745 Scott Ullrich
146 0d6a185a Scott Ullrich
	function saveFile(file) {
147 e3c1ea9b Vinicius Coque
		jQuery("#fileStatus").html("<?=gettext("Saving file"); ?> ...");
148
		jQuery("#fileStatusBox").show(500);
149 df61b7b4 mcrane
		
150 e3c1ea9b Vinicius Coque
		var fileContent = Base64.encode(jQuery("#fileContent").val());
151 df61b7b4 mcrane
		fileContent = fileContent.replace(/\+/g,"%2B");
152
		
153 e3c1ea9b Vinicius Coque
		jQuery.ajax(
154 0d6a185a Scott Ullrich
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
155 e3c1ea9b Vinicius Coque
				type: "post",
156
				data: "action=save&file=" + jQuery("#fbTarget").val() +
157 ee650539 Scott Ullrich
							"&data=" + fileContent,
158 e3c1ea9b Vinicius Coque
				complete: function(req) {
159 0d6a185a Scott Ullrich
					var values = req.responseText.split("|");
160 e3c1ea9b Vinicius Coque
					jQuery("#fileStatus").html(values[1]);
161 0d6a185a Scott Ullrich
				}
162
			}
163
		);
164
	}
165 74286b9e Colin Fleming
//]]>
166 0d6a185a Scott Ullrich
</script>
167 5b237745 Scott Ullrich
168 0d6a185a Scott Ullrich
<!-- 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 48581bb7 Scott Ullrich
175 0d6a185a Scott Ullrich
<br />
176
177 74286b9e Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="file editor">
178 0d6a185a Scott Ullrich
	<tr>
179
		<td class="tabcont" align="center">
180
181
<!-- controls -->
182 74286b9e Colin Fleming
<table width="100%" cellpadding="9" cellspacing="9" summary="controls">
183 0d6a185a Scott Ullrich
	<tr>
184
		<td align="center" class="list">
185 a1c2ef43 Carlos Eduardo Ramos
			<?=gettext("Save / Load from path"); ?>:
186 0d6a185a Scott Ullrich
			<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 fae0b511 Scott Ullrich
			<?php
192
			/*
193
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
194
			*/
195
			?>
196 0d6a185a Scott Ullrich
		</td>
197
	</tr>
198
</table>
199 2e8eada0 Scott Ullrich
200 0d6a185a Scott Ullrich
<!-- filebrowser -->
201
<div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%;"></div>
202
203
<!-- file viewer/editor -->
204 74286b9e Colin Fleming
<table width="100%" summary="file editor">
205 0d6a185a Scott Ullrich
	<tr>
206 4fd09104 Charlie Marshall
		<td valign="top">
207 0d6a185a Scott Ullrich
			<div style="background:#eeeeee;" id="fileOutput">
208 74286b9e Colin Fleming
				<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 0d6a185a Scott Ullrich
			</div>
217
		</td>
218
	</tr>
219
</table>
220 2e8eada0 Scott Ullrich
221 0d6a185a Scott Ullrich
		</td>
222
	</tr>
223 5124d619 Scott Ullrich
</table>
224
225 0d6a185a Scott Ullrich
<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 74286b9e Colin Fleming
//<![CDATA[
232 e3c1ea9b Vinicius Coque
	jQuery(window).load(
233 0d6a185a Scott Ullrich
		function() {
234 e3c1ea9b Vinicius Coque
			jQuery("#fbTarget").focus();
235 0d6a185a Scott Ullrich
236
			NiftyCheck();
237
			Rounded("div#fileStatusBox", "all", "#ffffff", "#eeeeee", "smooth");
238
		}
239
	);
240
241
	<?php if($_GET['action'] == "load"): ?>
242 e3c1ea9b Vinicius Coque
		jQuery(window).load(
243 0d6a185a Scott Ullrich
			function() {
244 ae38cb75 Renato Botelho
				jQuery("#fbTarget").val("<?=htmlspecialchars($_GET['path']);?>");
245 0d6a185a Scott Ullrich
				loadFile();
246
			}
247
		);
248
	<?php endif; ?>
249 74286b9e Colin Fleming
//]]>
250 0d6a185a Scott Ullrich
</script>
251 ab541dbb Scott Ullrich
252 2900e518 Scott Ullrich
<?php include("fend.inc"); ?>
253 5b237745 Scott Ullrich
</body>
254
</html>