bandwidthd: Addition of 2 variants of the bandwidthd package. 1941/head
authorJean-Michel Lacroix <lacroix@lepine-lacroix.info>
Tue, 10 Nov 2015 18:36:57 +0000 (13:36 -0500)
committerJean-Michel Lacroix <lacroix@lepine-lacroix.info>
Tue, 10 Nov 2015 18:54:42 +0000 (13:54 -0500)
Addition of the bandwithd package variant from the oldpackage
Addition of the bandwidthd-pgsql package variant that can save also
in a postgres database.
Compile tested on CC and trunk (ar71xx and mvebu in both cases)
run tested on CC (ar71xx) and trunk (r47397 on mvebu)

Signed-off-by: Jean-Michel Lacroix <lacroix@lepine-lacroix.info>
utils/bandwidthd/Makefile [new file with mode: 0644]
utils/bandwidthd/files/bandwidthd-pgsql.config [new file with mode: 0644]
utils/bandwidthd/files/bandwidthd-pgsql.init [new file with mode: 0644]
utils/bandwidthd/files/bandwidthd.config [new file with mode: 0644]
utils/bandwidthd/files/bandwidthd.init [new file with mode: 0644]
utils/bandwidthd/files/logo.gif [new file with mode: 0644]
utils/bandwidthd/patches/010-dont-add-host-paths.patch [new file with mode: 0644]
utils/bandwidthd/patches/100-fix_config_file_location [new file with mode: 0644]

