From 39c45d06e35c5d06763ab40a624378755a281f52 Mon Sep 17 00:00:00 2001
From: Benjamin Sonntag
Date: Mon, 3 Sep 2012 14:12:26 +0000
Subject: [PATCH] update_upnp is working through php/class
---
.gitattributes | 2 +
upnp/m_upnp.php | 12 +++++-
upnp/update_upnp.sh | 68 ++++++++++++-------------------
upnp/upnp.sql | 1 +
upnp/upnp_change.php | 46 +++++++++++++++++++++
upnp/upnp_list.php | 97 ++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 182 insertions(+), 44 deletions(-)
create mode 100644 upnp/upnp_change.php
create mode 100644 upnp/upnp_list.php
diff --git a/.gitattributes b/.gitattributes
index 2a794a07..5fbf6066 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -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
diff --git a/upnp/m_upnp.php b/upnp/m_upnp.php
index 0f60189c..ab85549a 100644
--- a/upnp/m_upnp.php
+++ b/upnp/m_upnp.php
@@ -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"));
@@ -99,6 +103,10 @@ class m_upnp {
return true;
}
+
+
+
-}
\ No newline at end of file
+} /* Class UPnP */
+
diff --git a/upnp/update_upnp.sh b/upnp/update_upnp.sh
index 5e6da260..a3ba022d 100644
--- a/upnp/update_upnp.sh
+++ b/upnp/update_upnp.sh
@@ -1,47 +1,31 @@
-#!/bin/bash
-#
-# This configures the upnp client for AlternC
-#
+#!/usr/bin/php
+ "$LOCK_FILE"
-
-# Check the status of the router
-upnpc -s
-if [ "$?" != "0" ]
-then
-
-fi
-
-
-
-rm -f "$LOCK_FILE"
-
-exit 0
+$upnp->cron();
diff --git a/upnp/upnp.sql b/upnp/upnp.sql
index a1dc6132..bbe6da22 100644
--- a/upnp/upnp.sql
+++ b/upnp/upnp.sql
@@ -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.';
diff --git a/upnp/upnp_change.php b/upnp/upnp_change.php
new file mode 100644
index 00000000..6c4b24ca
--- /dev/null
+++ b/upnp/upnp_change.php
@@ -0,0 +1,46 @@
+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");
+
diff --git a/upnp/upnp_list.php b/upnp/upnp_list.php
new file mode 100644
index 00000000..25ed6619
--- /dev/null
+++ b/upnp/upnp_list.php
@@ -0,0 +1,97 @@
+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"),
+ );
+
+?>
+
+
+
+$error
";
+ }
+?>
+
+
+
+
+
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+
+
+
+
+
+ |
+
+ ">"> |
+
+ |
+ |
+ |
+ |
+ |
+ |
+
|
+
+
+
+
+
+