Menu

[r3313]: / experimental / webgui / services_websrv.php  Maximize  Restore  History

Download this file

270 lines (246 with data), 12.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/local/bin/php
<?php
/*
services_websrv.php
Copyright © 2006-2008 Volker Theile (votdev@gmx.de)
All rights reserved.
part of FreeNAS (http://www.freenas.org)
Copyright (C) 2005-2008 Olivier Cochard <olivier@freenas.org>.
All rights reserved.
Based on m0n0wall (http://m0n0.ch/wall)
Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require("guiconfig.inc");
$pgtitle = array(gettext("Services"),gettext("Webserver"));
if(!is_array($config['websrv']))
$config['websrv'] = array();
$pconfig['enable'] = isset($config['websrv']['enable']);
$pconfig['protocol'] = $config['websrv']['protocol'];
$pconfig['port'] = $config['websrv']['port'];
$pconfig['documentroot'] = $config['websrv']['documentroot'];
$pconfig['privatekey'] = base64_decode($config['websrv']['privatekey']);
$pconfig['certificate'] = base64_decode($config['websrv']['certificate']);
$pconfig['authentication'] = isset($config['websrv']['authentication']);
$pconfig['dirlisting'] = isset($config['websrv']['dirlisting']);
if($_POST) {
unset($input_errors);
$pconfig = $_POST;
// Input validation.
if($_POST['enable']) {
$reqdfields = explode(" ", "port documentroot");
$reqdfieldsn = array(gettext("Port"), gettext("Document root"));
$reqdfieldst = explode(" ", "port string");
if ("https" === $_POST['protocol']) {
$reqdfields = array_merge($reqdfields, explode(" ", "certificate privatekey"));
$reqdfieldsn = array_merge($reqdfieldsn, array(gettext("Certificate"), gettext("Private key")));
$reqdfieldst = array_merge($reqdfieldst, explode(" ", "certificate privatekey"));
}
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
do_input_validation_type($_POST, $reqdfields, $reqdfieldsn, $reqdfieldst, &$input_errors);
// Check if port is already used.
if (isset($config['system']['webgui']['port']) && ($config['system']['webgui']['port'] === $_POST['port'])) {
$input_errors[] = gettext("Port is already used by WebGUI.");
}
if (!isset($config['system']['webgui']['port']) && ("80" === $_POST['port'])) {
$input_errors[] = gettext("Port is already used by WebGUI.");
}
}
if(!$input_errors) {
$config['websrv']['enable'] = $_POST['enable'] ? true : false;
$config['websrv']['protocol'] = $_POST['protocol'];
$config['websrv']['port'] = $_POST['port'];
$config['websrv']['documentroot'] = $_POST['documentroot'];
$config['websrv']['privatekey'] = base64_encode($_POST['privatekey']);
$config['websrv']['certificate'] = base64_encode($_POST['certificate']);
$config['websrv']['authentication'] = $_POST['authentication'] ? true : false;
$config['websrv']['dirlisting'] = $_POST['dirlisting'] ? true : false;
write_config();
$retval = 0;
if(!file_exists($d_sysrebootreqd_path)) {
config_lock();
$retval |= rc_exec_service("websrv_htpasswd");
$retval |= rc_update_service("websrv");
config_unlock();
}
$savemsg = get_std_save_message($retval);
}
}
?>
<?php include("fbegin.inc");?>
<script language="JavaScript">
<!--
function enable_change(enable_change) {
var endis = !(document.iform.enable.checked || enable_change);
document.iform.protocol.disabled = endis;
document.iform.port.disabled = endis;
document.iform.documentroot.disabled = endis;
document.iform.privatekey.disabled = endis;
document.iform.certificate.disabled = endis;
document.iform.authentication.disabled = endis;
document.iform.dirlisting.disabled = endis;
}
function protocol_change() {
switch(document.iform.protocol.selectedIndex) {
case 0:
showElementById('privatekey_tr','hide');
showElementById('certificate_tr','hide');
break;
default:
showElementById('privatekey_tr','show');
showElementById('certificate_tr','show');
break;
}
}
function authentication_change() {
switch(document.iform.authentication.checked) {
case false:
showElementById('authdirs_tr','hide');
break;
case true:
showElementById('authdirs_tr','show');
break;
}
}
//-->
</script>
<form action="services_websrv.php" method="post" name="iform" id="iform">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="tabcont">
<?php if ($input_errors) print_input_errors($input_errors);?>
<?php if ($savemsg) print_info_box($savemsg);?>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr>
<td colspan="2" valign="top" class="optsect_t">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td class="optsect_s"><strong><?=gettext("Webserver");?></strong></td>
<td align="right" class="optsect_s"><input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)"> <strong><?=gettext("Enable");?></strong></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
<td width="78%" class="vtable">
<select name="protocol" class="formfld" id="protocol" onchange="protocol_change()">
<?php $types = array(gettext("HTTP"),gettext("HTTPS")); $vals = explode(" ", "http https");?>
<?php $j = 0; for ($j = 0; $j < count($vals); $j++):?>
<option value="<?=$vals[$j];?>" <?php if ($vals[$j] === $pconfig['protocol']) echo "selected";?>><?=htmlspecialchars($types[$j]);?></option>
<?php endfor;?>
</select>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Port");?></td>
<td width="78%" class="vtable">
<input name="port" type="text" class="formfld" id="port" size="5" value="<?=htmlspecialchars($pconfig['port']);?>"><br/>
<span class="vexpl"><?=gettext("TCP port to bind the server to.");?></span>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Document root");?></td>
<td width="78%" class="vtable">
<input name="documentroot" type="text" class="formfld" id="documentroot" size="60" value="<?=htmlspecialchars($pconfig['documentroot']);?>">
<input name="browse" type="button" class="formbtn" id="Browse" onClick='ifield = form.documentroot; filechooser = window.open("filechooser.php?p="+escape(ifield.value)+"&sd=/mnt", "filechooser", "scrollbars=yes,toolbar=no,menubar=no,statusbar=no,width=550,height=300"); filechooser.ifield = ifield; window.ifield = ifield;' value="..." \><br/>
<span class="vexpl"><?=gettext("Document root of the webserver. Home of the web page files.");?></span>
</td>
</tr>
<tr id="privatekey_tr">
<td width="22%" valign="top" class="vncellreq"><?=gettext("Private key");?></td>
<td width="78%" class="vtable">
<textarea name="privatekey" cols="65" rows="7" id="privatekey" class="formpre"><?=htmlspecialchars($pconfig['privatekey']);?></textarea></br>
<span class="vexpl"><?=gettext("Paste an private key in PEM format here.");?></span>
</td>
</tr>
<tr id="certificate_tr">
<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate");?></td>
<td width="78%" class="vtable">
<textarea name="certificate" cols="65" rows="7" id="certificate" class="formpre"><?=htmlspecialchars($pconfig['certificate']);?></textarea></br>
<span class="vexpl"><?=gettext("Paste a signed certificate in X.509 PEM format here.");?></span>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Authentication");?></td>
<td width="78%" class="vtable">
<input name="authentication" type="checkbox" id="authentication" value="yes" <?php if ($pconfig['authentication']) echo "checked";?> onchange="authentication_change()">
<?=gettext("Enable authentication.");?><br/>
<span class="vexpl"><?=gettext("Give only local users access to the web page.");?></span>
</td>
</tr>
<tr id="authdirs_tr">
<td width="22%" valign="top" class="vncell"><?=gettext("Directories");?></td>
<td width="78%" class="vtable">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="55%" class="listhdrr"><?=gettext("Directory");?></td>
<td width="35%" class="listhdrr"><?=gettext("Realm");?></td>
<td width="10%" class="list"></td>
</tr>
<?php if (is_array($config['samba']['auxparam'])):?>
<?php $i = 0; foreach($config['samba']['auxparam'] as $auxparamv):?>
<tr>
<td class="listlr"><?=htmlspecialchars($auxparamv);?>&nbsp;</td>
<td class="listr"><?=htmlspecialchars($auxparamv);?>&nbsp;</td>
<td valign="middle" nowrap class="list">
<?php if(isset($config['samba']['enable'])):?>
<a href="services_samba_auxparam.php?id=<?=$i;?>"><img src="e.gif" title="<?=gettext("Edit directory");?>" width="17" height="17" border="0"></a>&nbsp;
<a href="services_samba.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this directory?");?>')"><img src="x.gif" title="<?=gettext("Delete parameter"); ?>" width="17" height="17" border="0"></a>
<?php endif;?>
</td>
</tr>
<?php $i++; endforeach;?>
<?php endif;?>
<tr>
<td class="list" colspan="2"></td>
<td class="list"><a href="services_websrv_edit.php"><img src="plus.gif" title="<?=gettext("Add directory");?>" width="17" height="17" border="0"></a></td>
</tr>
</table>
<span class="vexpl"><?=gettext("Define directories that require authentication.");?></span>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Directory listing");?></td>
<td width="78%" class="vtable">
<input name="dirlisting" type="checkbox" id="dirlisting" value="yes" <?php if ($pconfig['dirlisting']) echo "checked"; ?>>
<?=gettext("Enable directory listing.");?><br/>
<span class="vexpl"><?=gettext("A directory listing is generated if a directory is requested and no index-file (index.php, index.html, index.htm or default.htm) was found in that directory.");?></span>
</td>
</tr>
<tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save and Restart");?>" onClick="enable_change(true)">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<script language="JavaScript">
<!--
enable_change(false);
protocol_change();
authentication_change();
//-->
</script>
<?php include("fend.inc");?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.