update_upnp is working through php/class
This commit is contained in:
parent
72da751578
commit
39c45d06e3
|
@ -599,3 +599,5 @@ upnp/m_upnp.php -text
|
|||
upnp/update_upnp.sh -text
|
||||
upnp/upnp-cron -text
|
||||
upnp/upnp.sql -text
|
||||
upnp/upnp_change.php -text
|
||||
upnp/upnp_list.php -text
|
||||
|
|
|
@ -85,11 +85,15 @@ class m_upnp {
|
|||
global $db,$err;
|
||||
$id=intval($id);
|
||||
$err->log("upnp","disable_port($id)");
|
||||
$db->query("SELECT enabled FROM upnp WHERE id=$id;");
|
||||
$db->query("SELECT enabled,mandatory FROM upnp WHERE id=$id;");
|
||||
if (!$db->next_record()) {
|
||||
$err->raise("upnp",_("The required port is not currently defined"));
|
||||
return false;
|
||||
}
|
||||
if ($db->f("mandatory")) {
|
||||
$err->raise("upnp",_("You can't disable that mandatory port forward"));
|
||||
return false;
|
||||
}
|
||||
if ($db->f("enabled")) {
|
||||
$db->query("UPDATE upnp SET enabled=0 WHERE id=$id;");
|
||||
$err->raise("upnp",_("The specified upnp port is now disabled"));
|
||||
|
@ -101,4 +105,8 @@ class m_upnp {
|
|||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} /* Class UPnP */
|
||||
|
||||
|
|
|
@ -1,47 +1,31 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This configures the upnp client for AlternC
|
||||
#
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
CONFIG_FILE="/etc/alternc/local.sh"
|
||||
$f=@fopen("/etc/alternc/local.sh","rb");
|
||||
if (!$f) {
|
||||
echo "Can't find /etc/alternc/local.sh, please install AlternC properly !\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
if [ ! -r "$CONFIG_FILE" ]; then
|
||||
echo "Can't access $CONFIG_FILE."
|
||||
exit 1
|
||||
fi
|
||||
. "$CONFIG_FILE"
|
||||
$ALTERNC_LOC="";
|
||||
while ($s=fgets($f,1024)) {
|
||||
if (strpos($s,"=")!==false) {
|
||||
list($key,$val)=explode("=",trim($s),2);
|
||||
if (trim($key)=="ALTERNC_LOC") {
|
||||
$val=trim(trim($val,"'\""));
|
||||
$ALTERNC_LOC=$val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
# Some vars
|
||||
umask 022
|
||||
LOCK_FILE="/tmp/alternc-upnp.lock"
|
||||
}
|
||||
fclose($f);
|
||||
if (!$ALTERNC_LOC) {
|
||||
echo "Can't find ALTERNC_LOC in /etc/alternc/local.sh, please install AlternC properly !\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
# Somes check before start operations
|
||||
if [ `id -u` -ne 0 ]; then
|
||||
log_error "must be launched as root"
|
||||
elif [ -z "$INTERNAL_IP" -o -z "$PUBLIC_IP" ]; then
|
||||
log_error "Bad configuration. Please use: dpkg-reconfigure alternc"
|
||||
elif [ -f "$LOCK_FILE" ]; then
|
||||
process=$(ps f -p `cat "$LOCK_FILE"|tail -1`|tail -1|awk '{print $NF;}')
|
||||
if [ "$(basename $process)" = "$(basename "$0")" ] ; then
|
||||
log_error "last cron unfinished or stale lock file ($LOCK_FILE)."
|
||||
else
|
||||
rm "$LOCK_FILE"
|
||||
fi
|
||||
fi
|
||||
require_once($ALTERNC_LOC."/class/config_nochk.php");
|
||||
|
||||
# We lock the application
|
||||
echo $$ > "$LOCK_FILE"
|
||||
|
||||
# Check the status of the router
|
||||
upnpc -s
|
||||
if [ "$?" != "0" ]
|
||||
then
|
||||
|
||||
fi
|
||||
|
||||
|
||||
|
||||
rm -f "$LOCK_FILE"
|
||||
|
||||
exit 0
|
||||
$upnp->cron();
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS `upnp` (
|
|||
`enabled` tinyint(3) unsigned NOT NULL,
|
||||
`lastcheck` datetime NOT NULL,
|
||||
`lastupdate` datetime NOT NULL,
|
||||
`action` enum('CREATE','OK','DISABLE','ENABLE','DELETE','DELETING') NOT NULL DEFAULT 'CREATE',
|
||||
`result` varchar(128) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM COMMENT='UPnP port forwards and their status.';
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/*
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2000-2012 by the AlternC Development Team.
|
||||
https://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
Purpose of file: Enable or disable a UPnP port forwarding
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
require_once("../class/config.php");
|
||||
include_once("head.php");
|
||||
|
||||
if (!$admin->enabled) {
|
||||
__("This page is restricted to authorized staff");
|
||||
exit();
|
||||
}
|
||||
|
||||
$fields = array (
|
||||
"id" => array ("request", "integer", 0),
|
||||
"action" => array("request", "string", "enable"),
|
||||
);
|
||||
getFields($fields);
|
||||
|
||||
if ($action=="disable") {
|
||||
$upnp->disable($id);
|
||||
} else {
|
||||
$upnp->enable($id);
|
||||
}
|
||||
|
||||
require_once("upnp_list.php");
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
/*
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2000-2012 by the AlternC Development Team.
|
||||
https://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
Purpose of file: Show the UPnP port forwarding list
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
require_once("../class/config.php");
|
||||
include_once("head.php");
|
||||
|
||||
if (!$admin->enabled) {
|
||||
__("This page is restricted to authorized staff");
|
||||
exit();
|
||||
}
|
||||
|
||||
$r=$upnp->get_forward_list();
|
||||
|
||||
$aaction=array("CREATE" => _("Creation in progress"),
|
||||
"DELETE" => _("Deletion in progress"),
|
||||
"DELETING" => _("Deletion in progress"),
|
||||
"DISABLE" => _("Will be disabled soon"),
|
||||
"ENABLE" => _("Will be enabled soon"),
|
||||
"OK" => _("OK"),
|
||||
);
|
||||
|
||||
?>
|
||||
<h3><?php __("UPnP port forwarding list"); ?></h3>
|
||||
<hr id="topbar"/>
|
||||
<br />
|
||||
<?php
|
||||
if (isset($error) && $error ) {
|
||||
echo "<p class=\"error\">$error</p>";
|
||||
}
|
||||
?>
|
||||
<p>
|
||||
<?php __("Here is the list of the requested port forward for AlternC's services, and their status. You can enable or disable some of them."); ?>
|
||||
|
||||
<table class="tlist">
|
||||
<tr>
|
||||
<th></th>
|
||||
<th><?php __("Name"); ?></th>
|
||||
<th><?php __("Class"); ?></th>
|
||||
<th><?php __("Protocol/Port") ?></th>
|
||||
<th><?php __("Mandatory") ?></th>
|
||||
<th><?php __("Enabled") ?></th>
|
||||
<th><?php __("Last Check"); ?></th>
|
||||
<th><?php __("Last Update"); ?></th>
|
||||
<th><?php __("Status"); ?></th>
|
||||
</tr>
|
||||
<?php
|
||||
reset($r);
|
||||
|
||||
$col=1;
|
||||
while (list($key,$val)=each($r))
|
||||
{
|
||||
$col=3-$col;
|
||||
?>
|
||||
<tr class="lst<?php echo $col; ?>">
|
||||
|
||||
<?php
|
||||
if ($val["mandatory"]) { ?>
|
||||
<td> </td>
|
||||
<?php } else { ?>
|
||||
<td><?php if ($val["enabled"]) { ?><a href="upnp_change.php?action=disable&id=<?php echo $val["id"]; ?>"><?php __("Disable"); ?></a><?php } else { ?><a href="upnp_change.php?action=enable&id=<?php echo $val["id"]; ?>"><?php __("Enable"); ?></a><?php } ?></td>
|
||||
<?php } ?>
|
||||
<td><?php echo $val["class"] ?></td>
|
||||
<td><?php echo $val["protocol"]."/".$val["port"] ?></td>
|
||||
<td><?php if ($val["mandatory"]) __("Yes"); else __("No"); ?></td>
|
||||
<td><?php if ($val["enabled"]) __("Yes"); else __("No"); ?></td>
|
||||
<td><?php echo $val["lastcheck"] ?></td>
|
||||
<td><?php echo $val["lastupdate"] ?></td>
|
||||
<td><?php echo $aaction[$val["status"]]; ?><br /><?php echo $val["result"]; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
} // for loop
|
||||
?>
|
||||
</table>
|
||||
</form>
|
||||
<?php include_once("foot.php"); ?>
|
||||
|
Loading…
Reference in New Issue