diff --git a/utils/bandwidthd-php/Makefile b/utils/bandwidthd-php/Makefile deleted file mode 100644 index c71d798dcd..0000000000 --- a/utils/bandwidthd-php/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -# -# Copyright (C) 2006-2016 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-php -PKG_VERSION:=2.0.1 -PKG_RELEASE:=2 - -PKG_MAINTAINER:=Jean-Michel Lacroix - -PKG_LICENSE:=GPL-2.0 - -include $(INCLUDE_DIR)/package.mk - -define Package/bandwidthd-php - SECTION:=utils - CATEGORY:=Utilities - DEPENDS:=+libpcre +libxml2 +php7 +php7-cgi +php7-mod-pgsql +php7-mod-gd - TITLE:=PHP files to graph bandwidthd data in a postgresql database - URL:=http://bandwidthd.sourceforge.net/ -endef - -define Package/bandwidthd-php/description - PHP files to graph bandwidthd data in a postgresql database -endef - -define Build/Compile -endef - -define Package/bandwidthd-php/install - $(INSTALL_DIR) $(1)/www/phphtdocs - $(INSTALL_DATA) ./files/legend.gif $(1)/www/phphtdocs/ - $(INSTALL_DATA) ./files/logo.gif $(1)/www/phphtdocs/ - $(INSTALL_DATA) ./files/details.php $(1)/www/phphtdocs/ - $(INSTALL_DATA) ./files/footer.php $(1)/www/phphtdocs/ - $(INSTALL_DATA) ./files/graph.php $(1)/www/phphtdocs/ - $(INSTALL_DATA) ./files/include.php $(1)/www/phphtdocs/ - $(INSTALL_DATA) ./files/index.php $(1)/www/phphtdocs/ - ln -s /var/etc/bandwidthd-php.conf $(1)/www/phphtdocs/config.conf - $(INSTALL_DIR) $(1)//etc/config - $(INSTALL_CONF) ./files/bandwidthd-php.config $(1)/etc/config/bandwidthd-php - $(INSTALL_DIR) $(1)/etc/init.d - $(INSTALL_BIN) ./files/bandwidthd-php.init $(1)/etc/init.d/bandwidthd-php -endef - -$(eval $(call BuildPackage,bandwidthd-php)) diff --git a/utils/bandwidthd-php/files/legend.gif b/utils/bandwidthd-php/files/legend.gif deleted file mode 100644 index 3df909037f..0000000000 Binary files a/utils/bandwidthd-php/files/legend.gif and /dev/null differ diff --git a/utils/bandwidthd/Makefile b/utils/bandwidthd/Makefile index 3d6514a5ed..955e735017 100644 --- a/utils/bandwidthd/Makefile +++ b/utils/bandwidthd/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2006-2015 OpenWrt.org +# Copyright (C) 2006-2017 OpenWrt.org # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. @@ -8,12 +8,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=bandwidthd -PKG_VERSION:=2.0.1 -PKG_RELEASE:=5 +PKG_VERSION:=2.0.1-34 +PKG_RELEASE:=1 -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tgz -PKG_SOURCE_URL:=@SF/bandwidthd -PKG_MD5SUM:=aa79aad7bd489fd2cae1f7dc086ca8b6 +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://github.com/NethServer/bandwidthd/archive/$(PKG_VERSION) +PKG_MD5SUM:=a4075335d06fe91ae815616ed9e27375 PKG_MAINTAINER:=Jean-Michel Lacroix @@ -21,6 +21,8 @@ PKG_LICENSE:=GPL-2.0 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION) +PKG_FIXUP:=autoreconf + include $(INCLUDE_DIR)/package.mk define Package/bandwidthd/Default @@ -32,8 +34,8 @@ endef define Package/bandwidthd $(call Package/bandwidthd/Default) - TITLE += (without postgresql) - VARIANT:=no-pgsql + TITLE += (without database) + VARIANT:=no-db DEPENDS:=+libgd +libpcap endef @@ -44,6 +46,20 @@ $(call Package/bandwidthd/Default) DEPENDS:=+libgd +libpcap +libpq endef +define Package/bandwidthd-sqlite +$(call Package/bandwidthd/Default) + TITLE += (with sqlite enabled) + VARIANT:=sqlite + DEPENDS:=+libgd +libpcap +libsqlite3 +php7 +php7-cgi +php7-mod-gd +php7-mod-pdo +php7-mod-pdo-sqlite +endef + +define Package/bandwidthd-php +$(call Package/bandwidthd/Default) + TITLE = PHP files to graph bandwidthd data from postgresql + VARIANT:=php + DEPENDS:=+libpcre +libxml2 +php7 +php7-cgi +php7-mod-pgsql +php7-mod-gd +endef + define Package/bandwidthd/description A bandwidthd tracking utility. endef @@ -53,15 +69,32 @@ $(call Package/bandwidthd/description) With the ability to store in a postgresql database. endef +define Package/bandwidthd-sqlite/description +$(call Package/bandwidthd/description) +With the ability to store in a sqlite database. +endef + +define Package/bandwidthd-php/description + PHP files to graph bandwidthd data from pgsql. +endef + define Package/bandwidthd/daemon - This package contains bandwidthd a bandwidth tracking utility. + This package contains bandwidthd, a bandwidth tracking utility. endef define Package/bandwidthd-pgsql/daemon - This package contains bandwidthd a bandwidth tracking utility. + This package contains bandwidthd, a bandwidth tracking utility. endef -ifeq ($(BUILD_VARIANT),no-pgsql) +define Package/bandwidthd-sqlite/daemon + This package contains bandwidthd, a bandwidth tracking utility. +endef + +define Package/bandwidthd-php/daemon + This package contains the PHP files to graph the data from a pgsql database. +endef + +ifeq ($(BUILD_VARIANT),no-db) CONFIGURE_ARGS += \ ac_cv_file__sw_lib=no \ ac_cv_file__sw_include=no \ @@ -69,20 +102,45 @@ CONFIGURE_ARGS += \ 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 + ac_cv_lib_pq_PQconnectdb=no \ + ac_cv_lib_sqlite3_sqlite3_open=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 + 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_sqlite3_sqlite3_open=no endif -EXTRA_CFLAGS+= $(TARGET_CPPFLAGS) -std=gnu89 +ifeq ($(BUILD_VARIANT),sqlite) +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),php) +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 \ + ac_cv_lib_sqlite3_sqlite3_open=no +endif + +EXTRA_CFLAGS+= $(TARGET_CPPFLAGS) EXTRA_LDFLAGS+= $(TARGET_LDFLAGS) -Wl,-rpath-link,$(STAGING_DIR)/usr/lib define Package/bandwidthd/install @@ -93,8 +151,8 @@ define Package/bandwidthd/install $(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/ + $(INSTALL_DATA) $(PKG_BUILD_DIR)/phphtdocs/legend.gif $(1)/www/ + $(INSTALL_DATA) ./files/logo-openwrt.gif $(1)/www/logo.gif endef define Package/bandwidthd-pgsql/install @@ -103,15 +161,50 @@ define Package/bandwidthd-pgsql/install $(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_BIN) ./files/bandwidthd.init $(1)/etc/init.d/bandwidthd + $(INSTALL_DIR) $(1)/www + $(INSTALL_DATA) $(PKG_BUILD_DIR)/phphtdocs/legend.gif $(1)/www/ + $(INSTALL_DATA) ./files/logo-openwrt.gif $(1)/www/logo.gif $(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-sqlite/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/bandwidthd $(1)/usr/sbin/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DATA) ./files/bandwidthd-sqlite.config $(1)/etc/config/bandwidthd + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/bandwidthd-sqlite.init $(1)/etc/init.d/bandwidthd + $(INSTALL_DIR) $(1)/www/phphtdocs + $(INSTALL_DATA) $(PKG_BUILD_DIR)/phphtdocs/legend.gif $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/phphtdocs-sqlite/details.php $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/phphtdocs-sqlite/footer.php $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/phphtdocs-sqlite/graph.php $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/phphtdocs-sqlite/include.php $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/phphtdocs-sqlite/index.php $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/logo-openwrt.gif $(1)/www/phphtdocs/logo.gif + ln -s /var/etc/bandwidthd-php.conf $(1)/www/phphtdocs/config.conf.php + $(INSTALL_DATA) $(PKG_BUILD_DIR)/phphtdocs/legend.gif $(1)/www/ + $(INSTALL_DATA) ./files/logo-openwrt.gif $(1)/www/logo.gif +endef + +define Package/bandwidthd-php/install + $(INSTALL_DIR) $(1)/www/phphtdocs + $(INSTALL_DATA) $(PKG_BUILD_DIR)/phphtdocs/legend.gif $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/phphtdocs/details.php $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/phphtdocs/footer.php $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/phphtdocs/graph.php $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/phphtdocs/include.php $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/phphtdocs/index.php $(1)/www/phphtdocs/ + $(INSTALL_DATA) ./files/logo-openwrt.gif $(1)/www/phphtdocs/logo.gif + ln -s /var/etc/bandwidthd-php.conf $(1)/www/phphtdocs/config.conf + $(INSTALL_DIR) $(1)//etc/config + $(INSTALL_CONF) ./files/bandwidthd-php.config $(1)/etc/config/bandwidthd-php + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/bandwidthd-php.init $(1)/etc/init.d/bandwidthd-php +endef + define Package/bandwidthd/conffiles /etc/config/bandwidthd endef @@ -120,5 +213,15 @@ define Package/bandwidthd-pgsql/conffiles /etc/config/bandwidthd endef +define Package/bandwidthd-sqlite/conffiles +/etc/config/bandwidthd +endef + +define Package/bandwidthd-php/conffiles +/etc/config/bandwidthd-php +endef + $(eval $(call BuildPackage,bandwidthd)) $(eval $(call BuildPackage,bandwidthd-pgsql)) +$(eval $(call BuildPackage,bandwidthd-sqlite)) +$(eval $(call BuildPackage,bandwidthd-php)) diff --git a/utils/bandwidthd/files/bandwidthd-pgsql.config b/utils/bandwidthd/files/bandwidthd-pgsql.config index 0f87687925..f94c737a56 100644 --- a/utils/bandwidthd/files/bandwidthd-pgsql.config +++ b/utils/bandwidthd/files/bandwidthd-pgsql.config @@ -1,5 +1,5 @@ config bandwidthd - option dev br-lan + option dev br-lan option subnets "192.168.1.0/24" option skip_intervals 0 option graph_cutoff 1024 @@ -9,5 +9,5 @@ config bandwidthd 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" + option pgsql_connect_string "user = postgres dbname = bandwidthd host = 192.168.1.1" + option sensor_id "openwrt" diff --git a/utils/bandwidthd-php/files/bandwidthd-php.config b/utils/bandwidthd/files/bandwidthd-php.config similarity index 100% rename from utils/bandwidthd-php/files/bandwidthd-php.config rename to utils/bandwidthd/files/bandwidthd-php.config diff --git a/utils/bandwidthd-php/files/bandwidthd-php.init b/utils/bandwidthd/files/bandwidthd-php.init similarity index 97% rename from utils/bandwidthd-php/files/bandwidthd-php.init rename to utils/bandwidthd/files/bandwidthd-php.init index f3a7c6702c..b7b6434f08 100755 --- a/utils/bandwidthd-php/files/bandwidthd-php.init +++ b/utils/bandwidthd/files/bandwidthd-php.init @@ -1,5 +1,5 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2006-2016 OpenWrt.org +# Copyright (C) 2006-2017 OpenWrt.org START=99 diff --git a/utils/bandwidthd/files/bandwidthd-sqlite.config b/utils/bandwidthd/files/bandwidthd-sqlite.config new file mode 100644 index 0000000000..bc4154af22 --- /dev/null +++ b/utils/bandwidthd/files/bandwidthd-sqlite.config @@ -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 sqlite_filename "/www/bandwidthd/stats.db" + option sensor_id "default" diff --git a/utils/bandwidthd/files/bandwidthd-pgsql.init b/utils/bandwidthd/files/bandwidthd-sqlite.init old mode 100644 new mode 100755 similarity index 50% rename from utils/bandwidthd/files/bandwidthd-pgsql.init rename to utils/bandwidthd/files/bandwidthd-sqlite.init index 232fa0cb8f..c456974ab8 --- a/utils/bandwidthd/files/bandwidthd-pgsql.init +++ b/utils/bandwidthd/files/bandwidthd-sqlite.init @@ -1,8 +1,15 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2008-2015 OpenWrt.org +# Copyright (C) 2008-2017 OpenWrt.org START=99 +USE_PROCD=1 + +CONFIGNAME="bandwidthd" +CONFIGPHPNAME="bandwidthd-php" +CONFIGFILE="/tmp/etc/bandwidthd.conf" +CONFIGPHPFILE="/tmp/etc/bandwidthd-php.conf" + config_cb() { local cfg_type="$1" local cfg_name="$2" @@ -50,18 +57,17 @@ export_string() { fi } -start() { - local subnet conffile +set_conf_file() { + local subnet conffile="# auto-generated config file from /etc/config/${CONFIGNAME}\n" [ -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 + rm -f $CONFIGFILE + touch $CONFIGFILE + [ -e /etc/bandwidthd.conf ] || ln -s $CONFIGFILE /etc/bandwidthd.conf + + config_load $CONFIGNAME for cfg in $cfgs; do config_get subnets $cfg subnets for subnet in $subnets; do @@ -77,14 +83,51 @@ start() { export_bool graph $cfg export_number meta_refresh $cfg export_string pgsql_connect_string $cfg + export_string sqlite_filename $cfg export_string sensor_id $cfg - [ -n "$conffile" ] && echo -e "$conffile" >>/tmp/bandwidthd.conf + [ -n "$conffile" ] && echo -e "$conffile" >>$CONFIGFILE unset conffile done cd / - service_start /usr/sbin/bandwidthd } -stop() { +set_php_conf_file() { + local subnet conffile="" + [ -n "$conffile" ] && echo -e "$conffile" >>$CONFIGPHPFILE + done + cd / +} + +service_triggers() { + procd_add_reload_trigger $CONFIGNAME + procd_add_reload_trigger $CONFIGPHPNAME +} + +start_service() { + set_conf_file + set_php_conf_file + procd_open_instance + procd_set_param command /usr/sbin/bandwidthd + procd_close_instance +} + +stop_service() { service_stop /usr/sbin/bandwidthd } diff --git a/utils/bandwidthd/files/bandwidthd.config b/utils/bandwidthd/files/bandwidthd.config index 0769b1c8ea..ac1669ef40 100644 --- a/utils/bandwidthd/files/bandwidthd.config +++ b/utils/bandwidthd/files/bandwidthd.config @@ -1,5 +1,5 @@ config bandwidthd - option dev br-lan + option dev br-lan option subnets "192.168.1.0/24" option skip_intervals 0 option graph_cutoff 1024 diff --git a/utils/bandwidthd/files/bandwidthd.init b/utils/bandwidthd/files/bandwidthd.init old mode 100644 new mode 100755 index 38d9cb165c..ac9d01dc47 --- a/utils/bandwidthd/files/bandwidthd.init +++ b/utils/bandwidthd/files/bandwidthd.init @@ -1,8 +1,13 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2008-2015 OpenWrt.org +# Copyright (C) 2008-2017 OpenWrt.org START=99 +USE_PROCD=1 + +CONFIGNAME="bandwidthd" +CONFIGFILE="/tmp/etc/bandwidthd.conf" + config_cb() { local cfg_type="$1" local cfg_name="$2" @@ -50,18 +55,17 @@ export_string() { fi } -start() { +set_conf_file() { 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 + rm -f $CONFIGFILE + touch $CONFIGFILE + [ -e /etc/bandwidthd.conf ] || ln -s $CONFIGFILE /etc/bandwidthd.conf - - config_load bandwidthd + config_load $CONFIGNAME for cfg in $cfgs; do config_get subnets $cfg subnets for subnet in $subnets; do @@ -76,13 +80,27 @@ start() { export_string filter $cfg export_bool graph $cfg export_number meta_refresh $cfg - [ -n "$conffile" ] && echo -e "$conffile" >>/tmp/bandwidthd.conf + export_string pgsql_connect_string $cfg + export_string sqlite_filename $cfg + export_string sensor_id $cfg + [ -n "$conffile" ] && echo -e "$conffile" >>$CONFIGFILE unset conffile done cd / - service_start /usr/sbin/bandwidthd } -stop() { +service_triggers() +{ + procd_add_reload_trigger $CONFIGNAME +} + +start_service() { + set_conf_file + procd_open_instance + procd_set_param command /usr/sbin/bandwidthd + procd_close_instance +} + +stop_service() { service_stop /usr/sbin/bandwidthd } diff --git a/utils/bandwidthd-php/files/logo.gif b/utils/bandwidthd/files/logo-openwrt.gif similarity index 100% rename from utils/bandwidthd-php/files/logo.gif rename to utils/bandwidthd/files/logo-openwrt.gif diff --git a/utils/bandwidthd/files/logo.gif b/utils/bandwidthd/files/logo.gif deleted file mode 100644 index 2ffec5605b..0000000000 Binary files a/utils/bandwidthd/files/logo.gif and /dev/null differ diff --git a/utils/bandwidthd/files/phphtdocs-sqlite/details.php b/utils/bandwidthd/files/phphtdocs-sqlite/details.php new file mode 100644 index 0000000000..448ea46e00 --- /dev/null +++ b/utils/bandwidthd/files/phphtdocs-sqlite/details.php @@ -0,0 +1,104 @@ + + +
+ +Please provide a sensor_name"; + exit(1); + } + +if (isset($_GET['ip'])) + $ip = $_GET['ip']; +else + { + echo "
Please provide an ip address"; + exit(1); + } + +echo "

