Project

General

Profile

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

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

    
35
if($_REQUEST['action']) {
36
	switch($_REQUEST['action']) {
37
		case 'load':
38
			if(strlen($_REQUEST['file']) < 1) {
39
				echo "|5|" . gettext("No file name specified") . ".|";
40
			} elseif(is_dir($_REQUEST['file'])) {
41
				echo "|4|" . gettext("Loading a directory is not supported") . ".|";
42
			} elseif(! is_file($_REQUEST['file'])) {
43
				echo "|3|" . gettext("File does not exist or is not a regular file") . ".|";
44
			} else {
45
				$data = file_get_contents(urldecode($_REQUEST['file']));
46
				if($data === false) {
47
					echo "|1|" . gettext("Failed to read file") . ".|";
48
				} else {
49
					echo "|0|{$_REQUEST['file']}|{$data}|";	
50
				}
51
			}
52
			exit;
53
		case 'save':
54
			if(strlen($_REQUEST['file']) < 1) {
55
				echo "|" . gettext("No file name specified") . ".|";
56
			} else {
57
				conf_mount_rw();
58
				$_REQUEST['data'] = str_replace("\r", "", base64_decode($_REQUEST['data']));
59
				$ret = file_put_contents($_REQUEST['file'], $_REQUEST['data']);
60
				conf_mount_ro();
61
				if($_REQUEST['file'] == "/conf/config.xml" || $_REQUEST['file'] == "/cf/conf/config.xml") {
62
					if(file_exists("/tmp/config.cache"))
63
						unlink("/tmp/config.cache");
64
					disable_security_checks();
65
				}
66
				if($ret === false) {
67
					echo "|" . gettext("Failed to write file") . ".|";
68
				} elseif($ret <> strlen($_REQUEST['data'])) {
69
					echo "|" . gettext("Error while writing file") . ".|";
70
				} else {
71
					echo "|" . gettext("File successfully saved") . ".|";
72
				}
73
			}
74
			exit;
75
	}
76
	exit;
77
}
78

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

    
84
?>
85

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

    
89
<script type="text/javascript">	
90
	function loadFile() {
91
		$("fileStatus").innerHTML = "<?=gettext("Loading file"); ?> ...";
92
		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

    
103
	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
			$("fileStatus").innerHTML = "<?=gettext("File successfully loaded"); ?>.";
111
			$("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
		new Effect.Appear("fileContent");
130
	}
131

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

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

    
160
<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
			<?=gettext("Save / Load from path"); ?>:
171
			<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
			<?php
177
			/*
178
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
179
			*/
180
			?>
181
		</td>
182
	</tr>
183
</table>
184

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

    
199
		</td>
200
	</tr>
201
</table>
202

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

    
230
<?php include("fend.inc"); ?>
231
</body>
232
</html>
(43-43/222)