first bulk of overwork before testing

This commit is contained in:
Matthias Strubel 2015-02-12 13:22:34 +01:00
parent 761e0bf54a
commit 333158912b
23 changed files with 433 additions and 169 deletions

View file

@ -0,0 +1,37 @@
#!/bin/sh
PIRATEBOX_FOLDER=${PIRATEBOX_FOLDER:=/opt/piratebox}
PIRATEBOX_CONF="${PIRATEBOX_FOLDER}/conf/piratebox.conf"
. "${PIRATEBOX_CONF}"
. "${PIRATEBOX_FOLDER}/lib/module_maintain.sh"
DEBUG=${DEBUG:=false}
export cfg_modules=${MODULE_ENABLED}
export cfg_modules_lib=${MODULE_AVAILABLE}
case "$1" in
start)
_run_ "start"
;;
stop)
_run_ "stop"
;;
enable)
_enable_ "$2"
;;
disable)
_disable_ "$2"
;;
# module)
# ;;
*)
echo "Usage: piratebox_modules.sh {start|stop}"
echo " piratebox_modules.sh enable module"
echo " piratebox_modules.sh disable module"
exit 1
;;
esac
exit 0

View file

@ -1,9 +0,0 @@
#!/bin/sh
###
# This file contains some valid informations for the content
##
CHAT_MODULE_FILE="modules/chat.html"
UPLOAD_MODULE_FILE="modules/upload.html"

View file

@ -0,0 +1,6 @@
#HOSTNAME ... if you really want to change it, plz change:
# www/index.html
#
# That is the Domain-Specifi part, where you reach always the local box
HOST="piratebox.lan"

View file

@ -0,0 +1,10 @@
#TODO
#Generate config json for frontend
PBX_JSON_GENERATION="yes"
PBX_JSON_FILE="$WWW_FOLDER/piratebox_config.json"
CHAT_MODULE_FILE="modules/chat.html"
UPLOAD_MODULE_FILE="modules/upload.html"

View file

@ -0,0 +1,7 @@
DO_CLEANUP="yes"
# things like
# - remove 0Byte files
# - remove tmp* files
CLEANUP_FOLDER="$UPLOADFOLDER"

View file

@ -0,0 +1,4 @@
#Provide files needed for PirateBox custom dirlisting
CUSTOM_DIRLIST_COPY="yes"

View file

@ -0,0 +1,8 @@
### TODO - Create a new Bridge netowrk
#DO_CREATE_BRIDGE
#BRIDGE_NAME="br0"
##Include the following interface, which are already active on the box
## does not include the AP network...
## example
##BRIDGE_INTERFACES="eth0"
#BRIDGE_INTERFACES=""

View file

@ -0,0 +1,27 @@
### Shoutbox is enabled.
# When you set this option to "no", then the shoutbox file is not writable anymore
# and in the json file the module is disabled. You should adjust the chat_init.txt
# to make clear, that the box is not working anymore.
SHOUTBOX_ENABLED="yes"
#Configuration for chat (If you decide to move the chat folder, you have to change
/opt/piratebox/chat/cgi-bin/py* files )
CHATFILE="$WWW_FOLDER/cgi-bin/data.pso"
#Generated File
GEN_CHATFILE="$WWW_FOLDER/chat_content.html"
# Reset Shoutbox on Startup?
RESET_CHAT="yes"
#Inititiation Chat-Message
### This option was removed, you can find the chat message in conf/chat_init.txt
#Activate Global chat
# Still experimentall!
GLOBAL_CHAT="no"
#On which broadcast address should it send
# Take care on the syntax!!
GLOBAL_DEST="[ #255.255.255.255# , #10.255.255.255# , #$NET.255# ]"

View file

@ -0,0 +1,19 @@
#Do IW config - setting up a wlan0 interface with iw
# for some wifi-cards required
DO_IW="no"
#Iw physical interface
PHY_IF="phy0"
HOSTAPD_INTERFACE="wlan0"
# Check if interface exists
# should be set to yes if you use a USB wifi card
PROBE_INTERFACE="no"
# wait how many seconds until throw an error
PROBE_TIME=10
#Start services...
# act like a apn / <yes|no>
# please have a look @ hostapd.conf ; you may need to change some options, regarding wifi-card
USE_APN="yes"