"; +if (strpos($ip, "/") === FALSE) + echo "$ip - ".gethostbyaddr($ip)."

"; +else + echo "Total - $ip"; + +$db = ConnectDb(); + +if ($ip == "0.0.0.0/0") + { + $rxtable = "bd_rx_total_log"; + $txtable = "bd_tx_total_log"; + } +else + { + $rxtable = "bd_rx_log"; + $txtable = "bd_tx_log"; + } + +$sql = "select rx.scale as rxscale, tx.scale as txscale, tx.total+rx.total as total, tx.total as sent, +rx.total as received, tx.tcp+rx.tcp as tcp, tx.udp+rx.udp as udp, +tx.icmp+rx.icmp as icmp, tx.http+rx.http as http, +tx.p2p+rx.p2p as p2p, tx.ftp+rx.ftp as ftp +from + +(SELECT ip, max(total/sample_duration)*8 as scale, sum(total) as total, sum(tcp) as tcp, sum(udp) as udp, sum(icmp) as icmp, +sum(http) as http, sum(p2p) as p2p, sum(ftp) as ftp +from sensors, $txtable +where sensor_name = '$sensor_name' +and sensors.sensor_id = ".$txtable.".sensor_id +$sql_subnet +group by ip) as tx, + +(SELECT ip, max(total/sample_duration)*8 as scale, sum(total) as total, sum(tcp) as tcp, sum(udp) as udp, sum(icmp) as icmp, +sum(http) as http, sum(p2p) as p2p, sum(ftp) as ftp +from sensors, $rxtable +where sensor_name = '$sensor_name' +and sensors.sensor_id = ".$rxtable.".sensor_id +$sql_subnet +group by ip) as rx + +where tx.ip = rx.ip;"; +//error_log($sql); printf('
%s
', $sql); +$db = ConnectDb(); +$result = $db->query($sql); +echo "
IpNameTotalSentReceivedtcpudpicmphttpsmtpftp"; +$r = $result->fetch(); +$db = NULL; +echo "
"; +if (strpos($ip, "/") === FALSE) + echo "$ip".gethostbyaddr($ip); +else + echo "Total$ip"; +echo fmtb($r['total']).fmtb($r['sent']).fmtb($r['received']). + fmtb($r['tcp']).fmtb($r['udp']).fmtb($r['icmp']).fmtb($r['http']). + fmtb($r['p2p']).fmtb($r['ftp']); +echo "
"; + +echo "

