Project

General

Profile

Download (11.7 KB) Statistics
| Branch: | Tag: | Revision:
1 447611c4 Scott Ullrich
<?php
2 a7f908db Scott Ullrich
/*
3 aaec5634 Renato Botelho
 * diag_arp.php
4 fd9ebcd5 Stephen Beaver
 *
5 aaec5634 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * All rights reserved.
8 fd9ebcd5 Stephen Beaver
 *
9 aaec5634 Renato Botelho
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11 fd9ebcd5 Stephen Beaver
 *
12 aaec5634 Renato Botelho
 * 1. Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14 fd9ebcd5 Stephen Beaver
 *
15 aaec5634 Renato Botelho
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in
17
 *    the documentation and/or other materials provided with the
18
 *    distribution.
19 fd9ebcd5 Stephen Beaver
 *
20 aaec5634 Renato Botelho
 * 3. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgment:
22
 *    "This product includes software developed by the pfSense Project
23
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
24 fd9ebcd5 Stephen Beaver
 *
25 aaec5634 Renato Botelho
 * 4. The names "pfSense" and "pfSense Project" must not be used to
26
 *    endorse or promote products derived from this software without
27
 *    prior written permission. For written permission, please contact
28
 *    coreteam@pfsense.org.
29 fd9ebcd5 Stephen Beaver
 *
30 aaec5634 Renato Botelho
 * 5. Products derived from this software may not be called "pfSense"
31
 *    nor may "pfSense" appear in their names without prior written
32
 *    permission of the Electric Sheep Fencing, LLC.
33 fd9ebcd5 Stephen Beaver
 *
34 aaec5634 Renato Botelho
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36 919d91f9 Phil Davis
 *
37 aaec5634 Renato Botelho
 * "This product includes software developed by the pfSense Project
38
 * for use in the pfSense software distribution (http://www.pfsense.org/).
39 fd9ebcd5 Stephen Beaver
 *
40 aaec5634 Renato Botelho
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 fd9ebcd5 Stephen Beaver
 */
