From 0d0c37f3d40f31e7a8fd58b6829b6c239316d961 Mon Sep 17 00:00:00 2001 From: Matthias Strubel Date: Sun, 11 Aug 2013 17:09:03 +0200 Subject: [PATCH 1/3] Generating lease-file location based on config file. Place it on OpenWRT into /tmp => memory Conflicts: CHANGELOG --- CHANGELOG | 2 ++ Makefile | 1 + piratebox/piratebox/bin/generate_config_files.sh | 2 +- piratebox/piratebox/conf/piratebox.conf | 4 ++++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index ac5801c..b58de39 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,8 @@ NOTE: This may only be a partial changelog, check github / your package manager * [Removed] [Testing] Executable, we will stick to service based * [Fixed] Overwritten saved timestamp with 1970 one * [New] possibility in install_piratebox.sh to exchange the hostname easily +* [Fixed] Hide dot files in directory-listing which are usually hidden files +* [New] Moved DHCP leasefile into memory on OpenWRT system (/tmp is memory) === v0.6G === * [Fixed] Hide dot files in directory-listing which are usually hidden files diff --git a/Makefile b/Makefile index 09c9628..c2c043b 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,7 @@ $(OPENWRT_CONFIG_FOLDER): sed 's:DNSMASQ_INTERFACE="wlan0":DNSMASQ_INTERFACE="br-lan":' -i $@/piratebox.conf sed 's:192.168.77:192.168.1:g' -i $@/piratebox.conf sed 's:DROOPY_USE_USER="yes":DROOPY_USE_USER="no":' -i $@/piratebox.conf + sed 's:LEASE_FILE_LOCATION=$PIRATEBOX_FOLDER/tmp/lease.file:LEASE_FILE_LOCATION=/tmp/lease.file:' -i $@/piratebox.conf $(TGZ_IMAGE_FILE): tar czf $(TGZ_IMAGE_FILE) $(SRC_IMAGE_UNPACKED) diff --git a/piratebox/piratebox/bin/generate_config_files.sh b/piratebox/piratebox/bin/generate_config_files.sh index 94ac288..52e4aa9 100755 --- a/piratebox/piratebox/bin/generate_config_files.sh +++ b/piratebox/piratebox/bin/generate_config_files.sh @@ -45,7 +45,7 @@ set_pathnames() { DEFAULT_HOSTS=$CONFIG_PATH/hosts DEFAULT_DNSMASQ=$CONFIG_PATH/dnsmasq_default.conf RADVD_CONFIG=$CONFIG_PATH/radvd_generated.conf - LEASE_FILE=$1/tmp/leases + LEASE_FILE=$LEASE_FILE_LOCATION LIGHTTPD_ENV_CONFIG=$CONFIG_PATH/lighttpd/env } diff --git a/piratebox/piratebox/conf/piratebox.conf b/piratebox/piratebox/conf/piratebox.conf index 97d6bf5..9ad9a5d 100644 --- a/piratebox/piratebox/conf/piratebox.conf +++ b/piratebox/piratebox/conf/piratebox.conf @@ -97,6 +97,10 @@ END_LEASE=250 #Leasetime (When should the client renew it's IP) LEASE_DURATION=12h +# Where is the leasefile stored to? +LEASE_FILE_LOCATION=$PIRATEBOX_FOLDER/tmp/lease.file + + # Define the netmask NETMASK=255.255.255.0 From 057aacea2c405b00e4173559b57350792e487fbf Mon Sep 17 00:00:00 2001 From: Matthias Strubel Date: Sun, 11 Aug 2013 16:55:43 +0200 Subject: [PATCH 2/3] Fix for droopy on OpenWRT #49 --- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c2c043b..e7804e8 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ SRC_IMAGE_UNPACKED=image_stuff/piratebox_img MOUNT_POINT=image_stuff/image OPENWRT_FOLDER=image_stuff/openwrt OPENWRT_CONFIG_FOLDER=$(OPENWRT_FOLDER)/conf - +OPENWRT_BIN_FOLDER=$(OPENWRT_FOLDER)/bin .DEFAULT_GOAL = package @@ -26,7 +26,7 @@ $(PACKAGE): $(VERSION) tar czf $@ $(PB_FOLDER) -$(IMAGE_FILE): $(VERSION) $(SRC_IMAGE_UNPACKED) $(OPENWRT_CONFIG_FOLDER) +$(IMAGE_FILE): $(VERSION) $(SRC_IMAGE_UNPACKED) $(OPENWRT_CONFIG_FOLDER) $(OPENWRT_BIN_FOLDER) mkdir -p $(MOUNT_POINT) echo "#### Mounting image-file" sudo mount -o loop,rw,sync $(SRC_IMAGE_UNPACKED) $(MOUNT_POINT) @@ -50,6 +50,11 @@ $(OPENWRT_CONFIG_FOLDER): sed 's:DROOPY_USE_USER="yes":DROOPY_USE_USER="no":' -i $@/piratebox.conf sed 's:LEASE_FILE_LOCATION=$PIRATEBOX_FOLDER/tmp/lease.file:LEASE_FILE_LOCATION=/tmp/lease.file:' -i $@/piratebox.conf +$(OPENWRT_BIN_FOLDER): + mkdir -p $@ + cp -v $(PB_SRC_FOLDER)/bin/droopy $@ + sed "s:libc.so.6:libc.so.0:" -i $@/droopy + $(TGZ_IMAGE_FILE): tar czf $(TGZ_IMAGE_FILE) $(SRC_IMAGE_UNPACKED) From c5ae25d7b1d4fa13feba1dc425d0f5dcf26a5090 Mon Sep 17 00:00:00 2001 From: Matthias Strubel Date: Sun, 11 Aug 2013 16:22:06 +0200 Subject: [PATCH 3/3] removal of service Conflicts: CHANGELOG --- CHANGELOG | 1 - piratebox/piratebox/bin/piratebox.sh | 406 ------------------- piratebox/piratebox/init.d/piratebox.service | 12 - 3 files changed, 419 deletions(-) delete mode 100755 piratebox/piratebox/bin/piratebox.sh delete mode 100755 piratebox/piratebox/init.d/piratebox.service diff --git a/CHANGELOG b/CHANGELOG index b58de39..9a76b69 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,7 +7,6 @@ NOTE: This may only be a partial changelog, check github / your package manager * [New] push of systemd structure * [New] install method * [New] install dependencies - * [New] can now use restart in init * [Fixed] General cleaning * [Removed] [Testing] Executable, we will stick to service based * [Fixed] Overwritten saved timestamp with 1970 one diff --git a/piratebox/piratebox/bin/piratebox.sh b/piratebox/piratebox/bin/piratebox.sh deleted file mode 100755 index 5cb4caf..0000000 --- a/piratebox/piratebox/bin/piratebox.sh +++ /dev/null @@ -1,406 +0,0 @@ -#!/bin/bash - -#=============================================================================== -# -# FILE: piratebox.sh -# -# USAGE: systemctl piratebox start -# -# DESCRIPTION: systemd file that piratebox.service points to. The systemd -#+ alternative to init.d -# -# OPTIONS: start stop restart -# REQUIREMENTS: --- -# BUGS: --- -# NOTES: --- -# AUTHOR: Cale 'TerrorByte' Black (cablack@rams.colostate.edu) -# ORGANIZATION: -# CREATED: 02/02/2013 07:37:35 PM MST -# REVISION: 0.2.0 -#=============================================================================== - -#TODO Make ExecStop in service file kill dnsmasq, lighttpd, hostapd, droopy -#TODO Fully modular with new systemd standards -#TODO Add lock -set -o nounset # Treat unset variables as an error - -# PATH for /opt piratebox folder -PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/:/usr/local/sbin:/opt/piratebox/bin - -PIDFILE_DROOPY=/var/run/piratebox_droopy.pid -PIDFILE_HOSTAPN=/var/run/piratebox_hostapn.pid -PIDFILE_DNSMASQ=/var/run/piratebox_dnsmasq.pid -PIDFILE_LIGHTTPD=/opt/piratebox/tmp/lighttpd.pid -PIDFILE_SHOUTBOX=/opt/piratebox/tmp/shoutbox_daemon.pid - -PIRATEBOX=/opt/piratebox -CONF=$PIRATEBOX/conf/piratebox.conf -#CONF_DROOPY=/opt/piratebox/conf/droopy.conf #not used -CONF_APN=$PIRATEBOX/conf/hostapd.conf - -#Some extra config files for dnsmasq -CONF_DNSMASQ=$PIRATEBOX/conf/dnsmasq_generated.conf - -CONF_LIGHTTPD=$PIRATEBOX/conf/lighttpd/lighttpd.conf - -export PYTHONPATH=:$PYTHONPATH:$PIRATEBOX_PYTHONPATH - -#Check for config file -if [ -f $CONF ] ; then - . $CONF -else - log_failure_msg "Configuration file not found" - exit 1 -fi - -# Do basic initialization on non-openWRT Systems, too -if [ -f $PIRATEBOX/conf/init_done ] ; then - INIT=OK -else - $PIRATEBOX/bin/hooks/hook_pre_init.sh "$CONF" - $PIRATEBOX/bin/install_piratebox.sh "$CONF" part2 - $PIRATEBOX/bin/hooks/hook_post_init.sh "$CONF" - touch $PIRATEBOX/conf/init_done -fi - -# Command Line for DNSMASQ, use extra config file generated from command above -CMD_DNSMASQ="-x $PIDFILE_DNSMASQ -C $CONF_DNSMASQ " - -# Carry out specific functions when asked to by the system -case "$1" in - start) - echo "Starting script piratebox " - echo "" - - # Generate hosts & dnsmasq file - $PIRATEBOX/bin/generate_config_files.sh "$CONF" - $PIRATEBOX/bin/hooks/hook_piratebox_start.sh "$CONF" - - echo "Empty tmp folder" - find $PIRATEBOX/tmp/ -exec rm {} \; - - if [ "$DO_IW" = "yes" ] ; then - echo " Setting up Interface (iw) " - iw $PHY_IF interface add $INTERFACE type managed - fi - - if [ "$DO_IFCONFIG" = yes ] ; then - echo "Setting up wlan" - #Setting up WLAN Interface - #TODO Why not place the few lines from piratebox_setup_wlan.sh in here? - piratebox_setup_wlan.sh $CONF start - fi - if [ $? -ne 0 ] ; then - echo "Failed setting up Interface" - else - - # Only activate - if [ "$USE_APN" = "yes" ] ; then - echo "Starting hostap... " - /usr/sbin/hostapd -- $CONF_APN & #TODO Possible to change PIDFILE of hostapd? - if [ $? -ne 0 ]; then - echo $? - fi - fi - - #BRIDGE - if [ "$DO_BRIDGE" = "yes" ] ; then - echo "Adding $INTERFACE to bridge $BRIDGE // brctl addif $BRIDGE $INTERFACE " - sleep 1 - BR_CMD="brctl addif $BRIDGE $INTERFACE" - ( $BR_CMD ; ) - if [ $? -ne 0 ]; then - echo $? - fi - fi - - if [ "$USE_DNSMASQ" = "yes" ] ; then - echo "Starting dnsmasq... " - # pidfile is written by dnsmasq - /usr/sbin/dnsmasq -- $CMD_DNSMASQ - if [ $? -ne 0 ]; then - echo $? - fi - fi - - - if [ "$DROOPY_ENABLED" = "yes" ] ; then - #Start here the PirateBox-Parts droopy i.e. - #TODO More elegant way of doing this with: find -name 'file*' -size 0 -delete - #Delete 0 Byte Files - delete_empty.sh $UPLOADFOLDER - find $UPLOADFOLDER/ -iname tmp\* -exec rm {} \; - - DROOPY_USER="" - if [ "$DROOPY_USE_USER" = "yes" ] ; then - DROOPY_USER=" -c $LIGHTTPD_USER:$LIGHTTPD_GROUP " - fi - echo "Starting droopy..." - $PIRATEBOX/bin/droopy -- -H $HOST -d $UPLOADFOLDER -c "" -m "$DROOPY_TXT" $DROOPY_USERDIR $DROOPY_PORT - echo $? - fi - - #Do shoutbox stuff - $PIRATEBOX/bin/shoutbox_stuff.sh $WWW_FOLDER $CONF - - - #Start here the lighttpd i.e. - echo "Starting lighttpd..." - /usr/sbin/lighttpd -- -f $CONF_LIGHTTPD - if [ $? -ne 0 ]; then - echo $? - fi - - #Start Global Chat daemon if needed. - if [ "$GLOBAL_CHAT" = "yes" ] ; then - echo "Starting global chat service..." - $PIRATEBOX/bin/shoutbox_daemon.sh -- $CONF - if [ $? -ne 0 ]; then - echo $? - fi - fi -fi - -$PIRATEBOX/bin/hooks/hook_piratebox_start_done.sh "$CONF" - -;; - -stop) - echo "Stopping script piratebox" - echo "" - - $PIRATEBOX/bin/hooks/hook_piratebox_stop.sh "$CONF" - - if [ "$USE_APN" = "yes" ] ; then - echo "Stopping hostapd... " - systemctl stop hostapd - if [ $? -ne 0 ]; then - echo $? - fi - fi - - if [ "$USE_DNSMASQ" = "yes" ] ; then - echo "Stopping dnsmasq..." - systemctl stop dnsmasq - if [ $? -ne 0 ]; then - echo $? - fi - fi - - #Stop Global Chat daemon - if [ "$GLOBAL_CHAT" = "yes" ] ; then - echo "Stopping global chat service..." - kill $PIDFILE_SHOUTBOX #TODO better way? - if [ $? -ne 0 ]; then - echo $? - fi - fi - - echo "Stopping lighttpd..." - systemctl stop lighttpd - if [ $? -ne 0 ]; then - echo $? - fi - - if [ "$DROOPY_ENABLED" = "yes" ] ; then - #Kill Droopy - echo "Stopping droopy... " - pkill -9 -f python /opt/piratebox/bin/droopy - if [ $? -ne 0 ]; then - echo $? - fi - fi - - if [ "$DO_IFCONFIG" = yes ] ; then - piratebox_setup_wlan.sh $CONF stop - fi - - if [ "$DO_IW" = "yes" ] ; then - iw dev $INTERFACE del - fi - - # REMOVE BRIDGE - if [ "$DO_BRIDGE" = "yes" ] ; then - echo "Remove Bridge..." - BR_CMD="brctl delif $BRIDGE $INTERFACE" - ( $BR_CMD ; ) - if [ $? -ne 0 ]; then - echo $? - fi - fi - -$PIRATEBOX/bin/hooks/hook_piratebox_stop_done.sh "$CONF" - - -;; - -restart) - echo "Stopping script piratebox" - echo "" - - $PIRATEBOX/bin/hooks/hook_piratebox_stop.sh "$CONF" - - if [ "$USE_APN" = "yes" ] ; then - echo "Stopping hostapd... " - systemctl stop hostapd - if [ $? -ne 0 ]; then - echo $? - fi - fi - - if [ "$USE_DNSMASQ" = "yes" ] ; then - echo "Stopping dnsmasq..." - systemctl stop dnsmasq - if [ $? -ne 0 ]; then - echo $? - fi - fi - - #Stop Global Chat daemon - if [ "$GLOBAL_CHAT" = "yes" ] ; then - echo "Stopping global chat service..." - kill $PIDFILE_SHOUTBOX #TODO better way? - if [ $? -ne 0 ]; then - echo $? - fi - fi - - echo "Stopping lighttpd..." - systemctl stop lighttpd - if [ $? -ne 0 ]; then - echo $? - fi - - if [ "$DROOPY_ENABLED" = "yes" ] ; then - #Kill Droopy - echo "Stopping droopy... " - pkill -9 -f python /opt/piratebox/bin/droopy - if [ $? -ne 0 ]; then - echo $? - fi - fi - - if [ "$DO_IFCONFIG" = yes ] ; then - piratebox_setup_wlan.sh $CONF stop - fi - - if [ "$DO_IW" = "yes" ] ; then - iw dev $INTERFACE del - fi - - # REMOVE BRIDGE - if [ "$DO_BRIDGE" = "yes" ] ; then - echo "Remove Bridge..." - BR_CMD="brctl delif $BRIDGE $INTERFACE" - ( $BR_CMD ; ) - if [ $? -ne 0 ]; then - echo $? - fi - fi - -$PIRATEBOX/bin/hooks/hook_piratebox_stop_done.sh "$CONF" - -### Now start ### - -echo "Starting script piratebox " - echo "" - - # Generate hosts & dnsmasq file - $PIRATEBOX/bin/generate_config_files.sh "$CONF" - $PIRATEBOX/bin/hooks/hook_piratebox_start.sh "$CONF" - - echo "Empty tmp folder" - find $PIRATEBOX/tmp/ -exec rm {} \; - - if [ "$DO_IW" = "yes" ] ; then - echo " Setting up Interface (iw) " - iw $PHY_IF interface add $INTERFACE type managed - fi - - if [ "$DO_IFCONFIG" = yes ] ; then - echo "Setting up wlan" - #Setting up WLAN Interface - #TODO Why not place the few lines from piratebox_setup_wlan.sh in here? - piratebox_setup_wlan.sh $CONF start - fi - if [ $? -ne 0 ] ; then - echo "Failed setting up Interface" - else - - # Only activate - if [ "$USE_APN" = "yes" ] ; then - echo "Starting hostap... " - /usr/sbin/hostapd -- $CONF_APN & #TODO Possible to change PIDFILE of hostapd? - if [ $? -ne 0 ]; then - echo $? - fi - fi - - #BRIDGE - if [ "$DO_BRIDGE" = "yes" ] ; then - echo "Adding $INTERFACE to bridge $BRIDGE // brctl addif $BRIDGE $INTERFACE " - sleep 1 - BR_CMD="brctl addif $BRIDGE $INTERFACE" - ( $BR_CMD ; ) - if [ $? -ne 0 ]; then - echo $? - fi - fi - - if [ "$USE_DNSMASQ" = "yes" ] ; then - echo "Starting dnsmasq... " - # pidfile is written by dnsmasq - /usr/sbin/dnsmasq -- $CMD_DNSMASQ - if [ $? -ne 0 ]; then - echo $? - fi - fi - - - if [ "$DROOPY_ENABLED" = "yes" ] ; then - #Start here the PirateBox-Parts droopy i.e. - #TODO More elegant way of doing this with: find -name 'file*' -size 0 -delete - #Delete 0 Byte Files - delete_empty.sh $UPLOADFOLDER - find $UPLOADFOLDER/ -iname tmp\* -exec rm {} \; - - DROOPY_USER="" - if [ "$DROOPY_USE_USER" = "yes" ] ; then - DROOPY_USER=" -c $LIGHTTPD_USER:$LIGHTTPD_GROUP " - fi - echo "Starting droopy..." - $PIRATEBOX/bin/droopy -- -H $HOST -d $UPLOADFOLDER -c "" -m "$DROOPY_TXT" $DROOPY_USERDIR $DROOPY_PORT - if [ $? -ne 0 ]; then - echo $? - fi - fi - - #Do shoutbox stuff - $PIRATEBOX/bin/shoutbox_stuff.sh $WWW_FOLDER $CONF - - - #Start here the lighttpd i.e. - echo "Starting lighttpd..." - /usr/sbin/lighttpd -- -f $CONF_LIGHTTPD - if [ $? -ne 0 ]; then - echo $? - fi - - #Start Global Chat daemon if needed. - if [ "$GLOBAL_CHAT" = "yes" ] ; then - echo "Starting global chat service..." - $PIRATEBOX/bin/shoutbox_daemon.sh -- $CONF - if [ $? -ne 0 ]; then - echo $? - fi - fi -fi - -$PIRATEBOX/bin/hooks/hook_piratebox_start_done.sh "$CONF" - -;; -*) - echo "Usage: /etc/init.d/piratebox {start|stop|restart}" - exit 1 - ;; -esac -exit 0 diff --git a/piratebox/piratebox/init.d/piratebox.service b/piratebox/piratebox/init.d/piratebox.service deleted file mode 100755 index b3accff..0000000 --- a/piratebox/piratebox/init.d/piratebox.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=PirateBox Service - -[Service] -Type=forking -ExecStart=/opt/piratebox/bin/piratebox.sh start -ExecStop=/opt/piratebox/bin/piratebox.sh stop -Restart=/opt/piratebox/bin/piratebox.sh restart -PIDFile=/var/run/piratebox.pid - -[Install] -WantedBy=multi-user.target