Daily

"; +echo "Send:

"; +echo "
"; +echo "Receive:

"; +echo "
"; + +echo "

Weekly

"; +echo "Send:

"; +echo "
"; +echo "Receive:

"; +echo "
"; + +echo "

Monthly

"; +echo "Send:

"; +echo "
"; +echo "Receive:

"; +echo "
"; + +echo "

Yearly

"; +echo "Send:

"; +echo "
"; +echo "Receive:

"; +echo "
"; diff --git a/utils/bandwidthd-php/files/footer.php b/utils/bandwidthd/files/phphtdocs-sqlite/footer.php similarity index 100% rename from utils/bandwidthd-php/files/footer.php rename to utils/bandwidthd/files/phphtdocs-sqlite/footer.php diff --git a/utils/bandwidthd/files/phphtdocs-sqlite/graph.php b/utils/bandwidthd/files/phphtdocs-sqlite/graph.php new file mode 100644 index 0000000000..82df317fba --- /dev/null +++ b/utils/bandwidthd/files/phphtdocs-sqlite/graph.php @@ -0,0 +1,455 @@ + $number) + { + $total[$key] /= $number; + $icmp[$key] /= $number; + $udp[$key] /= $number; + $tcp[$key] /= $number; + $ftp[$key] /= $number; + $http[$key] /= $number; + $p2p[$key] /= $number; + } + + foreach ($Count as $key => $number) + { + $a_total[$key] += $total[$key]; + $a_icmp[$key] += $icmp[$key]; + $a_udp[$key] += $udp[$key]; + $a_tcp[$key] += $tcp[$key]; + $a_ftp[$key] += $ftp[$key]; + $a_http[$key] += $http[$key]; + $a_p2p[$key] += $p2p[$key]; + + if ($a_total[$key] > $YMax) + $YMax = $a_total[$key]; + } + + unset($GLOBALS['total'], $GLOBALS['icmp'], $GLOBALS['udp'], $GLOBALS['tcp'], $GLOBALS['ftp'], $GLOBALS['http'], $GLOBALS['p2p'], $GLOBALS['Count']); + + $total = array(); + $icmp = array(); + $udp = array(); + $tcp = array(); + $ftp = array(); + $http = array(); + $p2p = array(); + $Count = array(); + } + +$db = ConnectDb(); + +// Get parameters + +if (isset($_GET['width'])) + $width = $_GET['width']; +else + $width = DFLT_WIDTH; + +if (isset($_GET['height'])) + $height = $_GET['height']; +else + $height = DFLT_HEIGHT; + +if (isset($_GET['interval'])) + $interval = $_GET['interval']; +else + $interval = DFLT_INTERVAL; + +if (isset($_GET['ip'])) + $ip = $_GET['ip']; +else + exit(1); + +if (isset($_GET['sensor_name'])) + $sensor_name = $_GET['sensor_name']; +else + exit(1); + +if (isset($_GET['timestamp'])) + $timestamp = $_GET['timestamp']; +else + $timestamp = time() - $interval + (0.05*$interval); + +if (isset($_GET['table'])) + $table = $_GET['table']; +else + $table = "bd_rx_log"; + +if (isset($_GET['yscale'])) + $yscale = $_GET['yscale']; + +$total = array(); +$icmp = array(); +$udp = array(); +$tcp = array(); +$ftp = array(); +$http = array(); +$p2p = array(); +$Count = array(); + +// Accumulator +$a_total = array(); +$a_icmp = array(); +$a_udp = array(); +$a_tcp = array(); +$a_ftp = array(); +$a_http = array(); +$a_p2p = array(); + +$sql_subnet = prepare_sql_subnet($ip); +$sql = "select *, timestamp as ts from sensors, $table where sensors.sensor_id = ".$table.".sensor_id $sql_subnet and sensor_name = '$sensor_name' and timestamp > $timestamp and timestamp < ".($timestamp+$interval)." order by ip;"; +//error_log($sql); +$result = $db->query($sql); + +// The SQL statement pulls the data out of the database ordered by IP address, that way we can average each +// datapoint for each IP address to provide smoothing and then toss the smoothed value into the accumulator +// to provide accurate total traffic rate. + +while ($row = $result->fetch()) + { + if ($row['ip'] != $last_ip) + { + AverageAndAccumulate(); + $last_ip = $row['ip']; + } + + $x = ($row['ts']-$timestamp)*(($width-XOFFSET)/$interval)+XOFFSET; + $xint = (int) $x; + + //echo "xint: ".$xint."
"; + $Count[$xint]++; + + if ($row['total']/$row['sample_duration'] > $SentPeak) + $SentPeak = $row['total']/$row['sample_duration']; + $TotalSent += $row['total']; + $total[$xint] += $row['total']/$row['sample_duration']; + $icmp[$xint] += $row['icmp']/$row['sample_duration']; + $udp[$xint] += $row['udp']/$row['sample_duration']; + $tcp[$xint] += $row['tcp']/$row['sample_duration']; + $ftp[$xint] += $row['ftp']/$row['sample_duration']; + $http[$xint] += $row['http']/$row['sample_duration']; + $p2p[$xint] += $row['p2p']/$row['sample_duration']; + } + +// One more time for the last IP +AverageAndAccumulate(); + +// Pull the data out of Accumulator +$total = $a_total; +$icmp = $a_icmp; +$udp = $a_udp; +$tcp = $a_tcp; +$ftp = $a_ftp; +$http = $a_http; +$p2p = $a_p2p; + +$YMax += $YMax*0.05; // Add an extra 5% + +// if a y scale was specified override YMax +if (isset($yscale)&& $yscale > 0) + $YMax = $yscale/8; + +// Plot the data + +header("Content-type: image/png"); + +$im = imagecreate($width, $height); +$white = imagecolorallocate($im, 255, 255, 255); +$purple = ImageColorAllocate($im, 255, 0, 255); +$green = ImageColorAllocate($im, 0, 255, 0); +$blue = ImageColorAllocate($im, 0, 0, 255); +$lblue = ImageColorAllocate($im, 128, 128, 255); +$brown = ImageColorAllocate($im, 128, 0, 0); +$red = ImageColorAllocate($im, 255, 0, 0); +$black = ImageColorAllocate($im, 0, 0, 0); + +for($Counter=XOFFSET+1; $Counter < $width; $Counter++) + { + if (isset($total[$Counter])) + { + // Convert the bytes/sec to y coords + $total[$Counter] = ($total[$Counter]*($height-YOFFSET))/$YMax; + $tcp[$Counter] = ($tcp[$Counter]*($height-YOFFSET))/$YMax; + $ftp[$Counter] = ($ftp[$Counter]*($height-YOFFSET))/$YMax; + $http[$Counter] = ($http[$Counter]*($height-YOFFSET))/$YMax; + $p2p[$Counter] = ($p2p[$Counter]*($height-YOFFSET))/$YMax; + $udp[$Counter] = ($udp[$Counter]*($height-YOFFSET))/$YMax; + $icmp[$Counter] = ($icmp[$Counter]*($height-YOFFSET))/$YMax; + + // Stack 'em up! + // Total is stacked from the bottom + // Icmp is on the bottom too + // Udp is stacked on top of icmp + $udp[$Counter] += $icmp[$Counter]; + // TCP and p2p are stacked on top of Udp + $tcp[$Counter] += $udp[$Counter]; + $p2p[$Counter] += $udp[$Counter]; + // Http is stacked on top of p2p + $http[$Counter] += $p2p[$Counter]; + // Ftp is stacked on top of http + $ftp[$Counter] += $http[$Counter]; + + // Plot them! + //echo "$Counter:".$Counter." (h-y)-t:".($height-YOFFSET) - $total[$Counter]." h-YO-1:".$height-YOFFSET-1; + ImageLine($im, $Counter, ($height-YOFFSET) - $icmp[$Counter], $Counter, $height-YOFFSET-1, $red); + ImageLine($im, $Counter, ($height-YOFFSET) - $udp[$Counter], $Counter, ($height-YOFFSET) - $icmp[$Counter] - 1, $brown); + ImageLine($im, $Counter, ($height-YOFFSET) - $tcp[$Counter], $Counter, ($height-YOFFSET) - $udp[$Counter] - 1, $green); + ImageLine($im, $Counter, ($height-YOFFSET) - $p2p[$Counter], $Counter, ($height-YOFFSET) - $udp[$Counter] - 1, $purple); + ImageLine($im, $Counter, ($height-YOFFSET) - $http[$Counter], $Counter, ($height-YOFFSET) - $p2p[$Counter] - 1, $blue); + ImageLine($im, $Counter, ($height-YOFFSET) - $ftp[$Counter], $Counter, ($height-YOFFSET) - $http[$Counter] - 1, $lblue); + } +// else +// echo $Counter." not set
"; + } + +// Margin Text +if ($SentPeak < 1024/8) + $txtPeakSendRate = sprintf("Peak Send Rate: %.1f KBits/sec", $SentPeak*8); +else if ($SentPeak < (1024*1024)/8) + $txtPeakSendRate = sprintf("Peak Send Rate: %.1f MBits/sec", ($SentPeak*8.0)/1024.0); +else + $txtPeakSendRate = sprintf("Peak Send Rate: %.1f GBits/sec", ($SentPeak*8.0)/(1024.0*1024.0)); + +if ($TotalSent < 1024) + $txtTotalSent = sprintf("Sent %.1f KBytes", $TotalSent); +else if ($TotalSent < 1024*1024) + $txtTotalSent = sprintf("Sent %.1f MBytes", $TotalSent/1024.0); +else + $txtTotalSent = sprintf("Sent %.1f GBytes", $TotalSent/(1024.0*1024.0)); + +ImageString($im, 2, XOFFSET+5, $height-20, $txtTotalSent, $black); +ImageString($im, 2, $width/2+XOFFSET/2, $height-20, $txtPeakSendRate, $black); + +// Draw X Axis + +ImageLine($im, 0, $height-YOFFSET, $width, $height-YOFFSET, $black); + +// Day/Month Seperator bars + +if ((24*60*60*($width-XOFFSET))/$interval > ($width-XOFFSET)/10) + { + $ts = getdate($timestamp); + $MarkTime = mktime(0, 0, 0, $ts['mon'], $ts['mday'], $ts['year']); + + $x = ts2x($MarkTime); + while ($x < XOFFSET) + { + $MarkTime += (24*60*60); + $x = ts2x($MarkTime); + } + + while ($x < ($width-10)) + { + // Day Lines + ImageLine($im, $x, 0, $x, $height-YOFFSET, $black); + ImageLine($im, $x+1, 0, $x+1, $height-YOFFSET, $black); + + $txtDate = strftime("%a, %b %d", $MarkTime); + ImageString($im, 2, $x-30, $height-YOFFSET+10, $txtDate, $black); + + // Calculate Next x + $MarkTime += (24*60*60); + $x = ts2x($MarkTime); + } + } +else if ((24*60*60*30*($width-XOFFSET))/$interval > ($width-XOFFSET)/10) + { + // Monthly Bars + $ts = getdate($timestamp); + $month = $ts['mon']; + $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); + + $x = ts2x($MarkTime); + while ($x < XOFFSET) + { + $month++; + $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); + $x = ts2x($MarkTime); + } + + while ($x < ($width-10)) + { + // Day Lines + ImageLine($im, $x, 0, $x, $height-YOFFSET, $black); + ImageLine($im, $x+1, 0, $x+1, $height-YOFFSET, $black); + + $txtDate = strftime("%b, %Y", $MarkTime); + ImageString($im, 2, $x-25, $height-YOFFSET+10, $txtDate, $black); + + // Calculate Next x + $month++; + $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); + $x = ts2x($MarkTime); + } + } +else + { + // Year Bars + $ts = getdate($timestamp); + $year = $ts['year']; + $MarkTime = mktime(0, 0, 0, 1, 1, $year); + + $x = ts2x($MarkTime); + while ($x < XOFFSET) + { + $year++; + $MarkTime = mktime(0, 0, 0, 1, 1, $year); + $x = ts2x($MarkTime); + } + + while ($x < ($width-10)) + { + // Day Lines + ImageLine($im, $x, 0, $x, $height-YOFFSET, $black); + ImageLine($im, $x+1, 0, $x+1, $height-YOFFSET, $black); + + $txtDate = strftime("%b, %Y", $MarkTime); + ImageString($im, 2, $x-25, $height-YOFFSET+10, $txtDate, $black); + + // Calculate Next x + $year++; + $MarkTime = mktime(0, 0, 0, 1, 1, $year); + $x = ts2x($MarkTime); + } + } + +// Draw Major Tick Marks +if ((6*60*60*($width-XOFFSET))/$interval > 10) // pixels per 6 hours is more than 2 + $MarkTimeStep = 6*60*60; // Major ticks are 6 hours +else if ((24*60*60*($width-XOFFSET))/$interval > 10) + $MarkTimeStep = 24*60*60; // Major ticks are 24 hours; +else if ((24*60*60*30*($width-XOFFSET))/$interval > 10) + { + // Major tick marks are months + $MarkTimeStep = 0; // Skip the standard way of drawing major tick marks below + + $ts = getdate($timestamp); + $month = $ts['mon']; + $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); + + $x = ts2x($MarkTime); + while ($x < XOFFSET) + { + $month++; + $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); + $x = ts2x($MarkTime); + } + + while ($x < ($width-10)) + { + // Day Lines + $date = getdate($MarkTime); + if ($date['mon'] != 1) + { + ImageLine($im, $x, $height-YOFFSET-5, $x, $height-YOFFSET+5, $black); + $txtDate = strftime("%b", $MarkTime); + ImageString($im, 2, $x-5, $height-YOFFSET+10, $txtDate, $black); + } + + // Calculate Next x + $month++; + $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); + $x = ts2x($MarkTime); + } + } +else + $MarkTimeStep = 0; // Skip Major Tick Marks + +if ($MarkTimeStep) + { + $ts = getdate($timestamp); + $MarkTime = mktime(0, 0, 0, $ts['mon'], $ts['mday'], $ts['year']); + $x = ts2x($MarkTime); + + while ($x < ($width-10)) + { + if ($x > XOFFSET) + { + ImageLine($im, $x, $height-YOFFSET-5, $x, $height-YOFFSET+5, $black); + } + $MarkTime += $MarkTimeStep; + $x = ts2x($MarkTime); + } + } + +// Draw Minor Tick marks +if ((60*60*($width-XOFFSET))/$interval > 4) // pixels per hour is more than 2 + $MarkTimeStep = 60*60; // Minor ticks are 1 hour +else if ((6*60*60*($width-XOFFSET))/$interval > 4) + $MarkTimeStep = 6*60*60; // Minor ticks are 6 hours +else if ((24*60*60*($width-XOFFSET))/$interval > 4) + $MarkTimeStep = 24*60*60; +else + $MarkTimeStep = 0; // Skip minor tick marks + +if ($MarkTimeStep) + { + $ts = getdate($timestamp); + $MarkTime = mktime(0, 0, 0, $ts['mon'], $ts['mday'], $ts['year']); + $x = ts2x($MarkTime); + + while ($x < ($width-10)) + { + if ($x > XOFFSET) + { + ImageLine($im, $x, $height-YOFFSET, $x, $height-YOFFSET+5, $black); + } + $MarkTime += $MarkTimeStep; + $x = ts2x($MarkTime); + } + } + +// Draw Y Axis +ImageLine($im, XOFFSET, 0, XOFFSET, $height, $black); + +$YLegend = 'k'; +$Divisor = 1; +if ($YMax*8 > 1024*2) + { + $Divisor = 1024; // Display in m + $YLegend = 'm'; + } + +if ($YMax*8 > 1024*1024*2) + { + $Divisor = 1024*1024; // Display in g + $YLegend = 'g'; + } + +if ($YMax*8 > 1024*1024*1024*2) + { + $Divisor = 1024*1024*1024; // Display in t + $YLegend = 't'; + } + +$YStep = $YMax/10; +if ($YStep < 1) + $YStep=1; +$YTic=$YStep; + +while ($YTic <= ($YMax - $YMax/10)) + { + $y = ($height-YOFFSET)-(($YTic*($height-YOFFSET))/$YMax); + ImageLine($im, XOFFSET, $y, $width, $y, $black); + $txtYLegend = sprintf("%4.1f %sbits/s", (8.0*$YTic)/$Divisor, $YLegend); + ImageString($im, 2, 3, $y-7, $txtYLegend, $black); + $YTic += $YStep; + } + +imagepng($im); +imagedestroy($im); diff --git a/utils/bandwidthd/files/phphtdocs-sqlite/include.php b/utils/bandwidthd/files/phphtdocs-sqlite/include.php new file mode 100644 index 0000000000..51950980db --- /dev/null +++ b/utils/bandwidthd/files/phphtdocs-sqlite/include.php @@ -0,0 +1,69 @@ +getMessage()); + } + return $db; +} + +function fmtb($kbytes) + { + $Max = 1024; + $Output = $kbytes; + $Suffix = 'K'; + + if ($Output > $Max) + { + $Output /= 1024; + $Suffix = 'M'; + } + + if ($Output > $Max) + { + $Output /= 1024; + $Suffix = 'G'; + } + + if ($Output > $Max) + { + $Output /= 1024; + $Suffix = 'T'; + } + + return(sprintf("%.1f%s", $Output, $Suffix)); + } + +function ip2s32($ip) { + $i = ip2long($ip); + return ($i & 0x80000000 ? '-' . ((~$i & 0x7fffffff)+1) : ''. ($i & 0x7fffffff)); +} + +function prepare_sql_subnet($subnet) { + list($snet, $smask) = explode('/', $subnet); + $inet = ip2s32($snet); + if($smask > 0 && $smask < 32) { + $mask = -1 << (32 - (int)$smask); + return "and (ip & $mask = $inet)"; + } elseif ($inet) { + return "and ip = " . $inet; + } + return ""; +} + +$starttime = time(); +set_time_limit(300); +?> diff --git a/utils/bandwidthd/files/phphtdocs-sqlite/index.php b/utils/bandwidthd/files/phphtdocs-sqlite/index.php new file mode 100644 index 0000000000..c8b8598d15 --- /dev/null +++ b/utils/bandwidthd/files/phphtdocs-sqlite/index.php @@ -0,0 +1,190 @@ + + +
+ + +
+ + +
+ + + +Subnet Filter:"> + +
+
+Top $limit - $sensor_name"; +else + echo "