53 a7f908db Scott Ullrich
54 9fbb3599 Ermal
##|+PRIV
55
##|*IDENT=page-diagnostics-edit
56 9599211d jim-p
##|*NAME=Diagnostics: Edit File
57 9fbb3599 Ermal
##|*DESCR=Allow access to the 'Diagnostics: Edit File' page.
58 a09f3d8e Phil Davis
##|*MATCH=diag_edit.php*
59 c0f613e2 Ermal
##|*MATCH=browser.php*
60 18e7bc46 Stephen Beaver
##|*MATCH=vendor/filebrowser/browser.php*
61 9fbb3599 Ermal
##|-PRIV
62
63 a6a6ee00 k-paulius
$pgtitle = array(gettext("Diagnostics"), gettext("Edit File"));
64 aceaf18c Phil Davis
require_once("guiconfig.inc");
65 859329c8 Scott Ullrich
66 41b1ff89 Phil Davis
if ($_POST['action']) {
67
	switch ($_POST['action']) {
68 0d6a185a Scott Ullrich
		case 'load':
69 288a2a0f Phil Davis
			if (strlen($_POST['file']) < 1) {
70 1bd5e62d k-paulius
				print('|5|');
71 ed98ef92 Phil Davis
				print_info_box(gettext("No file name specified."), 'danger');
72 1bd5e62d k-paulius
				print('|');
73 288a2a0f Phil Davis
			} elseif (is_dir($_POST['file'])) {
74 1bd5e62d k-paulius
				print('|4|');
75 ed98ef92 Phil Davis
				print_info_box(gettext("Loading a directory is not supported."), 'danger');
76 1bd5e62d k-paulius
				print('|');
77 288a2a0f Phil Davis
			} elseif (!is_file($_POST['file'])) {
78 1bd5e62d k-paulius
				print('|3|');
79 ed98ef92 Phil Davis
				print_info_box(gettext("File does not exist or is not a regular file."), 'danger');
80 1bd5e62d k-paulius
				print('|');
81 0d6a185a Scott Ullrich
			} else {
82 55344e2c Ermal
				$data = file_get_contents(urldecode($_POST['file']));
83 288a2a0f Phil Davis
				if ($data === false) {
84 1bd5e62d k-paulius
					print('|1|');
85 ed98ef92 Phil Davis
					print_info_box(gettext("Failed to read file."), 'danger');
86 1bd5e62d k-paulius
					print('|');
87 0d6a185a Scott Ullrich
				} else {
88 b71f0cbb Ermal
					$data = base64_encode($data);
89 45d6ada5 Sjon Hortensius
					print("|0|{$_POST['file']}|{$data}|");
90 0d6a185a Scott Ullrich
				}
91
			}
92
			exit;
93 45d6ada5 Sjon Hortensius
94 0d6a185a Scott Ullrich
		case 'save':
95 288a2a0f Phil Davis
			if (strlen($_POST['file']) < 1) {
96 1bd5e62d k-paulius
				print('|');
97 ed98ef92 Phil Davis
				print_info_box(gettext("No file name specified."), 'danger');
98 1bd5e62d k-paulius
				print('|');
99 0d6a185a Scott Ullrich
			} else {
100 5a557f44 jim-p
				conf_mount_rw();
101 55344e2c Ermal
				$_POST['data'] = str_replace("\r", "", base64_decode($_POST['data']));
102
				$ret = file_put_contents($_POST['file'], $_POST['data']);
103 5a557f44 jim-p
				conf_mount_ro();
104 41b1ff89 Phil Davis
				if ($_POST['file'] == "/conf/config.xml" || $_POST['file'] == "/cf/conf/config.xml") {
105
					if (file_exists("/tmp/config.cache")) {
106 5f05c1e8 Scott Ullrich
						unlink("/tmp/config.cache");
107 41b1ff89 Phil Davis
					}
108 0f806eca Erik Fonnesbeck
					disable_security_checks();
109
				}
110 288a2a0f Phil Davis
				if ($ret === false) {
111 1bd5e62d k-paulius
					print('|');
112 ed98ef92 Phil Davis
					print_info_box(gettext("Failed to write file."), 'danger');
113 1bd5e62d k-paulius
					print('|');
114 288a2a0f Phil Davis
				} elseif ($ret != strlen($_POST['data'])) {
115 1bd5e62d k-paulius
					print('|');
116 ed98ef92 Phil Davis
					print_info_box(gettext("Error while writing file."), 'danger');
117 1bd5e62d k-paulius
					print('|');
118 0d6a185a Scott Ullrich
				} else {
119 1bd5e62d k-paulius
					print('|');
120 ed98ef92 Phil Davis
					print_info_box(gettext("File saved successfully."), 'success');
121 1bd5e62d k-paulius
					print('|');
122 0d6a185a Scott Ullrich
				}
123
			}
124
			exit;
125 5124d619 Scott Ullrich
	}
126 0d6a185a Scott Ullrich
	exit;
127 5124d619 Scott Ullrich
}
128
129 aceaf18c Phil Davis
require_once("head.inc");
130 2fef3ed9 Jared Dillard
131
print_callout(gettext("The capabilities offered here can be dangerous. No support is available. Use them at your own risk!"), 'danger', gettext('Advanced Users Only'));
132
133 5b237745 Scott Ullrich
?>
134 45d6ada5 Sjon Hortensius
<!-- file status box -->
135
<div style="display:none; background:#eeeeee;" id="fileStatusBox">
136 1bd5e62d k-paulius
	<div id="fileStatus"></div>
137 45d6ada5 Sjon Hortensius
</div>
138
139
<div class="panel panel-default">
140 3d7a8696 k-paulius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Save / Load a File from the Filesystem")?></h2></div>
141 45d6ada5 Sjon Hortensius
	<div class="panel-body">
