Project

General

Profile

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