diff --git a/utils/bandwidthd/Makefile b/utils/bandwidthd/Makefile
new file mode 100644 (file)
index 0000000..6cbace9
--- /dev/null
@@ -0,0 +1,124 @@
+#
+# Copyright (C) 2006-2015 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=bandwidthd
+PKG_VERSION:=2.0.1
+PKG_RELEASE:=5
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tgz
+PKG_SOURCE_URL:=@SF/bandwidthd
+PKG_MD5SUM:=aa79aad7bd489fd2cae1f7dc086ca8b6
+
+PKG_MAINTAINER:=Jean-Michel Lacroix <lacroix@lepine-lacroix.info>
+
+PKG_LICENSE:=GPL-2.0
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/bandwidthd/Default
+  SECTION:=utils
+  CATEGORY:=Utilities
+  TITLE:=Bandwidthd
+  URL:=http://bandwidthd.sourceforge.net/
+endef
+
+define Package/bandwidthd
+$(call Package/bandwidthd/Default)
+  TITLE += (without postgresql)
+  VARIANT:=no-pgsql
+  DEPENDS:=+libgd +libpcap
+endef
+
+define Package/bandwidthd-pgsql
+$(call Package/bandwidthd/Default)
+  TITLE += (with postgresql enabled)
+  VARIANT:=pgsql
+  DEPENDS:=+libgd +libpcap +libpq
+endef
+
+define Package/bandwidthd/description
+  A bandwidthd tracking utility.
+endef
+
+define Package/bandwidthd-pgsql/description
+$(call Package/bandwidthd/description)
+With the ability to store in a postgresql database.
+endef
+
+define Package/bandwidthd/daemon
+ This package contains bandwidthd a bandwith tracking utility.
+endef
+
+define Package/bandwidthd-pgsql/daemon
+ This package contains bandwidthd a bandwith tracking utility.
+endef
+
+ifeq ($(BUILD_VARIANT),no-pgsql)
+CONFIGURE_ARGS += \
+       ac_cv_file__sw_lib=no \
+       ac_cv_file__sw_include=no \
+       ac_cv_file__usr_pkg_lib=no \
+       ac_cv_file__usr_pkg_include=no \
+       ac_cv_file__usr_local_pgsql_lib=no \
+       ac_cv_file__usr_local_pgsql_include=no \
+       ac_cv_lib_pq_PQconnectdb=no 
+endif
+
+ifeq ($(BUILD_VARIANT),pgsql)
+CONFIGURE_ARGS += \
+        ac_cv_file__sw_lib=no \
+        ac_cv_file__sw_include=no \
+        ac_cv_file__usr_pkg_lib=no \
+        ac_cv_file__usr_pkg_include=no \
+        ac_cv_file__usr_local_pgsql_lib=no \
+        ac_cv_file__usr_local_pgsql_include=no
+endif
+
+EXTRA_CFLAGS+= $(TARGET_CPPFLAGS)
+EXTRA_LDFLAGS+= $(TARGET_LDFLAGS) -Wl,-rpath-link,$(STAGING_DIR)/usr/lib
+
+define Package/bandwidthd/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/bandwidthd $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) ./files/bandwidthd.config $(1)/etc/config/bandwidthd
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/bandwidthd.init $(1)/etc/init.d/bandwidthd
+       $(INSTALL_DIR) $(1)/www
+       $(INSTALL_DATA) $(PKG_BUILD_DIR)/htdocs/legend.gif $(1)/www/
+       $(INSTALL_DATA) $(PKG_BUILD_DIR)/htdocs/logo.gif $(1)/www/
+endef
+
+define Package/bandwidthd-pgsql/install
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/bandwidthd $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) ./files/bandwidthd-pgsql.config $(1)/etc/config/bandwidthd
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/bandwidthd-pgsql.init $(1)/etc/init.d/bandwidthd
+       $(INSTALL_DIR) $(1)/www/phphtdocs
+       $(INSTALL_DATA) $(PKG_BUILD_DIR)/htdocs/legend.gif $(1)/www/
+       $(INSTALL_DATA) ./files/logo.gif $(1)/www/
+       $(INSTALL_DIR) $(1)/usr/share/postgresql
+       $(INSTALL_DATA) $(PKG_BUILD_DIR)/schema.postgresql $(1)/usr/share/postgresql
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/phphtdocs/bd_pgsql_purge.sh $(1)/usr/share/postgresql
+endef
+
+define Package/bandwidthd/conffiles
+/etc/config/bandwidthd
+endef
+
+define Package/bandwidthd-pgsql/conffiles
+/etc/config/bandwidthd
+endef
+
+$(eval $(call BuildPackage,bandwidthd))
+$(eval $(call BuildPackage,bandwidthd-pgsql))
diff --git a/utils/bandwidthd/files/bandwidthd-pgsql.config b/utils/bandwidthd/files/bandwidthd-pgsql.config
new file mode 100644 (file)
index 0000000..0f87687
--- /dev/null
@@ -0,0 +1,13 @@
+config bandwidthd
+       option dev      br-lan
+       option subnets          "192.168.1.0/24"
+       option skip_intervals   0
+       option graph_cutoff     1024
+       option promiscuous      true
+       option output_cdf       false
+       option recover_cdf      false
+       option filter           ip
+       option graph            true
+       option meta_refresh     150
+       option disabled_pgsql_connect_string    "user = postgres dbname = bandwidthd host = 192.168.1.1"
+       option disabled_sensor_id       "openwrt.mydomain.domain"
diff --git a/utils/bandwidthd/files/bandwidthd-pgsql.init b/utils/bandwidthd/files/bandwidthd-pgsql.init
new file mode 100644 (file)
index 0000000..232fa0c
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2008-2015 OpenWrt.org
+
+START=99
+
+config_cb() {
+       local cfg_type="$1"
+       local cfg_name="$2"
+
+       case "$cfg_type" in
+               bandwidthd)
+                       append cfgs "$cfg_name"
+               ;;
+       esac
+}
+
+export_bool() {
+       local option="$1"
+       local section="$2"
+       local _loctmp
+       config_get_bool _loctmp "$section" "$option"
+       if [ -n "$_loctmp" ]; then
+               conffile="${conffile}$option "
+               if [ 1 -eq "$_loctmp" ]; then
+                       conffile="${conffile}true"
+               else
+                       conffile="${conffile}false"
+               fi
+               conffile="${conffile}\n"
+       fi
+}
+
+export_number() {
+       local option="$1"
+       local section="$2"
+       local _loctmp
+       config_get _loctmp "$section" "$option"
+       if [ -n "$_loctmp" ]; then
+               conffile="${conffile}$option ${_loctmp}\n"
+       fi
+}
+
+export_string() {
+       local option="$1"
+       local section="$2"
+       local _loctmp
+       config_get _loctmp "$section" "$option"
+       if [ -n "$_loctmp" ]; then
+               conffile="${conffile}$option \"${_loctmp}\"\n"
+       fi
+}
+
+start() {
+       local subnet conffile
+
+       [ -d /tmp/bandwidthd ] || mkdir -p /tmp/bandwidthd && cp /www/legend.gif /www/logo.gif /tmp/bandwidthd/
+       [ -e /htdocs ] || ln -s /tmp/bandwidthd /htdocs
+       [ -e /www/bandwidthd ] || ln -s /tmp/bandwidthd /www/bandwidthd
+       rm -f /tmp/bandwidthd.conf
+       touch /tmp/bandwidthd.conf
+       [ -e /etc/bandwidthd.conf ] || ln -s /tmp/bandwidthd.conf /etc/bandwidthd.conf
+       
+       
+       config_load bandwidthd
+       for cfg in $cfgs; do
+               config_get subnets $cfg subnets
+                       for subnet in $subnets; do
+                               conffile="${conffile}subnet ${subnet}\n"
+                       done
+               export_string dev $cfg
+               export_number skip_intervals $cfg
+               export_number graph_cutoff $cfg
+               export_bool promiscuous $cfg
+               export_bool output_cdf $cfg
+               export_bool recover_cdf $cfg
+               export_string filter $cfg
+               export_bool graph $cfg
+               export_number meta_refresh $cfg
+               export_string pgsql_connect_string $cfg
+               export_string sensor_id $cfg
+               [ -n "$conffile" ] && echo -e "$conffile" >>/tmp/bandwidthd.conf
+               unset conffile
+       done
+       cd /
+       service_start /usr/sbin/bandwidthd
+}
+
+stop() {
+       service_stop /usr/sbin/bandwidthd
+}
diff --git a/utils/bandwidthd/files/bandwidthd.config b/utils/bandwidthd/files/bandwidthd.config
new file mode 100644 (file)
index 0000000..0769b1c
--- /dev/null
@@ -0,0 +1,11 @@
+config bandwidthd
+       option dev      br-lan
+       option subnets          "192.168.1.0/24"
+       option skip_intervals   0
+       option graph_cutoff     1024
+       option promiscuous      true
+       option output_cdf       false
+       option recover_cdf      false
+       option filter           ip
+       option graph            true
+       option meta_refresh     150
diff --git a/utils/bandwidthd/files/bandwidthd.init b/utils/bandwidthd/files/bandwidthd.init
new file mode 100644 (file)
index 0000000..6483daa
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2008-2011 OpenWrt.org
+
+START=99
+
+config_cb() {
+       local cfg_type="$1"
+       local cfg_name="$2"
+
+       case "$cfg_type" in
+               bandwidthd)
+                       append cfgs "$cfg_name"
+               ;;
+       esac
+}
+
+export_bool() {
+       local option="$1"
+       local section="$2"
+       local _loctmp
+       config_get_bool _loctmp "$section" "$option"
+       if [ -n "$_loctmp" ]; then
+               conffile="${conffile}$option "
+               if [ 1 -eq "$_loctmp" ]; then
+                       conffile="${conffile}true"
+               else
+                       conffile="${conffile}false"
+               fi
+               conffile="${conffile}\n"
+       fi
+}
+
+export_number() {
+       local option="$1"
+       local section="$2"
+       local _loctmp
+       config_get _loctmp "$section" "$option"
+       if [ -n "$_loctmp" ]; then
+               conffile="${conffile}$option ${_loctmp}\n"
+       fi
+}
+
+export_string() {
+       local option="$1"
+       local section="$2"
+       local _loctmp
+       config_get _loctmp "$section" "$option"
+       if [ -n "$_loctmp" ]; then
+               conffile="${conffile}$option \"${_loctmp}\"\n"
+       fi
+}
+
+start() {
+       local subnet conffile
+
+       [ -d /tmp/bandwidthd ] || mkdir -p /tmp/bandwidthd && cp /www/legend.gif /www/logo.gif /tmp/bandwidthd/
+       [ -e /htdocs ] || ln -s /tmp/bandwidthd /htdocs
+       [ -e /www/bandwidthd ] || ln -s /tmp/bandwidthd /www/bandwidthd
+       rm -f /tmp/bandwidthd.conf
+       touch /tmp/bandwidthd.conf
+       [ -e /etc/bandwidthd.conf ] || ln -s /tmp/bandwidthd.conf /etc/bandwidthd.conf
+       
+       
+       config_load bandwidthd
+       for cfg in $cfgs; do
+               config_get subnets $cfg subnets
+                       for subnet in $subnets; do
+                               conffile="${conffile}subnet ${subnet}\n"
+                       done
+               export_string dev $cfg
+               export_number skip_intervals $cfg
+               export_number graph_cutoff $cfg
+               export_bool promiscuous $cfg
+               export_bool output_cdf $cfg
+               export_bool recover_cdf $cfg
+               export_string filter $cfg
+               export_bool graph $cfg
+               export_number meta_refresh $cfg
+               [ -n "$conffile" ] && echo -e "$conffile" >>/tmp/bandwidthd.conf
+               unset conffile
+       done
+       cd /
+       service_start /usr/sbin/bandwidthd
+}
+
+stop() {
+       service_stop /usr/sbin/bandwidthd
+}
diff --git a/utils/bandwidthd/files/logo.gif b/utils/bandwidthd/files/logo.gif
new file mode 100644 (file)
index 0000000..2ffec56
Binary files /dev/null and b/utils/bandwidthd/files/logo.gif differ
diff --git a/utils/bandwidthd/patches/010-dont-add-host-paths.patch b/utils/bandwidthd/patches/010-dont-add-host-paths.patch
new file mode 100644 (file)
index 0000000..59a5737
--- /dev/null
@@ -0,0 +1,36 @@
+diff --git a/configure b/configure
+index 4c2546e..e516137 100755
+--- a/configure
++++ b/configure
+@@ -2439,11 +2439,6 @@ if test -n "$x_libraries" && test "x$x_libraries" != xNONE ; then
+       LDFLAGS="$LDFLAGS -L$x_libraries"
+ fi
+-# May be equired for BSD
+-LDFLAGS="$LDFLAGS -L/usr/local/lib"
+-
+-CPPFLAGS="$CPPFLAGS -I/usr/local/include"
+-
+ #Check for Darwin sw directory
+ echo "$as_me:2448: checking for /sw/lib" >&5
+ echo $ECHO_N "checking for /sw/lib... $ECHO_C" >&6
+@@ -2505,9 +2500,6 @@ fi
+ fi
+ echo "$as_me:2506: result: $ac_cv_file__usr_pkg_lib" >&5
+ echo "${ECHO_T}$ac_cv_file__usr_pkg_lib" >&6
+-if test $ac_cv_file__usr_pkg_lib = yes; then
+-  LDFLAGS="$LDFLAGS -L/usr/pkg/lib"
+-fi
+ echo "$as_me:2512: checking for /usr/pkg/include" >&5
+ echo $ECHO_N "checking for /usr/pkg/include... $ECHO_C" >&6
+@@ -3092,9 +3084,6 @@ fi
+ fi
+ echo "$as_me:3093: result: $ac_cv_file__usr_local_pgsql_lib" >&5
+ echo "${ECHO_T}$ac_cv_file__usr_local_pgsql_lib" >&6
+-if test $ac_cv_file__usr_local_pgsql_lib = yes; then
+-  LDFLAGS="$LDFLAGS -L/usr/local/pgsql/lib"
+-fi
+ echo "$as_me:3099: checking for /usr/local/pgsql/include" >&5
+ echo $ECHO_N "checking for /usr/local/pgsql/include... $ECHO_C" >&6
diff --git a/utils/bandwidthd/patches/100-fix_config_file_location b/utils/bandwidthd/patches/100-fix_config_file_location
new file mode 100644 (file)
index 0000000..ae44cd2
--- /dev/null
@@ -0,0 +1,31 @@
+--- bandwidthd-2.0.1/bandwidthd.c.orig 2008-05-09 10:06:37.000000000 -0500
++++ bandwidthd-2.0.1/bandwidthd.c      2008-05-09 10:32:54.000000000 -0500
+@@ -255,22 +255,22 @@
+       openlog("bandwidthd", LOG_CONS, LOG_DAEMON);
+-      if (stat("./etc/bandwidthd.conf", &StatBuf))
++      if (stat("/etc/bandwidthd.conf", &StatBuf))
+               {
+               chdir(INSTALL_DIR);
+-              if (stat("./etc/bandwidthd.conf", &StatBuf))
++              if (stat("/etc/bandwidthd.conf", &StatBuf))
+                       {
+-                      printf("Cannot find ./etc/bandwidthd.conf or %s/etc/bandwidthd.conf\n", INSTALL_DIR);
+-                      syslog(LOG_ERR, "Cannot find ./etc/bandwidthd.conf or %s/etc/bandwidthd.conf", INSTALL_DIR);
++                      printf("Cannot find /etc/bandwidthd.conf or %s/etc/bandwidthd.conf\n", INSTALL_DIR);
++                      syslog(LOG_ERR, "Cannot find /etc/bandwidthd.conf or %s/etc/bandwidthd.conf", INSTALL_DIR);
+                       exit(1);
+                       }
+               }
+-      bdconfig_in = fopen("./etc/bandwidthd.conf", "rt");
++      bdconfig_in = fopen("/etc/bandwidthd.conf", "rt");
+       if (!bdconfig_in)
+               {
+               syslog(LOG_ERR, "Cannot open bandwidthd.conf");
+-              printf("Cannot open ./etc/bandwidthd.conf\n");
++              printf("Cannot open /etc/bandwidthd.conf\n");
+               exit(1);
+               }
+       bdconfig_parse();