142 2ca4eec2 Jared Dillard
		<div class="content">
143
			<form>
144 2fef3ed9 Jared Dillard
				<p><input type="text" class="form-control" id="fbTarget"/></p>
145 37676f4e jim-p
				<div class="btn-group">
146 2fef3ed9 Jared Dillard
					<p>
147
						<button type="button" class="btn btn-default btn-sm" onclick="loadFile();"	value="<?=gettext('Load')?>">
148
							<i class="fa fa-file-text-o"></i>
149
							<?=gettext('Load')?>
150
						</button>
151
						<button type="button" class="btn btn-default btn-sm" id="fbOpen"		value="<?=gettext('Browse')?>">
152
							<i class="fa fa-list"></i>
153
							<?=gettext('Browse')?>
154
						</button>
155
						<button type="button" class="btn btn-default btn-sm" onclick="saveFile();"	value="<?=gettext('Save')?>">
156
							<i class="fa fa-save"></i>
157
							<?=gettext('Save')?>
158
						</button>
159
					</p>
160 37676f4e jim-p
				</div>
161 2fef3ed9 Jared Dillard
				<p class="pull-right">
162
					<button id="btngoto" class="btn btn-default btn-sm"><i class="fa fa-forward"></i><?=gettext("GoTo Line #")?></button> <input type="number" id="gotoline" size="6" style="padding: 3px 0px;"/>
163
				</p>
164 2ca4eec2 Jared Dillard
			</form>
165 45d6ada5 Sjon Hortensius
166 2fef3ed9 Jared Dillard
			<div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%; padding:10px"></div>
167 45d6ada5 Sjon Hortensius
168 2fef3ed9 Jared Dillard
			<script type="text/javascript">
169
			//<![CDATA[
170
			window.onload=function() {
171
				document.getElementById("fileContent").wrap='off';
172
			}
173
			//]]>
174
			</script>
175
			<textarea id="fileContent" name="fileContent" class="form-control" rows="30" cols="20"></textarea>
176 45d6ada5 Sjon Hortensius
		</div>
177
	</div>
178
</div>
179
180 8fd9052f Colin Fleming
<script type="text/javascript">
181
//<![CDATA[
182 b54c2035 Stephen Beaver
	events.push(function(){
183
184
		function showLine(tarea, lineNum) {
185
186
			lineNum--; // array starts at 0
187
			var lines = tarea.value.split("\n");
188
189
			// calculate start/end
190
			var startPos = 0, endPos = tarea.value.length;
191
			for(var x = 0; x < lines.length; x++) {
192
				if(x == lineNum) {
193
					break;
194
				}
195
				startPos += (lines[x].length+1);
196
197
			}
198
199
			var endPos = lines[lineNum].length+startPos;
200
201
			// do selection
202
			// Chrome / Firefox
203
204
			if(typeof(tarea.selectionStart) != "undefined") {
205
				tarea.focus();
206
				tarea.selectionStart = startPos;
207
				tarea.selectionEnd = endPos;
208
				return true;
209
			}
210
211
			// IE
212
			if (document.selection && document.selection.createRange) {
213
				tarea.focus();
214
				tarea.select();
215
				var range = document.selection.createRange();
216
				range.collapse(true);
217
				range.moveEnd("character", endPos);
218
				range.moveStart("character", startPos);
219
				range.select();
220
				return true;
221
			}
222
223
			return false;
224
		}
225
226
		$("#btngoto").prop('type','button');
227
228
		$('#btngoto').click(function() {
229
			var tarea = document.getElementById("fileContent");
230
			showLine(tarea, $('#gotoline').val());
231
		});
232
	});