View file

@ -0,0 +1,19 @@
#Do network config
DO_IFCONFIG="yes"
# Name of the wlan interface
IFCONFIG_INTERFACE="wlan0"
#Network
NET=192.168.77
#IP-SHORT (is stringed together)
# Which IP is your Box?? i.e. 1 => 192.168.77.1
IP_SHORT=1
# Define the netmask
NETMASK=255.255.255.0
#SET IP for ifconfig stuff - DON'T CHANGE
IP=$NET.$IP_SHORT

View file

@ -0,0 +1,16 @@
# act like dns&dhcp (dnsmasq)
USE_DNSMASQ="yes"
# On which interface DNSMASQ should listen. -i is the parameter for dnsmasq
# Make it empty to disable
DNSMASQ_INTERFACE="wlan0"
#DHCP LEASE Start
START_LEASE=10
#DHCP LEASE End Range
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

View file

@ -17,3 +17,5 @@ IPV6_MASK="64"
# Prefix to piratebox ipv6 adress
IPV6_PREFIX="fdc0:ffea"

View file

@ -25,3 +25,4 @@ NODE_GEN="yes"
NODE_INTERFACE='$INTERFACE'
# Should the Node-Interface setup via the PirateBox-Scripts
NODE_IPV6_SET_IP='no'

View file

@ -0,0 +1,5 @@
#Brdige add interfacce (setr yes to enable bridging)
DO_BRIDGE="no"
ADD_INTERFACES_TO_BRIDGE="wlan0"
ADD_TO_BRIDGE="br-lan"

View file

@ -0,0 +1,5 @@
# Configuration file for Timesave functions.
## Timesave file for non RTC devices
TIMESAVE="$PIRATEBOX_FOLDER/share/timesave_file"

View file

@ -0,0 +1,15 @@
DROOPY_UPLOAD_FOLDER="$UPLOADFOLDER"
#Start droopy? - Enable upload?
DROOPY_ENABLED="no"
#Image-SRC
IMAGENAME="piratebox-logo-small.png"
IMAGE="$PIRATEBOX_FOLDER/src/$IMAGENAME"
DROOPY_TXT=""
DROOPY_PORT="8080"
DROOPY_USERDIR=""
# Uncomment line below for adding directory feature
#DROOPY_USERDIR=" -u True "
#Use UserId from lighttpd for droopy (use on ext-filesystems)
DROOPY_USE_USER="yes"

View file

@ -1,6 +1,9 @@
#------------------------ IRC Configuration
#Switch to yes if you want to enable the IRC-Server
ENABLE_IRC_SERVER="no"
### Configuration file for mniircd server
IRC_CONFIG_FOLDER=$PIRATEBOX_FOLDER/conf/irc
#Save state ; keeps topic config. Enable with removing #
@ -9,5 +12,3 @@ IRC_CONFIG_FOLDER=$PIRATEBOX_FOLDER/conf/irc
#MOTD Message
IRC_MOTD=$IRC_CONFIG_FOLDER/motd.txt

View file

@ -0,0 +1,9 @@
#------------------------ Additional configuration for lighttpd
LIGHTTPD_ENABLED="yes"
PIDFILE_LIGHTTPD="${PIRATEBOX_TMP_FOLDER}/lighttpd.pid"
CONF_LIGHTTPD="${PIRATEBOX}/conf/lighttpd/lighttpd.conf"
LIGHTTPD_USER=nobody
LIGHTTPD_GROUP=nogroup

View file

