From: <abe...@us...> - 2012-07-08 01:36:12
|
Revision: 5597 http://astlinux.svn.sourceforge.net/astlinux/?rev=5597&view=rev Author: abelbeck Date: 2012-07-08 01:36:05 +0000 (Sun, 08 Jul 2012) Log Message: ----------- webinterface, add support for miniupnpd Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/edit.php branches/1.0/package/webinterface/altweb/admin/network.php branches/1.0/package/webinterface/altweb/common/status.inc branches/1.0/package/webinterface/altweb/common/version.php Modified: branches/1.0/package/webinterface/altweb/admin/edit.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/edit.php 2012-07-07 21:26:26 UTC (rev 5596) +++ branches/1.0/package/webinterface/altweb/admin/edit.php 2012-07-08 01:36:05 UTC (rev 5597) @@ -27,6 +27,7 @@ 'openvpnclient' => 'Restart OpenVPN Client', 'racoon' => 'Restart IPsec VPN', 'pptpd' => 'Restart PPTP VPN Server', + 'miniupnpd' => 'Restart Univ. Plug\'n\'Play', 'apcupsd' => 'Restart UPS Daemon', 'asterisk' => 'Restart Asterisk', 'cron' => 'Reload Cron for root' @@ -198,8 +199,10 @@ $result = restartPROCESS($process, 32, $result, 'init'); } elseif ($process === 'pptpd') { $result = restartPROCESS($process, 33, $result, 'init'); + } elseif ($process === 'miniupnpd') { + $result = restartPROCESS($process, 34, $result, 'init'); } elseif ($process === 'apcupsd') { - $result = restartPROCESS($process, 34, $result, 'init'); + $result = restartPROCESS($process, 35, $result, 'init'); } elseif ($process === 'cron') { $result = updateCRON('root', 30, $result); } @@ -302,6 +305,8 @@ } elseif ($result == 33) { putHtml('<p style="color: green;">PPTP VPN Server has Restarted.</p>'); } elseif ($result == 34) { + putHtml('<p style="color: green;">Universal Plug\'n\'Play has Restarted.</p>'); + } elseif ($result == 35) { putHtml('<p style="color: green;">UPS Daemon has Restarted.</p>'); } elseif ($result == 99) { putHtml('<p style="color: red;">Action Failed.</p>'); Modified: branches/1.0/package/webinterface/altweb/admin/network.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/network.php 2012-07-07 21:26:26 UTC (rev 5596) +++ branches/1.0/package/webinterface/altweb/admin/network.php 2012-07-08 01:36:05 UTC (rev 5597) @@ -30,6 +30,7 @@ // 05-24-2011, Added SIP Monitoring // 12-03-2011, Added HTTP_ACCESSLOG and HTTPS_ACCESSLOG support // 01-28-2012, Added LOCALDNS_LOCAL_DOMAIN support +// 07-07-2012, Added Universal Plug & Play support // // System location of rc.conf file $CONFFILE = '/etc/rc.conf'; @@ -98,6 +99,13 @@ 'simple' => 'simple' ); +$select_upnp = array ( + 'disabled' => 'no:no', + 'NAT-PMP only' => 'yes:no', + 'UPnP only' => 'no:yes', + 'NAT-PMP & UPnP' => 'yes:yes' +); + // Function: checkNETWORKsettings // function checkNETWORKsettings() { @@ -389,6 +397,29 @@ $value = 'CLI_PROXY_SERVER="'.$_POST['cli_proxy'].'"'; fwrite($fp, "### CLI Proxy Server\n".$value."\n"); + $x_value = $_POST['upnp']; + $tokens = explode(':', $x_value); + $value = 'UPNP_ENABLE_NATPMP="'.$tokens[0].'"'; + fwrite($fp, "### UPnP NAT-PMP\n".$value."\n"); + $value = 'UPNP_ENABLE_UPNP="'.$tokens[1].'"'; + fwrite($fp, "### UPnP Enable\n".$value."\n"); + + $x_value = ''; + if (isset($_POST['upnp_INTIF'])) { + $x_value .= ' INTIF'; + } + if (isset($_POST['upnp_INT2IF'])) { + $x_value .= ' INT2IF'; + } + if (isset($_POST['upnp_INT3IF'])) { + $x_value .= ' INT3IF'; + } + if (isset($_POST['upnp_DMZIF'])) { + $x_value .= ' DMZIF'; + } + $value = 'UPNP_LISTEN="'.trim($x_value).'"'; + fwrite($fp, "### UPnP Listen Interfaces\n".$value."\n"); + $value = 'HTTPDIR="'.trim($_POST['http_dir']).'"'; fwrite($fp, "### HTTP Server Directory\n".$value."\n"); @@ -835,8 +866,10 @@ $result = restartPROCESS($process, 32, $result, 'init'); } elseif ($process === 'pptpd') { $result = restartPROCESS($process, 33, $result, 'init'); + } elseif ($process === 'miniupnpd') { + $result = restartPROCESS($process, 34, $result, 'init'); } elseif ($process === 'apcupsd') { - $result = restartPROCESS($process, 34, $result, 'init'); + $result = restartPROCESS($process, 35, $result, 'init'); } } else { $result = 2; @@ -902,6 +935,8 @@ } elseif ($result == 33) { putHtml('<p style="color: green;">PPTP VPN Server has Restarted.</p>'); } elseif ($result == 34) { + putHtml('<p style="color: green;">Universal Plug\'n\'Play has Restarted.</p>'); + } elseif ($result == 35) { putHtml('<p style="color: green;">UPS Daemon has Restarted.</p>'); } elseif ($result == 99) { putHtml('<p style="color: red;">Action Failed.</p>'); @@ -921,9 +956,27 @@ } putHtml("</center>"); ?> + <script language="JavaScript" type="text/javascript"> + //<![CDATA[ + function upnp_change() { + var form = document.getElementById("iform"); + switch (form.upnp.selectedIndex) { + case 0: // disabled + break; + case 1: + case 2: + case 3: + alert('WARNING: Enabling either NAT-PMP or UPnP has security implications!\ +\n\nNAT EXT->LAN rules can be created automatically.\ +\n\nIf you must, try NAT-PMP only.'); + break; + } + } + //]]> + </script> <center> <table class="layout"><tr><td><center> - <form method="post" action="<?php echo $myself;?>"> + <form id="iform" method="post" action="<?php echo $myself;?>"> <table width="100%" class="stdtable"> <tr><td style="text-align: center;" colspan="2"> <h2>Network Configuration Settings:</h2> @@ -960,6 +1013,8 @@ putHtml('<option value="racoon"'.$sel.'>Restart IPsec VPN</option>'); $sel = ($reboot_restart === 'pptpd') ? ' selected="selected"' : ''; putHtml('<option value="pptpd"'.$sel.'>Restart PPTP VPN Server</option>'); + $sel = ($reboot_restart === 'miniupnpd') ? ' selected="selected"' : ''; + putHtml('<option value="miniupnpd"'.$sel.'>Restart Univ. Plug\'n\'Play</option>'); $sel = ($reboot_restart === 'apcupsd') ? ' selected="selected"' : ''; putHtml('<option value="apcupsd"'.$sel.'>Restart UPS Daemon</option>'); $sel = ($reboot_restart === 'asterisk') ? ' selected="selected"' : ''; @@ -1354,6 +1409,27 @@ putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); + putHtml("Universal Plug'n'Play:"); + $upnp_natpmp = getVARdef($db, 'UPNP_ENABLE_NATPMP', $cur_db) === 'yes' ? 'yes' : 'no'; + $upnp_upnp = getVARdef($db, 'UPNP_ENABLE_UPNP', $cur_db) === 'yes' ? 'yes' : 'no'; + putHtml('<select name="upnp" onchange="upnp_change()">'); + foreach ($select_upnp as $key => $value) { + $sel = ("$upnp_natpmp:$upnp_upnp" === $value) ? ' selected="selected"' : ''; + putHtml('<option value="'.$value.'"'.$sel.'>'.$key.'</option>'); + } + putHtml('</select>'); + putHtml('– Interfaces:'); + $sel = isVARtype('UPNP_LISTEN', $db, $cur_db, 'INTIF') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="upnp_INTIF" name="upnp_INTIF"'.$sel.' /> 1st LAN'); + $sel = isVARtype('UPNP_LISTEN', $db, $cur_db, 'INT2IF') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="upnp_INT2IF" name="upnp_INT2IF"'.$sel.' /> 2nd LAN'); + $sel = isVARtype('UPNP_LISTEN', $db, $cur_db, 'INT3IF') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="upnp_INT3IF" name="upnp_INT3IF"'.$sel.' /> 3rd LAN'); + $sel = isVARtype('UPNP_LISTEN', $db, $cur_db, 'DMZIF') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="upnp_DMZIF" name="upnp_DMZIF"'.$sel.' /> DMZ'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); $value = getVARdef($db, 'HTTPDIR', $cur_db); putHtml('HTTP Server Directory:<input type="text" size="45" maxlength="64" value="'.$value.'" name="http_dir" />'); putHtml('</td></tr>'); Modified: branches/1.0/package/webinterface/altweb/common/status.inc =================================================================== --- branches/1.0/package/webinterface/altweb/common/status.inc 2012-07-07 21:26:26 UTC (rev 5596) +++ branches/1.0/package/webinterface/altweb/common/status.inc 2012-07-08 01:36:05 UTC (rev 5597) @@ -25,11 +25,14 @@ // 05-05-2011, Added DAHDI Status and Hardware Monitoring sections // 08-10-2011, Added APC UPS Status // 01-02-2012, Added Jabber Status +// 07-07-2012, Added UPnP Status // // System location of OpenVPN Client logfile $OVPNCLOGFILE = '/var/log/openvpnclient-status.log'; // System location of OpenVPN Server logfile $OVPNLOGFILE = '/var/log/openvpn-status.log'; +// System location of MINIUPNPD leases +$MINIUPNPDLEASES = '/var/db/upnp.leases'; // System location of DNSMASQ leases $DNSMASQLEASES = '/var/db/dnsmasq.leases'; // System location of nf_conntrack file @@ -60,6 +63,7 @@ function getDaemons() { $status['asterisk'] = 0; $status['ntpd'] = 0; + $status['miniupnpd'] = 0; $status['dnsmasq'] = 0; $status['openvpn'] = 0; $status['racoon'] = 0; @@ -77,6 +81,8 @@ $status['asterisk']++; } elseif (strpos($line, ' ntpd') !== FALSE || strpos($line, '/ntpd') !== FALSE) { $status['ntpd']++; + } elseif (strpos($line, ' miniupnpd') !== FALSE || strpos($line, '/miniupnpd') !== FALSE) { + $status['miniupnpd']++; } elseif (strpos($line, ' dnsmasq') !== FALSE || strpos($line, '/dnsmasq') !== FALSE) { $status['dnsmasq']++; } elseif (strpos($line, ' syslogd') !== FALSE || strpos($line, '/syslogd') !== FALSE) { @@ -312,6 +318,37 @@ return($status != 0); } +// Function: parseMINIUPNPDleases +// +function parseMINIUPNPDleases($log) { + $cid = 0; + if (($ph = @fopen($log, "r")) !== FALSE) { + while (! feof($ph)) { + if ($line = trim(fgets($ph, 1024))) { + $linetokens = explode(':', $line); + if (isset($linetokens[4])) { + $status['clients'][$cid]['proto'] = $linetokens[0]; + $status['clients'][$cid]['p_port'] = $linetokens[1]; + $status['clients'][$cid]['l_ip'] = $linetokens[2]; + $status['clients'][$cid]['l_port'] = $linetokens[3]; + $status['clients'][$cid]['expire'] = $linetokens[4]; + $status['clients'][$cid]['desc'] = $linetokens[5]; + $cid++; + } + } + } + fclose($ph); + } + // Sort by Public Port + if ($cid > 1) { + foreach ($status['clients'] as $key => $row) { + $p_port[$key] = $row['p_port']; + } + array_multisort($p_port, SORT_ASC, SORT_STRING, $status['clients']); + } + return($status); +} + // Function: parseDNSMASQleases // function parseDNSMASQleases($log) { @@ -620,6 +657,45 @@ } } +if ($daemon['miniupnpd'] > 0) { + if (getPREFdef($global_prefs, 'status_show_miniupnpd_leases') !== 'no') { // currently not set in the Prefs tab + putHtml("<h2>Universal Plug'n'Play (NAT-PMP and UPnP) Leases:</h2>"); + + if (is_null($upnp = parseMINIUPNPDleases($MINIUPNPDLEASES))) { + putHtml("<pre>"); + putText('No Active NAT-PMP or UPnP Leases'); + putHtml("</pre>"); + } else { + putHtml('<pre><table class="statusdatatable">'); + putHtml("<tr>"); + $cur_time = time(); + if (($n = count($upnp['clients'])) > 0) { + echo "<td>", "Public Port", "</td>"; + echo "<td>", "Protocol", "</td>"; + echo "<td>", "Local IPv4", "</td>"; + echo "<td>", "Local Port", "</td>"; + echo "<td>", "Expire Time", "</td>"; + echo "<td>", "Description", "</td>"; + for ($i = 0; $i < $n; $i++) { + putHtml("</tr><tr>"); + echo "<td>", $upnp['clients'][$i]['p_port'], "</td>"; + echo "<td>", $upnp['clients'][$i]['proto'], "</td>"; + echo "<td>", $upnp['clients'][$i]['l_ip'], "</td>"; + echo "<td>", $upnp['clients'][$i]['l_port'], "</td>"; + if ($upnp['clients'][$i]['expire'] > $cur_time) { + echo "<td>", date('Y-m-d H:i:s', $upnp['clients'][$i]['expire']), "</td>"; + } else { + echo "<td>N/A</td>"; + } + echo "<td>", htmlspecialchars($upnp['clients'][$i]['desc']), "</td>"; + } + } + putHtml("</tr>"); + putHtml("</table></pre>"); + } + } +} + if ($daemon['dnsmasq'] > 0) { if (getPREFdef($global_prefs, 'status_show_dhcp_leases') !== 'no' && isDHCPactive()) { putHtml("<h2>DHCP Leases:</h2>"); Modified: branches/1.0/package/webinterface/altweb/common/version.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/version.php 2012-07-07 21:26:26 UTC (rev 5596) +++ branches/1.0/package/webinterface/altweb/common/version.php 2012-07-08 01:36:05 UTC (rev 5597) @@ -1,6 +1,6 @@ <?php // version.php for AstLinux Alternate Web Interface -$GUI_VERSION = '1.8.12'; +$GUI_VERSION = '1.8.13'; ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |