Project

General

Profile

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