Skip to content

Commit

Permalink
ntopng: update for dsm 7 and debian 12 dev env (#6218)
Browse files Browse the repository at this point in the history
* ntopng: update for dsm 7 and debian 12 dev env
- ntopng: avoid patching the generated configure file (file content depends on version of autoconf)
- make patching of generated Makefile independent of number of white spaces
- patch Makefile.in to avoid some patches of generated Makefile
- update paths in start-stop-status.sh and ntopng.conf for DSM 7 compatibility
- install ntopng.conf file into var folder (instead of etc folder)
- fix mysql_config by cross/mysql-connector-c

* add wizard page for DSM 7 with notes for patching the privilege file
  • Loading branch information
hgy59 authored Sep 1, 2024
1 parent 9af59c0 commit a4274e1
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 158 deletions.
7 changes: 7 additions & 0 deletions cross/mysql-connector-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ LICENSE = GNU GPLv2
USE_NATIVE_CMAKE_LEGACY = 1
CMAKE_USE_NINJA = 1

POST_INSTALL_TARGET = mysql-connector-c_post_install

include ../../mk/spksrc.cross-cmake.mk

# give access to comp_err binary on host
Expand Down Expand Up @@ -60,3 +62,8 @@ CMAKE_ARGS += -DWITH_ZLIB=system
ifneq ($(findstring $(ARCH),$(PPC_ARCHS)),)
CMAKE_ARGS += -DHAVE_GCC_ATOMIC_BUILTINS=1
endif

.PHONY: mysql-connector-c_post_install
mysql-connector-c_post_install:
@$(MSG) Fix for mysql_config --libs
@$(RUN) sed 's|"$$libs -l "|"$$libs -lmysqlclient "|g' -i $(INSTALL_DIR)$(INSTALL_PREFIX)/bin/mysql_config
63 changes: 28 additions & 35 deletions cross/ntopng/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DEPENDS += cross/json-c cross/rrdtool cross/lua
UNSUPPORTED_ARCHS = $(OLD_PPC_ARCHS) $(ARMv5_ARCHS)

HOMEPAGE = https://www.ntop.org/
COMMENT = ntopng is the next generation version of the original ntop, a network traffic probe that monitors network usage. ntopng is based on libpcap and it has been written in a portable way in order to virtually run on every Unix platform, MacOSX and on Windows as well.
COMMENT = High-Speed Web-based Traffic Analysis and Flow Collection.
LICENSE = GPLv3

include ../../mk/spksrc.archs.mk
Expand All @@ -25,74 +25,67 @@ ifeq ($(findstring $(ARCH),$(SRM_ARCHS)),$(ARCH))
SYNOLOGY_OS = SRM
endif

RW_LOCKS_SUPPORTED = yes
ADDITIONAL_LIBRARIES = -lcurl -llua
# similar to 'uname -m' on the target plattform (not essential, for information only)
PACKAGE_MACHINE = x86_64

ifeq ($(findstring $(ARCH),$(ARMv5_ARCHS)),$(ARCH))
PACKAGE_MACHINE = armv5
endif
ifeq ($(findstring $(ARCH),$(ARMv7L_ARCHS)),$(ARCH))
PACKAGE_MACHINE = armv7l
RW_LOCKS_SUPPORTED = no
endif
ifeq ($(findstring $(ARCH),$(ARMv7_ARCHS)),$(ARCH))
PACKAGE_MACHINE = armv7
RW_LOCKS_SUPPORTED = no
endif
ifeq ($(findstring $(ARCH),$(ARMv8_ARCHS)),$(ARCH))
PACKAGE_MACHINE = aarch64
RW_LOCKS_SUPPORTED = no
endif
ifeq ($(findstring $(ARCH),$(PPC_ARCHS)),$(ARCH))
PACKAGE_MACHINE = ppc
RW_LOCKS_SUPPORTED = no
# for qoriq:
ADDITIONAL_LIBRARIES += -latomic
endif
ifeq ($(findstring $(ARCH),$(i686_ARCHS)),$(ARCH))
PACKAGE_MACHINE = i686
RW_LOCKS_SUPPORTED = no
endif

GNU_CONFIGURE = 1
PRE_PATCH_TARGET = ntopng_pre_patch
PRE_CONFIGURE_TARGET = ntopng_pre_configure
PRE_COMPILE_TARGET = ntopng_pre_compile

CONFIGURE_ARGS = --prefix=$(INSTALL_PREFIX)
CONFIGURE_ARGS += --with-ndpi-includes=$(STAGING_INSTALL_PREFIX)/include/ndpi
CONFIGURE_ARGS += --with-ndpi-static-lib=$(STAGING_INSTALL_PREFIX)/lib
CONFIGURE_ARGS += my_cv_rw_locks_supported=$(RW_LOCKS_SUPPORTED)

# May be required as mysql-connector-c include
# files are now located under include/mysql
# ADDITIONAL_CFLAGS = -I$(STAGING_INSTALL_PREFIX)/include/mysql

ENV += DESTDIR=$(INSTALL_DIR)
# let ./configure find mysql_config (it is a script and works for cross compile)
ENV += "PATH=$(PATH):$(STAGING_INSTALL_PREFIX)/bin"
ENV += DESTDIR=$(INSTALL_DIR)

include ../../mk/spksrc.cross-cc.mk

.PHONY: ntopng_pre_patch
ntopng_pre_patch:
@$(RUN) ./autogen.sh

.PHONY: ntopng_pre_configure
ntopng_pre_configure:
@$(MSG) "- patch generated configure file to define synology specific package info"
@$(RUN) sed -i 's|#define PACKAGE_OSNAME "$${OSNAME}"|#define PACKAGE_OSNAME "Synology $(SYNOLOGY_OS) $(TCVERSION)+"|g' ./configure
@$(RUN) sed -i 's|#define PACKAGE_OS "$${OS}"|#define PACKAGE_OS "$(TC_ARCH)"|g' ./configure
@$(RUN) sed -i 's|#define PACKAGE_MACHINE "$$MACHINE"|#define PACKAGE_MACHINE "$(PACKAGE_MACHINE)"|g' ./configure
@$(MSG) "- patch sources to define real version instead of 'major.minor.currentdate', fix github links, reformat copyright date"
@$(RUN) sed -i "s|PACKAGE_VERSION='.*'|PACKAGE_VERSION='$(PKG_VERS)'|g" ./configure
@$(RUN) sed -i "s|PACKAGE_STRING='ntopng .*'|PACKAGE_STRING='ntopng $(PKG_VERS)'|g" ./configure
@$(RUN) sed -i 's|GIT_RELEASE=".*"|GIT_RELEASE="$(PKG_VERS)"|g' ./configure
@$(RUN) sed -i 's|"https://github.com/ntop/ntopng/commit/"..|"https://github.com/ntop/ntopng/releases/tag/"..|g' ./scripts/lua/about.lua
@$(RUN) sed -i 's|"http://www.d3js.org|"http://d3js.org|g' ./scripts/lua/about.lua
@$(RUN) sed -i 's|"(C) 1998-\(..\) ntop.org"|"(C) 1998-20\1 ntop.org"|g' ./include/ntop_defines.h
@$(RUN) sed -i 's|copy; 1998-\(..\) - ntop.org"|copy; 1998-20\1 - ntop.org"|g' ./src/LuaEngine.cpp
@$(RUN) sed -i 's|"Welcome to %s %s v.%s - (C) 1998-\(..\) ntop.org"|"Welcome to %s %s v.%s - (C) 1998-20\1 ntop.org"|g' ./src/Ntop.cpp
@$(MSG) "- RUN autogen to create configure file"
@$(RUN) ./autogen.sh
@$(MSG) "- PATCH generated configure file to define synology specific package info"
@$(RUN) sed 's|#define PACKAGE_OSNAME \\"$${OSNAME}\\"|#define PACKAGE_OSNAME \\"Synology $(SYNOLOGY_OS) $(TCVERSION)+\\"|g' -i ./configure
@$(RUN) sed 's|#define PACKAGE_OS \\"$${OS}\\"|#define PACKAGE_OS \\"$(TC_ARCH)\\"|g' -i ./configure
@$(RUN) sed 's|#define PACKAGE_MACHINE \\"$$MACHINE\\"|#define PACKAGE_MACHINE \\"$(PACKAGE_MACHINE)\\"|g' -i ./configure
@$(MSG) "- PATCH sources to define real version instead of 'major.minor.currentdate', fix github links, reformat copyright date"
@$(RUN) sed "s|PACKAGE_VERSION='.*'|PACKAGE_VERSION='$(PKG_VERS)'|g" -i ./configure
@$(RUN) sed "s|PACKAGE_STRING='ntopng .*'|PACKAGE_STRING='ntopng $(PKG_VERS)'|g" -i ./configure
@$(RUN) sed 's|GIT_RELEASE=".*"|GIT_RELEASE="$(PKG_VERS)"|g' -i ./configure
@$(RUN) sed 's|"https://github.com/ntop/ntopng/commit/"..|"https://github.com/ntop/ntopng/releases/tag/"..|g' -i ./scripts/lua/about.lua
@$(RUN) sed 's|"(C) 1998-\(..\) ntop.org"|"(C) 1998-20\1 ntop.org"|g' -i ./include/ntop_defines.h
@$(RUN) sed 's|"Welcome to %s %s v.%s - (C) 1998-\(..\) ntop.org"|"Welcome to %s %s v.%s - (C) 1998-20\1 ntop.org"|g' -i ./src/Ntop.cpp
@$(RUN) sed 's|copy; 1998-\(..\) - ntop.org"|copy; 1998-20\1 - ntop.org"|g' -i ./src/LuaEngineNtop.cpp.inc

.PHONY: ntopng_pre_compile
ntopng_pre_compile:
@$(MSG) "- patch generated Makefile to ignore third-party libs and use cross/* packages instead"
@$(RUN) sed -i 's|LIB_TARGETS = $$(LUA_LIB)|LIB_TARGETS =|g' ./Makefile
@$(RUN) sed -i 's|$$(LIBPCAP) $$(LUA_LIB) $$(LIBRRDTOOL_LIB)|$$(LIBPCAP) $$(LIBRRDTOOL_LIB)|g' ./Makefile
@$(RUN) sed -i 's| -l -L/| -L/|g' ./Makefile
@$(RUN) sed -i 's| -l -lexpat -L/| -lexpat -L/|g' ./Makefile
@$(RUN) sed -i 's| -lssl -lssl | -lssl -lcurl -llua -lmysqlclient |g' ./Makefile
@$(RUN) sed -i 's|-L/usr/local/lib -lrt -lz -ldl -lcurl |-L/usr/local/lib -lrt -lz -ldl |g' ./Makefile
@$(RUN) sed -i 's|-L/usr/local/lib -lcap -lrt -lz -ldl -lcurl |-L/usr/local/lib -lcap -lrt -lz -ldl |g' ./Makefile
@$(MSG) "- PATCH generated Makefile to link with additional (cross/*) libraries"
@$(RUN) sed 's| -lssl *-lssl | -lssl $(ADDITIONAL_LIBRARIES) |g' -i ./Makefile
58 changes: 0 additions & 58 deletions cross/ntopng/patches/001-disable-rw_locks_support.patch

This file was deleted.

23 changes: 23 additions & 0 deletions cross/ntopng/patches/001-makefile.in_ignore_local_static_lua.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ignore static lua library within ntopng sources
# we use cross/lua instead
#
--- Makefile.in.orig 2020-11-02 21:27:19.000000000 +0000
+++ Makefile.in 2024-09-01 14:35:35.320735253 +0000
@@ -106,7 +106,7 @@

######
TARGET = ntopng
-NLIBS = $(NDPI_LIB) $(LIBPCAP) $(LUA_LIB) $(LIBRRDTOOL_LIB) $(ZEROMQ_LIB) $(JSON_LIB) $(SNMP_LIB) @MAXMINDDB_LIB@ $(SODIUM_LIB) @HIREDIS_LIB@ @SQLITE_LIB@ @MYSQL_LIB@ @RADCLI_LIB@ @EXPAT_LIB@ @SSL_LIB@ @LINK_OPTS@ @LDFLAGS@ @PRO_LIBS@ $(ZSTD_LIB) -lm -lpthread
+NLIBS = $(NDPI_LIB) $(LIBPCAP) $(LIBRRDTOOL_LIB) $(ZEROMQ_LIB) $(JSON_LIB) $(SNMP_LIB) @MAXMINDDB_LIB@ $(SODIUM_LIB) @HIREDIS_LIB@ @SQLITE_LIB@ @MYSQL_LIB@ @RADCLI_LIB@ @EXPAT_LIB@ @SSL_LIB@ @LINK_OPTS@ @LDFLAGS@ @PRO_LIBS@ $(ZSTD_LIB) -lm -lpthread
CPPFLAGS = @CFLAGS@ @HIREDIS_INC@ $(MONGOOSE_INC) $(JSON_INC) $(SNMP_INC) $(SODIUM_INC) $(NDPI_INC) $(LUA_INC) $(LIBRRDTOOL_INC) $(ZEROMQ_INC) @MYSQL_INC@ @CPPFLAGS@ -I$(HTTPCLIENT_INC) @SSL_INC@ @PRO_INCS@ -DDATA_DIR='"$(datadir)"' -I${PWD}/third-party/libgeohash -I${PWD}/third-party/patricia # -D_GLIBCXX_DEBUG
######
# ntopng-1.0_1234.x86_64.rpm
@@ -118,7 +118,7 @@
RPM_DATA_PKG = $(TARGET)-data-$(NTOPNG_VERSION)-@[email protected]
######

-LIB_TARGETS = $(LUA_LIB)
+LIB_TARGETS =

ifneq ($(HAS_ZEROMQ), 0)
LIB_TARGETS += $(ZEROMQ_LIB)
12 changes: 0 additions & 12 deletions cross/ntopng/patches/88f6281/001-define-atomic-not-cstatomic.patch

This file was deleted.

11 changes: 0 additions & 11 deletions cross/ntopng/patches/qoriq/001-add-atomic-lib.patch

This file was deleted.

14 changes: 0 additions & 14 deletions cross/ntopng/patches/x64/001-enable-rwlock-arch-x64.patch

This file was deleted.

43 changes: 26 additions & 17 deletions spk/ntopng/Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
SPK_NAME = ntopng
SPK_VERS = 4.2
SPK_REV = 3
SPK_ICON = src/$(SPK_NAME).png
SPK_REV = 4
SPK_ICON = src/ntopng.png

DEPENDS = cross/$(SPK_NAME)
DEPENDS = cross/ntopng

SPK_DEPENDS = "redis"

# toolchains of DSM <=5.2 have outdated compiler (PPC archs except qoriq)
UNSUPPORTED_ARCHS = $(OLD_PPC_ARCHS)
# cross/libcap not supported:
UNSUPPORTED_ARCHS = $(OLD_PPC_ARCHS) $(ARMv5_ARCHS)

MAINTAINER = hgy59
DESCRIPTION = ntopng is the next generation version of the original ntop, a network traffic probe that monitors network usage. ntopng is based on libpcap and it has been written in a portable way in order to virtually run on every Unix platform, MacOSX and on Windows as well.
CHANGELOG = "1. Update to version 4.2<br/>2. Update nDPI to version 3.4"
DESCRIPTION = High-Speed Web-based Traffic Analysis and Flow Collection. ntopng is a network traffic probe that provides 360° Network visibility, with its ability to gather traffic information from traffic mirrors, NetFlow exporters, SNMP devices, Firewall logs, Intrusion Detection systems. To run ntopng on DSM 7, the installed privileges file must be manually patched after installation or update.
CHANGELOG = "1. Update to version 4.2<br/>2. Update nDPI to version 3.4<br/>3. Add support for DSM 7."
DISPLAY_NAME = ntopng

HELPURL = https://www.ntop.org/guides/ntopng/index.html
LICENSE = GNU GPLv3
LICENSE = GPLv3

# 'auto' (reserved value) grabs SPK_NAME
SERVICE_USER = auto
SSS_SCRIPT = src/start-stop-status.sh
STARTABLE = yes
SERVICE_PORT = 3000
SERVICE_USER = auto
SSS_SCRIPT = src/start-stop-status.sh
STARTABLE = yes

SERVICE_PORT = 3000
SERVICE_PORT_TITLE = ntopng (HTTP)

# generate app/config and app/images/*.png
DSM_UI_DIR = app

# In case script start-stop-status has to run as root on DSM 6, package can
# provide its own conf/privilege file as far as CONF_DIR variable is set.
include ../../mk/spksrc.common.mk

ifeq ($(call version_lt, ${TCVERSION}, 7.0),1)
# On DSM 6: package runs as root
CONF_DIR = src/conf
else
# On DSM 7: package must be defined to run as package user to allow installation.
# Since ntopng must be run as root, the privilege file must be manually
# patched after installation (and after package update or package repair).
CONF_DIR = src/conf.dsm7
WIZARDS_DIR = src/wizard.dsm7/
endif

POST_STRIP_TARGET = ntopng_extra_install


include ../../mk/spksrc.spk.mk

.PHONY: ntopng_extra_install
ntopng_extra_install:
install -m 755 -d $(STAGING_DIR)/var/data
install -m 755 -d $(STAGING_DIR)/etc
install -m 644 src/ntopng.conf $(STAGING_DIR)/etc/ntopng.conf
install -m 644 src/ntopng.conf $(STAGING_DIR)/var/ntopng.conf
unzip -o src/GeoLite2.mmdb.zip -d $(STAGING_DIR)/share/ntopng/httpdocs/geoip/
6 changes: 6 additions & 0 deletions spk/ntopng/src/conf.dsm7/privilege
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"defaults":{
"run-as": "package"
},
"username": "sc-ntopng"
}
8 changes: 4 additions & 4 deletions spk/ntopng/src/ntopng.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
## initial configuration by spk installation
--user sc-ntopng
--daemon
--pid /usr/local/ntopng/var/ntopng.pid
--data-dir /usr/local/ntopng/var/data
--prefsdir /usr/local/ntopng/var/data
--pcapdir /usr/local/ntopng/var/data
--pid /var/packages/ntopng/var/ntopng.pid
--data-dir /var/packages/ntopng/var/data
--prefsdir /var/packages/ntopng/var/data
--pcapdir /var/packages/ntopng/var/data


