Project

General

Profile

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

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

    
79
?>
80

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

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

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

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

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

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

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

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

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

    
155
<br />
156

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

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

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

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

    
194
		</td>
195
	</tr>
196
</table>
197

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

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

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

    
225
<?php include("fend.inc"); ?>
226
</body>
227
</html>
(39-39/217)