Project

General

Profile

Download (6.88 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
require("guiconfig.inc");
31

    
32
if (($_GET['submit'] == "Load") && file_exists($_GET['savetopath'])) {
33
	$fd = fopen($_GET['savetopath'], "r");
34
	if ((filesize($_GET['savetopath']) != 0)) {  $content = fread($fd, filesize($_GET['savetopath'])); } else { $content = ""; }
35
	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
if (($_POST['submit'] == "Load") && file_exists($_POST['savetopath'])) {
51
	$fd = fopen($_POST['savetopath'], "r");
52
	if ((filesize($_POST['savetopath']) != "0")) {  $content = fread($fd, filesize($_POST['savetopath'])); } else { $content = ""; }
53
	fclose($fd);
54
	$edit_area="";
55
	$loadmsg = "Loaded text from " . $_POST['savetopath'];
56
	if(stristr($_POST['savetopath'], ".php") == true)
57
		$language = "php";
58
	else if(stristr($_POST['savetopath'], ".inc") == true)
59
		$language = "php";
60
	else if(stristr($_POST['savetopath'], ".sh") == true)
61
		$language = "core";
62
	else if(stristr($_POST['savetopath'], ".xml") == true)
63
		$language = "xml";
64
	$savetopath = $_POST['savetopath'];
65
} else if (($_POST['submit'] == "Save")) {
66
	conf_mount_rw();
67
	$content = ereg_replace("\r","",$_POST['code']) ;
68
	$fd = fopen($_POST['savetopath'], "w");
69
	fwrite($fd, $content);
70
	fclose($fd);
71
	$edit_area="";
72
	$savemsg = "Saved text to " . $_POST['savetopath'];
73
	if($_POST['savetopath'] == "/cf/conf/config.xml")
74
		unlink_if_exists("/tmp/config.cache");
75
	conf_mount_ro();
76
	$savetopath = $_POST['savetopath'];
77
} else if (($_POST['submit'] == "Load") && !file_exists($_POST['savetopath'])) {
78
	$savemsg = "File not found " . $_POST['savetopath'];
79
	$content = "";
80
	$_POST['savetopath'] = "";
81
}
82

    
83
if($_POST['highlight'] <> "") {
84
	if($_POST['highlight'] == "yes" or
85
	  $_POST['highlight'] == "enabled") {
86
		$highlight = "yes";
87
	} else {
88
		$highlight = "no";
89
	}
90
} else {
91
	$highlight = "no";
92
}
93

    
94
if($_POST['rows'] <> "")
95
	$rows = $_POST['rows'];
96
else
97
	$rows = 30;
98

    
99
if($_POST['cols'] <> "")
100
	$cols = $_POST['cols'];
101
else
102
	$cols = 66;
103
?>
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
        (modified for pfSense Edit/Save file by Scott Ullrich, Copyright 2004, 2005)
111
*/
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
$pgtitle = "Diagnostics: Edit File";
134

    
135
include("head.inc");
136

    
137
?>
138

    
139
<?php include("fbegin.inc"); ?>
140

    
141
<script language="Javascript">
142
function sf() { document.forms[0].savetopath.focus(); }
143
</script>
144
<body onLoad="sf();">
145
<p><span class="pgtitle"><?=$pgtitle?></span>
146
<?php if ($savemsg) print_info_box($savemsg); ?>
147
<?php if ($loadmsg) echo "<p><b><div style=\"background:#eeeeee\" id=\"shapeme\">&nbsp;&nbsp;&nbsp;{$loadmsg}</div><br>"; ?>
148
<form action="edit.php" method="POST">
149

    
150
<div id="shapeme">
151
<table width="100%" cellpadding='9' cellspacing='9' bgcolor='#eeeeee'>
152
 <tr>
153
  <td>
154
	<center>
155
	Save/Load from path: <input size="42" id="savetopath" name="savetopath" value="<?php echo $savetopath; ?>">
156
	<input name="submit" type="submit"  class="button" id="Load" value="Load"> <input name="submit" type="submit"  class="button" id="Save" value="Save">
157
	<hr noshade>
158
	<?php if($_POST['highlight'] == "no"): ?>
159
	   Rows: <input size="3" name="rows" value="<? echo $rows; ?>">
160
	   Cols: <input size="3" name="cols" value="<? echo $cols; ?>">
161
	<?php endif; ?>
162
  </td>
163
 </tr>
164
</table>
165
</div>
166

    
167
<br>
168

    
169
  <table width='100%'>
170
    <tr>
171
      <td valign="top" class="label">
172
	<div style="background:#eeeeee" id="textareaitem">
173
	&nbsp;<br>&nbsp;
174
	<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
	&nbsp;
177
	</div>
178
        <p>
179
    </td>
180
    </tr>
181
  </table>
182
<?php include("fend.inc"); ?>
183
</form>
184
</body>
185
</html>
186

    
187
<script language="Javascript">
188
sf();
189
</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
	echo "</script>\n";
206
}
207
?>
208

    
209
<script type="text/javascript">
210
NiftyCheck();
211
Rounded("div#shapeme","all","#FFF","#eeeeee","smooth");
212
Rounded("div#textareaitem","all","#FFF","#eeeeee","smooth");
213
</script>
(34-34/175)