43 $err->log(
"upnp",
"get_forward_list");
44 $db->query(
"SELECT * FROM upnp");
46 while ($db->next_record()) {
62 $err->log(
"upnp",
"enable_port($id)");
63 $db->query(
"SELECT enabled FROM upnp WHERE id=$id;");
64 if (!$db->next_record()) {
65 $err->raise(
"upnp",_(
"The required port is not currently defined"));
68 if (!$db->f(
"enabled")) {
69 $db->query(
"UPDATE upnp SET enabled=1 WHERE id=$id;");
70 $err->raise(
"upnp",_(
"The specified upnp port is now enabled"));
73 $err->raise(
"upnp",_(
"The specified upnp port is already enabled"));
87 $err->log(
"upnp",
"disable_port($id)");
88 $db->query(
"SELECT enabled,mandatory FROM upnp WHERE id=$id;");
89 if (!$db->next_record()) {
90 $err->raise(
"upnp",_(
"The required port is not currently defined"));
93 if ($db->f(
"mandatory")) {
94 $err->raise(
"upnp",_(
"You can't disable that mandatory port forward"));
97 if ($db->f(
"enabled")) {
98 $db->query(
"UPDATE upnp SET enabled=0 WHERE id=$id;");
99 $err->raise(
"upnp",_(
"The specified upnp port is now disabled"));
102 $err->raise(
"upnp",_(
"The specified upnp port is already disabled"));
111 global
$hooks,$L_INTERNAL_IP,$PUBLIC_IP;
113 $db->query(
"SELECT UNIX_TIMESTAMP(lastcheck) AS lc, * FROM upnp ORDER BY lastcheck ASC;");
116 if (!
$db->next_record()) {
119 if (
$db->f(
"lc")+600<time()) {
123 $db->Record[
"found"]=
false;
124 $forwards[]=
$db->Record;
125 }
while (
$db->next_record());
130 $res=$hooks->invoke(
"hooks_upnp_list");
131 foreach(
$res as
$c=>$tmp) {
132 if (is_array($tmp) && count($tmp)) {
133 foreach($tmp as $name=>$v) {
137 for(
$i=0;
$i<count($forwards);
$i++) {
138 if ($forwards[
$i][
"class"]==
$c &&
139 $forwards[
$i][
"name"]==$name &&
140 $forwards[
$i][
"protocol"]==$v[
"protocol"] &&
141 $forwards[
$i][
"port"]==$v[
"port"] &&
142 $forwards[
$i][
"mandatory"]==$v[
"mandatory"]) {
144 $forwards[
$i][
"found"]=
true;
150 $db->query(
"INSERT INTO upnp SET mandatory='".addslashes($v[
"mandatory"]).
"', protocol='".addslashes($v[
"protocol"]).
"', port='".addslashes($v[
"port"]).
"', name='".addslashes($name).
"', action='CREATE'");
152 $forwards[]=array(
"id"=>$id,
"mandatory" => intval($v[
"mandatory"]),
"protocol" => $v[
"protocol"],
"port" => intval($v[
"port"]),
"name" => $name,
"action" =>
"CREATE");
158 for(
$i=0;
$i<count($forwards);
$i++) {
159 if (!$forwards[
$i][
"found"]) {
160 $forwards[
$i][
"action"]=
"DELETING";
161 $db->query(
"UPDATE upnp SET action='DELETING' WHERE id=".$forwards[$i][
"id"].
";");
168 $status=array(); $statusout=array(); $bad=
false;
170 exec(
"upnpc -l 2>&1",
$res,$out);
171 foreach($out as $line) {
173 if (preg_match(
"#^ *([0-9]+) (TCP|UDP) *([0-9]+)\->([0-9\.]+):([0-9]+) *#",$line,$mat)) {
174 if ($mat[4]==$L_INTERNAL_IP) {
175 $status[]=array(
"protocol" => $mat[2],
"port" => $mat[3]);
177 $statusout[]=array(
"protocol" => $mat[2],
"port" => $mat[3],
"ip" => $mat[4]);
180 if (preg_match(
"#No IGD UPnP Device found on the network#",$line)) {
187 foreach($forwards as $f) {
188 if ($f[
"action"]!=
"OK") {
189 $db->query(
"UPDATE upnp SET lastupdate=NOW(), lastcheck=NOW(), result='No UPnP device detected in your network !' WHERE id=".$f[
"id"].
";");
191 $db->query(
"UPDATE upnp SET lastupdate=NOW(), lastcheck=NOW(), WHERE id=".$f[
"id"].
";");
201 foreach($forwards as $f) {
202 switch ($f[
"action"]) {
205 foreach($status as $s) {
206 if ($s[
"port"]==$f[
"port"] && $s[
"protocol"]==$s[
"protocol"]) {
208 $db->query(
"UPDATE upnp SET lastcheck=NOW() WHERE id=".$f[
"id"].
";");