Menu

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

Download this file

265 lines (231 with data), 10.8 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
#!/usr/local/bin/php
<?php
/*
services_upnp.php
Modified for XHTML by Daisuke Aoyama (aoyama@peach.ne.jp)
Copyright (C) 2010 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-2010 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("UPnP"));
if (!is_array($config['upnp']))
$config['upnp'] = array();
if (!is_array($config['upnp']['content']))
$config['upnp']['content'] = array();
sort($config['upnp']['content']);
$pconfig['enable'] = isset($config['upnp']['enable']);
$pconfig['name'] = $config['upnp']['name'];
$pconfig['if'] = $config['upnp']['if'];
$pconfig['port'] = $config['upnp']['port'];
$pconfig['web'] = isset($config['upnp']['web']);
$pconfig['home'] = $config['upnp']['home'];
$pconfig['profile'] = $config['upnp']['profile'];
$pconfig['deviceip'] = $config['upnp']['deviceip'];
$pconfig['transcoding'] = isset($config['upnp']['transcoding']);
$pconfig['tempdir'] = $config['upnp']['tempdir'];
$pconfig['content'] = $config['upnp']['content'];
// Set name to configured hostname if it is not set.
if (!$pconfig['name'])
$pconfig['name'] = $config['system']['hostname'];
if ($_POST) {
unset($input_errors);
$pconfig = $_POST;
// Input validation.
if ($_POST['enable']) {
$reqdfields = explode(" ", "name if port content home");
$reqdfieldsn = array(gettext("Name"), gettext("Interface"), gettext("Port"), gettext("Content"), gettext("Database directory"));
$reqdfieldst = explode(" ", "string string port array string");
if ("Terratec_Noxon_iRadio" === $_POST['profile']) {
$reqdfields = array_merge($reqdfields, array("deviceip"));
$reqdfieldsn = array_merge($reqdfieldsn, array(gettext("Device IP")));
$reqdfieldst = array_merge($reqdfieldst, array("ipaddr"));
}
if (isset($_POST['transcoding'])) {
$reqdfields = array_merge($reqdfields, array("tempdir"));
$reqdfieldsn = array_merge($reqdfieldsn, array(gettext("Temporary directory")));
$reqdfieldst = array_merge($reqdfieldst, array("string"));
}
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'], "upnp"))
$input_errors[] = sprintf(gettext("Port %ld is already used by another service."), $_POST['port']);
// Check port range.
if ($_POST['port'] && ((1024 > $_POST['port']) || (65535 < $_POST['port']))) {
$input_errors[] = sprintf(gettext("The attribute '%s' must be in the range from %d to %d."), gettext("Port"), 1025, 65535);
}
}
if (!$input_errors) {
$config['upnp']['enable'] = $_POST['enable'] ? true : false;
$config['upnp']['name'] = $_POST['name'];
$config['upnp']['if'] = $_POST['if'];
$config['upnp']['port'] = $_POST['port'];
$config['upnp']['web'] = $_POST['web'] ? true : false;
$config['upnp']['home'] = $_POST['home'];
$config['upnp']['profile'] = $_POST['profile'];
$config['upnp']['deviceip'] = $_POST['deviceip'];
$config['upnp']['transcoding'] = $_POST['transcoding'] ? true : false;
$config['upnp']['tempdir'] = $_POST['tempdir'];
$config['upnp']['content'] = $_POST['content'];
write_config();
$retval = 0;
if (!file_exists($d_sysrebootreqd_path)) {
config_lock();
$retval |= rc_update_service("fuppes");
$retval |= rc_update_service("mdnsresponder");
config_unlock();
}
$savemsg = get_std_save_message($retval);
if ($retval == 0) {
if (file_exists($d_upnpconfdirty_path))
unlink($d_upnpconfdirty_path);
}
}
}
$a_interface = get_interface_list();
// Use first interface as default if it is not set.
if (empty($pconfig['if']) && is_array($a_interface))
$pconfig['if'] = key($a_interface);
?>
<?php include("fbegin.inc");?>
<script type="text/javascript">
<!--
function enable_change(enable_change) {
var endis = !(document.iform.enable.checked || enable_change);
document.iform.name.disabled = endis;
document.iform.xif.disabled = endis;
document.iform.port.disabled = endis;
document.iform.web.disabled = endis;
document.iform.home.disabled = endis;
document.iform.homebrowsebtn.disabled = endis;
document.iform.content.disabled = endis;
document.iform.contentaddbtn.disabled = endis;
document.iform.contentchangebtn.disabled = endis;
document.iform.contentdeletebtn.disabled = endis;
document.iform.contentdata.disabled = endis;
document.iform.contentbrowsebtn.disabled = endis;
document.iform.profile.disabled = endis;
document.iform.deviceip.disabled = endis;
document.iform.transcoding.disabled = endis;
document.iform.tempdir.disabled = endis;
}
function profile_change() {
switch(document.iform.profile.value) {
case "Terratec_Noxon_iRadio":
showElementById('deviceip_tr','show');
break;
default:
showElementById('deviceip_tr','hide');
break;
}
}
function web_change() {
switch(document.iform.web.checked) {
case false:
showElementById('url_tr','hide');
break;
case true:
showElementById('url_tr','show');
break;
}
}
function transcoding_change() {
switch(document.iform.transcoding.checked) {
case false:
showElementById('tempdir_tr','hide');
break;
case true:
showElementById('tempdir_tr','show');
break;
}
}
//-->
</script>
<form action="services_upnp.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); ?>
<?php if (file_exists($d_upnpconfdirty_path)) print_config_change_box();?>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<?php html_titleline_checkbox("enable", gettext("UPnP A/V Media Server"), $pconfig['enable'] ? true : false, gettext("Enable"), "enable_change(false)");?>
<?php html_inputbox("name", gettext("Name"), $pconfig['name'], gettext("UPnP friendly name."), true, 20);?>
<!--
<?php html_interfacecombobox("if", gettext("Interface"), $pconfig['if'], gettext("Interface to listen to."), true);?>
-->
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
<td width="78%" class="vtable">
<select name="if" class="formfld" id="xif">
<?php foreach($a_interface as $if => $ifinfo):?>
<?php $ifinfo = get_interface_info($if); if (("up" == $ifinfo['status']) || ("associated" == $ifinfo['status'])):?>
<option value="<?=$if;?>"<?php if ($if == $pconfig['if']) echo "selected=\"selected\"";?>><?=$if?></option>
<?php endif;?>
<?php endforeach;?>
</select>
<br /><?=gettext("Interface to listen to.");?>
</td>
</tr>
<?php html_inputbox("port", gettext("Port"), $pconfig['port'], sprintf(gettext("Port to listen on. Only dynamic or private ports can be used (from %d through %d). Default port is %d."), 1025, 65535, 49152), true, 5);?>
<?php html_filechooser("home", gettext("Database directory"), $pconfig['home'], gettext("Location where the content database file will be stored."), $g['media_path'], true, 60);?>
<?php html_folderbox("content", gettext("Content"), $pconfig['content'], gettext("Location of the files to share."), $g['media_path'], true);?>
<?php html_combobox("profile", gettext("Profile"), $pconfig['profile'], array("default" => gettext("Default"), "DLNA" => "DLNA", "PS3" => "Sony Playstation 3", "Telegent_TG100" => "Telegent TG100", "ZyXEL_DMA1000" => "ZyXEL DMA-1000", "Helios_X3000" => "Helios X3000", "DLink_DSM320" => "D-Link DSM320", "Microsoft_XBox360" => "Microsoft XBox 360", "Terratec_Noxon_iRadio" => "Terratec Noxon iRadio", "Yamaha_RXN600" => "Yamaha RX-N600", "Loewe_Connect" => "Loewe Connect"), gettext("Compliant profile to be used."), true, false, "profile_change()");?>
<?php html_inputbox("deviceip", gettext("Device IP"), $pconfig['deviceip'], gettext("The device's IP address."), true, 20);?>
<?php html_checkbox("transcoding", gettext("Transcoding"), $pconfig['transcoding'] ? true : false, gettext("Enable transcoding."), "", false, "transcoding_change()");?>
<?php html_filechooser("tempdir", gettext("Temporary directory"), $pconfig['tempdir'], gettext("Temporary directory to store transcoded files."), $g['media_path'], true, 60);?>
<?php html_separator();?>
<?php html_titleline(gettext("Administrative WebGUI"));?>
<?php html_checkbox("web", gettext("WebGUI"), $pconfig['web'] ? true : false, gettext("Enable web user interface."), "", false, "web_change()");?>
<?php
$if = get_ifname($pconfig['if']);
$ipaddr = get_ipaddr($if);
$url = htmlspecialchars("http://{$ipaddr}:{$pconfig['port']}");
$text = "<a href='{$url}' target='_blank'>{$url}</a>";
?>
<?php html_text("url", gettext("URL"), $text);?>
</table>
<div id="submit">
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save and Restart");?>" onclick="onsubmit_content(); enable_change(true)" />
</div>
</td>
</tr>
</table>
<?php include("formend.inc");?>
</form>
<script type="text/javascript">
<!--
profile_change();
web_change();
transcoding_change();
enable_change(false);
//-->
</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.