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/update_upnp.sh -text
|
||||||
upnp/upnp-cron -text
|
upnp/upnp-cron -text
|
||||||
upnp/upnp.sql -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;
|
global $db,$err;
|
||||||
$id=intval($id);
|
$id=intval($id);
|
||||||
$err->log("upnp","disable_port($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()) {
|
if (!$db->next_record()) {
|
||||||
$err->raise("upnp",_("The required port is not currently defined"));
|
$err->raise("upnp",_("The required port is not currently defined"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if ($db->f("mandatory")) {
|
||||||
|
$err->raise("upnp",_("You can't disable that mandatory port forward"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if ($db->f("enabled")) {
|
if ($db->f("enabled")) {
|
||||||
$db->query("UPDATE upnp SET enabled=0 WHERE id=$id;");
|
$db->query("UPDATE upnp SET enabled=0 WHERE id=$id;");
|
||||||
$err->raise("upnp",_("The specified upnp port is now disabled"));
|
$err->raise("upnp",_("The specified upnp port is now disabled"));
|
||||||
|
@ -99,6 +103,10 @@ class m_upnp {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
} /* Class UPnP */
|
||||||
|
|
||||||
|
|
|
@ -1,47 +1,31 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/php
|
||||||
#
|
<?php
|
||||||
# This configures the upnp client for AlternC
|
|
||||||
#
|
|
||||||
|
|
||||||
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
|
$ALTERNC_LOC="";
|
||||||
echo "Can't access $CONFIG_FILE."
|
while ($s=fgets($f,1024)) {
|
||||||
exit 1
|
if (strpos($s,"=")!==false) {
|
||||||
fi
|
list($key,$val)=explode("=",trim($s),2);
|
||||||
. "$CONFIG_FILE"
|
if (trim($key)=="ALTERNC_LOC") {
|
||||||
|
$val=trim(trim($val,"'\""));
|
||||||
|
$ALTERNC_LOC=$val;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
fclose($f);
|
||||||
|
if (!$ALTERNC_LOC) {
|
||||||
|
echo "Can't find ALTERNC_LOC in /etc/alternc/local.sh, please install AlternC properly !\n";
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
# Some vars
|
require_once($ALTERNC_LOC."/class/config_nochk.php");
|
||||||
umask 022
|
|
||||||
LOCK_FILE="/tmp/alternc-upnp.lock"
|
|
||||||
|
|
||||||
# Somes check before start operations
|
$upnp->cron();
|
||||||
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
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS `upnp` (
|
||||||
`enabled` tinyint(3) unsigned NOT NULL,
|
`enabled` tinyint(3) unsigned NOT NULL,
|
||||||
`lastcheck` datetime NOT NULL,
|
`lastcheck` datetime NOT NULL,
|
||||||
`lastupdate` datetime NOT NULL,
|
`lastupdate` datetime NOT NULL,
|
||||||
|
`action` enum('CREATE','OK','DISABLE','ENABLE','DELETE','DELETING') NOT NULL DEFAULT 'CREATE',
|
||||||
`result` varchar(128) NOT NULL,
|
`result` varchar(128) NOT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=MyISAM COMMENT='UPnP port forwards and their status.';
|
) 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