233
234 0d6a185a Scott Ullrich
	function loadFile() {
235 3f98044a Francisco Cavalcante
		$("#fileStatus").html("");
236
		$("#fileStatusBox").show(500);
237
		$.ajax(
238 45d6ada5 Sjon Hortensius
			"<?=$_SERVER['SCRIPT_NAME']?>", {
239 e3c1ea9b Vinicius Coque
				type: "post",
240 3f98044a Francisco Cavalcante
				data: "action=load&file=" + $("#fbTarget").val(),
241 e3c1ea9b Vinicius Coque
				complete: loadComplete
242 0d6a185a Scott Ullrich
			}
243
		);
244
	}
245 5b237745 Scott Ullrich
246 0d6a185a Scott Ullrich
	function loadComplete(req) {
247 3f98044a Francisco Cavalcante
		$("#fileContent").show(1000);
248 0d6a185a Scott Ullrich
		var values = req.responseText.split("|");
249
		values.shift(); values.pop();
250
251 41b1ff89 Phil Davis
		if (values.shift() == "0") {
252 0d6a185a Scott Ullrich
			var file = values.shift();
253 45d6ada5 Sjon Hortensius
			var fileContent = window.atob(values.join("|"));
254 0d6a185a Scott Ullrich
255 3f98044a Francisco Cavalcante
			$("#fileContent").val(fileContent);
256 947141fd Phil Davis
		} else {
257 3f98044a Francisco Cavalcante
			$("#fileStatus").html(values[0]);
258
			$("#fileContent").val("");
259 0d6a185a Scott Ullrich
		}
260 45d6ada5 Sjon Hortensius
261 3f98044a Francisco Cavalcante
		$("#fileContent").show(1000);
262 0d6a185a Scott Ullrich
	}
263 5b237745 Scott Ullrich
264 0d6a185a Scott Ullrich
	function saveFile(file) {
265 3f98044a Francisco Cavalcante
		$("#fileStatus").html("");
266
		$("#fileStatusBox").show(500);
267 41b1ff89 Phil Davis
268 3f98044a Francisco Cavalcante
		var fileContent = Base64.encode($("#fileContent").val());
269 6c07db48 Phil Davis
		fileContent = fileContent.replace(/\+/g, "%2B");
270 45d6ada5 Sjon Hortensius
271 3f98044a Francisco Cavalcante
		$.ajax(
272 45d6ada5 Sjon Hortensius
			"<?=$_SERVER['SCRIPT_NAME']?>", {
273 e3c1ea9b Vinicius Coque
				type: "post",
274 3f98044a Francisco Cavalcante
				data: "action=save&file=" + $("#fbTarget").val() +
275 ee650539 Scott Ullrich
							"&data=" + fileContent,
276 e3c1ea9b Vinicius Coque
				complete: function(req) {
277 0d6a185a Scott Ullrich
					var values = req.responseText.split("|");
278 3f98044a Francisco Cavalcante
					$("#fileStatus").html(values[1]);
279 0d6a185a Scott Ullrich
				}
280
			}
281
		);
282
	}
283
284 e561ccdf Stephen Beaver
/**
285
 *
286
 *	Base64 encode / decode
287
 *	http://www.webtoolkit.info/
288
 *	http://www.webtoolkit.info/licence
289
 **/