@ -4,176 +4,32 @@
## licenced by GPL-3 ; feel free to improve or send me feedback
##
########
## Configuration help
## If you plan to use one laptop as the piratebox:
## Set DO_IFCONFIG , USE_APN, USE_DNSMASQ to yes
## If you plan to run a two component setup (one router and one providing the storage+website)
## connected with ethernet:
## Set DO_IFCONFIG , USE_APN, USE_DNSMASQ to no
## Configure your ethernet eth0 (or whatever) to a static IP
## force your router to publish the HOST Option with your static IP; in case of dnsmasq add the /etc/hosts entrys
## Have a look at http://www.piratebox.cc for futher instructions
##
## You may deactivated severall option as needed. It's flexible.
#### These path variables are available everywhere
#----------------- Folder Configuration -------------------#
PIRATEBOX_FOLDER="/opt/piratebox"
PIRATEBOX_TMP_FOLDER="/opt/piratebox/tmp"
WWW_FOLDER="/opt/piratebox/www"
#Do not change untill really needed.
PIRATEBOX_PYTHONPATH="$PIRATEBOX_FOLDER/python_lib"
PIRATEBOX_PYTHONPATH="${PIRATEBOX_FOLDER}/python_lib"
#Datafolder , where is you usb-stick // drive mounted
SHARE_FOLDER="$PIRATEBOX_FOLDER/share"
SHARE_FOLDER="${PIRATEBOX_FOLDER}/share"
#Upload Folder
# Change this if you want to user uploaded data in a subfolder
# Make sure the folder exists
# UPLOADFOLDER="$SHARE_FOLDER/Upload"
UPLOADFOLDER="$SHARE_FOLDER/Shared"
UPLOADFOLDER="${SHARE_FOLDER}/Shared"
#----------------- Startup Configuration -------------------#
# Which Steps has to be done
#Module configuration folder
MODULE_CONFIG="${PIRATEBOX_FOLDER}/conf/modules_conf"
MODULE_ENABLED="${PIRATEBOX_FOLDER}/modules.enabled"
MODULE_AVAILABLE="${PIRATEBOX_FOLDER}/modules.available"
#Do network config
DO_IFCONFIG="yes"
#Do IW config - setting up a wlan0 interface with iw
# for some wifi-cards required
DO_IW="no"
#Iw physical interface
PHY_IF="phy0"
# Check if interface exists
# should be set to yes if you use a USB wifi card
PROBE_INTERFACE="no"
# wait how many seconds until throw an error
PROBE_TIME=10
#Start services...
# act like a apn / <yes|no>
# please have a look @ hostapd.conf ; you may need to change some options, regarding wifi-card
USE_APN="yes"
# act like dns&dhcp (dnsmasq)
USE_DNSMASQ="yes"
#HOSTNAME ... if you really want to change it, plz change:
# www/index.html
#
# That is the Domain-Specifi part, where you reach always the local box
HOST="piratebox.lan"
#----------------- Configuration for DNSMASQ & IF-Setup -------------------#
# Name of the wlan interface
INTERFACE="wlan0"
# On which interface DNSMASQ should listen. -i is the parameter for dnsmasq
# Make it empty to disable
DNSMASQ_INTERFACE="wlan0"
#Brdige add interfacce (setr yes to enable bridging)
DO_BRIDGE="no"
BRIDGE="br-lan"
#Network
NET=192.168.77
#IP-SHORT (is stringed together)
# Which IP is your Box?? i.e. 1 => 192.168.77.1
IP_SHORT=1
#DHCP LEASE Start
START_LEASE=10
#DHCP LEASE End Range
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
#SET IP for ifconfig stuff - DON'T CHANGE
IP=$NET.$IP_SHORT
#Load Config about ipv6 stuff - DON'T CHANGE
. $PIRATEBOX_FOLDER/conf/ipv6.conf
#--------------------------------------------------------------------------#
# Node-Config path
NODE_CONFIG="$PIRATEBOX_FOLDER/conf/node.conf"
#----------------- Configuration for the pure piratebox -------------------#
## droopy, webserver, shoutbox- and forum-server
## Timesave file for non RTC devices
TIMESAVE="$PIRATEBOX_FOLDER/share/timesave_file"
#Start droopy? - Enable upload?
DROOPY_ENABLED="no"
#Image-SRC
IMAGENAME="piratebox-logo-small.png"
IMAGE="$PIRATEBOX_FOLDER/src/$IMAGENAME"
DROOPY_TXT=""
DROOPY_PORT="8080"
DROOPY_USERDIR=""
# Uncomment line below for adding directory feature
#DROOPY_USERDIR=" -u True "
#Use UserId from lighttpd for droopy (use on ext-filesystems)
DROOPY_USE_USER="yes"
#Configuration for chat (If you decide to move the chat folder, you have to change /opt/piratebox/chat/cgi-bin/py* files )
CHATFILE="$WWW_FOLDER/cgi-bin/data.pso"
#Generated File
GEN_CHATFILE="$WWW_FOLDER/chat_content.html"
# Reset Shoutbox on Startup?
RESET_CHAT="yes"
### Shoutbox is enabled.
# When you set this option to "no", then the shoutbox file is not writable anymore
# and in the json file the module is disabled. You should adjust the chat_init.txt
# to make clear, that the box is not working anymore.
SHOUTBOX_ENABLED="yes"
SHOUTBOX_CLIENT_TIMESTAMP="no"
#Inititiation Chat-Message
### This option was removed, you can find the chat message in conf/chat_init.txt
#Provide files needed for PirateBox custom dirlisting
CUSTOM_DIRLIST_COPY="yes"
#Generate config json for frontend
PBX_JSON_GENERATION="yes"
PBX_JSON_FILE="$WWW_FOLDER/piratebox_config.json"
#Activate Global chat
# Still experimentall!
GLOBAL_CHAT="no"
#On which broadcast address should it send
# Take care on the syntax!!
GLOBAL_DEST="[ #255.255.255.255# , #10.255.255.255# , #$NET.255# ]"
#------------------------ Additional configuration for lighttpd
LIGHTTPD_USER=nobody
LIGHTTPD_GROUP=nogroup
#------------------------ IRC Configuration
#Switch to yes if you want to enable the IRC-Server
ENABLE_IRC_SERVER="no"
#------------------------ Hook in user-config
. $PIRATEBOX_FOLDER/conf/hook_custom.conf
#Function library
PIRATEBOX_RC_LIB="${PIRATEBOX_FOLDER}/lib/rc.sh"

