Project

General

Profile

Download (6.08 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 (($_POST['submit'] == "Load") && file_exists($_POST['savetopath'])) {
33
	$fd = fopen($_POST['savetopath'], "r");
34
	$content = fread($fd, filesize($_POST['savetopath']));
35
	fclose($fd);
36
	$edit_area="";
37
	$loadmsg = "Loaded text from " . $_POST['savetopath'];
38
	if(stristr($_POST['savetopath'], ".php") == true)
39
		$language = "php";
40
	else if(stristr($_POST['savetopath'], ".inc") == true)
41
		$language = "php";
42
	else if(stristr($_POST['savetopath'], ".sh") == true)
43
		$language = "core";
44
	else if(stristr($_POST['savetopath'], ".xml") == true)
45
		$language = "xml";
46
} else if (($_POST['submit'] == "Save")) {
47
	conf_mount_rw();
48
	$content = ereg_replace("\r","",$_POST['code']) ;
49
	$fd = fopen($_POST['savetopath'], "w");
50
	fwrite($fd, $content);
51
	fclose($fd);
52
	$edit_area="";
53
	$savemsg = "Saved text to " . $_POST['savetopath'];
54
	if($_POST['savetopath'] == "/cf/conf/config.xml")
55
		unlink_if_exists("/tmp/config.cache");
56
	conf_mount_ro();
57
} else if (($_POST['submit'] == "Load") && !file_exists($_POST['savetopath'])) {
58
	$savemsg = "File not found " . $_POST['savetopath'];
59
	$content = "";
60
	$_POST['savetopath'] = "";
61
}
62

    
63
if($_POST['highlight'] <> "") {
64
	if($_POST['highlight'] == "yes" or
65
	  $_POST['highlight'] == "enabled") {
66
		$highlight = "yes";
67
	} else {
68
		$highlight = "no";
69
	}
70
} else {
71
	$highlight = "no";
72
}
73

    
74
if($_POST['rows'] <> "")
75
	$rows = $_POST['rows'];
76
else
77
	$rows = 30;
78

    
79
if($_POST['cols'] <> "")
80
	$cols = $_POST['cols'];
81
else
82
	$cols = 66;
83
?>
84
<?php
85

    
86
/*
87
	Exec+ v1.02-000 - Copyright 2001-2003, All rights reserved
88
	Created by technologEase (http://www.technologEase.com).
89
	(modified for m0n0wall by Manuel Kasper <mk@neon1.net>)
90
        (modified for pfSense Edit/Save file by Scott Ullrich, Copyright 2004, 2005)
91
*/
92

    
93
// Function: is Blank
94
// Returns true or false depending on blankness of argument.
95

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

    
98
// Function: Puts
99
// Put string, Ruby-style.
100

    
101
function puts( $arg ) { echo "$arg\n"; }
102

    
103
// "Constants".
104

    
105
$Version    = '';
106
$ScriptName = $HTTP_SERVER_VARS['SCRIPT_NAME'];
107

    
108
// Get year.
109

    
110
$arrDT   = localtime();
111
$intYear = $arrDT[5] + 1900;
112

    
113
$pgtitle = "Diagnostics: Edit File";
114

    
115
include("head.inc");
116

    
117
?>
118

    
119
<?php include("fbegin.inc"); ?>
120

    
121
<script language="Javascript">
122
function sf() { document.forms[0].savetopath.focus(); }
123
</script>
124
<body onLoad="sf();">
125
<p><span class="pgtitle"><?=$pgtitle?></span>
126
<?php if ($savemsg) print_info_box($savemsg); ?>
127
<?php if ($loadmsg) echo "<p><b><div style=\"background:#eeeeee\" id=\"shapeme\">&nbsp;&nbsp;&nbsp;{$loadmsg}</div><br>"; ?>
128
<form action="edit.php" method="POST">
129

    
130
<div id="shapeme">
131
<table width="100%" cellpadding='9' cellspacing='9' bgcolor='#eeeeee'>
132
 <tr>
133
  <td>
134
	<center>
135
	Save/Load from path: <input size="42" id="savetopath" name="savetopath" value="<?php echo $_POST['savetopath']; ?>">
136
	<input name="submit" type="submit"  class="button" id="Load" value="Load"> <input name="submit" type="submit"  class="button" id="Save" value="Save">
137
	<hr noshade>
138
	<?php if($_POST['highlight'] == "no"): ?>
139
	   Rows: <input size="3" name="rows" value="<? echo $rows; ?>">
140
	   Cols: <input size="3" name="cols" value="<? echo $cols; ?>">
141
	<?php endif; ?>
142
  </td>
143
 </tr>
144
</table>
145
</div>
146

    
147
<br>
148

    
149
  <table width='100%'>
150
    <tr>
151
      <td valign="top" class="label">
152
	<div style="background:#eeeeee" id="textareaitem">
153
	&nbsp;<br>&nbsp;
154
	<center>
155
	<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>
156
	&nbsp;
157
	</div>
158
        <p>
159
    </td>
160
    </tr>
161
  </table>
162
<?php include("fend.inc"); ?>
163
</form>
164
</body>
165
</html>
166

    
167
<script language="Javascript">
168
sf();
169
</script>
170

    
171
</div>
172
<script language="javascript" src="/code-syntax-highlighter/shCore.js"></script>
173
<script language="javascript" src="/code-syntax-highlighter/shBrushCSharp.js"></script>
174
<script language="javascript" src="/code-syntax-highlighter/shBrushPhp.js"></script>
175
<script language="javascript" src="/code-syntax-highlighter/shBrushJScript.js"></script>
176
<script language="javascript" src="/code-syntax-highlighter/shBrushVb.js"></script>
177
<script language="javascript" src="/code-syntax-highlighter/shBrushSql.js"></script>
178
<script language="javascript" src="/code-syntax-highlighter/shBrushXml.js"></script>
179
<script language="javascript" src="/code-syntax-highlighter/shBrushDelphi.js"></script>
180
<script language="javascript" src="/code-syntax-highlighter/shBrushPython.js"></script>
181

    
182
<?php if($_POST['highlight'] == "yes") {
183
	echo "<script language=\"javascript\">\n";
184
	echo "dp.SyntaxHighlighter.HighlightAll('code', true, true);\n";
185
	echo "</script>\n";
186
}
187
?>
188

    
189
<script type="text/javascript">
190
NiftyCheck();
191
Rounded("div#shapeme","all","#FFF","#eeeeee","smooth");
192
Rounded("div#textareaitem","all","#FFF","#eeeeee","smooth");
193
</script>
(30-30/164)