All Records - $sensor_name

"; + +// Sqlize the incomming variables +if (isset($subnet)) { + $sql_subnet = prepare_sql_subnet($subnet); +} + +// Sql Statement +$sql = "select tx.ip, rx.scale as rxscale, tx.scale as txscale, tx.total+rx.total as total, tx.total as sent, +rx.total as received, tx.tcp+rx.tcp as tcp, tx.udp+rx.udp as udp, +tx.icmp+rx.icmp as icmp, tx.http+rx.http as http, +tx.p2p+rx.p2p as p2p, tx.ftp+rx.ftp as ftp +from + +(SELECT ip, max(total/sample_duration)*8 as scale, sum(total) as total, sum(tcp) as tcp, sum(udp) as udp, sum(icmp) as icmp, +sum(http) as http, sum(p2p) as p2p, sum(ftp) as ftp +from sensors, bd_tx_log +where sensor_name = '$sensor_name' +and sensors.sensor_id = bd_tx_log.sensor_id +$sql_subnet +and timestamp > $timestamp and timestamp < ".($timestamp+$interval)." +group by ip) as tx, + +(SELECT ip, max(total/sample_duration)*8 as scale, sum(total) as total, sum(tcp) as tcp, sum(udp) as udp, sum(icmp) as icmp, +sum(http) as http, sum(p2p) as p2p, sum(ftp) as ftp +from sensors, bd_rx_log +where sensor_name = '$sensor_name' +and sensors.sensor_id = bd_rx_log.sensor_id +$sql_subnet +and timestamp > $timestamp and timestamp < ".($timestamp+$interval)." +group by ip) as rx + +where tx.ip = rx.ip +order by total desc;"; + +//echo "
$sql
"; error_log($sql); +$pdoResult = $db->query($sql); +$result = $pdoResult->fetchAll(); +$db = NULL; +$num_rows = count($result); +if ($limit == "all") + $limit = $num_rows; + +echo "
IpNameTotalSentReceivedtcpudpicmphttpsmtpftp"; + +if (!isset($subnet)) // Set this now for total graphs + $subnet = "0.0.0.0/0"; + +// Output Total Line +echo "
Total$subnet"; +foreach (array("total", "sent", "received", "tcp", "udp", "icmp", "http", "p2p", "ftp") as $key) + { + for($Counter=0, $Total = 0; $Counter < $num_rows; $Counter++) + { + $r = $result[$Counter]; + $Total += $r[$key]; + } + echo fmtb($Total); + } +echo "\n"; + +// Output Other Lines +for($Counter=0; $Counter < $num_rows && $Counter < $limit; $Counter++) + { + $r = $result[$Counter]; + $r['ip'] = long2ip($r['ip']); + echo "
"; + echo $r['ip']."".gethostbyaddr($r['ip']); + echo ""; + echo fmtb($r['total']).fmtb($r['sent']).fmtb($r['received']). + fmtb($r['tcp']).fmtb($r['udp']).fmtb($r['icmp']).fmtb($r['http']). + fmtb($r['p2p']).fmtb($r['ftp'])."\n"; + } +echo "
"; + +// Output Total Graph +for($Counter=0, $Total = 0; $Counter < $num_rows; $Counter++) + { + $r = $result[$Counter]; + $scale = max($r['txscale'], $scale); + $scale = max($r['rxscale'], $scale); + } + +if ($subnet == "0.0.0.0/0") + $total_table = "bd_tx_total_log"; +else + $total_table = "bd_tx_log"; +echo "

