ZNC: Fix webadmin, allow external config and minor fixes
authorjogo <jogo@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Tue, 19 Apr 2011 15:11:02 +0000 (15:11 +0000)
committerjogo <jogo@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Tue, 19 Apr 2011 15:11:02 +0000 (15:11 +0000)
 * Fix the webadmin module and add the themes

 * Allow providing ZNC an external config (closes #9110)

 * Allow specifying the user and group to run ZNC as (needs su when using
   external config)

 * Allow providing a certificate for incoming SSL connections

 * Reduce buildtime by not rebuilding everything everytime

Signed-off-by: Jonas Gorski <jonas.gorski+openwrt@gmail.com>
git-svn-id: svn://svn.openwrt.org/openwrt/packages@26722 3c298f89-4303-0410-b956-a3cf2f4a3e73

net/znc/Makefile
net/znc/files/znc.conf
net/znc/files/znc.init
net/znc/patches/003-Reduce_rebuild_time.patch [new file with mode: 0644]

index 45d2000..1de6243 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=znc
 PKG_VERSION:=0.098
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://znc.in/releases
@@ -73,12 +73,58 @@ define module
   define Package/znc-mod-$(strip $(1))/install
        $(INSTALL_DIR) $$(1)/usr/lib/znc/
        $(INSTALL_BIN) $$(PKG_BUILD_DIR)/modules/$(strip $(3))$(subst -,_,$(strip $(1))).so $$(1)/usr/lib/znc/
+       # include webadmin page templates if existing
+       if [ -d $$(PKG_BUILD_DIR)/modules/$(strip $(3))$(subst -,_,$(strip $(1))) ]; then \
+               $(INSTALL_DIR) $$(1)/usr/share/znc/ ;\
+               $(CP) -r $$(PKG_BUILD_DIR)/modules/$(strip $(3))$(subst -,_,$(strip $(1))) $$(1)/usr/share/znc/ ;\
+       fi
   endef
 
   ZNC_MODULES += znc-mod-$(strip $(1))
   $(if $(CONFIG_PACKAGE_znc-mod-$(strip $(1))),ZNC_MODULE_TARGETS += $(strip $(3))$(subst -,_,$(strip $(1))).so)
 endef
 
+define webadmin
+  define Package/znc-mod-webadmin
+    $(Package/znc/default)
+    TITLE+= (webadmin plugin)
+    DEPENDS:=znc
+  endef
+
+  define Package/znc-mod-webadmin/description
+   Allows you to add/remove/edit users and settings on the fly via a web browser.
+  endef
+
+  define Package/znc-mod-webadmin/install
+       $(INSTALL_DIR) $$(1)/usr/lib/znc/
+       $(INSTALL_BIN) $$(PKG_BUILD_DIR)/modules/webadmin.so $$(1)/usr/lib/znc/
+       $(INSTALL_DIR) $$(1)/usr/share/znc/
+       $(CP) -r $$(PKG_BUILD_DIR)/modules/webadmin $$(1)/usr/share/znc/
+       $(INSTALL_DIR) $$(1)/usr/share/znc/webskins/
+       $(CP) -r $$(PKG_BUILD_DIR)/webskins/_default_ $$(1)/usr/share/znc/webskins/
+  endef
+
+  ZNC_MODULES += znc-mod-webadmin
+  $(if $(CONFIG_PACKAGE_znc-mod-webadmin),ZNC_MODULE_TARGETS += webadmin.so)
+endef
+
+define webskin
+  define Package/znc-webskin-$(strip $(1))
+    $(Package/znc/default)
+    TITLE+= ($(strip $(1)) webskin)
+    DEPENDS:=znc-mod-webadmin
+  endef
+
+  define Package/znc-webskin-$(strip $(1))/description
+    $(strip $(1)) webskin for webadmin
+  endef
+
+  define Package/znc-webskin-$(strip $(1))/install
+       $(INSTALL_DIR) $$(1)/usr/share/znc/webskins/
+       $(CP) -r $$(PKG_BUILD_DIR)/webskins/$(strip $(1)) $$(1)/usr/share/znc/webskins/
+  endef
+  ZNC_MODULES += znc-webskin-$(strip $(1))
+endef
 
 , := ,
 
@@ -164,9 +210,6 @@ $(eval $(call module,stickychan,Keeps you sticked to specific channels.))
 $(eval $(call module,watch,Monitor activity for specific text patterns from \
        specific users and have the text sent to a special query window.))
 
-$(eval $(call module,webadmin,Allows you to add/remove/edit users and settings \
-       on the fly via a web browser.))
-
 $(eval $(call module,antiidle,Hides your idle time.,extra/))
 
 $(eval $(call module,autovoice,Autovoices everyone who joins some channel., \
@@ -203,6 +246,11 @@ $(eval $(call module,send-raw,Allows you to send raw traffic to IRC from \
 $(eval $(call module,shell,Have your unix shell in a query window right inside \
        of your IRC client.,extra/))
 
+$(eval $(call webadmin))
+
+$(eval $(call webskin,dark-clouds))
+$(eval $(call webskin,forest))
+$(eval $(call webskin,ice))
 
 PKG_CONFIG_DEPENDS := $(patsubst %,CONFIG_PACKAGE_%,$(ZNC_MODULES))
 
index f7eceb1..b281f44 100644 (file)
@@ -1,6 +1,9 @@
 config znc
        # where to listen for connections
        list listener   '192.168.1.1 1234'
+       # If using SSL sockets, use the following certifcate:
+       # option znc_ssl_cert '/etc/znc.cert'
+
        # load global modules (You need to install them first):
        # list module 'fail2ban'
 
index 856b646..be2f3f5 100644 (file)
@@ -3,8 +3,14 @@
 
 START=60
 
-PID_FILE=/tmp/etc/znc/znc.pid
-ZNC_CONFIG=/tmp/etc/znc/configs/znc.conf
+ZNC_CONFIG_PATH=/tmp/etc/znc
+PID_FILE=${ZNC_CONFIG_PATH}/znc.pid
+ZNC_CONFIG=${ZNC_CONFIG_PATH}/configs/znc.conf
+
+EXTERNAL_CONFIG=0
+
+RUNAS_USER=
+RUNAS_GROUP=
 
 add_param() {
        echo "$1 = $2" >> $ZNC_CONFIG
@@ -24,24 +30,42 @@ znc_global() {
        local maxbuffersize
        local connectdelay
        local serverthrottle
+       local znc_config_path
+       local znc_pem_file
+
+       config_get znc_config_path "$znc" znc_config_path
+
+       config_get RUNAS_USER "$znc" runas_user
+       config_get RUNAS_GROUP "$znc" runas_group
+
+       if [ "${znc_config_path}" ]
+       then
+               ZNC_CONFIG_PATH=$znc_config_path
+               EXTERNAL_CONFIG=1
+       else
+               mkdir -p $ZNC_CONFIG_PATH/configs/
+               [ ! -f "$ZNC_CONFIG" ] || rm "$ZNC_CONFIG"
 
+               config_get anoniplimit "$znc" anoniplimit
+               config_get maxbuffersize "$znc" maxbuffersize
+               config_get connectdelay "$znc" connectdelay
+               config_get serverthrottle "$znc" serverthrottle
+               config_get znc_pem_file "$znc" znc_ssl_cert
 
-       config_get anoniplimit "$znc" anoniplimit
-       config_get maxbuffersize "$znc" maxbuffersize
-       config_get connectdelay "$znc" connectdelay
-       config_get serverthrottle "$znc" serverthrottle
+               [ -z $znc_pem_file -o -f $ZNC_CONFIG_PATH/znc.pem ] || ln -s "$znc_pem_file" $ZNC_CONFIG_PATH/znc.pem
 
-       [ -z $anoniplimit ] || echo "AnonIPLimit = $anoniplimit" >> $ZNC_CONFIG
-       [ -z $maxbuffersize ] || echo "MaxBufferSize = $maxbuffersize" >> $ZNC_CONFIG
-       [ -z $connectdelay ] || echo "ConnectDelay = $connectdelay" >> $ZNC_CONFIG
-       [ -z $serverthrottle ] || echo "ServerThrottle = $anoniplimit" >> $ZNC_CONFIG
+               [ -z $anoniplimit ] || echo "AnonIPLimit = $anoniplimit" >> $ZNC_CONFIG
+               [ -z $maxbuffersize ] || echo "MaxBufferSize = $maxbuffersize" >> $ZNC_CONFIG
+               [ -z $connectdelay ] || echo "ConnectDelay = $connectdelay" >> $ZNC_CONFIG
+               [ -z $serverthrottle ] || echo "ServerThrottle = $anoniplimit" >> $ZNC_CONFIG
 
-       echo "PidFile = $PID_FILE" >> $ZNC_CONFIG
+               echo "PidFile = $PID_FILE" >> $ZNC_CONFIG
 
-       config_list_foreach "$znc" listener "add_param Listener"
-       config_list_foreach "$znc" module "add_param LoadModule"
+               config_list_foreach "$znc" listener "add_param Listener"
+               config_list_foreach "$znc" module "add_param LoadModule"
 
-       add_param LoadModule "droproot nobody nogroup"
+               add_param LoadModule "droproot ${RUNAS_USER:-nobody} ${RUNAS_GROUP:-nogroup}"
+       fi
 }
 
 add_user() {
@@ -95,18 +119,38 @@ add_user() {
 
 
 start() {
-       mkdir -p /tmp/etc/znc/configs/
-       [ -f "$ZNC_CONFIG" ] && rm "$ZNC_CONFIG"
        config_load znc
        config_foreach znc_global znc
-       config_foreach add_listener listener
-       config_foreach add_user user
 
-       chown -R nobody:nogroup /tmp/etc/znc
-       /usr/bin/znc -d/tmp/etc/znc -r >/dev/null &
+       if [ "$EXTERNAL_CONFIG" -eq 0 ]
+       then
+               config_foreach add_listener listener
+               config_foreach add_user user
+
+               chown -R ${RUNAS_USER:-nobody}:${RUNAS_GROUP:-nogroup} /tmp/etc/znc
+       fi
+
+       if [ "$EXTERNAL_CONFIG" -eq 1 -a "$RUNAS_USER"  ]
+       then
+               local SU=$(which su)
+               if [ "$SU" ]
+               then
+                       $SU -c "/usr/bin/znc -d$ZNC_CONFIG_PATH >/dev/null &" $RUNAS_USER
+               else
+                       logger -s -t ZNC -p daemon.err "Could not run ZNC as user $RUNAS_USER: su not found."
+                       exit 1
+               fi
+       else
+               /usr/bin/znc -d$ZNC_CONFIG_PATH >/dev/null &
+       fi
 }
 
 stop() {
-       [ -f "$PID_FILE" ] && kill $(cat "$PID_FILE")
+       if [ -f "$PID_FILE" ]
+       then
+               kill $(cat "$PID_FILE")
+       else
+               killall znc
+       fi
 }
 
diff --git a/net/znc/patches/003-Reduce_rebuild_time.patch b/net/znc/patches/003-Reduce_rebuild_time.patch
new file mode 100644 (file)
index 0000000..0f48c65
--- /dev/null
@@ -0,0 +1,32 @@
+From 94aff4c3389111fc85054eb06b40bea26a216d0c Mon Sep 17 00:00:00 2001
+From: Jonas Gorski <jonas.gorski+openwrt@gmail.com>
+Date: Sat, 16 Apr 2011 05:51:04 +0200
+Subject: [PATCH] Don't rebuild everything when the Makefile's timestamp changed
+
+---
+ Makefile.in         |    2 +-
+ modules/Makefile.in |    2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+--- a/Makefile.in
++++ b/Makefile.in
+@@ -96,7 +96,7 @@ clean:
+ distclean: clean
+       rm -rf $(DISTCLEAN)
+-%.o: %.cpp Makefile
++%.o: %.cpp
+       @mkdir -p .depend
+       $(E) Building $@...
+       $(Q)$(CXX) $(CXXFLAGS) -c -o $@ $< -MMD -MF .depend/$@.dep
+--- a/modules/Makefile.in
++++ b/modules/Makefile.in
+@@ -114,7 +114,7 @@ install_metadirs: create_install_dir
+ clean:
+       rm -rf $(CLEAN)
+-%.so: %.cpp Makefile
++%.so: %.cpp
+       @mkdir -p .depend
+       @mkdir -p extra
+       $(E) Building $(if $(filter %extra/,$(dir $<)),extra )module $(notdir $(basename $@))...