Project

General

Profile

Download (6.88 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
?>
115
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
116
<html>
117
<head>
118
	<title><?=gentitle($pgtitle);?></title>
119
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
120
	<link rel="stylesheet" type="text/css" href="/niftycssCode.css">
121
	<link rel="stylesheet" type="text/css" href="/niftycssprintCode.css" media="print">
122
	<link href="gui.css" rel="stylesheet" type="text/css">
123
	<link type="text/css" rel="stylesheet" href="/code-syntax-highlighter/SyntaxHighlighter.css"></link>
124
	<script type="text/javascript" src="/niftyjsCode.js"></script>
125
	<style>
126
	/* @import url(SyntaxHighlighter.css); */
127
	
128
	body {
129
	    font-family: Arial;
130
	    font-size: 12px;
131
	}
132
	</style>
133
    
134
</head>
135

    
136
<?php include("fbegin.inc"); ?>
137

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

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

    
168
<br>
169

    
170
  <table width='100%'>
171
    <tr>
172
      <td valign="top" class="label">
173
	<div style="background:#eeeeee" id="textareaitem">
174
	&nbsp;<br>&nbsp;
175
	<textarea 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>
(21-21/128)