Project

General

Profile

Download (7.04 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
##|+PRIV
31
##|*IDENT=page-diagnostics-editfile
32
##|*NAME=Diagnostics: Edit File page
33
##|*DESCR=Allow access to the 'Diagnostics: Edit File' page.
34
##|*MATCH=edit.php*
35
##|-PRIV
36

    
37

    
38
require("guiconfig.inc");
39

    
40
if (($_GET['submit'] == "Load") && file_exists($_GET['savetopath'])) {
41
	$fd = fopen($_GET['savetopath'], "r");
42
	if ((filesize($_GET['savetopath']) != 0)) {  $content = fread($fd, filesize($_GET['savetopath'])); } else { $content = ""; }
43
	fclose($fd);
44
	$edit_area="";
45
	$loadmsg = gettext("Loaded text from")." " . $_GET['savetopath'];
46
	if(stristr($_GET['savetopath'], ".php") == true)
47
		$language = "php";
48
	else if(stristr($_GET['savetopath'], ".inc") == true)
49
		$language = "php";
50
	else if(stristr($_GET['savetopath'], ".sh") == true)
51
		$language = "core";
52
	else if(stristr($_GET['savetopath'], ".xml") == true)
53
		$language = "xml";
54

    
55
	$savetopath = $_GET['savetopath'];
56
}
57

    
58
if (($_POST['submit'] == "Load") && file_exists($_POST['savetopath'])) {
59
	$fd = fopen($_POST['savetopath'], "r");
60
	if ((filesize($_POST['savetopath']) != "0")) {  $content = fread($fd, filesize($_POST['savetopath'])); } else { $content = ""; }
61
	fclose($fd);
62
	$edit_area="";
63
	$loadmsg = "Loaded text from " . $_POST['savetopath'];
64
	if(stristr($_POST['savetopath'], ".php") == true)
65
		$language = "php";
66
	else if(stristr($_POST['savetopath'], ".inc") == true)
67
		$language = "php";
68
	else if(stristr($_POST['savetopath'], ".sh") == true)
69
		$language = "core";
70
	else if(stristr($_POST['savetopath'], ".xml") == true)
71
		$language = "xml";
72
	$savetopath = $_POST['savetopath'];
73
} else if (($_POST['submit'] == "Save")) {
74
	conf_mount_rw();
75
	$content = ereg_replace("\r","",$_POST['code']) ;
76
	$fd = fopen($_POST['savetopath'], "w");
77
	fwrite($fd, $content);
78
	fclose($fd);
79
	$edit_area="";
80
	$savemsg = "Saved text to " . $_POST['savetopath'];
81
	if($_POST['savetopath'] == "/cf/conf/config.xml")
82
		unlink_if_exists("/tmp/config.cache");
83
	conf_mount_ro();
84
	$savetopath = $_POST['savetopath'];
85
} else if (($_POST['submit'] == "Load") && !file_exists($_POST['savetopath'])) {
86
	$savemsg = "File not found " . $_POST['savetopath'];
87
	$content = "";
88
	$_POST['savetopath'] = "";
89
}
90

    
91
if($_POST['highlight'] <> "") {
92
	if($_POST['highlight'] == "yes" or
93
	  $_POST['highlight'] == "enabled") {
94
		$highlight = "yes";
95
	} else {
96
		$highlight = "no";
97
	}
98
} else {
99
	$highlight = "no";
100
}
101

    
102
if($_POST['rows'] <> "")
103
	$rows = $_POST['rows'];
104
else
105
	$rows = 30;
106

    
107
if($_POST['cols'] <> "")
108
	$cols = $_POST['cols'];
109
else
110
	$cols = 66;
111
?>
112
<?php
113

    
114
/*
115
	Exec+ v1.02-000 - Copyright 2001-2003, All rights reserved
116
	Created by technologEase (http://www.technologEase.com).
117
	(modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
118
        (modified for {$g['product_name']} Edit/Save file by Scott Ullrich, Copyright 2004, 2005)
119
*/
120

    
121
// Function: is Blank
122
// Returns true or false depending on blankness of argument.
123

    
124
function isBlank( $arg ) { return ereg( "^\s*$", $arg ); }
125

    
126
// Function: Puts
127
// Put string, Ruby-style.
128

    
129
function puts( $arg ) { echo "$arg\n"; }
130

    
131
// "Constants".
132

    
133
$Version    = '';
134
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
135

    
136
// Get year.
137

    
138
$arrDT   = localtime();
139
$intYear = $arrDT[5] + 1900;
140

    
141
$pgtitle = array("Diagnostics","Edit File");
142

    
143
include("head.inc");
144

    
145
?>
146

    
147
<?php include("fbegin.inc"); ?>
148

    
149
<script language="Javascript">
150
function sf() { document.forms[0].savetopath.focus(); }
151
</script>
152
<body onLoad="sf();">
153
<?php if ($savemsg) print_info_box($savemsg); ?>
154
<?php if ($loadmsg) echo "<p><b><div style=\"background:#eeeeee\" id=\"shapeme\">&nbsp;&nbsp;&nbsp;{$loadmsg}</div><br>"; ?>
155
<form action="edit.php" method="POST">
156

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

    
174
<br>
175

    
176
  <table width='100%'>
177
    <tr>
178
      <td valign="top" class="label">
179
	<div style="background:#eeeeee" id="textareaitem">
180
	&nbsp;<br>&nbsp;
181
	<center>
182
	<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>
183
	&nbsp;
184
	</div>
185
        <p>
186
    </td>
187
    </tr>
188
  </table>
189
<?php include("fend.inc"); ?>
190
</form>
191
</body>
192
</html>
193

    
194
<script language="Javascript">
195
sf();
196
</script>
197

    
198
</div>
199
<script language="javascript" src="/code-syntax-highlighter/shCore.js"></script>
200
<script language="javascript" src="/code-syntax-highlighter/shBrushCSharp.js"></script>
201
<script language="javascript" src="/code-syntax-highlighter/shBrushPhp.js"></script>
202
<script language="javascript" src="/code-syntax-highlighter/shBrushJScript.js"></script>
203
<script language="javascript" src="/code-syntax-highlighter/shBrushVb.js"></script>
204
<script language="javascript" src="/code-syntax-highlighter/shBrushSql.js"></script>
205
<script language="javascript" src="/code-syntax-highlighter/shBrushXml.js"></script>
206
<script language="javascript" src="/code-syntax-highlighter/shBrushDelphi.js"></script>
207
<script language="javascript" src="/code-syntax-highlighter/shBrushPython.js"></script>
208

    
209
<?php if($_POST['highlight'] == "yes") {
210
	echo "<script language=\"javascript\">\n";
211
	echo "dp.SyntaxHighlighter.HighlightAll('code', true, true);\n";
212
	echo "</script>\n";
213
}
214
?>
215

    
216
<script type="text/javascript">
217
NiftyCheck();
218
Rounded("div#shapeme","all","#FFF","#eeeeee","smooth");
219
Rounded("div#textareaitem","all","#FFF","#eeeeee","smooth");
220
</script>
(34-34/205)