Project

General

Profile

Download (6.69 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
				$ret = file_put_contents($_REQUEST['file'], $_REQUEST['data']);
60
				conf_mount_ro();
61
				if($_REQUEST['file'] == "config.xml")
62
					if(file_exists("/tmp/config.cache"))
63
						unlink("/tmp/config.cache");
64
				if($ret === false) {
65
					echo "|Failed to write file.|";
66
				} elseif($ret <> strlen($_REQUEST['data'])) {
67
					echo "|Error while writing file.|";
68
				} else {
69
					echo "|File successfully saved.|";
70
				}
71
			}
72
			exit;
73
	}
74
	exit;
75
}
76

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

    
81
?>
82

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

    
86
<script type="text/javascript">	
87
	function loadFile() {
88
		$("fileStatus").innerHTML = "Loading file ...";
89
		Effect.Appear("fileStatusBox", { duration: 0.5 });
90

    
91
		new Ajax.Request(
92
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
93
				method:     "post",
94
				postBody:   "action=load&file=" + $("fbTarget").value,
95
				onComplete: loadComplete
96
			}
97
		);
98
	}
99

    
100
	function loadComplete(req) {
101
		Element.show("fileContent")
102
		var values = req.responseText.split("|");
103
		values.shift(); values.pop();
104

    
105
		if(values.shift() == "0") {
106
			var file = values.shift();
107
			$("fileStatus").innerHTML = "File successfully loaded.";
108
			$("fileContent").value    = values.join("|");
109

    
110
			var lang = "none";
111
				 if(file.indexOf(".php") > 0) lang = "php";
112
			else if(file.indexOf(".inc") > 0) lang = "php";
113
			else if(file.indexOf(".xml") > 0) lang = "xml";
114
			else if(file.indexOf(".js" ) > 0) lang = "js";
115
			else if(file.indexOf(".css") > 0) lang = "css";
116

    
117
			if($("highlight").checked && lang != "none") {
118
				$("fileContent").className = lang + ":showcolumns";
119
				dp.SyntaxHighlighter.HighlightAll("fileContent", true, false);
120
			}
121
		}
122
		else {
123
			$("fileStatus").innerHTML = values[0];
124
			$("fileContent").value = "";
125
		}
126
		new Effect.Appear("fileContent");
127
	}
128

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

    
150
<!-- file status box -->
151
<div style="display:none; background:#eeeeee;" id="fileStatusBox">
152
	<div class="vexpl" style="padding-left:15px;">
153
		<strong id="fileStatus"></strong>
154
	</div>
155
</div>
156

    
157
<br />
158

    
159
<table width="100%" border="0" cellpadding="0" cellspacing="0">
160
	<tr>
161
		<td class="tabcont" align="center">
162

    
163
<!-- controls -->
164
<table width="100%" cellpadding="9" cellspacing="9">
165
	<tr>
166
		<td align="center" class="list">
167
			Save / Load from path:
168
			<input type="text"   class="formfld file" id="fbTarget"         size="45" />
169
			<input type="button" class="formbtn"      onclick="loadFile();" value="<?=gettext('Load');?>" />
170
			<input type="button" class="formbtn"      id="fbOpen"           value="<?=gettext('Browse');?>" />
171
			<input type="button" class="formbtn"      onclick="saveFile();" value="<?=gettext('Save');?>" />
172
			<br />
173
			<?php
174
			/*
175
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
176
			*/
177
			?>
178
		</td>
179
	</tr>
180
</table>
181

    
182
<!-- filebrowser -->
183
<div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%;"></div>
184

    
185
<!-- file viewer/editor -->
186
<table width="100%">
187
	<tr>
188
		<td valign="top" class="label">
189
			<div style="background:#eeeeee;" id="fileOutput">
190
				<textarea id="fileContent" name="fileContent" style="width:100%;" rows="30" wrap="off"></textarea>
191
			</div>
192
		</td>
193
	</tr>
194
</table>
195

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

    
200
<script type="text/javascript" src="/code-syntax-highlighter/shCore.js"></script>
201
<script type="text/javascript" src="/code-syntax-highlighter/shBrushCss.js"></script>
202
<script type="text/javascript" src="/code-syntax-highlighter/shBrushJScript.js"></script>
203
<script type="text/javascript" src="/code-syntax-highlighter/shBrushPhp.js"></script>
204
<script type="text/javascript" src="/code-syntax-highlighter/shBrushXml.js"></script>
205
<script type="text/javascript">
206
	Event.observe(
207
		window, "load",
208
		function() {
209
			$("fbTarget").focus();
210

    
211
			NiftyCheck();
212
			Rounded("div#fileStatusBox", "all", "#ffffff", "#eeeeee", "smooth");
213
		}
214
	);
215

    
216
	<?php if($_GET['action'] == "load"): ?>
217
		Event.observe(
218
			window, "load",
219
			function() {
220
				$("fbTarget").value = "<?=$_GET['path'];?>";
221
				loadFile();
222
			}
223
		);
224
	<?php endif; ?>
225
</script>
226

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