diff --git a/.gitattributes b/.gitattributes index 1d611e0c..2a794a07 100644 --- a/.gitattributes +++ b/.gitattributes @@ -593,3 +593,9 @@ tools/top_ftp_users -text tools/top_http_users -text tools/top_mysql_users -text /tx-to-repos.sh -text +upnp/Makefile -text +upnp/adminmenu_upnp.php -text +upnp/m_upnp.php -text +upnp/update_upnp.sh -text +upnp/upnp-cron -text +upnp/upnp.sql -text diff --git a/debian/control b/debian/control index 25253e26..68760366 100644 --- a/debian/control +++ b/debian/control @@ -91,7 +91,7 @@ Description: Squirrelmail-Webmail plugin and configuration for AlternC . More information at http://www.alternc.com/ Homepage: http://www.alternc.com/ -Description-fr.UTF-8: Suite logicielle d'hébergement mutualisé pour Debian +Description-fr.UTF-8: Webmail Squirrelmail pour AlternC AlternC est un logiciel d'hébergement mutualisé pour serveur Linux. Il permet de gérer les sites web, domaines, ftp, emails, alias, statistiques web, listes de discussions, comptes jabber, etc. @@ -122,7 +122,7 @@ Description: Roundcube-Webmail plugin and configuration for AlternC . More information at http://www.alternc.com/ Homepage: http://www.alternc.com/ -Description-fr.UTF-8: Suite logicielle d'hébergement mutualisé pour Debian +Description-fr.UTF-8: Webmail Roundcube pour AlternC AlternC est un logiciel d'hébergement mutualisé pour serveur Linux. Il permet de gérer les sites web, domaines, ftp, emails, alias, statistiques web, listes de discussions, comptes jabber, etc. @@ -150,3 +150,32 @@ Description: Awstats statistics module for AlternC managment to the virtual desktop. . More information on http://www.alternc.com/. + +Package: alternc-upnp +Architecture: all +Pre-depends: debconf (>= 0.5.00) | debconf-2.0 +Depends: debianutils (>= 1.13.1), alternc (>= 1.1), miniupnpc +Description: UPnP client for AlternC + AlternC is a mutualized hosting software manager for Linux. + It allows you to manage your websites, domains, ftp, emails, aliases, + web statistics, mailing-lists, jabber accounts, etc. + . + This extension to AlternC is installing a UPnP IGD client and make it so + that your router required tcp and udp port are forwarded to AlternC. + You need that only if your AlternC's server is behind a NAT router. + . + More information at http://www.alternc.com/ +Homepage: http://www.alternc.com/ +Description-fr.UTF-8: Client UPnP pour AlternC + AlternC est un logiciel d'hébergement mutualisé pour serveur Linux. + Il permet de gérer les sites web, domaines, ftp, emails, alias, + statistiques web, listes de discussions, comptes jabber, etc. + . + Cette extension d'AlternC installe un client UPnP IGD et fait de telle + sorte que les ports udp et tcp nécessaire au fonctionnement de votre + serveur sous AlternC soient transmis depuis votre routeur. + Vous n'avez besoin de cette extension que si votre serveur AlternC est + situé derrière un routeur NAT. + . + Pour plus d'informations, consultez http://www.alternc.com/ + diff --git a/debian/rules b/debian/rules index 7313345e..e91e37cb 100755 --- a/debian/rules +++ b/debian/rules @@ -99,6 +99,9 @@ install: build # alternc-squirrelmail: (cd squirrelmail && $(MAKE) install DESTDIR=$(CURDIR)/debian/alternc-squirrelmail) + # alternc-upnp + (cd upnp && $(MAKE) install DESTDIR=$(CURDIR)/debian/alternc-upnp) + # alternc-awstats: (cd awstats && $(MAKE) install DESTDIR=$(CURDIR)/debian/alternc-awstats) cd .. diff --git a/upnp/Makefile b/upnp/Makefile new file mode 100644 index 00000000..043b9abd --- /dev/null +++ b/upnp/Makefile @@ -0,0 +1,32 @@ +# ---------------------------------------------------------------------- +# 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: Install the files of alternc-upnp packages +# ---------------------------------------------------------------------- + +install: + # Desktop files + install -m 644 m_upnp.php $(DESTDIR)/var/alternc/bureau/class/ + install -m 644 upnp_list.php upnp_change.php $(DESTDIR)/var/alternc/bureau/admin/ + install -m 644 adminmenu_upnp.php $(DESTDIR)/var/alternc/bureau/admin/ + # Cron + install -m 755 update_upnp.sh $(DESTDIR)/usr/lib/alternc/ + # Install script + install -m 644 upnp.sql $(DESTDIR)/usr/share/alternc/install/ + install -m 755 upnp-install $(DESTDIR)/usr/lib/alternc/install.d diff --git a/upnp/adminmenu_upnp.php b/upnp/adminmenu_upnp.php new file mode 100644 index 00000000..325e29a3 --- /dev/null +++ b/upnp/adminmenu_upnp.php @@ -0,0 +1 @@ + diff --git a/upnp/m_upnp.php b/upnp/m_upnp.php new file mode 100644 index 00000000..0f60189c --- /dev/null +++ b/upnp/m_upnp.php @@ -0,0 +1,104 @@ +log("upnp","get_forward_list"); + $db->query("SELECT * FROM upnp"); + $res=array(); + while ($db->next_record()) { + $res[]=$db->Record; + } + return $res; + } + + + /* ----------------------------------------------------------------- */ + /** enable a upnp port in the upnp table + * @param integer the id of the port to enable + * @return boolean TRUE if the port has been properly forwarded + * FALSE if an error occurred + */ + function enable_port($id) { + global $db,$err; + $id=intval($id); + $err->log("upnp","enable_port($id)"); + $db->query("SELECT enabled FROM upnp WHERE id=$id;"); + if (!$db->next_record()) { + $err->raise("upnp",_("The required port is not currently defined")); + return false; + } + if (!$db->f("enabled")) { + $db->query("UPDATE upnp SET enabled=1 WHERE id=$id;"); + $err->raise("upnp",_("The specified upnp port is now enabled")); + return true; + } + $err->raise("upnp",_("The specified upnp port is already enabled")); + return true; + } + + + /* ----------------------------------------------------------------- */ + /** disable a upnp port in the upnp table + * @param integer the id of the port to disable + * @return boolean TRUE if the port has been properly forwarded + * FALSE if an error occurred + */ + function disable_port($id) { + global $db,$err; + $id=intval($id); + $err->log("upnp","disable_port($id)"); + $db->query("SELECT enabled FROM upnp WHERE id=$id;"); + if (!$db->next_record()) { + $err->raise("upnp",_("The required port is not currently defined")); + 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")); + return true; + } + $err->raise("upnp",_("The specified upnp port is already disabled")); + return true; + } + + + +} \ No newline at end of file diff --git a/upnp/update_upnp.sh b/upnp/update_upnp.sh new file mode 100644 index 00000000..5e6da260 --- /dev/null +++ b/upnp/update_upnp.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# This configures the upnp client for AlternC +# + +CONFIG_FILE="/etc/alternc/local.sh" + +if [ ! -r "$CONFIG_FILE" ]; then + echo "Can't access $CONFIG_FILE." + exit 1 +fi +. "$CONFIG_FILE" + +# Some vars +umask 022 +LOCK_FILE="/tmp/alternc-upnp.lock" + +# 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 + +# 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 + diff --git a/upnp/upnp-cron b/upnp/upnp-cron new file mode 100644 index 00000000..70884321 --- /dev/null +++ b/upnp/upnp-cron @@ -0,0 +1,3 @@ + +# This shell script configures the UPnP client if necessary: +* * * * * root /usr/lib/alternc/update_upnp.sh diff --git a/upnp/upnp.sql b/upnp/upnp.sql new file mode 100644 index 00000000..a1dc6132 --- /dev/null +++ b/upnp/upnp.sql @@ -0,0 +1,15 @@ + +CREATE TABLE IF NOT EXISTS `upnp` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(128) NOT NULL, + `class` varchar(64) NOT NULL, + `protocol` varchar(3) NOT NULL, + `port` int(10) unsigned NOT NULL, + `mandatory` tinyint(3) unsigned NOT NULL, + `enabled` tinyint(3) unsigned NOT NULL, + `lastcheck` datetime NOT NULL, + `lastupdate` datetime NOT NULL, + `result` varchar(128) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM COMMENT='UPnP port forwards and their status.'; +