Project

General

Profile

Download (6.76 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	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
*/
29
/*
30
	pfSense_MODULE:	shell
31
*/
32

    
33
$pgtitle = array(gettext("Diagnostics"), gettext("Edit file"));
34
require("guiconfig.inc");
35

    
36
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
				$data = file_get_contents(urldecode($_REQUEST['file']));
47
				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
				conf_mount_rw();
59
				$_REQUEST['data'] = str_replace("\r", "", $_REQUEST['data']);
60
				$ret = file_put_contents($_REQUEST['file'], $_REQUEST['data']);
61
				conf_mount_ro();
62
				if($_REQUEST['file'] == "config.xml")
63
					if(file_exists("/tmp/config.cache"))
64
						unlink("/tmp/config.cache");
65
				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
	}
75
	exit;
76
}
77

    
78
require("head.inc");
79
outputCSSFileInline("code-syntax-highlighter/SyntaxHighlighter.css");
80
outputJavaScriptFileInline("filebrowser/browser.js");
81

    
82
?>
83

    
84
<body link="#000000" vlink="#000000" alink="#000000">
85
<?php include("fbegin.inc"); ?>
86

    
87
<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

    
101
	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
		new Effect.Appear("fileContent");
128
	}
129

    
130
	function saveFile(file) {
131
		$("fileStatus").innerHTML = "Saving file ...";
132
		Effect.Appear("fileStatusBox", { duration: 0.5 });
133
		
134
		var fileContent = escape($("fileContent").value);
135
		fileContent = fileContent.replace(/\+/g,"%2B");
136
		
137
		new Ajax.Request(
138
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
139
				method:     "post",
140
				postBody:   "action=save&file=" + $("fbTarget").value +
141
							"&data=" + fileContent,
142
				onComplete: function(req) {
143
					var values = req.responseText.split("|");
144
					$("fileStatus").innerHTML = values[1];
145
				}
146
			}
147
		);
148
	}
149
</script>
150

    
151
<!-- 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

    
158
<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
			<?php
175
			/*
176
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
177
			*/
178
			?>
179
		</td>
180
	</tr>
181
</table>
182

    
183
<!-- 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

    
197
		</td>
198
	</tr>
199
</table>
200

    
201
<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

    
228
<?php include("fend.inc"); ?>
229
</body>
230
</html>
(41-41/221)