"; +echo "Total - Total of $subnet

"; +echo ""; +echo "Send:

"; +echo "
\n"; +if ($subnet == "0.0.0.0/0") + $total_table = "bd_rx_total_log"; +else + $total_table = "bd_rx_log"; +echo "Receive:

"; +echo "
\n"; + + +// Output Other Graphs +for($Counter=0; $Counter < $num_rows && $Counter < $limit; $Counter++) + { + $r = $result[$Counter]; + $r['ip'] = long2ip($r['ip']); + echo "

"; + if ($r['ip'] == "0.0.0.0") + echo "Total - Total of all subnets

"; + else + echo $r['ip']." - ".gethostbyaddr($r['ip']).""; + echo ""; + echo "Send:

"; + echo "
\n"; + echo "Receive:

"; + echo "
\n"; + } + +include('footer.php'); diff --git a/utils/bandwidthd-php/files/details.php b/utils/bandwidthd/files/phphtdocs/details.php similarity index 99% rename from utils/bandwidthd-php/files/details.php rename to utils/bandwidthd/files/phphtdocs/details.php index d2f0786f91..cb52f43278 100644 --- a/utils/bandwidthd-php/files/details.php +++ b/utils/bandwidthd/files/phphtdocs/details.php @@ -65,7 +65,7 @@ group by ip) as rx where tx.ip = rx.ip;"; //echo "
$sql
";exit(0); $result = pg_query($sql); -echo "
IpNameTotalSentReceivedtcpudpicmphttpp2pftp"; +echo "
IpNameTotalSentReceivedtcpudpicmphttpsmtpftp"; $r = pg_fetch_array($result); echo "
"; if (strpos($ip, "/") === FALSE) diff --git a/utils/bandwidthd/files/phphtdocs/footer.php b/utils/bandwidthd/files/phphtdocs/footer.php new file mode 100644 index 0000000000..b3428250d4 --- /dev/null +++ b/utils/bandwidthd/files/phphtdocs/footer.php @@ -0,0 +1,3 @@ + diff --git a/utils/bandwidthd-php/files/graph.php b/utils/bandwidthd/files/phphtdocs/graph.php similarity index 80% rename from utils/bandwidthd-php/files/graph.php rename to utils/bandwidthd/files/phphtdocs/graph.php index b97817738b..323d659edc 100644 --- a/utils/bandwidthd-php/files/graph.php +++ b/utils/bandwidthd/files/phphtdocs/graph.php @@ -13,7 +13,7 @@ function AverageAndAccumulate() { global $Count, $total, $icmp, $udp, $tcp, $ftp, $http, $p2p, $YMax; global $a_total, $a_icmp, $a_udp, $a_tcp, $a_ftp, $a_http, $a_p2p; - + foreach ($Count as $key => $number) { $total[$key] /= $number; @@ -25,7 +25,7 @@ function AverageAndAccumulate() $p2p[$key] /= $number; } - foreach ($Count as $key => $number) + foreach ($Count as $key => $number) { $a_total[$key] += $total[$key]; $a_icmp[$key] += $icmp[$key]; @@ -38,7 +38,7 @@ function AverageAndAccumulate() if ($a_total[$key] > $YMax) $YMax = $a_total[$key]; } - + unset($GLOBALS['total'], $GLOBALS['icmp'], $GLOBALS['udp'], $GLOBALS['tcp'], $GLOBALS['ftp'], $GLOBALS['http'], $GLOBALS['p2p'], $GLOBALS['Count']); $total = array(); @@ -50,7 +50,6 @@ function AverageAndAccumulate() $p2p = array(); $Count = array(); } - $db = ConnectDb(); @@ -133,7 +132,7 @@ while ($row = pg_fetch_array($result)) //echo "xint: ".$xint."
"; $Count[$xint]++; - + if ($row['total']/$row['sample_duration'] > $SentPeak) $SentPeak = $row['total']/$row['sample_duration']; $TotalSent += $row['total']; @@ -143,7 +142,7 @@ while ($row = pg_fetch_array($result)) $tcp[$xint] += $row['tcp']/$row['sample_duration']; $ftp[$xint] += $row['ftp']/$row['sample_duration']; $http[$xint] += $row['http']/$row['sample_duration']; - $p2p[$xint] += $row['p2p']/$row['sample_duration']; + $p2p[$xint] += $row['p2p']/$row['sample_duration']; } // One more time for the last IP @@ -170,7 +169,6 @@ header("Content-type: image/png"); $im = imagecreate($width, $height); $white = imagecolorallocate($im, 255, 255, 255); -$yellow = ImageColorAllocate($im, 255, 255, 0); $purple = ImageColorAllocate($im, 255, 0, 255); $green = ImageColorAllocate($im, 0, 255, 0); $blue = ImageColorAllocate($im, 0, 0, 255); @@ -207,7 +205,6 @@ for($Counter=XOFFSET+1; $Counter < $width; $Counter++) // Plot them! //echo "$Counter:".$Counter." (h-y)-t:".($height-YOFFSET) - $total[$Counter]." h-YO-1:".$height-YOFFSET-1; - ImageLine($im, $Counter, ($height-YOFFSET) - $total[$Counter], $Counter, $height-YOFFSET-1, $yellow); ImageLine($im, $Counter, ($height-YOFFSET) - $icmp[$Counter], $Counter, $height-YOFFSET-1, $red); ImageLine($im, $Counter, ($height-YOFFSET) - $udp[$Counter], $Counter, ($height-YOFFSET) - $icmp[$Counter] - 1, $brown); ImageLine($im, $Counter, ($height-YOFFSET) - $tcp[$Counter], $Counter, ($height-YOFFSET) - $udp[$Counter] - 1, $green); @@ -217,23 +214,23 @@ for($Counter=XOFFSET+1; $Counter < $width; $Counter++) } // else // echo $Counter." not set
"; - } + } // Margin Text if ($SentPeak < 1024/8) $txtPeakSendRate = sprintf("Peak Send Rate: %.1f KBits/sec", $SentPeak*8); else if ($SentPeak < (1024*1024)/8) $txtPeakSendRate = sprintf("Peak Send Rate: %.1f MBits/sec", ($SentPeak*8.0)/1024.0); -else +else $txtPeakSendRate = sprintf("Peak Send Rate: %.1f GBits/sec", ($SentPeak*8.0)/(1024.0*1024.0)); - + if ($TotalSent < 1024) $txtTotalSent = sprintf("Sent %.1f KBytes", $TotalSent); else if ($TotalSent < 1024*1024) $txtTotalSent = sprintf("Sent %.1f MBytes", $TotalSent/1024.0); -else +else $txtTotalSent = sprintf("Sent %.1f GBytes", $TotalSent/(1024.0*1024.0)); - + ImageString($im, 2, XOFFSET+5, $height-20, $txtTotalSent, $black); ImageString($im, 2, $width/2+XOFFSET/2, $height-20, $txtPeakSendRate, $black); @@ -247,23 +244,23 @@ if ((24*60*60*($width-XOFFSET))/$interval > ($width-XOFFSET)/10) { $ts = getdate($timestamp); $MarkTime = mktime(0, 0, 0, $ts['mon'], $ts['mday'], $ts['year']); - + $x = ts2x($MarkTime); while ($x < XOFFSET) { $MarkTime += (24*60*60); $x = ts2x($MarkTime); } - + while ($x < ($width-10)) { // Day Lines ImageLine($im, $x, 0, $x, $height-YOFFSET, $black); ImageLine($im, $x+1, 0, $x+1, $height-YOFFSET, $black); - + $txtDate = strftime("%a, %b %d", $MarkTime); ImageString($im, 2, $x-30, $height-YOFFSET+10, $txtDate, $black); - + // Calculate Next x $MarkTime += (24*60*60); $x = ts2x($MarkTime); @@ -275,7 +272,7 @@ else if ((24*60*60*30*($width-XOFFSET))/$interval > ($width-XOFFSET)/10) $ts = getdate($timestamp); $month = $ts['mon']; $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); - + $x = ts2x($MarkTime); while ($x < XOFFSET) { @@ -283,16 +280,16 @@ else if ((24*60*60*30*($width-XOFFSET))/$interval > ($width-XOFFSET)/10) $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); $x = ts2x($MarkTime); } - + while ($x < ($width-10)) { // Day Lines ImageLine($im, $x, 0, $x, $height-YOFFSET, $black); ImageLine($im, $x+1, 0, $x+1, $height-YOFFSET, $black); - + $txtDate = strftime("%b, %Y", $MarkTime); ImageString($im, 2, $x-25, $height-YOFFSET+10, $txtDate, $black); - + // Calculate Next x $month++; $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); @@ -305,7 +302,7 @@ else $ts = getdate($timestamp); $year = $ts['year']; $MarkTime = mktime(0, 0, 0, 1, 1, $year); - + $x = ts2x($MarkTime); while ($x < XOFFSET) { @@ -313,21 +310,21 @@ else $MarkTime = mktime(0, 0, 0, 1, 1, $year); $x = ts2x($MarkTime); } - + while ($x < ($width-10)) { // Day Lines ImageLine($im, $x, 0, $x, $height-YOFFSET, $black); ImageLine($im, $x+1, 0, $x+1, $height-YOFFSET, $black); - + $txtDate = strftime("%b, %Y", $MarkTime); ImageString($im, 2, $x-25, $height-YOFFSET+10, $txtDate, $black); - + // Calculate Next x $year++; $MarkTime = mktime(0, 0, 0, 1, 1, $year); $x = ts2x($MarkTime); - } + } } // Draw Major Tick Marks @@ -343,7 +340,7 @@ else if ((24*60*60*30*($width-XOFFSET))/$interval > 10) $ts = getdate($timestamp); $month = $ts['mon']; $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); - + $x = ts2x($MarkTime); while ($x < XOFFSET) { @@ -351,18 +348,18 @@ else if ((24*60*60*30*($width-XOFFSET))/$interval > 10) $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); $x = ts2x($MarkTime); } - + while ($x < ($width-10)) { // Day Lines $date = getdate($MarkTime); if ($date['mon'] != 1) { - ImageLine($im, $x, $height-YOFFSET-5, $x, $height-YOFFSET+5, $black); + ImageLine($im, $x, $height-YOFFSET-5, $x, $height-YOFFSET+5, $black); $txtDate = strftime("%b", $MarkTime); ImageString($im, 2, $x-5, $height-YOFFSET+10, $txtDate, $black); } - + // Calculate Next x $month++; $MarkTime = mktime(0, 0, 0, $month, 1, $ts['year']); @@ -380,13 +377,13 @@ if ($MarkTimeStep) while ($x < ($width-10)) { - if ($x > XOFFSET) + if ($x > XOFFSET) { ImageLine($im, $x, $height-YOFFSET-5, $x, $height-YOFFSET+5, $black); } $MarkTime += $MarkTimeStep; $x = ts2x($MarkTime); - } + } } // Draw Minor Tick marks @@ -407,7 +404,7 @@ if ($MarkTimeStep) while ($x < ($width-10)) { - if ($x > XOFFSET) + if ($x > XOFFSET) { ImageLine($im, $x, $height-YOFFSET, $x, $height-YOFFSET+5, $black); } @@ -438,12 +435,12 @@ if ($YMax*8 > 1024*1024*1024*2) $Divisor = 1024*1024*1024; // Display in t $YLegend = 't'; } - + $YStep = $YMax/10; if ($YStep < 1) $YStep=1; $YTic=$YStep; - + while ($YTic <= ($YMax - $YMax/10)) { $y = ($height-YOFFSET)-(($YTic*($height-YOFFSET))/$YMax); @@ -453,5 +450,5 @@ while ($YTic <= ($YMax - $YMax/10)) $YTic += $YStep; } -imagepng($im); +imagepng($im); imagedestroy($im); diff --git a/utils/bandwidthd-php/files/include.php b/utils/bandwidthd/files/phphtdocs/include.php similarity index 100% rename from utils/bandwidthd-php/files/include.php rename to utils/bandwidthd/files/phphtdocs/include.php diff --git a/utils/bandwidthd-php/files/index.php b/utils/bandwidthd/files/phphtdocs/index.php similarity index 99% rename from utils/bandwidthd-php/files/index.php rename to utils/bandwidthd/files/phphtdocs/index.php index 5159f85d93..b3602afdeb 100644 --- a/utils/bandwidthd-php/files/index.php +++ b/utils/bandwidthd/files/phphtdocs/index.php @@ -122,7 +122,7 @@ pg_query("set sort_mem to default;"); if ($limit == "all") $limit = pg_num_rows($result); -echo "
IpNameTotalSentReceivedtcpudpicmphttpp2pftp"; +echo "
IpNameTotalSentReceivedtcpudpicmphttpsmtpftp"; if (!isset($subnet)) // Set this now for total graphs $subnet = "0.0.0.0/0"; diff --git a/utils/bandwidthd/patches/010-dont-add-host-paths-in-config.in.patch b/utils/bandwidthd/patches/010-dont-add-host-paths-in-config.in.patch new file mode 100644 index 0000000000..cfaba70bd4 --- /dev/null +++ b/utils/bandwidthd/patches/010-dont-add-host-paths-in-config.in.patch @@ -0,0 +1,24 @@ +--- a/configure.in ++++ b/configure.in +@@ -24,11 +24,6 @@ if test -n "$x_libraries" && test "x$x_l + 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 + AC_CHECK_FILE(/sw/lib, LDFLAGS="$LDFLAGS -L/sw/lib") + AC_CHECK_FILE(/sw/include, CPPFLAGS="$CPPFLAGS -I/sw/include") +@@ -55,8 +50,7 @@ AC_CHECK_LIB(pcap, pcap_open_live, , + [AC_CHECK_LIB(wpcap, pcap_open_live, ,[AC_MSG_ERROR([Bandwidthd requires but cannot find libpcap])])]) + + # Optional Library +-AC_CHECK_FILE(/usr/lib, LDFLAGS="$LDFLAGS -L/usr/lib") +-AC_CHECK_FILE(/usr/include/pgsql, CPPFLAGS="$CPPFLAGS -I/usr/include/pgsql") ++AC_CHECK_FILE(/usr/local/pgsql/include, CPPFLAGS="$CPPFLAGS -I/usr/local/pgsql/include") + AC_CHECK_LIB(pq, PQconnectdb, + [AC_CHECK_LIB(pq,PQexecParams, ,AC_MSG_WARN([libpq exists but is too old... bandwidthd requires support for PQexecParams]))]) + AC_CHECK_LIB(sqlite3, sqlite3_open, ,AC_MSG_WARN([sqlite3 is recommended for storage of data but cannot be found])) diff --git a/utils/bandwidthd/patches/010-dont-add-host-paths.patch b/utils/bandwidthd/patches/010-dont-add-host-paths.patch deleted file mode 100644 index 59a57373db..0000000000 --- a/utils/bandwidthd/patches/010-dont-add-host-paths.patch +++ /dev/null @@ -1,36 +0,0 @@ -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/020-change-p2p-to-smtp.patch b/utils/bandwidthd/patches/020-change-p2p-to-smtp.patch new file mode 100644 index 0000000000..d0e614476a --- /dev/null +++ b/utils/bandwidthd/patches/020-change-p2p-to-smtp.patch @@ -0,0 +1,20 @@ +--- a/graph.c ++++ b/graph.c +@@ -274,7 +274,7 @@ void MakeIndexPages(int NumIps, struct S + + // PASS 1: Write out the table + +- fprintf(file, "
Ip and NameTotalTotal SentTotal ReceivedFTPHTTPP2PTCPUDPICMP\n"); ++ fprintf(file, "
Ip and NameTotalTotal SentTotal ReceivedFTPHTTPSMTPTCPUDPICMP\n"); + for (Counter=0; Counter < 21 && Counter < NumIps; Counter++) + PrintTableLine(file, SummaryData[Counter], Counter); + +@@ -341,7 +341,7 @@ void MakeIndexPages(int NumIps, struct S + + // PASS 1: Write out the table + +- fprintf(file, "
Ip and NameTotalTotal SentTotal ReceivedFTPHTTPP2PTCPUDPICMP\n"); ++ fprintf(file, "
Ip and NameTotalTotal SentTotal ReceivedFTPHTTPSMTPTCPUDPICMP\n"); + for (tCounter=0, Counter=0; Counter < NumIps; Counter++) + { + if (SubnetTable[SubnetCounter].ip == (SummaryData[Counter]->IP & SubnetTable[SubnetCounter].mask)) diff --git a/utils/bandwidthd/patches/100-fix_config_file_location b/utils/bandwidthd/patches/100-fix_config_file_location deleted file mode 100644 index ae44cd2e47..0000000000 --- a/utils/bandwidthd/patches/100-fix_config_file_location +++ /dev/null @@ -1,31 +0,0 @@ ---- 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();