Project

General

Profile

Download (7.61 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
	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 74286b9e Colin Fleming
$closehead = false;
90 0d6a185a Scott Ullrich
require("head.inc");
91
outputCSSFileInline("code-syntax-highlighter/SyntaxHighlighter.css");
92
outputJavaScriptFileInline("filebrowser/browser.js");
93 c13b0b31 Ermal
outputJavaScriptFileInline("javascript/base64.js");
94 5b237745 Scott Ullrich
95
?>
96 74286b9e Colin Fleming
</head>
97 0d6a185a Scott Ullrich
<body link="#000000" vlink="#000000" alink="#000000">
98
<?php include("fbegin.inc"); ?>
99 5b237745 Scott Ullrich
100 0d6a185a Scott Ullrich
<script type="text/javascript">	
101 74286b9e Colin Fleming
//<![CDATA[
102 0d6a185a Scott Ullrich
	function loadFile() {
103 e3c1ea9b Vinicius Coque
		jQuery("#fileStatus").html("<?=gettext("Loading file"); ?> ...");
104
		jQuery("#fileStatusBox").show(500);
105 0d6a185a Scott Ullrich
106 e3c1ea9b Vinicius Coque
		jQuery.ajax(
107 0d6a185a Scott Ullrich
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
108 e3c1ea9b Vinicius Coque
				type: "post",
109
				data: "action=load&file=" + jQuery("#fbTarget").val(),
110
				complete: loadComplete
111 0d6a185a Scott Ullrich
			}
112
		);
113
	}
114 5b237745 Scott Ullrich
115 0d6a185a Scott Ullrich
	function loadComplete(req) {
116 e3c1ea9b Vinicius Coque
		jQuery("#fileContent").show(1000);
117 0d6a185a Scott Ullrich
		var values = req.responseText.split("|");
118
		values.shift(); values.pop();
119
120
		if(values.shift() == "0") {
121
			var file = values.shift();
122 b71f0cbb Ermal
			var fileContent = Base64.decode(values.join("|"));
123 e3c1ea9b Vinicius Coque
			jQuery("#fileStatus").html("<?=gettext("File successfully loaded"); ?>.");
124 b71f0cbb Ermal
			jQuery("#fileContent").val(fileContent);
125 0d6a185a Scott Ullrich
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 e3c1ea9b Vinicius Coque
			if(jQuery("#highlight").checked && lang != "none") {
134
				jQuery("fileContent").prop("className",lang + ":showcolumns");
135 0d6a185a Scott Ullrich
				dp.SyntaxHighlighter.HighlightAll("fileContent", true, false);
136
			}
137
		}
138
		else {
139 e3c1ea9b Vinicius Coque
			jQuery("#fileStatus").html(values[0]);
140
			jQuery("#fileContent").val("");
141 0d6a185a Scott Ullrich
		}
142 e3c1ea9b Vinicius Coque
		jQuery("#fileContent").show(1000);
143 0d6a185a Scott Ullrich
	}
144 5b237745 Scott Ullrich
145 0d6a185a Scott Ullrich
	function saveFile(file) {
146 e3c1ea9b Vinicius Coque
		jQuery("#fileStatus").html("<?=gettext("Saving file"); ?> ...");
147
		jQuery("#fileStatusBox").show(500);
148 df61b7b4 mcrane
		
149 e3c1ea9b Vinicius Coque
		var fileContent = Base64.encode(jQuery("#fileContent").val());
150 df61b7b4 mcrane
		fileContent = fileContent.replace(/\+/g,"%2B");
151
		
152 e3c1ea9b Vinicius Coque
		jQuery.ajax(
153 0d6a185a Scott Ullrich
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
154 e3c1ea9b Vinicius Coque
				type: "post",
155
				data: "action=save&file=" + jQuery("#fbTarget").val() +
156 ee650539 Scott Ullrich
							"&data=" + fileContent,
157 e3c1ea9b Vinicius Coque
				complete: function(req) {
158 0d6a185a Scott Ullrich
					var values = req.responseText.split("|");
159 e3c1ea9b Vinicius Coque
					jQuery("#fileStatus").html(values[1]);
160 0d6a185a Scott Ullrich
				}
161
			}
162
		);
163
	}
164 74286b9e Colin Fleming
//]]>
165 0d6a185a Scott Ullrich
</script>
166 5b237745 Scott Ullrich
167 0d6a185a Scott Ullrich
<!-- 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 48581bb7 Scott Ullrich
174 0d6a185a Scott Ullrich
<br />
175
176 74286b9e Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="file editor">
177 0d6a185a Scott Ullrich
	<tr>
178
		<td class="tabcont" align="center">
179
180
<!-- controls -->
181 74286b9e Colin Fleming
<table width="100%" cellpadding="9" cellspacing="9" summary="controls">
182 0d6a185a Scott Ullrich
	<tr>
183
		<td align="center" class="list">
184 a1c2ef43 Carlos Eduardo Ramos
			<?=gettext("Save / Load from path"); ?>:
185 0d6a185a Scott Ullrich
			<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 fae0b511 Scott Ullrich
			<?php
191
			/*
192
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
193
			*/
194
			?>
195 0d6a185a Scott Ullrich
		</td>
196
	</tr>
197
</table>
198 2e8eada0 Scott Ullrich
199 0d6a185a Scott Ullrich
<!-- filebrowser -->
200
<div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%;"></div>
201
202
<!-- file viewer/editor -->
203 74286b9e Colin Fleming
<table width="100%" summary="file editor">
204 0d6a185a Scott Ullrich
	<tr>
205 4fd09104 Charlie Marshall
		<td valign="top">
206 0d6a185a Scott Ullrich
			<div style="background:#eeeeee;" id="fileOutput">
207 74286b9e Colin Fleming
				<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 0d6a185a Scott Ullrich
			</div>
216
		</td>
217
	</tr>
218
</table>
219 2e8eada0 Scott Ullrich
220 0d6a185a Scott Ullrich
		</td>
221
	</tr>
222 5124d619 Scott Ullrich
</table>
223
224 0d6a185a Scott Ullrich
<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 74286b9e Colin Fleming
//<![CDATA[
231 e3c1ea9b Vinicius Coque
	jQuery(window).load(
232 0d6a185a Scott Ullrich
		function() {
233 e3c1ea9b Vinicius Coque
			jQuery("#fbTarget").focus();
234 0d6a185a Scott Ullrich
235
			NiftyCheck();
236
			Rounded("div#fileStatusBox", "all", "#ffffff", "#eeeeee", "smooth");
237
		}
238
	);
239
240
	<?php if($_GET['action'] == "load"): ?>
241 e3c1ea9b Vinicius Coque
		jQuery(window).load(
242 0d6a185a Scott Ullrich
			function() {
243 e3c1ea9b Vinicius Coque
				jQuery("#fbTarget").val("<?=$_GET['path'];?>");
244 0d6a185a Scott Ullrich
				loadFile();
245
			}
246
		);
247
	<?php endif; ?>
248 74286b9e Colin Fleming
//]]>
249 0d6a185a Scott Ullrich
</script>
250 ab541dbb Scott Ullrich
251 2900e518 Scott Ullrich
<?php include("fend.inc"); ?>
252 5b237745 Scott Ullrich
</body>
253
</html>