Project

General

Profile

Download (6.7 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 = 80;
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
$Title      = gentitle("edit file");
107

    
108
// Get year.
109

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

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

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

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

    
139
<script language="Javascript">
140
function sf() { document.forms[0].savetopath.focus(); }
141
</script>
142
<body onLoad="sf();">
143
<p><span class="pgtitle"><?=$Title ?></span>
144
<?php if ($savemsg) print_info_box($savemsg); ?>
145
<?php if ($loadmsg) echo "<p><b>{$loadmsg}<p>"; ?>
146
<form action="edit.php" method="POST">
147

    
148
<div id="shapeme">
149
<table width="100%" cellpadding='9' cellspacing='9' bgcolor='#eeeeee'>
150
 <tr>
151
  <td>
152
	<center>
153
	Save/Load from path: <input size="42" id="savetopath" name="savetopath" value="<?php echo $_POST['savetopath']; ?>">
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
	<input name="submit" type="submit"  class="button" id="Load" value="Load"> |
160
	<input name="submit" type="submit"  class="button" id="Save" value="Save"> |
161
	Highlighting: <input name="highlight" type="radio" value="yes"
162
	<?php if($highlight == "yes") echo " checked"; ?>>Enabled
163
	<input name="highlight" type="radio" value="no"<?php if($highlight == "no") echo " checked"; ?>>Disabled
164
  </td>
165
 </tr>
166
</table>
167
</div>
168

    
169
<br>
170

    
171
  <table width='100%'>
172
    <tr>
173
      <td valign="top" class="label">
174
	<textarea name="code" language="<?php echo $language; ?>" rows="<?php echo $rows; ?>" cols="<?php echo $cols; ?>" name="content"><?php echo htmlentities($content); ?></textarea><br>
175
        <p>
176
    </td>
177
    </tr>
178
  </table>
179
<?php include("fend.inc"); ?>
180
</form>
181
</body>
182
</html>
183

    
184
<script language="Javascript">
185
sf();
186
</script>
187

    
188
</div>
189
<script language="javascript" src="/code-syntax-highlighter/shCore.js"></script>
190
<script language="javascript" src="/code-syntax-highlighter/shBrushCSharp.js"></script>
191
<script language="javascript" src="/code-syntax-highlighter/shBrushPhp.js"></script>
192
<script language="javascript" src="/code-syntax-highlighter/shBrushJScript.js"></script>
193
<script language="javascript" src="/code-syntax-highlighter/shBrushVb.js"></script>
194
<script language="javascript" src="/code-syntax-highlighter/shBrushSql.js"></script>
195
<script language="javascript" src="/code-syntax-highlighter/shBrushXml.js"></script>
196
<script language="javascript" src="/code-syntax-highlighter/shBrushDelphi.js"></script>
197
<script language="javascript" src="/code-syntax-highlighter/shBrushPython.js"></script>
198

    
199
<?php if($_POST['highlight'] == "yes") {
200
	echo "<script language=\"javascript\">\n";
201
	echo "dp.SyntaxHighlighter.HighlightAll('code', true, true);\n";
202
	echo "</script>\n";
203
}
204
?>
205

    
206
<script type="text/javascript">
207
NiftyCheck();
208
Rounded("div#shapeme","all","#FFF","#eeeeee","smooth");
209
</script>
(21-21/127)