adding upnp next step, not finished yet, almost ;)

This commit is contained in:
Benjamin Sonntag 2012-09-04 13:51:53 +00:00
parent 8d7c7690c8
commit 70074ab15c
3 changed files with 65 additions and 9 deletions

View File

@ -1,13 +1,9 @@
<?php <?php
/* /*
$Id: main.php,v 1.3 2004/05/19 14:23:06 benjamin Exp $
---------------------------------------------------------------------- ----------------------------------------------------------------------
AlternC - Web Hosting System AlternC - Web Hosting System
Copyright (C) 2002 by the AlternC Development Team. Copyright (C) 2000-2012 by the AlternC Development Team.
http://alternc.org/ https://alternc.org/
----------------------------------------------------------------------
Based on:
Valentin Lacambre's web hosting softwares: http://altern.org/
---------------------------------------------------------------------- ----------------------------------------------------------------------
LICENSE LICENSE
@ -23,8 +19,7 @@
To read the license please visit http://www.gnu.org/copyleft/gpl.html To read the license please visit http://www.gnu.org/copyleft/gpl.html
---------------------------------------------------------------------- ----------------------------------------------------------------------
Original Author of file: Purpose of file: Main page shown after login, display misc information
Purpose of file:
---------------------------------------------------------------------- ----------------------------------------------------------------------
*/ */
require_once("../class/config.php"); require_once("../class/config.php");

View File

@ -104,6 +104,67 @@ class m_upnp {
} }
/* ----------------------------------------------------------------- */
/** cron launched every minute to check the status of UPnP forwarding
*/
function cron() {
global $hooks;
// if we check anything less than 5 minutes ago, or if the upnp table is empty, let's make a check...
$db->query("SELECT UNIX_TIMESTAMP(lastcheck) AS lc, * FROM upnp ORDER BY lastcheck ASC;");
$forwards=array();
$bigcheck=false;
if (!$db->next_record()) {
$bigcheck=true;
} else {
if ($db->f("lc")+600<time()) {
$bigcheck=true;
}
do {
$db->Record["found"]=false;
$forwards[]=$db->Record;
} while ($db->next_record());
}
if ($bigcheck) {
// Do the check first by calling the hooks & comparing the arrays
$res=$hooks->invoke("hooks_upnp_list");
foreach($res as $c=>$tmp) {
foreach($tmp as $name=>$v) {
// We compare the hook array with the forwards array
$found=false;
for($i=0;$i<count($forwards);$i++) {
if ($forwards[$i]["class"]==$c &&
$forwards[$i]["name"]==$name &&
$forwards[$i]["protocol"]==$v["protocol"] &&
$forwards[$i]["port"]==$v["port"] &&
$forwards[$i]["mandatory"]==$v["mandatory"]) {
// Found it and unchanged
$forwards[$i]["found"]=true;
$found=true;
}
} // compare with forwards class.
if (!$found) {
// Mark it for creation
$db->query("INSERT INTO upnp SET mandatory='".addslashes($v["mandatory"])."', protocol='".addslashes($v["protocol"])."', port='".addslashes($v["port"])."', name='".addslashes($name)."', action='CREATE'");
$id=$db->last_id();
$forwards[]=array("id"=>$id, "mandatory" => intval($v["mandatory"]), "protocol" => $v["protocol"], "port" => intval($v["port"]), "name" => $name, "action" => "CREATE");
}
} // for each port forward in that class
} // for each hooked class
// We search the "not found" and remove them from the array
for($i=0;$i<count($forwards);$i++) {
if (!$forwards[$i]["found"]) {
$forwards[$i]["action"]="DELETING";
$db->query("UPDATE upnp SET action='DELETING' WHERE id=".$forwards[$i]["id"].";");
}
}
} // bigcheck ?
}