Project

General

Profile

Download (7.29 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
##|-PRIV
38
39 fdb38c10 Scott Ullrich
$pgtitle = array(gettext("Diagnostics"), gettext("Edit file"));
40 859329c8 Scott Ullrich
require("guiconfig.inc");
41
42 0d6a185a Scott Ullrich
if($_REQUEST['action']) {
43
	switch($_REQUEST['action']) {
44
		case 'load':
45
			if(strlen($_REQUEST['file']) < 1) {
46 a1c2ef43 Carlos Eduardo Ramos
				echo "|5|" . gettext("No file name specified") . ".|";
47 0d6a185a Scott Ullrich
			} elseif(is_dir($_REQUEST['file'])) {
48 a1c2ef43 Carlos Eduardo Ramos
				echo "|4|" . gettext("Loading a directory is not supported") . ".|";
49 0d6a185a Scott Ullrich
			} elseif(! is_file($_REQUEST['file'])) {
50 a1c2ef43 Carlos Eduardo Ramos
				echo "|3|" . gettext("File does not exist or is not a regular file") . ".|";
51 0d6a185a Scott Ullrich
			} else {
52 bd125eb2 Scott Ullrich
				$data = file_get_contents(urldecode($_REQUEST['file']));
53 0d6a185a Scott Ullrich
				if($data === false) {
54 a1c2ef43 Carlos Eduardo Ramos
					echo "|1|" . gettext("Failed to read file") . ".|";
55 0d6a185a Scott Ullrich
				} else {
56
					echo "|0|{$_REQUEST['file']}|{$data}|";	
57
				}
58
			}
59
			exit;
60
		case 'save':
61
			if(strlen($_REQUEST['file']) < 1) {
62 a1c2ef43 Carlos Eduardo Ramos
				echo "|" . gettext("No file name specified") . ".|";
63 0d6a185a Scott Ullrich
			} else {
64 5a557f44 jim-p
				conf_mount_rw();
65 c13b0b31 Ermal
				$_REQUEST['data'] = str_replace("\r", "", base64_decode($_REQUEST['data']));
66 0d6a185a Scott Ullrich
				$ret = file_put_contents($_REQUEST['file'], $_REQUEST['data']);
67 5a557f44 jim-p
				conf_mount_ro();
68 0f806eca Erik Fonnesbeck
				if($_REQUEST['file'] == "/conf/config.xml" || $_REQUEST['file'] == "/cf/conf/config.xml") {
69 5f05c1e8 Scott Ullrich
					if(file_exists("/tmp/config.cache"))
70
						unlink("/tmp/config.cache");
71 0f806eca Erik Fonnesbeck
					disable_security_checks();
72
				}
73 0d6a185a Scott Ullrich
				if($ret === false) {
74 a1c2ef43 Carlos Eduardo Ramos
					echo "|" . gettext("Failed to write file") . ".|";
75 0d6a185a Scott Ullrich
				} elseif($ret <> strlen($_REQUEST['data'])) {
76 a1c2ef43 Carlos Eduardo Ramos
					echo "|" . gettext("Error while writing file") . ".|";
77 0d6a185a Scott Ullrich
				} else {
78 a1c2ef43 Carlos Eduardo Ramos
					echo "|" . gettext("File successfully saved") . ".|";
79 0d6a185a Scott Ullrich
				}
80
			}
81
			exit;
82 5124d619 Scott Ullrich
	}
83 0d6a185a Scott Ullrich
	exit;
84 5124d619 Scott Ullrich
}
85
86 0d6a185a Scott Ullrich
require("head.inc");
87
outputCSSFileInline("code-syntax-highlighter/SyntaxHighlighter.css");
88
outputJavaScriptFileInline("filebrowser/browser.js");
89 c13b0b31 Ermal
outputJavaScriptFileInline("javascript/base64.js");
90 5b237745 Scott Ullrich
91
?>
92
93 0d6a185a Scott Ullrich
<body link="#000000" vlink="#000000" alink="#000000">
94
<?php include("fbegin.inc"); ?>
95 5b237745 Scott Ullrich
96 0d6a185a Scott Ullrich
<script type="text/javascript">	
97
	function loadFile() {
98 a1c2ef43 Carlos Eduardo Ramos
		$("fileStatus").innerHTML = "<?=gettext("Loading file"); ?> ...";
99 0d6a185a Scott Ullrich
		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 5b237745 Scott Ullrich
110 0d6a185a Scott Ullrich
	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 a1c2ef43 Carlos Eduardo Ramos
			$("fileStatus").innerHTML = "<?=gettext("File successfully loaded"); ?>.";
118 0d6a185a Scott Ullrich
			$("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 ccce75df Scott Ullrich
		new Effect.Appear("fileContent");
137 0d6a185a Scott Ullrich
	}
138 5b237745 Scott Ullrich
139 0d6a185a Scott Ullrich
	function saveFile(file) {
140 a1c2ef43 Carlos Eduardo Ramos
		$("fileStatus").innerHTML = "<?=gettext("Saving file"); ?> ...";
141 0d6a185a Scott Ullrich
		Effect.Appear("fileStatusBox", { duration: 0.5 });
142 df61b7b4 mcrane
		
143 c13b0b31 Ermal
		var fileContent = Base64.encode($("fileContent").value);
144 df61b7b4 mcrane
		fileContent = fileContent.replace(/\+/g,"%2B");
145
		
146 0d6a185a Scott Ullrich
		new Ajax.Request(
147
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
148
				method:     "post",
149
				postBody:   "action=save&file=" + $("fbTarget").value +
150 ee650539 Scott Ullrich
							"&data=" + fileContent,
151 0d6a185a Scott Ullrich
				onComplete: function(req) {
152
					var values = req.responseText.split("|");
153
					$("fileStatus").innerHTML = values[1];
154
				}
155
			}
156
		);
157
	}
158
</script>
159 5b237745 Scott Ullrich
160 0d6a185a Scott Ullrich
<!-- 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 48581bb7 Scott Ullrich
167 0d6a185a Scott Ullrich
<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 a1c2ef43 Carlos Eduardo Ramos
			<?=gettext("Save / Load from path"); ?>:
178 0d6a185a Scott Ullrich
			<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 fae0b511 Scott Ullrich
			<?php
184
			/*
185
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
186
			*/
187
			?>
188 0d6a185a Scott Ullrich
		</td>
189
	</tr>
190
</table>
191 2e8eada0 Scott Ullrich
192 0d6a185a Scott Ullrich
<!-- 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 2e8eada0 Scott Ullrich
206 0d6a185a Scott Ullrich
		</td>
207
	</tr>
208 5124d619 Scott Ullrich
</table>
209
210 0d6a185a Scott Ullrich
<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 ab541dbb Scott Ullrich
237 2900e518 Scott Ullrich
<?php include("fend.inc"); ?>
238 5b237745 Scott Ullrich
</body>
239
</html>