Menu

[r10367]: / legacy / www / services_websrv.php  Maximize  Restore  History

Download this file

274 lines (241 with data), 11.6 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
270
271
272
273
#!/usr/local/bin/php
<?php
/*
services_websrv.php
Modified for XHTML by Daisuke Aoyama (aoyama@peach.ne.jp)
Copyright (C) 2010-2011 Daisuke Aoyama <aoyama@peach.ne.jp>.
All rights reserved.
Copyright (C) 2006-2010 Volker Theile (votdev@gmx.de)
All rights reserved.
part of FreeNAS (http://www.freenas.org)
Copyright (C) 2005-2011 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("auth.inc");
require("guiconfig.inc");
require("services.inc");
$pgtitle = array(gettext("Services"),gettext("Webserver"));
if (!is_array($config['websrv']))
$config['websrv'] = array();
if (!is_array($config['websrv']['authentication']['url']))
$config['websrv']['authentication']['url'] = 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']['enable']);
$pconfig['dirlisting'] = isset($config['websrv']['dirlisting']);
$pconfig['auxparam'] = "";
if (is_array($config['websrv']['auxparam']))
$pconfig['auxparam'] = implode("\n", $config['websrv']['auxparam']);
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 (services_is_port_used($_POST['port'], "websrv"))
$input_errors[] = sprintf(gettext("Port %ld is already used by another service."), $_POST['port']);
// Check Webserver document root if auth is required
if (isset($_POST['authentication'])
&& !is_dir($_POST['documentroot'])) {
$input_errors[] = gettext("Webserver document root is missing.");
}
}
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']['enable'] = $_POST['authentication'] ? true : false;
$config['websrv']['dirlisting'] = $_POST['dirlisting'] ? true : false;
// Write additional parameters.
unset($config['websrv']['auxparam']);
foreach (explode("\n", $_POST['auxparam']) as $auxparam) {
$auxparam = trim($auxparam, "\t\n\r");
if (!empty($auxparam))
$config['websrv']['auxparam'][] = $auxparam;
}
write_config();
$retval = 0;
if (!file_exists($d_sysrebootreqd_path)) {
$retval |= updatenotify_process("websrvauth", "websrvauth_process_updatenotification");
config_lock();
$retval |= rc_exec_service("websrv_htpasswd");
$retval |= rc_update_service("websrv");
config_unlock();
}
$savemsg = get_std_save_message($retval);
if (0 == $retval) {
updatenotify_delete("websrvauth");
}
}
}
if($_GET['act'] === "del") {
updatenotify_set("websrvauth", UPDATENOTIFY_MODE_DIRTY, $_GET['uuid']);
header("Location: services_websrv.php");
exit;
}
function websrvauth_process_updatenotification($mode, $data) {
global $config;
$retval = 0;
switch ($mode) {
case UPDATENOTIFY_MODE_NEW:
case UPDATENOTIFY_MODE_MODIFIED:
break;
case UPDATENOTIFY_MODE_DIRTY:
$cnid = array_search_ex($data, $config['websrv']['authentication']['url'], "uuid");
if (FALSE !== $cnid) {
unset($config['websrv']['authentication']['url'][$cnid]);
write_config();
}
break;
}
return $retval;
}
?>
<?php include("fbegin.inc");?>
<script type="text/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.documentrootbrowsebtn.disabled = endis;
document.iform.privatekey.disabled = endis;
document.iform.certificate.disabled = endis;
document.iform.authentication.disabled = endis;
document.iform.dirlisting.disabled = endis;
document.iform.auxparam.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>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="tabcont">
<form action="services_websrv.php" method="post" name="iform" id="iform">
<?php if ($input_errors) print_input_errors($input_errors);?>
<?php if ($savemsg) print_info_box($savemsg);?>
<?php if (updatenotify_exists("websrvauth")) print_config_change_box();?>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<?php html_titleline_checkbox("enable", gettext("Webserver"), $pconfig['enable'] ? true : false, gettext("Enable"), "enable_change(false)");?>
<?php html_combobox("protocol", gettext("Protocol"), $pconfig['protocol'], array("http" => "HTTP", "https" => "HTTPS"), "", true, false, "protocol_change()");?>
<?php html_inputbox("port", gettext("Port"), $pconfig['port'], gettext("TCP port to bind the server to."), true, 5);?>
<?php html_textarea("certificate", gettext("Certificate"), $pconfig['certificate'], gettext("Paste a signed certificate in X.509 PEM format here."), true, 65, 7, false, false);?>
<?php html_textarea("privatekey", gettext("Private key"), $pconfig['privatekey'], gettext("Paste an private key in PEM format here."), true, 65, 7, false, false);?>
<?php html_filechooser("documentroot", gettext("Document root"), $pconfig['documentroot'], gettext("Document root of the webserver. Home of the web page files."), $g['media_path'], true, 60);?>
<?php html_checkbox("authentication", gettext("Authentication"), $pconfig['authentication'] ? true : false, gettext("Enable authentication."), gettext("Give only local users access to the web page."), false, "authentication_change()");?>
<tr id="authdirs_tr">
<td width="22%" valign="top" class="vncell">&nbsp;</td>
<td width="78%" class="vtable">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="45%" class="listhdrlr"><?=gettext("URL");?></td>
<td width="45%" class="listhdrr"><?=gettext("Realm");?></td>
<td width="10%" class="list"></td>
</tr>
<?php foreach ($config['websrv']['authentication']['url'] as $urlv):?>
<?php $notificationmode = updatenotify_get_mode("websrvauth", $urlv['uuid']);?>
<tr>
<td class="listlr"><?=htmlspecialchars($urlv['path']);?>&nbsp;</td>
<td class="listr"><?=htmlspecialchars($urlv['realm']);?>&nbsp;</td>
<?php if (UPDATENOTIFY_MODE_DIRTY != $notificationmode):?>
<td valign="middle" nowrap="nowrap" class="list">
<?php if (isset($config['websrv']['enable'])):?>
<a href="services_websrv_authurl.php?uuid=<?=$urlv['uuid'];?>"><img src="e.gif" title="<?=gettext("Edit URL");?>" border="0" alt="<?=gettext("Edit URL");?>" /></a>&nbsp;
<a href="services_websrv.php?act=del&amp;uuid=<?=$urlv['uuid'];?>" onclick="return confirm('<?=gettext("Do you really want to delete this URL?");?>')"><img src="x.gif" title="<?=gettext("Delete URL");?>" border="0" alt="<?=gettext("Delete URL");?>" /></a>
<?php endif;?>
</td>
<?php else:?>
<td valign="middle" nowrap="nowrap" class="list">
<img src="del.gif" border="0" alt="" />
</td>
<?php endif;?>
</tr>
<?php endforeach;?>
<tr>
<td class="list" colspan="2"></td>
<td class="list">
<a href="services_websrv_authurl.php"><img src="plus.gif" title="<?=gettext("Add URL");?>" border="0" alt="<?=gettext("Add URL");?>" /></a>
</td>
</tr>
</table>
<span class="vexpl"><?=gettext("Define directories/URL's that require authentication.");?></span>
</td>
</tr>
<?php html_checkbox("dirlisting", gettext("Directory listing"), $pconfig['dirlisting'] ? true : false, gettext("Enable directory listing."), 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."), false);?>
<?php html_textarea("auxparam", gettext("Auxiliary parameters"), $pconfig['auxparam'], sprintf(gettext("These parameters will be added to %s."), "wersrv.conf") . " " . sprintf(gettext("Please check the <a href='%s' target='_blank'>documentation</a>."), "http://redmine.lighttpd.net/wiki/lighttpd"), false, 65, 5, false, false);?>
</table>
<div id="submit">
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save and Restart");?>" onclick="enable_change(true)" />
</div>
<?php include("formend.inc");?>
</form>
</td>
</tr>
</table>
<script type="text/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.