Project

General

Profile

Download (6.24 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
    edit.php
6
    Copyright (C) 2004, 2005 Scott Ullrich
7
    All rights reserved.
8

    
9
    Redistribution and use in source and binary forms, with or without
10
    modification, are permitted provided that the following conditions are met:
11

    
12
    1. Redistributions of source code must retain the above copyright notice,
13
       this list of conditions and the following disclaimer.
14

    
15
    2. Redistributions in binary form must reproduce the above copyright
16
       notice, this list of conditions and the following disclaimer in the
17
       documentation and/or other materials provided with the distribution.
18

    
19
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
    POSSIBILITY OF SUCH DAMAGE.
29
*/
30

    
31
require("guiconfig.inc");
32

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

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

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

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

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

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

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

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

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

    
102
// "Constants".
103

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

    
107
// Get year.
108

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

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

    
114
include("head.inc");
115

    
116
?>
117

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

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

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

    
150
<br>
151

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

    
170
<script language="Javascript">
171
sf();
172
</script>
173

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

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

    
192
<script type="text/javascript">
193
NiftyCheck();
194
Rounded("div#shapeme","all","#FFF","#eeeeee","smooth");
195
Rounded("div#textareaitem","all","#FFF","#eeeeee","smooth");
196
</script>
(25-25/143)