View file

@ -43,7 +43,7 @@ CONF_DNSMASQ=$PIRATEBOX/conf/dnsmasq_generated.conf
CONF_RADVD=$PIRATEBOX/conf/radvd_generated.conf
CONF_LIGHTTPD=$PIRATEBOX/conf/lighttpd/lighttpd.conf
export PYTHONPATH=:$PYTHONPATH:$PIRATEBOX_PYTHONPATH

View file

@ -0,0 +1,160 @@
#!/bin/sh
MODULE_LIST=""
# Opmode Prefixes
PREFIX_START="S"
PREFIX_STOP="K"
_get_prefix_for_start(){
echo $PREFIX_START
}
_get_prefix_for_stop(){
echo $PREFIX_STOP
}
_work_on_module_(){
local op_mode="$1"
local module="$2"
abort_start=0
echo "Working on $module"
_load_configuration_ "$module"
return "func_${module}_${op_mode}"
}
#Processes all modules.enabled
auto_process_all() {
local op_mode="$1"
clean_exit=1
abort_start=0
for module in $MODULE_LIST
do
_work_on_module_ "${op_mode}" "${module}"
[[ "${abort_start}" == "1" ]] && return 99
done
return 0
}
_load_configuration_(){
local module_name="$1"
$DEBUG && echo "Loading configuration for ${module_name}"
local config_list=$( func_"${module_name}"_get_config )
$DEBUG && echo " ... $config_list"
for config_file in "$config_list" ; do
local is_module_config="yes"
if "$config_file" | grep -q "/" ; then
$DEBUG && echo " .. absolude config path."
. $config_file
else
$DEBUG && echo " .. module config."
. "${MODULE_CONFIG}/${config_file}"
fi
done
return 0
}
_load_modules_() {
local module_path=$1 ; shift
local search_prefix=$( _get_prefix_for_$op_mode )
local available_module_files=$(ls -x ${cfg_modules}/$[search_prefix}??_*)
$DEBUG && echo "modules_folder $cfg_modules "
$DEBUG && echo "ls result: $available_module_files"
for this_module in $available_module_files
do
this_module_name=$( echo "$this_module" | cut -d '_' -f2 )
echo -n "Loading module $this_module_name .."
. $cfg_modules/$this_module_name
echo "done"
done
echo "Available modules: $MODULE_LIST "
return 0
}
_run_single_(){
local module_name="$1"
local op_mode="$2"
$DEBUG && echo "Loading Module $module_name"
. $cfg_modules/$module_name
$DEBUG && echo ".. Processing $module_name $op_mode"
exit _work_on_module_ "$op_mode" "$module_name"
}
_run_() {
local op_mode="$1"
clean_exit=1
# check if $cfg_modules is available
if [ ! -d $cfg_modules ] ; then
echo "config module folder $cfg_modules does not exists"
exit 1
fi
# load modules
_load_modules_ "$op_mode" || exit $?
# Run configuration
auto_process_all "$op_mode"
if [ "$clean_exit" == "1" ] ; then
#If we changed something we deliver 0 as RC, because
#we did our work successfully
exit 0
else
#So, we haven't changed something, so, we inform with
#RC 1 as a hint
exit 255
fi
}
_enable_(){
local module_name="$1"
# check if $cfg_modules is available
if [ ! -d $cfg_modules ] ; then
echo "config module folder $cfg_modules does not exists"
exit 1
fi
if [ ! -e $cfg_modules_lib/$module_name ] ; then
echo "unknown module ${module_name}"
exit 1
fi
$DEBUG && echo "Loading Module $module_name"
local start_num=$( func_"${module_name"}_get_start_order )
local stop_num=$( func_"${module_name"}_get_stop_order )
local linkname_start="${PREFIX_START}${start_num}_${module_name}"
local linkname_stop="${PREFIX_STOP}${stop_num}_${module_name}"
cd $cfg_modules
#TODO better way to make this relative linking working...
ln -s "../modules.available/"$module_name ${linkname_start}
ln -s "../modules.available/"$module_name ${linkname_stop}
}
_disable_(){
local module_name="$1"
cd $cfg_modules
ls -1 ./???_$module_name | xargs -I {} rm -v {}
}

