Revize 1821
Přidáno uživatelem Ondřej Fibich před téměř 12 roky(ů)
freenetis/branches/1.1/application/vendors/deb/freenetis-dhcp/freenetis-dhcp.cron | ||
---|---|---|
# /etc/cron.d/freenetis-dhcp: Regular CRON file for freenetis-dhcp package (triggered each minute)
|
||
|
||
SHELL=/bin/sh
|
||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
freenetis/branches/1.1/application/vendors/deb/freenetis-dhcp/control | ||
---|---|---|
Priority: optional
|
||
Section: web
|
||
Pre-Depends: debconf (>= 0.5) | debconf-2.0
|
||
Depends: coreutils, wget, isc-dhcp-server, diffutils
|
||
Depends: coreutils, wget, isc-dhcp-server, diffutils, procps
|
||
Suggests: freenetis
|
||
Architecture: all
|
||
Maintainer: Ondrej Fibich <ondrej.fibich@gmail.com>
|
freenetis/branches/1.1/application/vendors/deb/freenetis-dhcp/postinst | ||
---|---|---|
db_get freenetis-dhcp/device_id
|
||
DEVICE_ID="$RET"
|
||
|
||
db_get freenetis-dhcp/timeout
|
||
TIMEOUT="$RET"
|
||
|
||
# check path
|
||
if [ -z "$PATH_FN" ]; then
|
||
echo "Empty path to FreenetIS instance, configuration failed!"
|
||
... | ... | |
exit 1
|
||
fi
|
||
|
||
# check timeout ID
|
||
if [[ ! "$TIMEOUT" =~ ^[0-9]+$ ]] || [ $TIMEOUT -lt 1 ]; then
|
||
echo "Wrong configuration (TIMEOUT not set properly), configuration failed!" 1>&2
|
||
exit 1
|
||
fi
|
||
|
||
cp -a -f $CONFIGFILE $CONFIGFILE.tmp
|
||
|
||
# If the admin deleted or commented some variables but then set
|
||
... | ... | |
|
||
test -z "$PATH_FN" || grep -Eq '^ *PATH_FN=' $CONFIGFILE || echo "PATH_FN=" >> $CONFIGFILE
|
||
test -z "$DEVICE_ID" || grep -Eq '^ *DEVICE_ID=' $CONFIGFILE || echo "DEVICE_ID=" >> $CONFIGFILE
|
||
test -z "$TIMEOUT" || grep -Eq '^ *TIMEOUT=' $CONFIGFILE || echo "TIMEOUT=" >> $CONFIGFILE
|
||
|
||
PATH_FN_ESCAPED="${PATH_FN//\//\\/}"
|
||
DEVICE_ID_ESCAPED="${DEVICE_ID//\//\\/}"
|
||
TIMEOUT_ESCAPED="${TIMEOUT//\//\\/}"
|
||
|
||
sed -e "s/^ *PATH_FN=.*/PATH_FN=\"$PATH_FN_ESCAPED\"/" \
|
||
-e "s/^ *DEVICE_ID=.*/DEVICE_ID=\"$DEVICE_ID_ESCAPED\"/" < $CONFIGFILE > $CONFIGFILE.tmp
|
||
-e "s/^ *DEVICE_ID=.*/DEVICE_ID=\"$DEVICE_ID_ESCAPED\"/" \
|
||
-e "s/^ *TIMEOUT=.*/TIMEOUT=\"$TIMEOUT_ESCAPED\"/" < $CONFIGFILE > $CONFIGFILE.tmp
|
||
|
||
mv -f $CONFIGFILE.tmp $CONFIGFILE
|
||
|
||
... | ... | |
# 1) Rights
|
||
|
||
# set rights
|
||
chmod u+x /etc/init.d/${NAME}
|
||
chmod u+x /usr/sbin/freenetis-dhcp-sync
|
||
|
||
# 2) CRON
|
||
# 2) Startup at boot
|
||
|
||
echo "Preparing CRON"
|
||
# set on fire after boot
|
||
update-rc.d ${NAME} defaults
|
||
|
||
echo "# /etc/cron.d/freenetis-dhcp: Regular CRON file for freenetis-dhcp package (triggered each minute)" > /etc/cron.d/freenetis-dhcp
|
||
echo "" >> /etc/cron.d/freenetis-dhcp
|
||
echo "SHELL=/bin/sh" >> /etc/cron.d/freenetis-dhcp
|
||
echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" >> /etc/cron.d/freenetis-dhcp
|
||
echo "* * * * * root /usr/sbin/freenetis-dhcp-sync 1>>\"$LOG_FILE\"" >> /etc/cron.d/freenetis-dhcp
|
||
|
||
if [ -x /usr/sbin/invoke-rc.d ]; then
|
||
invoke-rc.d cron restart 3>/dev/null || true
|
||
else
|
||
/etc/init.d/cron restart 3>/dev/null || true
|
||
fi
|
||
|
||
exit 0
|
freenetis/branches/1.1/application/vendors/deb/freenetis-dhcp/postrm | ||
---|---|---|
# FreenetIS-dhcp DEB: actions before uninstalling of package
|
||
|
||
set -e
|
||
. /usr/share/debconf/confmodule
|
||
|
||
NAME=freenetis-dhcp
|
||
CONFIGFILE=/etc/freenetis/freenetis-dhcp.conf
|
||
|
||
# disable startup from update-rc.d
|
||
set +e
|
||
update-rc.d -f ${NAME} remove
|
||
set -e
|
||
|
||
# remove all configuration if purge
|
||
if [ "$1" = purge ]; then
|
||
# remove defconf values
|
||
if [ -e /usr/share/debconf/confmodule ]; then
|
||
. /usr/share/debconf/confmodule
|
||
db_purge
|
||
fi
|
||
# remove config files
|
||
... | ... | |
[ "$(ls -A /etc/freenetis)" ] || rm -rf /etc/freenetis
|
||
fi
|
||
|
||
#DEBHELPER#
|
||
|
||
exit 0
|
freenetis/branches/1.1/application/vendors/deb/freenetis-dhcp/config | ||
---|---|---|
. $CONFIGFILE || true
|
||
db_set freenetis-dhcp/path_freenetis "$PATH_FN"
|
||
db_set freenetis-dhcp/device_id "$DEVICE_ID"
|
||
db_set freenetis-dhcp/timeout "$TIMEOUT"
|
||
fi
|
||
fi
|
||
|
||
... | ... | |
# Ask questions.
|
||
db_input critical freenetis-dhcp/path_freenetis || true
|
||
db_input critical freenetis-dhcp/device_id || true
|
||
db_input critical freenetis-dhcp/timeout || true
|
||
db_go || true
|
freenetis/branches/1.1/application/vendors/deb/freenetis-dhcp/prerm | ||
---|---|---|
#!/bin/sh
|
||
# FreenetIS-dhcp DEB: actions before uninstalling of package
|
||
|
||
set -e
|
||
|
||
NAME=freenetis-dhcp
|
||
|
||
# stop daemon
|
||
/etc/init.d/$NAME stop
|
||
|
||
#DEBHELPER#
|
||
|
||
exit 0
|
freenetis/branches/1.1/application/vendors/deb/freenetis-dhcp/debianization.sh | ||
---|---|---|
mkdir DEBIAN
|
||
mkdir etc
|
||
mkdir etc/freenetis
|
||
mkdir etc/cron.d
|
||
mkdir etc/init.d
|
||
mkdir usr
|
||
mkdir usr/sbin
|
||
|
||
# copy content of package ######################################################
|
||
cp ../../../dhcp/freenetis-dhcp.init.sh etc/init.d/${NAME}
|
||
cp ../../../dhcp/freenetis-dhcp-sync.sh usr/sbin/freenetis-dhcp-sync
|
||
cp ../../../dhcp/freenetis-dhcp.conf etc/freenetis/
|
||
cp ../../freenetis-dhcp/freenetis-dhcp.cron etc/cron.d/freenetis-dhcp
|
||
|
||
# count size
|
||
SIZE=`du -s etc usr | cut -f1 | paste -sd+ | bc`
|
||
... | ... | |
|
||
cat ../../${NAME}/postinst >> DEBIAN/postinst
|
||
cat ../../${NAME}/postrm >> DEBIAN/postrm
|
||
cat ../../${NAME}/prerm >> DEBIAN/prerm
|
||
cat ../../${NAME}/templates >> DEBIAN/templates
|
||
cat ../../${NAME}/config >> DEBIAN/config
|
||
|
||
chmod +x DEBIAN/postinst DEBIAN/postrm DEBIAN/config
|
||
chmod +x DEBIAN/postinst DEBIAN/postrm DEBIAN/prerm DEBIAN/config
|
||
|
||
# create deb ###################################################################
|
||
|
||
# change owner of files to root (security)
|
||
cd ..
|
||
sudo chown -hR root:root *
|
||
sudo chmod g-w tmp/etc/cron.d/freenetis-dhcp
|
||
|
||
# make package
|
||
sudo dpkg-deb -b tmp ${NAME}_${VERSION}+${DEBIAN}.deb
|
freenetis/branches/1.1/application/vendors/deb/freenetis-dhcp/templates | ||
---|---|---|
Description-cs.UTF-8: Vstupní rozhraní:
|
||
ID zařízení z FreenetISu.
|
||
|
||
Template: freenetis-dhcp/timeout
|
||
Type: string
|
||
Default: 300
|
||
Description: Timeout:
|
||
Timeout in seconds after that the synchronization is made (default 5 minutes).
|
||
Description-cs.UTF-8: Timeout:
|
||
Timeout v sekundách, po kterém je provedena synchronizace (defaultně 5 minut).
|
||
|
||
Template: freenetis-dhcp/hack_reload
|
||
Type: boolean
|
||
Default: true
|
freenetis/branches/1.1/application/vendors/dhcp/freenetis-dhcp-sync.sh | ||
---|---|---|
################################################################################
|
||
|
||
CONFIG=/etc/freenetis/freenetis-dhcp.conf
|
||
CUSTOM_DHCP_CONF=/etc/dhcp/dhcp.conf.custom
|
||
|
||
# Load variables
|
||
if [ -e $CONFIG ]; then
|
||
. $CONFIG || true
|
||
TMPFILE=`mktemp`
|
||
. $CONFIG || true
|
||
else
|
||
echo "`date -R` Config file is missing at path $CONFIG. Terminating..."
|
||
exit 0
|
||
echo "`date -R` Config file is missing at path $CONFIG. Terminating..."
|
||
exit 0
|
||
fi
|
||
|
||
# check config
|
||
if [[ ! "$DEVICE_ID" =~ ^[0-9]+$ ]] || [ $DEVICE_ID -lt 1 ]; then
|
||
echo "[ERROR] `date -R` Wrong configuration (ID not set properly)"
|
||
exit 1
|
||
echo "[ERROR] `date -R` Wrong configuration (ID not set properly)"
|
||
exit 1
|
||
fi
|
||
|
||
# download
|
||
rm -f "$TMPFILE"
|
||
echo "[INFO] `date -R` Downloading ISC DHCP SERVER config from (${PATH_FN})"
|
||
status=`wget --no-check-certificate --server-response -q "$FULL_PATH" -O "$TMPFILE" 2>&1 | awk '/^ HTTP/{print $2}'`
|
||
if [[ ! "$TIMEOUT" =~ ^[0-9]+$ ]] || [ $TIMEOUT -lt 1 ]; then
|
||
echo "[ERROR] `date -R` Wrong configuration (TIMEOUT not set properly)"
|
||
exit 1
|
||
fi
|
||
|
||
# make sure that config exist
|
||
touch "$DHCP_CONF"
|
||
# endless loop
|
||
while true;
|
||
do
|
||
# download
|
||
TMPFILE=`mktemp`
|
||
echo "[INFO] `date -R` Downloading ISC DHCP SERVER config from (${PATH_FN})"
|
||
status=`wget --no-check-certificate --server-response -q "$FULL_PATH" -O "$TMPFILE" 2>&1 | awk '/^ HTTP/{print $2}'`
|
||
|
||
# check download
|
||
if [ "$status" = "200" ]; then
|
||
# config has been change
|
||
if [ `diff "$TMPFILE" "$DHCP_CONF" | wc -l` -gt 0 ]; then
|
||
echo "[INFO] `date -R` Downloaded (code: $status)"
|
||
echo "[INFO] `date -R` Backuping old config to $DHCP_CONF.save"
|
||
mv -f "$DHCP_CONF" "$DHCP_CONF".save
|
||
echo "[INFO] `date -R` Loading new config to $DHCP_CONF.save..."
|
||
mv -f "$TMPFILE" "$DHCP_CONF"
|
||
echo "[INFO] `date -R` Restarting ISC DHCP server"
|
||
service isc-dhcp-server restart 2>&1 >/dev/null
|
||
else
|
||
echo "[ERROR] `date -R` No change -> keeping old configuration"
|
||
fi
|
||
else
|
||
echo "[ERROR] `date -R` Download failed (code: $status)"
|
||
fi
|
||
# make sure that config exist
|
||
touch "$DHCP_CONF"
|
||
|
||
# check download
|
||
if [ "$status" = "200" ]; then
|
||
# attach custom conf if exists
|
||
if [ -r "$CUSTOM_DHCP_CONF" ]; then
|
||
cat "$CUSTOM_DHCP_CONF" >> "$TMPFILE"
|
||
fi
|
||
# config has been change
|
||
if [ `diff "$TMPFILE" "$DHCP_CONF" | wc -l` -gt 0 ]; then
|
||
echo "[INFO] `date -R` Downloaded (code: $status)"
|
||
echo "[INFO] `date -R` Backuping old config to $DHCP_CONF.save"
|
||
mv -f "$DHCP_CONF" "$DHCP_CONF".save
|
||
echo "[INFO] `date -R` Loading new config to $DHCP_CONF.save..."
|
||
# copy config
|
||
mv -f "$TMPFILE" "$DHCP_CONF"
|
||
#restart DHCP server
|
||
echo "[INFO] `date -R` Restarting ISC DHCP server"
|
||
service isc-dhcp-server restart 2>&1 >/dev/null
|
||
else
|
||
echo "[INFO] `date -R` No change -> keeping old configuration"
|
||
fi
|
||
else
|
||
echo "[ERROR] `date -R` Download failed (code: $status)"
|
||
fi
|
||
|
||
rm -f "$TMPFILE"
|
||
sleep $TIMEOUT
|
||
done
|
freenetis/branches/1.1/application/vendors/dhcp/freenetis-dhcp.conf | ||
---|---|---|
# ID of device from FreenetIS
|
||
DEVICE_ID=0
|
||
|
||
# Timeout in seconds after that the synchronization is made
|
||
TIMEOUT=300
|
||
|
||
# Log file, change to /dev/null to disable logging
|
||
LOG_FILE=/var/log/freenetis-dhcp.log
|
||
|
||
# Filename with ISC DHCP server config
|
||
DHCP_CONF="/etc/dhcp/dhcpd.conf"
|
||
|
||
# This file (if exists) is attached to generated DHCP conf file
|
||
CUSTOM_DHCP_CONF="/etc/dhcp/dhcpd.conf.custom"
|
||
|
||
# Full path [DO NOT CHANGE THIS VARIABLE!!!]
|
||
FULL_PATH=$PATH_FN"/index.php/en/devices/export/"$DEVICE_ID"/debian-etc-dhcp-dhcpd/text"
|
||
FULL_PATH=$PATH_FN"/index.php/en/devices/export/"$DEVICE_ID"/debian-etc-dhcp-dhcpd/text"
|
freenetis/branches/1.1/application/vendors/dhcp/freenetis-dhcp.init.sh | ||
---|---|---|
#! /bin/bash
|
||
|
||
### BEGIN INIT INFO
|
||
# Provides: freenetis-dhcp
|
||
# Required-Start: $remote_fs
|
||
# Required-Stop: $remote_fs
|
||
# Should-Start: $network $syslog
|
||
# Should-Stop: $network $syslog
|
||
# Default-Start: 2 3 4 5
|
||
# Default-Stop: 0 1 6
|
||
# Short-Description: Start and stop freenetis DHCP sync daemon
|
||
# Description: FreenetIS initialization DHCP synchronization script.
|
||
### END INIT INFO
|
||
|
||
################################################################################
|
||
# #
|
||
# This script serves for initialization of DHCP of IS FreenetIS #
|
||
# #
|
||
# Author Ondrej Fibich 2013 #
|
||
# Email ondrej.fibic@gmail.com #
|
||
# #
|
||
# Name freenetis-dhcp.init.sh #
|
||
# Version 0.1.0 #
|
||
# #
|
||
################################################################################
|
||
|
||
#Load variables from config file
|
||
CONFIG=/etc/freenetis/freenetis-dhcp.conf
|
||
|
||
# Path to DHCP synchronization file
|
||
DHCP_SYNCFILE=/usr/sbin/freenetis-dhcp-sync
|
||
|
||
#Load variables
|
||
if [ -f ${CONFIG} ]; then
|
||
. $CONFIG;
|
||
else
|
||
echo "Config file is missing at path $CONFIG."
|
||
echo "Terminating..."
|
||
exit 0
|
||
fi
|
||
|
||
start_dhcp ()
|
||
{
|
||
if [ `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | wc -l` -gt 0 ]; then
|
||
echo "Already started"
|
||
return 0
|
||
fi
|
||
|
||
cat /dev/null > "$LOG_FILE"
|
||
|
||
echo -n "Starting FreenetIS DHCP deamon: "
|
||
nohup $DHCP_SYNCFILE >> "$LOG_FILE" 2>&1 &
|
||
|
||
# test if daemon is started
|
||
if [ `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | wc -l` -gt 0 ];
|
||
then
|
||
echo "OK"
|
||
else
|
||
echo "FAILED!"
|
||
fi
|
||
|
||
return 0
|
||
}
|
||
|
||
stop_dhcp ()
|
||
{
|
||
if [ `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | wc -l` -lt 1 ]; then
|
||
echo "Already stopped"
|
||
return 0
|
||
fi
|
||
|
||
#Killing of process by sigterm
|
||
echo -n "Stopping FreenetIS DHCP deamon: "
|
||
set +e
|
||
killall freenetis-dhcp-sync
|
||
set -e
|
||
|
||
# test if daemon is stopped
|
||
if [ `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | wc -l` -eq 0 ];
|
||
then
|
||
echo "OK"
|
||
else
|
||
echo "FAILED!";
|
||
fi
|
||
|
||
return 0
|
||
}
|
||
|
||
status_dhcp ()
|
||
{
|
||
if [ `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | wc -l` -gt 0 ]; then
|
||
echo -n "Freenetis DHCP is running with PID "
|
||
echo `ps aux | grep "$DHCP_SYNCFILE" | grep -v grep | awk '{print $2}'`
|
||
return 0
|
||
else
|
||
echo "Freenetis DHCP is not running"
|
||
return 0
|
||
fi
|
||
}
|
||
|
||
usage_dhcp ()
|
||
{
|
||
echo "usage : `echo $0` (start|stop|restart|status|help)"
|
||
}
|
||
|
||
help_dhcp ()
|
||
{
|
||
echo " start - initialization of synchronization of DHCP"
|
||
echo " stop - stops synchronization of DHCP"
|
||
echo " restart - restarts synchronization of DHCP"
|
||
echo " status - returns current state of DHCP synchronization"
|
||
echo " help - prints help for DHCP synchronization"
|
||
}
|
||
|
||
# Is parameter #1 zero length?
|
||
if [ -z "$1" ]; then
|
||
usage_dhcp
|
||
exit 0
|
||
fi;
|
||
|
||
case "$1" in
|
||
|
||
start)
|
||
start_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
restart)
|
||
stop_dhcp
|
||
start_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
stop)
|
||
stop_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
status)
|
||
status_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
help)
|
||
usage_dhcp
|
||
help_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
*)
|
||
usage_dhcp
|
||
exit 0
|
||
;;
|
||
|
||
esac
|
||
|
||
exit 0
|
freenetis/branches/1.1/application/controllers/connection_requests.php | ||
---|---|---|
|
||
if ($dhcp_device)
|
||
{
|
||
$snmp = Snmp_Factory::factoryForDevice($dhcp_device->ip_address);
|
||
|
||
try
|
||
{
|
||
$snmp = Snmp_Factory::factoryForDevice($dhcp_device->ip_address);
|
||
$mac_address = $snmp->getMacAddressOf($ip_address);
|
||
$this->session->set('connection_request_mac', $mac_address);
|
||
}
|
Také k dispozici: Unified diff
Novinky:
- fixes #453: Balik pro freenetis-dhcp (prepis na init a deamon)
Opravy:
- drobne osetreni chyby v pridavani zadosti o pripojeni