Project

General

Profile

Download (6.88 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 a7f908db Scott Ullrich
/*
4
    edit.php
5 b49448ac Scott Ullrich
    Copyright (C) 2004, 2005 Scott Ullrich
6 a7f908db Scott Ullrich
    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 859329c8 Scott Ullrich
require("guiconfig.inc");
31
32 ad6eae25 Scott Ullrich
if (($_GET['submit'] == "Load") && file_exists($_GET['savetopath'])) {
33
	$fd = fopen($_GET['savetopath'], "r");
34 7e2dd51d Scott Ullrich
	if ((filesize($_GET['savetopath']) != 0)) {  $content = fread($fd, filesize($_GET['savetopath'])); } else { $content = ""; }
35 ad6eae25 Scott Ullrich
	fclose($fd);
36
	$edit_area="";
37
	$loadmsg = gettext("Loaded text from")." " . $_GET['savetopath'];
38
	if(stristr($_GET['savetopath'], ".php") == true)
39
		$language = "php";
40
	else if(stristr($_GET['savetopath'], ".inc") == true)
41
		$language = "php";
42
	else if(stristr($_GET['savetopath'], ".sh") == true)
43
		$language = "core";
44
	else if(stristr($_GET['savetopath'], ".xml") == true)
45
		$language = "xml";
46
47
	$savetopath = $_GET['savetopath'];
48
}
49
50 5b237745 Scott Ullrich
if (($_POST['submit'] == "Load") && file_exists($_POST['savetopath'])) {
51
	$fd = fopen($_POST['savetopath'], "r");
52 7e2dd51d Scott Ullrich
	if ((filesize($_POST['savetopath']) != "0")) {  $content = fread($fd, filesize($_POST['savetopath'])); } else { $content = ""; }
53 5b237745 Scott Ullrich
	fclose($fd);
54
	$edit_area="";
55 7c35be3e Scott Ullrich
	$loadmsg = "Loaded text from " . $_POST['savetopath'];
56 207c6304 Scott Ullrich
	if(stristr($_POST['savetopath'], ".php") == true)
57 2e8eada0 Scott Ullrich
		$language = "php";
58 f14e4c2a Scott Ullrich
	else if(stristr($_POST['savetopath'], ".inc") == true)
59 5cfb93bc Scott Ullrich
		$language = "php";
60 207c6304 Scott Ullrich
	else if(stristr($_POST['savetopath'], ".sh") == true)
61 f14e4c2a Scott Ullrich
		$language = "core";
62 207c6304 Scott Ullrich
	else if(stristr($_POST['savetopath'], ".xml") == true)
63 2e8eada0 Scott Ullrich
		$language = "xml";
64 ad6eae25 Scott Ullrich
	$savetopath = $_POST['savetopath'];
65 5b237745 Scott Ullrich
} else if (($_POST['submit'] == "Save")) {
66 c52087ad Scott Ullrich
	conf_mount_rw();
67 5124d619 Scott Ullrich
	$content = ereg_replace("\r","",$_POST['code']) ;
68 5b237745 Scott Ullrich
	$fd = fopen($_POST['savetopath'], "w");
69
	fwrite($fd, $content);
70
	fclose($fd);
71
	$edit_area="";
72 e613545f Scott Ullrich
	$savemsg = "Saved text to " . $_POST['savetopath'];
73 5cfb93bc Scott Ullrich
	if($_POST['savetopath'] == "/cf/conf/config.xml")
74
		unlink_if_exists("/tmp/config.cache");
75 c52087ad Scott Ullrich
	conf_mount_ro();
76 ad6eae25 Scott Ullrich
	$savetopath = $_POST['savetopath'];
77 5b237745 Scott Ullrich
} else if (($_POST['submit'] == "Load") && !file_exists($_POST['savetopath'])) {
78 c52087ad Scott Ullrich
	$savemsg = "File not found " . $_POST['savetopath'];
79 5b237745 Scott Ullrich
	$content = "";
80
	$_POST['savetopath'] = "";
81
}
82
83 5124d619 Scott Ullrich
if($_POST['highlight'] <> "") {
84 bd19c08a Scott Ullrich
	if($_POST['highlight'] == "yes" or
85
	  $_POST['highlight'] == "enabled") {
86 5124d619 Scott Ullrich
		$highlight = "yes";
87
	} else {
88
		$highlight = "no";
89
	}
90
} else {
91
	$highlight = "no";
92
}
93
94 5b237745 Scott Ullrich
if($_POST['rows'] <> "")
95
	$rows = $_POST['rows'];
96
else
97 5124d619 Scott Ullrich
	$rows = 30;
98 5b237745 Scott Ullrich
99
if($_POST['cols'] <> "")
100
	$cols = $_POST['cols'];
101
else
102 ee6d9b34 Scott Ullrich
	$cols = 66;
103 5b237745 Scott Ullrich
?>
104
<?php
105
106
/*
107
	Exec+ v1.02-000 - Copyright 2001-2003, All rights reserved
108
	Created by technologEase (http://www.technologEase.com).
109
	(modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
110 b49448ac Scott Ullrich
        (modified for pfSense Edit/Save file by Scott Ullrich, Copyright 2004, 2005)
111 5b237745 Scott Ullrich
*/
112
113
// Function: is Blank
114
// Returns true or false depending on blankness of argument.
115
116
function isBlank( $arg ) { return ereg( "^\s*$", $arg ); }
117
118
// Function: Puts
119
// Put string, Ruby-style.
120
121
function puts( $arg ) { echo "$arg\n"; }
122
123
// "Constants".
124
125
$Version    = '';
126
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
127
128
// Get year.
129
130
$arrDT   = localtime();
131
$intYear = $arrDT[5] + 1900;
132
133 f9c14a6f Scott Ullrich
$pgtitle = "Diagnostics: Edit File";
134 5b237745 Scott Ullrich
135 48581bb7 Scott Ullrich
include("head.inc");
136
137 f9c14a6f Scott Ullrich
?>
138 2e8eada0 Scott Ullrich
139 5124d619 Scott Ullrich
<?php include("fbegin.inc"); ?>
140 2e8eada0 Scott Ullrich
141 be4b8e72 Scott Ullrich
<script language="Javascript">
142
function sf() { document.forms[0].savetopath.focus(); }
143
</script>
144
<body onLoad="sf();">
145 998abf60 Bill Marquette
<p><span class="pgtitle"><?=$pgtitle?></span>
146 e613545f Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
147 8a1ec45d Scott Ullrich
<?php if ($loadmsg) echo "<p><b><div style=\"background:#eeeeee\" id=\"shapeme\">&nbsp;&nbsp;&nbsp;{$loadmsg}</div><br>"; ?>
148 767067da Scott Ullrich
<form action="edit.php" method="POST">
149 5124d619 Scott Ullrich
150
<div id="shapeme">
151
<table width="100%" cellpadding='9' cellspacing='9' bgcolor='#eeeeee'>
152
 <tr>
153
  <td>
154
	<center>
155 ad6eae25 Scott Ullrich
	Save/Load from path: <input size="42" id="savetopath" name="savetopath" value="<?php echo $savetopath; ?>">
156 6e558e52 Scott Ullrich
	<input name="submit" type="submit"  class="button" id="Load" value="Load"> <input name="submit" type="submit"  class="button" id="Save" value="Save">
157 bd19c08a Scott Ullrich
	<hr noshade>
158 5124d619 Scott Ullrich
	<?php if($_POST['highlight'] == "no"): ?>
159 5cfb93bc Scott Ullrich
	   Rows: <input size="3" name="rows" value="<? echo $rows; ?>">
160 5124d619 Scott Ullrich
	   Cols: <input size="3" name="cols" value="<? echo $cols; ?>">
161 0831bc86 Scott Ullrich
	<?php endif; ?>
162 5124d619 Scott Ullrich
  </td>
163
 </tr>
164
</table>
165
</div>
166
167 ab541dbb Scott Ullrich
<br>
168
169 5124d619 Scott Ullrich
  <table width='100%'>
170 5b237745 Scott Ullrich
    <tr>
171
      <td valign="top" class="label">
172 b16def07 Scott Ullrich
	<div style="background:#eeeeee" id="textareaitem">
173
	&nbsp;<br>&nbsp;
174 8e0e58ff Scott Ullrich
	<center>
175
	<textarea style="width:98%" name="code" language="<?php echo $language; ?>" rows="<?php echo $rows; ?>" cols="<?php echo $cols; ?>" name="content"><?php echo htmlentities($content); ?></textarea><br>
176 b16def07 Scott Ullrich
	&nbsp;
177
	</div>
178 5b237745 Scott Ullrich
        <p>
179 476ef195 Scott Ullrich
    </td>
180 5b237745 Scott Ullrich
    </tr>
181
  </table>
182 2900e518 Scott Ullrich
<?php include("fend.inc"); ?>
183 5b237745 Scott Ullrich
</form>
184
</body>
185
</html>
186
187 be4b8e72 Scott Ullrich
<script language="Javascript">
188
sf();
189 5124d619 Scott Ullrich
</script>
190
191
</div>
192
<script language="javascript" src="/code-syntax-highlighter/shCore.js"></script>
193
<script language="javascript" src="/code-syntax-highlighter/shBrushCSharp.js"></script>
194
<script language="javascript" src="/code-syntax-highlighter/shBrushPhp.js"></script>
195
<script language="javascript" src="/code-syntax-highlighter/shBrushJScript.js"></script>
196
<script language="javascript" src="/code-syntax-highlighter/shBrushVb.js"></script>
197
<script language="javascript" src="/code-syntax-highlighter/shBrushSql.js"></script>
198
<script language="javascript" src="/code-syntax-highlighter/shBrushXml.js"></script>
199
<script language="javascript" src="/code-syntax-highlighter/shBrushDelphi.js"></script>
200
<script language="javascript" src="/code-syntax-highlighter/shBrushPython.js"></script>
201
202
<?php if($_POST['highlight'] == "yes") {
203
	echo "<script language=\"javascript\">\n";
204
	echo "dp.SyntaxHighlighter.HighlightAll('code', true, true);\n";
205 f0df1e49 Bill Marquette
	echo "</script>\n";
206 5124d619 Scott Ullrich
}
207
?>
208
209
<script type="text/javascript">
210
NiftyCheck();
211
Rounded("div#shapeme","all","#FFF","#eeeeee","smooth");
212 b16def07 Scott Ullrich
Rounded("div#textareaitem","all","#FFF","#eeeeee","smooth");
213 5124d619 Scott Ullrich
</script>