Projet

Général

Profil

Télécharger (7,33 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / edit.php @ 0fab7eb1

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
##|+PRIV
33
##|*IDENT=page-diagnostics-edit
34
##|*NAME=Diagnostics: Edit FIle
35
##|*DESCR=Allow access to the 'Diagnostics: Edit File' page.
36
##|*MATCH=edit.php*
37
##|*MATCH=browser.php*
38
##|*MATCH=filebrowser/browser.php*
39
##|-PRIV
40

    
41
$pgtitle = array(gettext("Diagnostics"), gettext("Edit file"));
42
require("guiconfig.inc");
43

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

    
89
require("head.inc");
90
outputCSSFileInline("code-syntax-highlighter/SyntaxHighlighter.css");
91
outputJavaScriptFileInline("filebrowser/browser.js");
92
outputJavaScriptFileInline("javascript/base64.js");
93

    
94
?>
95

    
96
<body link="#000000" vlink="#000000" alink="#000000">
97
<?php include("fbegin.inc"); ?>
98

    
99
<script type="text/javascript">	
100
	function loadFile() {
101
		jQuery("#fileStatus").html("<?=gettext("Loading file"); ?> ...");
102
		jQuery("#fileStatusBox").show(500);
103

    
104
		jQuery.ajax(
105
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
106
				type: "post",
107
				data: "action=load&file=" + jQuery("#fbTarget").val(),
108
				complete: loadComplete
109
			}
110
		);
111
	}
112

    
113
	function loadComplete(req) {
114
		jQuery("#fileContent").show(1000);
115
		var values = req.responseText.split("|");
116
		values.shift(); values.pop();
117

    
118
		if(values.shift() == "0") {
119
			var file = values.shift();
120
			var fileContent = Base64.decode(values.join("|"));
121
			jQuery("#fileStatus").html("<?=gettext("File successfully loaded"); ?>.");
122
			jQuery("#fileContent").val(fileContent);
123

    
124
			var lang = "none";
125
				 if(file.indexOf(".php") > 0) lang = "php";
126
			else if(file.indexOf(".inc") > 0) lang = "php";
127
			else if(file.indexOf(".xml") > 0) lang = "xml";
128
			else if(file.indexOf(".js" ) > 0) lang = "js";
129
			else if(file.indexOf(".css") > 0) lang = "css";
130

    
131
			if(jQuery("#highlight").checked && lang != "none") {
132
				jQuery("fileContent").prop("className",lang + ":showcolumns");
133
				dp.SyntaxHighlighter.HighlightAll("fileContent", true, false);
134
			}
135
		}
136
		else {
137
			jQuery("#fileStatus").html(values[0]);
138
			jQuery("#fileContent").val("");
139
		}
140
		jQuery("#fileContent").show(1000);
141
	}
142

    
143
	function saveFile(file) {
144
		jQuery("#fileStatus").html("<?=gettext("Saving file"); ?> ...");
145
		jQuery("#fileStatusBox").show(500);
146
		
147
		var fileContent = Base64.encode(jQuery("#fileContent").val());
148
		fileContent = fileContent.replace(/\+/g,"%2B");
149
		
150
		jQuery.ajax(
151
			"<?=$_SERVER['SCRIPT_NAME'];?>", {
152
				type: "post",
153
				data: "action=save&file=" + jQuery("#fbTarget").val() +
154
							"&data=" + fileContent,
155
				complete: function(req) {
156
					var values = req.responseText.split("|");
157
					jQuery("#fileStatus").html(values[1]);
158
				}
159
			}
160
		);
161
	}
162
</script>
163

    
164
<!-- file status box -->
165
<div style="display:none; background:#eeeeee;" id="fileStatusBox">
166
	<div class="vexpl" style="padding-left:15px;">
167
		<strong id="fileStatus"></strong>
168
	</div>
169
</div>
170

    
171
<br />
172

    
173
<table width="100%" border="0" cellpadding="0" cellspacing="0">
174
	<tr>
175
		<td class="tabcont" align="center">
176

    
177
<!-- controls -->
178
<table width="100%" cellpadding="9" cellspacing="9">
179
	<tr>
180
		<td align="center" class="list">
181
			<?=gettext("Save / Load from path"); ?>:
182
			<input type="text"   class="formfld file" id="fbTarget"         size="45" />
183
			<input type="button" class="formbtn"      onclick="loadFile();" value="<?=gettext('Load');?>" />
184
			<input type="button" class="formbtn"      id="fbOpen"           value="<?=gettext('Browse');?>" />
185
			<input type="button" class="formbtn"      onclick="saveFile();" value="<?=gettext('Save');?>" />
186
			<br />
187
			<?php
188
			/*
189
			<input type="checkbox" id="highlight" /><?=gettext("Enable syntax highlighting");
190
			*/
191
			?>
192
		</td>
193
	</tr>
194
</table>
195

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

    
199
<!-- file viewer/editor -->
200
<table width="100%">
201
	<tr>
202
		<td valign="top">
203
			<div style="background:#eeeeee;" id="fileOutput">
204
				<textarea id="fileContent" name="fileContent" style="width:100%;" rows="30" wrap="off"></textarea>
205
			</div>
206
		</td>
207
	</tr>
208
</table>
209

    
210
		</td>
211
	</tr>
212
</table>
213

    
214
<script type="text/javascript" src="/code-syntax-highlighter/shCore.js"></script>
215
<script type="text/javascript" src="/code-syntax-highlighter/shBrushCss.js"></script>
216
<script type="text/javascript" src="/code-syntax-highlighter/shBrushJScript.js"></script>
217
<script type="text/javascript" src="/code-syntax-highlighter/shBrushPhp.js"></script>
218
<script type="text/javascript" src="/code-syntax-highlighter/shBrushXml.js"></script>
219
<script type="text/javascript">
220
	jQuery(window).load(
221
		function() {
222
			jQuery("#fbTarget").focus();
223

    
224
			NiftyCheck();
225
			Rounded("div#fileStatusBox", "all", "#ffffff", "#eeeeee", "smooth");
226
		}
227
	);
228

    
229
	<?php if($_GET['action'] == "load"): ?>
230
		jQuery(window).load(
231
			function() {
232
				jQuery("#fbTarget").val("<?=$_GET['path'];?>");
233
				loadFile();
234
			}
235
		);
236
	<?php endif; ?>
237
</script>
238

    
239
<?php include("fend.inc"); ?>
240
</body>
241
</html>
(53-53/254)