## DNS address resolution mode
Expand Down
25 changes: 18 additions & 7 deletions spk/ntopng/src/start-stop-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@

# start/stop script derived from ntopng/packages/etc/init.d/ntopng

SERVICE_CFG_FILE="${SYNOPKG_PKGDEST}/etc/ntopng.conf"
if [ -z "${SYNOPKG_PKGNAME}" ] || [ -z "${SYNOPKG_DSM_VERSION_MAJOR}" ]; then
echo "Error: Environment variables are not set." 1>&2;
echo "Please run me using synopkg instead. Example: 'synopkg start ntopng'" 1>&2;
exit 1
fi

if [ "$SYNOPKG_DSM_VERSION_MAJOR" -lt 7 ]; then
# define SYNOPKG_PKGVAR for forward compatibility
SYNOPKG_PKGVAR="${SYNOPKG_PKGDEST}/var"
fi

SERVICE_CFG_FILE="${SYNOPKG_PKGVAR}/ntopng.conf"
SERVICE_COMMAND="${SYNOPKG_PKGDEST}/bin/ntopng ${SERVICE_CFG_FILE}"
SERVICE_LOG_FILE="${SYNOPKG_PKGDEST}/var/ntopng.log"
SERVICE_LOG_FILE="${SYNOPKG_PKGVAR}/ntopng.log"

ERROR=0

Expand Down Expand Up @@ -161,24 +172,24 @@ status_ntopng() {
########

case "$1" in
start)
start)
start_ntopng;
;;

stop)
stop)
stop_ntopng;
;;

status)
status)
status_ntopng;
;;

restart)
restart)
stop_ntopng;
start_ntopng;
;;

*)
*)
echo "Usage: ${0} {start|stop|restart|status}]"
exit 1
esac
Expand Down
Loading

0 comments on commit a4274e1

Please sign in to comment.