290
291
var Base64 = {
292
293
	// private property
294
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
295
296
	// public method for encoding
297
	encode : function (input) {
298
		var output = "";
299
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
300
		var i = 0;
301
302
		input = Base64._utf8_encode(input);
303
304
		while (i < input.length) {
305
306
			chr1 = input.charCodeAt(i++);
307
			chr2 = input.charCodeAt(i++);
308
			chr3 = input.charCodeAt(i++);
309
310
			enc1 = chr1 >> 2;
311
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
312
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
313
			enc4 = chr3 & 63;
314
315
			if (isNaN(chr2)) {
316
				enc3 = enc4 = 64;
317
			} else if (isNaN(chr3)) {
318
				enc4 = 64;
319
			}
320
321
			output = output +
322
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
323
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
324
325
		}
326
327
		return output;
328
	},
329
330
	// public method for decoding
331
	decode : function (input) {
332
		var output = "";
333
		var chr1, chr2, chr3;
334
		var enc1, enc2, enc3, enc4;
335
		var i = 0;
336
337
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
338
339
		while (i < input.length) {
340
341
			enc1 = this._keyStr.indexOf(input.charAt(i++));
342
			enc2 = this._keyStr.indexOf(input.charAt(i++));
343
			enc3 = this._keyStr.indexOf(input.charAt(i++));
344
			enc4 = this._keyStr.indexOf(input.charAt(i++));
345
346
			chr1 = (enc1 << 2) | (enc2 >> 4);
347
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
348
			chr3 = ((enc3 & 3) << 6) | enc4;
349
350
			output = output + String.fromCharCode(chr1);
351
352
			if (enc3 != 64) {
353
				output = output + String.fromCharCode(chr2);
354
			}
355
			if (enc4 != 64) {
356
				output = output + String.fromCharCode(chr3);
357
			}
358
359
		}
360
361
		output = Base64._utf8_decode(output);
362
363
		return output;
364
365
	},
366
367
	// private method for UTF-8 encoding
368
	_utf8_encode : function (string) {
369
		string = string.replace(/\r\n/g,"\n");
370
		var utftext = "";
371
372
		for (var n = 0; n < string.length; n++) {
373
374
			var c = string.charCodeAt(n);
375
376
			if (c < 128) {
377
				utftext += String.fromCharCode(c);
378 947141fd Phil Davis
			} else if ((c > 127) && (c < 2048)) {
379 e561ccdf Stephen Beaver
				utftext += String.fromCharCode((c >> 6) | 192);
380
				utftext += String.fromCharCode((c & 63) | 128);
381 947141fd Phil Davis
			} else {
382 e561ccdf Stephen Beaver
				utftext += String.fromCharCode((c >> 12) | 224);
383
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
384
				utftext += String.fromCharCode((c & 63) | 128);
385
			}
386
387
		}
388
389
		return utftext;
390
	},
391
392
	// private method for UTF-8 decoding
393
	_utf8_decode : function (utftext) {
394
		var string = "";
395
		var i = 0;
396
		var c = c1 = c2 = 0;
397
398 947141fd Phil Davis
		while (i < utftext.length) {
399 e561ccdf Stephen Beaver
400
			c = utftext.charCodeAt(i);
401
402
			if (c < 128) {
403
				string += String.fromCharCode(c);
404
				i++;
405 947141fd Phil Davis
			} else if ((c > 191) && (c < 224)) {
406 e561ccdf Stephen Beaver
				c2 = utftext.charCodeAt(i+1);
407
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
408
				i += 2;
409 947141fd Phil Davis
			} else {
410 e561ccdf Stephen Beaver
				c2 = utftext.charCodeAt(i+1);
411
				c3 = utftext.charCodeAt(i+2);
412
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
413
				i += 3;
414
			}
415
416
		}
417
418
		return string;
419
	}
420
421
};
422
423 288a2a0f Phil Davis
	<?php if ($_GET['action'] == "load"): ?>
424 45d6ada5 Sjon Hortensius
		events.push(function() {
425 3f98044a Francisco Cavalcante
			$("#fbTarget").val("<?=htmlspecialchars($_GET['path'])?>");
426 45d6ada5 Sjon Hortensius
			loadFile();
427
		});
428 0d6a185a Scott Ullrich
	<?php endif; ?>
429 8fd9052f Colin Fleming
//]]>
430 0d6a185a Scott Ullrich
</script>
431 ab541dbb Scott Ullrich
432 45d6ada5 Sjon Hortensius
<?php include("foot.inc");
433
434 18e7bc46 Stephen Beaver
outputJavaScriptFileInline("vendor/filebrowser/browser.js");