mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
#-------------------------------------------------------------------------------
|
||||
# Pi.Alert v2.60 / 2021-01-20
|
||||
# Pi.Alert v2.61 / 2021-01-25
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# pialert.py - Back module. Network scanner
|
||||
@@ -79,6 +79,8 @@ def main ():
|
||||
res = check_internet_IP()
|
||||
elif cycle == 'update_vendors':
|
||||
res = update_devices_MAC_vendors()
|
||||
elif cycle == 'update_vendors_silent':
|
||||
res = update_devices_MAC_vendors('-s')
|
||||
else :
|
||||
res = scan_network()
|
||||
|
||||
@@ -163,18 +165,20 @@ def check_internet_IP ():
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def get_internet_IP ():
|
||||
# BUGFIX #46 - curl http://ipv4.icanhazip.com repeatedly is very slow
|
||||
# Using 'dig'
|
||||
# dig_args = ['dig', '+short', 'myip.opendns.com',
|
||||
# '@resolver1.opendns.com']
|
||||
dig_args = ['dig', '+short', '-4', 'myip.opendns.com',
|
||||
'@resolver1.opendns.com']
|
||||
cmd_output = subprocess.check_output (dig_args, universal_newlines=True)
|
||||
|
||||
# BUGFIX #12 - Query IPv4 address (not IPv6)
|
||||
# Using 'curl' instead of 'dig'
|
||||
# curl_args = ['curl', '-s', 'https://diagnostic.opendns.com/myip']
|
||||
curl_args = ['curl', '-s', QUERY_MYIP_SERVER]
|
||||
curl_output = subprocess.check_output (curl_args, universal_newlines=True)
|
||||
## BUGFIX #12 - Query IPv4 address (not IPv6)
|
||||
## Using 'curl' instead of 'dig'
|
||||
## curl_args = ['curl', '-s', 'https://diagnostic.opendns.com/myip']
|
||||
#curl_args = ['curl', '-s', QUERY_MYIP_SERVER]
|
||||
#cmd_output = subprocess.check_output (curl_args, universal_newlines=True)
|
||||
|
||||
# Check result is an IP
|
||||
IP = check_IP_format (curl_output)
|
||||
IP = check_IP_format (cmd_output)
|
||||
return IP
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -250,14 +254,14 @@ def check_IP_format (pIP):
|
||||
#===============================================================================
|
||||
# UPDATE DEVICE MAC VENDORS
|
||||
#===============================================================================
|
||||
def update_devices_MAC_vendors ():
|
||||
def update_devices_MAC_vendors (pArg = ''):
|
||||
# Header
|
||||
print ('Update HW Vendors')
|
||||
print (' Timestamp:', startTime )
|
||||
|
||||
# Update vendors DB (iab oui)
|
||||
print ('\nUpdating vendors DB (iab & oui)...')
|
||||
update_args = ['sh', PIALERT_BACK_PATH + '/vendors_db_update.sh']
|
||||
update_args = ['sh', PIALERT_BACK_PATH + '/update_vendors.sh', pArg]
|
||||
update_output = subprocess.check_output (update_args)
|
||||
# DEBUG
|
||||
# update_args = ['./vendors_db_update.sh']
|
||||
|
||||
@@ -24,17 +24,17 @@ sudo mkdir -p 2_backup
|
||||
sudo cp *.txt 2_backup
|
||||
sudo cp *.csv 2_backup
|
||||
|
||||
sudo curl -# -O http://standards-oui.ieee.org/iab/iab.csv
|
||||
sudo curl -# -O http://standards-oui.ieee.org/iab/iab.txt
|
||||
sudo curl -$1 -# -O http://standards-oui.ieee.org/iab/iab.csv
|
||||
sudo curl -$1 -# -O http://standards-oui.ieee.org/iab/iab.txt
|
||||
|
||||
sudo curl -# -O http://standards-oui.ieee.org/oui28/mam.csv
|
||||
sudo curl -# -O http://standards-oui.ieee.org/oui28/mam.txt
|
||||
sudo curl -$1 -# -O http://standards-oui.ieee.org/oui28/mam.csv
|
||||
sudo curl -$1 -# -O http://standards-oui.ieee.org/oui28/mam.txt
|
||||
|
||||
sudo curl -# -O http://standards-oui.ieee.org/oui36/oui36.csv
|
||||
sudo curl -# -O http://standards-oui.ieee.org/oui36/oui36.txt
|
||||
sudo curl -$1 -# -O http://standards-oui.ieee.org/oui36/oui36.csv
|
||||
sudo curl -$1 -# -O http://standards-oui.ieee.org/oui36/oui36.txt
|
||||
|
||||
sudo curl -# -O http://standards-oui.ieee.org/oui/oui.csv
|
||||
sudo curl -# -O http://standards-oui.ieee.org/oui/oui.txt
|
||||
sudo curl -$1 -# -O http://standards-oui.ieee.org/oui/oui.csv
|
||||
sudo curl -$1 -# -O http://standards-oui.ieee.org/oui/oui.txt
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
@@ -1,3 +1,3 @@
|
||||
VERSION = '2.60'
|
||||
VERSION = '2.61'
|
||||
VERSION_YEAR = '2021'
|
||||
VERSION_DATE = '2021-01-20'
|
||||
VERSION_DATE = '2021-01-25'
|
||||
|
||||
728
install/pialert_install.sh
Normal file
728
install/pialert_install.sh
Normal file
@@ -0,0 +1,728 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# pialert_install.sh - Installation script
|
||||
# ------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# stop on errors
|
||||
set -e
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Variables
|
||||
# ------------------------------------------------------------------------------
|
||||
COLS=70
|
||||
ROWS=12
|
||||
|
||||
INSTALL_DIR=~
|
||||
PIALERT_HOME="$INSTALL_DIR/pialert"
|
||||
|
||||
LIGHTTPD_CONF_DIR="/etc/lighttpd"
|
||||
WEBROOT="/var/www/html"
|
||||
PIALERT_DEFAULT_PAGE=false
|
||||
|
||||
LOG="pialert_install_`date +"%Y-%m-%d_%H-%M"`.log"
|
||||
|
||||
PIHOLE_INSTALL=false
|
||||
PIHOLE_ACTIVE=false
|
||||
DHCP_ACTIVATE=false
|
||||
DHCP_ACTIVE=false
|
||||
|
||||
DHCP_RANGE_START="192.168.1.200"
|
||||
DHCP_RANGE_END="192.168.1.251"
|
||||
DHCP_ROUTER="192.168.1.1"
|
||||
DHCP_LEASE="1"
|
||||
DHCP_DOMAIN="local"
|
||||
|
||||
USE_PYTHON_VERSION=0
|
||||
PYTHON_BIN=python
|
||||
|
||||
REPORT_MAIL=False
|
||||
REPORT_TO=user@gmail.com
|
||||
SMTP_SERVER=smtp.gmail.com
|
||||
SMTP_PORT=587
|
||||
SMTP_USER=user@gmail.com
|
||||
SMTP_PASS=password
|
||||
|
||||
DDNS_ACTIVE=False
|
||||
DDNS_DOMAIN='your_domain.freeddns.org'
|
||||
DDNS_USER='dynu_user'
|
||||
DDNS_PASSWORD='A0000000B0000000C0000000D0000000'
|
||||
DDNS_UPDATE_URL='https://api.dynu.com/nic/update?'
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Main
|
||||
# ------------------------------------------------------------------------------
|
||||
main() {
|
||||
print_superheader "Pi.Alert Installation"
|
||||
log "`date`"
|
||||
log "Logfile: $LOG"
|
||||
|
||||
check_pialert_home
|
||||
|
||||
print_msg "Use: - http://pi.alert/"
|
||||
ask_yesno "This script will install Pi.Alert in this system using this path:\n$PIALERT_HOME" \
|
||||
"Do you want to continue ?"
|
||||
if ! $ANSWER ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ask_config
|
||||
|
||||
msgbox "Configuration finished. To updete the configuration, edit file:" \
|
||||
"$PIALERT_HOME/config/pialert.conf"
|
||||
|
||||
msgbox "" "The installation will start now"
|
||||
|
||||
install_pihole
|
||||
activate_DHCP
|
||||
add_pialert_DNS
|
||||
install_lighttpd
|
||||
install_arpscan
|
||||
install_python
|
||||
install_pialert
|
||||
|
||||
print_header "Installation process finished"
|
||||
print_msg "Use: - http://pi.alert/"
|
||||
print_msg " - http://`hostname -I | tr -d ' '`/pialert/"
|
||||
print_msg "To access Pi.Alert web"
|
||||
print_msg ""
|
||||
|
||||
move_logfile
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Ask config questions
|
||||
# ------------------------------------------------------------------------------
|
||||
ask_config() {
|
||||
# Ask Pi-hole Installation
|
||||
PIHOLE_ACTIVE=false
|
||||
if [ -e /usr/local/bin/pihole ] || [ -e /etc/pihole ]; then
|
||||
PIHOLE_ACTIVE=true
|
||||
fi
|
||||
|
||||
PIHOLE_INSTALL=false
|
||||
if $PIHOLE_ACTIVE ; then
|
||||
msgbox "Pi-hole is already installed in this system." \
|
||||
"Perfect: Pi-hole Installation not necessary"
|
||||
else
|
||||
ask_yesno "Pi-hole is not installed." \
|
||||
"Do you want to install Pi-hole before installing Pi.Alert ?" "YES"
|
||||
if $ANSWER ; then
|
||||
PIHOLE_INSTALL=true
|
||||
msgbox "In the installation wizard of Pi-hole, select this options" \
|
||||
"'Install web admin interface' & 'Install web server lighttpd'"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Ask DHCP Activation
|
||||
DHCP_ACTIVE=false
|
||||
DHCP_ACTIVATE=false
|
||||
if $PIHOLE_ACTIVE ; then
|
||||
DHCP_ACTIVE=`sudo grep DHCP_ACTIVE /etc/pihole/setupVars.conf |
|
||||
awk -F= '/./{print $2}'`
|
||||
|
||||
if ! $DHCP_ACTIVE ; then
|
||||
ask_yesno "Pi-hole DHCP server is not active." \
|
||||
"Do you want to activate Pi-hole DHCP server ?"
|
||||
if $ANSWER ; then
|
||||
DHCP_ACTIVATE=true
|
||||
fi
|
||||
fi
|
||||
|
||||
elif $PIHOLE_INSTALL ; then
|
||||
ask_yesno "Pi-hole installation." \
|
||||
"Do you want to activate Pi-hole DHCP server ?"
|
||||
if $ANSWER ; then
|
||||
DHCP_ACTIVATE=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if $DHCP_ACTIVATE ; then
|
||||
msgbox "Default DHCP options will be used. Range=$DHCP_RANGE_START - $DHCP_RANGE_END / Router=$DHCP_ROUTER / Domain=$DHCP_DOMAIN / Leases=$DHCP_LEASE h." \
|
||||
"Yo can change this values in your Pi-hole Admin Portal"
|
||||
msgbox "Make sure your router's DHCP server is disabled" \
|
||||
"when using the Pi-hole DHCP server!"
|
||||
fi
|
||||
|
||||
# Ask Pi.Alert deafault page
|
||||
PIALERT_DEFAULT_PAGE=false
|
||||
if ! $PIHOLE_ACTIVE && ! $PIHOLE_INSTALL; then
|
||||
ask_yesno "As Pi-hole is not going to be available in this system," \
|
||||
"Do you want to use Pi.Alert as default web server page ?" "YES"
|
||||
if $ANSWER ; then
|
||||
PIALERT_DEFAULT_PAGE=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# Ask Python version
|
||||
ask_option "What Python version do you want to use ?" \
|
||||
3 \
|
||||
0 " - Use Python already installed in the system (DEFAULT)" \
|
||||
2 " - Use Python 2" \
|
||||
3 " - Use Python 3"
|
||||
if [ "$ANSWER" = "" ] ; then
|
||||
USE_PYTHON_VERSION=0
|
||||
else
|
||||
USE_PYTHON_VERSION=$ANSWER
|
||||
fi
|
||||
|
||||
# Ask e-mail notification config
|
||||
MAIL_REPORT=false
|
||||
ask_yesno "Pi.Alert can notify you by e-mail when a network event occurs" \
|
||||
"Do you want to activate this feature ?"
|
||||
if $ANSWER ; then
|
||||
ask_yesno "e-mail notification needs a SMTP server (i.e. smtp.gmail.com)" \
|
||||
"Do you want to continue activating this feature ?"
|
||||
MAIL_REPORT=$ANSWER
|
||||
fi
|
||||
|
||||
if $MAIL_REPORT ; then
|
||||
ask_input "" "Notify alert to this e-mail address:" "user@gmail.com"
|
||||
REPORT_TO=$ANSWER
|
||||
|
||||
ask_input "" "SMTP server:" "smtp.gmail.com"
|
||||
SMTP_SERVER=$ANSWER
|
||||
|
||||
ask_input "" "SMTP user:" "user@gmail.com"
|
||||
SMTP_USER=$ANSWER
|
||||
|
||||
ask_input "" "SMTP password:" "password"
|
||||
SMTP_PASS=$ANSWER
|
||||
fi
|
||||
|
||||
# Ask Dynamic DNS config
|
||||
DDNS_ACTIVE=false
|
||||
ask_yesno "Pi.Alert can update your Dynamic DNS IP (i.e with www.dynu.net)" \
|
||||
"Do you want to activate this feature ?"
|
||||
if $ANSWER ; then
|
||||
ask_yesno "Dynamics DNS updater needs a DNS with IP Update Protocol" \
|
||||
"(i.e with www.dynu.net). Do you want to continue ?"
|
||||
DDNS_ACTIVE=$ANSWER
|
||||
fi
|
||||
|
||||
if $DDNS_ACTIVE ; then
|
||||
ask_input "" "Domain to update:" "your_domain.freeddns.org"
|
||||
DDNS_DOMAIN=$ANSWER
|
||||
|
||||
ask_input "" "DDNS user:" "dynu_user"
|
||||
DDNS_USER=$ANSWER
|
||||
|
||||
ask_input "" "DDNS password:" "A0000000B0000000C0000000D0000000"
|
||||
DDNS_PASSWORD=$ANSWER
|
||||
|
||||
ask_input "" "URL to update DDNS IP:" "https://api.dynu.com/nic/update?"
|
||||
DDNS_UPDATE_URL=$ANSWER
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install Pi-hole
|
||||
# ------------------------------------------------------------------------------
|
||||
install_pihole() {
|
||||
print_header "Pi-hole"
|
||||
|
||||
if ! $PIHOLE_INSTALL ; then
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Checking if Pi-hole is installed..."
|
||||
if [ -e /usr/local/bin/pihole ] || [ -e /etc/pihole ]; then
|
||||
print_msg " - Pi-hole already installed"
|
||||
print_msg "`pihole -v 2>&1`"
|
||||
print_msg ""
|
||||
|
||||
PIHOLE_ACTIVE=true
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Installing Pi-hole..."
|
||||
print_msg " - Pi-hole has its own logfile"
|
||||
curl -sSL https://install.pi-hole.net | bash
|
||||
print_msg ""
|
||||
PIHOLE_ACTIVE=true
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Activate DHCP
|
||||
# ------------------------------------------------------------------------------
|
||||
activate_DHCP() {
|
||||
if ! $DHCP_ACTIVATE ; then
|
||||
return
|
||||
fi
|
||||
|
||||
if ! $PIHOLE_ACTIVE ; then
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Checking if DHCP is active..."
|
||||
if [ -e /etc/pihole ]; then
|
||||
DHCP_ACTIVE= \
|
||||
`grep DHCP_ACTIVE /etc/pihole/setupVars.conf | awk -F= '/./{print $2}'`
|
||||
fi
|
||||
|
||||
if $DHCP_ACTIVE ; then
|
||||
print_msg " - DHCP already active"
|
||||
fi
|
||||
|
||||
print_msg "- Activating DHCP..."
|
||||
sudo pihole -a enabledhcp "$DHCP_RANGE_START" "$DHCP_RANGE_END" \
|
||||
"$DHCP_ROUTER" "$DHCP_LEASE" "$DHCP_DOMAIN" 2>&1 >> "$LOG"
|
||||
DHCP_ACTIVE=true
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Add Pi.Alert DNS
|
||||
# ------------------------------------------------------------------------------
|
||||
add_pialert_DNS() {
|
||||
if ! $PIHOLE_ACTIVE ; then
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Checking if 'pi.alert' is configured in Local DNS..."
|
||||
if grep -Fq pi.alert /etc/pihole/custom.list; then
|
||||
print_msg " - 'pi.alert' already in Local DNS..."
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Adding 'pi.alert' to Local DNS..."
|
||||
sudo sh -c "echo `hostname -I` pi.alert >> /etc/pihole/custom.list" \
|
||||
2>&1 >> "$LOG"
|
||||
sudo pihole restartdns 2>&1 >> "$LOG"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install Lighttpd & PHP
|
||||
# ------------------------------------------------------------------------------
|
||||
install_lighttpd() {
|
||||
print_header "Lighttpd & PHP"
|
||||
|
||||
print_msg "- Installing lighttpd..."
|
||||
sudo apt-get install lighttpd -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Installing PHP..."
|
||||
sudo apt-get install php php-cgi php-fpm php-sqlite3 -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Activating PHP..."
|
||||
sudo lighttpd-enable-mod fastcgi-php 2>&1 >>"$LOG" || ERRNO=$?
|
||||
log_no_screen "-- Command error code: $ERRNO"
|
||||
if [ $ERRNO -eq 1 ] ; then
|
||||
process_error "Error activating PHP"
|
||||
fi
|
||||
|
||||
print_msg "- Restarting lighttpd..."
|
||||
sudo /etc/init.d/lighttpd restart 2>&1 >> "$LOG"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install arp-scan
|
||||
# ------------------------------------------------------------------------------
|
||||
install_arpscan() {
|
||||
print_header "arp-scan"
|
||||
|
||||
print_msg "- Installing arp-scan..."
|
||||
sudo apt-get install arp-scan -y 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Testing arp-scan..."
|
||||
sudo arp-scan -l | head -n -3 | tail +3 | tee -a "$LOG"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install Python
|
||||
# ------------------------------------------------------------------------------
|
||||
install_python() {
|
||||
print_header "Python"
|
||||
|
||||
check_python_versions
|
||||
|
||||
if [ $USE_PYTHON_VERSION -eq 0 ] ; then
|
||||
print_msg "- Using the available Python version installed"
|
||||
if $PYTHON3 ; then
|
||||
print_msg " - Python 3 is available"
|
||||
USE_PYTHON_VERSION=3
|
||||
elif $PYTHON2 ; then
|
||||
print_msg " - Python 2 is available"
|
||||
USE_PYTHON_VERSION=2
|
||||
else
|
||||
print_msg " - Python is not available in this system"
|
||||
print_msg " - Python 3 will be installed"
|
||||
USE_PYTHON_VERSION=3
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if [ $USE_PYTHON_VERSION -eq 2 ] ; then
|
||||
if $PYTHON2 ; then
|
||||
print_msg "- Using Python 2"
|
||||
else
|
||||
print_msg "- Installing Python 2..."
|
||||
sudo apt-get install python -y 2>&1 >> "$LOG"
|
||||
fi
|
||||
PYTHON_BIN="python"
|
||||
elif [ $USE_PYTHON_VERSION -eq 3 ] ; then
|
||||
if $PYTHON3 ; then
|
||||
print_msg "- Using Python 3"
|
||||
else
|
||||
print_msg "- Installing Python 3..."
|
||||
sudo apt-get install python -y 2>&1 >> "$LOG"
|
||||
fi
|
||||
PYTHON_BIN="python3"
|
||||
else
|
||||
process_error "Unknown Python version to use: $USE_PYTHON_VERSION"
|
||||
fi
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check Python versions available
|
||||
# ------------------------------------------------------------------------------
|
||||
check_python_versions() {
|
||||
print_msg "- Checking Python 2..."
|
||||
if [ -f /usr/bin/python ] ; then
|
||||
print_msg " - Python 2 is installed"
|
||||
print_msg " - `python -V 2>&1`"
|
||||
PYTHON2=true
|
||||
else
|
||||
print_msg " - Python 2 is NOT installed"
|
||||
PYTHON2=false
|
||||
fi
|
||||
echo ""
|
||||
|
||||
print_msg "- Checking Python 3..."
|
||||
if [ -f /usr/bin/python3 ] ; then
|
||||
print_msg " - Python 3 is installed"
|
||||
print_msg " - `python3 -V 2>&1`"
|
||||
PYTHON3=true
|
||||
else
|
||||
print_msg " - Python 3 is NOT installed"
|
||||
PYTHON3=false
|
||||
fi
|
||||
echo ""
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Install Pi.Alert
|
||||
# ------------------------------------------------------------------------------
|
||||
install_pialert() {
|
||||
print_header "Pi.Alert"
|
||||
|
||||
download_pialert
|
||||
configure_pialert
|
||||
test_pialert
|
||||
add_jobs_to_crontab
|
||||
publish_pialert
|
||||
set_pialert_default_page
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Download and uncompress Pi.Alert
|
||||
# ------------------------------------------------------------------------------
|
||||
download_pialert() {
|
||||
if [ -f "$INSTALL_DIR/pialert_latest.tar" ] ; then
|
||||
print_msg "- Deleting previous downloaded tar file"
|
||||
rm -r "$INSTALL_DIR/pialert_latest.tar"
|
||||
fi
|
||||
|
||||
print_msg "- Downloading installation tar file..."
|
||||
curl -Lo "$INSTALL_DIR/pialert_latest.tar" \
|
||||
https://github.com/pucherot/Pi.Alert/raw/main/tar/pialert_latest.tar
|
||||
echo ""
|
||||
|
||||
print_msg "- Uncompressing tar file"
|
||||
tar xf "$INSTALL_DIR/pialert_latest.tar" -C "$INSTALL_DIR" \
|
||||
--checkpoint=100 --checkpoint-action="ttyout=." 2>&1 >> "$LOG"
|
||||
echo ""
|
||||
|
||||
print_msg "- Deleting downloaded tar file..."
|
||||
rm -r "$INSTALL_DIR/pialert_latest.tar"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Configure Pi.Alert parameters
|
||||
# ------------------------------------------------------------------------------
|
||||
configure_pialert() {
|
||||
print_msg "- Settting Pi.Alert config file"
|
||||
|
||||
set_pialert_parameter PIALERT_PATH "'$PIALERT_HOME'"
|
||||
|
||||
set_pialert_parameter REPORT_MAIL "$REPORT_MAIL"
|
||||
set_pialert_parameter REPORT_TO "'$REPORT_TO'"
|
||||
set_pialert_parameter SMTP_SERVER "'$SMTP_SERVER'"
|
||||
set_pialert_parameter SMTP_PORT "$SMTP_PORT"
|
||||
set_pialert_parameter SMTP_USER "'$SMTP_USER'"
|
||||
set_pialert_parameter SMTP_PASS "'$SMTP_PASS'"
|
||||
|
||||
set_pialert_parameter DDNS_ACTIVE "$DDNS_ACTIVE"
|
||||
set_pialert_parameter DDNS_DOMAIN "'$DDNS_DOMAIN'"
|
||||
set_pialert_parameter DDNS_USER "'$DDNS_USER'"
|
||||
set_pialert_parameter DDNS_PASSWORD "'$DDNS_PASSWORD'"
|
||||
set_pialert_parameter DDNS_UPDATE_URL "'$DDNS_UPDATE_URL'"
|
||||
|
||||
set_pialert_parameter PIHOLE_ACTIVE "$PIHOLE_ACTIVE"
|
||||
set_pialert_parameter DHCP_ACTIVE "$DHCP_ACTIVE"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Set Pi.Alert parameter
|
||||
# ------------------------------------------------------------------------------
|
||||
set_pialert_parameter() {
|
||||
if [ "$2" = "false" ] ; then
|
||||
VALUE="False"
|
||||
elif [ "$2" = "true" ] ; then
|
||||
VALUE="True"
|
||||
else
|
||||
VALUE="$2"
|
||||
fi
|
||||
|
||||
sed -i "/^$1.*=/s|=.*|= $VALUE|" $PIALERT_HOME/config/pialert.conf \
|
||||
2>&1 >> "$LOG"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Test Pi.Alert
|
||||
# ------------------------------------------------------------------------------
|
||||
test_pialert() {
|
||||
print_msg "- Testing Pi.Alert HW vendors database update process..."
|
||||
print_msg "*** PLEASE WAIT A COUPLE OF MINUTES..."
|
||||
stdbuf -i0 -o0 -e0 \
|
||||
$PYTHON_BIN $PIALERT_HOME/back/pialert.py update_vendors_silent 2>&1 \
|
||||
| tee -ai "$LOG"
|
||||
|
||||
echo ""
|
||||
print_msg "- Testing Pi.Alert Internet IP Lookup..."
|
||||
stdbuf -i0 -o0 -e0 \
|
||||
$PYTHON_BIN $PIALERT_HOME/back/pialert.py internet_IP 2>&1 | tee -ai "$LOG"
|
||||
|
||||
echo ""
|
||||
print_msg "- Testing Pi.Alert Network scan..."
|
||||
print_msg "*** PLEASE WAIT A COUPLE OF MINUTES..."
|
||||
stdbuf -i0 -o0 -e0 \
|
||||
$PYTHON_BIN $PIALERT_HOME/back/pialert.py 1 2>&1 | tee -ai "$LOG"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Add Pi.Alert jobs to crontab
|
||||
# ------------------------------------------------------------------------------
|
||||
add_jobs_to_crontab() {
|
||||
if crontab -l 2>/dev/null | grep -Fq pialert ; then
|
||||
print_msg "- Pi.Alert crontab jobs already exists. This is your crontab:"
|
||||
crontab -l | grep -F pialert 2>&1 | tee -ai "$LOG"
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Adding jobs to the crontab..."
|
||||
if [ $USE_PYTHON_VERSION -eq 3 ] ; then
|
||||
sed -i "s/\<python\>/$PYTHON_BIN/g" $PIALERT_HOME/install/pialert.cron
|
||||
fi
|
||||
|
||||
(crontab -l 2>/dev/null || : ; cat $PIALERT_HOME/install/pialert.cron) | \
|
||||
crontab -
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Publish Pi.Alert web
|
||||
# ------------------------------------------------------------------------------
|
||||
publish_pialert() {
|
||||
if [ -e "$WEBROOT/pialert" ] || [ -L "$WEBROOT/pialert" ] ; then
|
||||
print_msg "- Deleting previous Pi.Alert site"
|
||||
sudo rm -r "$WEBROOT/pialert" 2>&1 >> "$LOG"
|
||||
fi
|
||||
|
||||
print_msg "- Setting permissions..."
|
||||
sudo chgrp -R www-data $PIALERT_HOME/db 2>&1 >> "$LOG"
|
||||
chmod -R 770 $PIALERT_HOME/db 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Publishing Pi.Alert web..."
|
||||
sudo ln -s "$PIALERT_HOME/front" "$WEBROOT/pialert" 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Configuring http://pi.alert/ redirection..."
|
||||
if [ -e "$LIGHTTPD_CONF_DIR/conf-available/pialert_front.conf" ] ; then
|
||||
sudo rm -r "$LIGHTTPD_CONF_DIR/conf-available/pialert_front.conf" \
|
||||
2>&1 >> "$LOG"
|
||||
fi
|
||||
sudo cp "$PIALERT_HOME/install/pialert_front.conf" \
|
||||
"$LIGHTTPD_CONF_DIR/conf-available" 2>&1 >> "$LOG"
|
||||
|
||||
if [ -e "$LIGHTTPD_CONF_DIR/conf-enabled/pialert_front.conf" ] || \
|
||||
[ -L "$LIGHTTPD_CONF_DIR/conf-enabled/pialert_front.conf" ] ; then
|
||||
sudo rm -r "$LIGHTTPD_CONF_DIR/conf-enabled/pialert_front.conf" \
|
||||
2>&1 >> "$LOG"
|
||||
fi
|
||||
|
||||
sudo ln -s ../conf-available/pialert_front.conf \
|
||||
"$LIGHTTPD_CONF_DIR/conf-enabled/pialert_front.conf" 2>&1 >> "$LOG"
|
||||
|
||||
print_msg "- Restarting lighttpd..."
|
||||
sudo /etc/init.d/lighttpd restart 2>&1 >> "$LOG"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Set Pi.Alert the default web server page
|
||||
# ------------------------------------------------------------------------------
|
||||
set_pialert_default_page() {
|
||||
if ! $PIALERT_DEFAULT_PAGE ; then
|
||||
return
|
||||
fi
|
||||
|
||||
print_msg "- Setting Pi.Alert as default web server page..."
|
||||
|
||||
if [ -e "$WEBROOT/index.lighttpd.html" ] ; then
|
||||
if [ -e "$WEBROOT/index.lighttpd.html.orig" ] ; then
|
||||
sudo rm "$WEBROOT/index.lighttpd.html" 2>&1 >> "$LOG"
|
||||
else
|
||||
sudo mv "$WEBROOT/index.lighttpd.html" \
|
||||
"$WEBROOT/index.lighttpd.html.orig" 2>&1 >> "$LOG"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e "$WEBROOT/index.html" ] || [ -L "$WEBROOT/index.html" ] ; then
|
||||
if [ -e "$WEBROOT/index.html.orig" ] ; then
|
||||
sudo rm "$WEBROOT/index.html" 2>&1 >> "$LOG"
|
||||
else
|
||||
sudo mv "$WEBROOT/index.html" "$WEBROOT/index.html.orig" 2>&1 >> "$LOG"
|
||||
fi
|
||||
fi
|
||||
|
||||
sudo cp "$PIALERT_HOME/install/index.html" "$WEBROOT/index.html" 2>&1 >>"$LOG"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check Pi.Alert Installation Path
|
||||
# ------------------------------------------------------------------------------
|
||||
check_pialert_home() {
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
if [ ! -d "$INSTALL_DIR" ] ; then
|
||||
process_error "Installation path does not exists: $INSTALL_DIR"
|
||||
fi
|
||||
|
||||
if [ -e "$PIALERT_HOME" ] || [ -L "$PIALERT_HOME" ] ; then
|
||||
process_error "Pi.Alert path already exists: $PIALERT_HOME"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Move Logfile
|
||||
# ------------------------------------------------------------------------------
|
||||
move_logfile() {
|
||||
NEWLOG="$PIALERT_HOME/log/$LOG"
|
||||
|
||||
mkdir -p "$PIALERT_HOME/log"
|
||||
mv $LOG $NEWLOG
|
||||
|
||||
LOG="$NEWLOG"
|
||||
NEWLOG=""
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# ASK
|
||||
# ------------------------------------------------------------------------------
|
||||
msgbox() {
|
||||
LINE1=$(printf "%*s" $(((${#1}+$COLS-5)/2)) "$1")
|
||||
LINE2=$(printf "%*s" $(((${#2}+$COLS-5)/2)) "$2")
|
||||
|
||||
whiptail --title "Pi.Alert Installation" --msgbox "$LINE1\\n\\n$LINE2" \
|
||||
$ROWS $COLS
|
||||
}
|
||||
|
||||
ask_yesno() {
|
||||
LINE1=$(printf "%*s" $(((${#1}+$COLS-5)/2)) "$1")
|
||||
LINE2=$(printf "%*s" $(((${#2}+$COLS-5)/2)) "$2")
|
||||
|
||||
if [ "$3" = "YES" ]; then
|
||||
DEF_BUTTON=""
|
||||
else
|
||||
DEF_BUTTON="--defaultno"
|
||||
fi
|
||||
|
||||
if whiptail --title "Pi.Alert Installation" --yesno $DEF_BUTTON \
|
||||
"$LINE1\\n\\n$LINE2" $ROWS $COLS; then
|
||||
ANSWER=true
|
||||
else
|
||||
ANSWER=false
|
||||
fi
|
||||
}
|
||||
|
||||
ask_option() {
|
||||
MENU_ARGS=("$@")
|
||||
MENU_ARGS=("${MENU_ARGS[@]:1}")
|
||||
|
||||
ANSWER=$(whiptail --title "Pi.Alert Installation" --menu "$1" $ROWS $COLS \
|
||||
"${MENU_ARGS[@]}" 3>&2 2>&1 1>&3 || : )
|
||||
}
|
||||
|
||||
ask_input() {
|
||||
LINE1=$(printf "%*s" $(((${#1}+$COLS-5)/2)) "$1")
|
||||
LINE2=$(printf "%*s" $(((${#2}+$COLS-5)/2)) "$2")
|
||||
|
||||
ANSWER=$(whiptail --title "Pi.Alert Installation" --inputbox \
|
||||
"$LINE1\\n\\n$LINE2" $ROWS $COLS $3 3>&2 2>&1 1>&3 || : )
|
||||
|
||||
if [ "$ANSWER" = "" ] ; then
|
||||
ANSWER=$3
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Log
|
||||
# ------------------------------------------------------------------------------
|
||||
log() {
|
||||
echo "$1" | tee -a "$LOG"
|
||||
}
|
||||
|
||||
log_no_screen () {
|
||||
echo "$1" >> "$LOG"
|
||||
}
|
||||
|
||||
log_only_screen () {
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
print_msg() {
|
||||
log_no_screen ""
|
||||
log "$1"
|
||||
}
|
||||
|
||||
print_superheader() {
|
||||
log ""
|
||||
log "############################################################"
|
||||
log " $1"
|
||||
log "############################################################"
|
||||
}
|
||||
|
||||
print_header() {
|
||||
log ""
|
||||
log "------------------------------------------------------------"
|
||||
log " $1"
|
||||
log "------------------------------------------------------------"
|
||||
}
|
||||
|
||||
process_error() {
|
||||
log "\n"
|
||||
log "************************************************************"
|
||||
log "************************************************************"
|
||||
log "** ERROR INSTALLING PI.ALERT **"
|
||||
log "************************************************************"
|
||||
log "************************************************************"
|
||||
log ""
|
||||
log "$1"
|
||||
log ""
|
||||
log "Use 'cat $LOG' to view installation log"
|
||||
log ""
|
||||
|
||||
msgbox "****** ERROR INSTALLING Pi.ALERT ******" "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
main
|
||||
exit 0
|
||||
Reference in New Issue
Block a user