View file

@ -0,0 +1,36 @@
#!/bin/sh
MODULE_LIST="$MODULE_LIST example"
example_myself="example"
example_start_order=99
example_stop_order=01
example_needed_config="00_hostname.conf"
example_crucial="no"
func_example_start(){
#Start here the example i.e.
echo "Hello World... ${HOSTNAME}"
local RC=$?
echo $RC
return $RC
}
func_example_stop(){
echo "Stopping Example..."
local RC=$?
echo $RC
return $RC
}
func_example_get_config(){
echo $example_needed_config
}
func_example_get_start_order(){
echo $example_start_order
}
func_example_get_stop_order(){
echo $example_stop_order
}

View file

@ -0,0 +1,30 @@
#!/bin/sh
MODULE_LIST="$MODULE_LIST lighttpd"
lighttpd_myself="lighttpd"
lighttpd_start_order=30
lighttpd_stop_order=10
lighttpd_needed_config="lighttpd.conf"
lighttpd_crucial="no"
func_lighttpd_start(){
#Start here the lighttpd i.e.
echo "Starting lighttpd..."
start-stop-daemon -S -q -p $PIDFILE_LIGHTTPD -x /usr/sbin/lighttpd -- -f $CONF_LIGHTTPD
local RC=$?
echo $RC
return $RC
}
func_lighttpd_stop(){
echo "Stopping lighttpd..."
start-stop-daemon -K -q -p $PIDFILE_LIGHTTPD
local RC=$?
echo $RC
return $RC
}
func_lighttpd_get_config(){
echo $lighttpd_needed_config
}