Compare commits
73 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b973d13c83 | ||
|
|
ae28886b2f | ||
|
|
ed0102b212 | ||
|
|
dff7171d3c | ||
|
|
4dd75fbd47 | ||
|
|
7583ad802b | ||
|
|
b1be970ff2 | ||
|
|
581d9c1e9f | ||
|
|
b38c2f5c16 | ||
|
|
d4b8f52138 | ||
|
|
b0138ef89f | ||
|
|
d6a742c6da | ||
|
|
43ed1376dc | ||
|
|
0a1ee8ba94 | ||
|
|
3501ebdf25 | ||
|
|
9e45441bf5 | ||
|
|
57105cb6a4 | ||
|
|
df33d07915 | ||
|
|
9ab7e01255 | ||
|
|
ecbd1a821a | ||
|
|
5781bb5c71 | ||
|
|
1c21a59a74 | ||
|
|
9b73c3a424 | ||
|
|
e5b3408377 | ||
|
|
d3c2c8699f | ||
|
|
b4acfff1b9 | ||
|
|
3d04cdbc57 | ||
|
|
e49dfc9c3d | ||
|
|
f3c8a5d407 | ||
|
|
a2f23d37ec | ||
|
|
cdb263e791 | ||
|
|
a983b374c9 | ||
|
|
40844c721c | ||
|
|
90242c8f3b | ||
|
|
5f73a286bb | ||
|
|
f8564f4dd7 | ||
|
|
78352ed5a4 | ||
|
|
bb4be279c8 | ||
|
|
9f73af8ce6 | ||
|
|
f6eedd84d8 | ||
|
|
cd9a1ac22a | ||
|
|
0e3f14dd9d | ||
|
|
dbe0a0548b | ||
|
|
e8f723d985 | ||
|
|
cc50d0f75e | ||
|
|
a473845242 | ||
|
|
bda526b202 | ||
|
|
9057e41ff8 | ||
|
|
75bb53fdd1 | ||
|
|
e7ebd9bab5 | ||
|
|
30aeab305d | ||
|
|
3e6d9847be | ||
|
|
3c34c822e7 | ||
|
|
424cf11752 | ||
|
|
8bf95aed5b | ||
|
|
2f9ccddd09 | ||
|
|
d0d5512e89 | ||
|
|
4c51e6cd43 | ||
|
|
35be1e65ea | ||
|
|
6b53dc54f5 | ||
|
|
3f0b7d9e2d | ||
|
|
f2b6cf9f0c | ||
|
|
1e6093fa50 | ||
|
|
5026b8c66e | ||
|
|
3a622b05be | ||
|
|
97ae38fbbf | ||
|
|
ec07af84a9 | ||
|
|
49f5dd3c39 | ||
|
|
f74246a1ec | ||
|
|
2cf457e145 | ||
|
|
d7913af341 | ||
|
|
0c55310ca8 | ||
|
|
87fbf1d587 |
40
README.md
@@ -36,16 +36,18 @@ Up to three scanning methods are used:
|
||||
## Components
|
||||
The system consists of two parts:
|
||||
|
||||
- **Back**, in charge of:
|
||||
### Back
|
||||
In charge of:
|
||||
- Scan the network searching connected devices using the scanning methods
|
||||
described
|
||||
described
|
||||
- Store the information in the DB
|
||||
- Report the changes detected by e-mail
|
||||
|
||||
| ![Report 1][report1] | ![Report 2][report2] |
|
||||
| -------------------- | -------------------- |
|
||||
|
||||
- **Front**, a web frontal that allows:
|
||||
### Front
|
||||
A web frontal that allows:
|
||||
- Manage the devices inventory and the characteristics
|
||||
- Display in a visual way all the information collected by the back
|
||||
- Sessions
|
||||
@@ -65,15 +67,25 @@ The system consists of two parts:
|
||||
|
||||
# Installation
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
Initially designed to run on a Raspberry PI, probably it can run on many other
|
||||
Initially designed to run on a Raspberry Pi, probably it can run on many other
|
||||
Linux distributions.
|
||||
- One-step Automated Install:
|
||||
#### `curl -sSL https://github.com/pucherot/Pi.Alert/raw/main/install/pialert_install.sh | bash`
|
||||
- [Installation Guide (step by step)](docs/INSTALL.md)
|
||||
|
||||
|
||||
## Device Management
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
|
||||
- [Device Management instructions](docs/DEVICE_MANAGEMENT.md)
|
||||
|
||||
[Instructions](doc/INSTALL.md)
|
||||
|
||||
|
||||
## Other useful info
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
|
||||
### [Versions History](docs/VERSIONS_HISTORY.md)
|
||||
|
||||
### Powered by:
|
||||
| Product | Objetive |
|
||||
| ------------ | -------------------------------------- |
|
||||
@@ -91,18 +103,20 @@ Linux distributions.
|
||||
|
||||
### License
|
||||
GPL 3.0
|
||||
[Read more here](doc/LICENSE.txt)
|
||||
[Read more here](LICENSE.txt)
|
||||
|
||||
### Contact
|
||||
pi.alert.application@gmail.com
|
||||
|
||||
***Suggestions and comments are welcome***
|
||||
|
||||
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
[main]: ./doc/img/1_devices.jpg "Main screen"
|
||||
[screen1]: ./doc/img/2_1_device_details.jpg "Screen 1"
|
||||
[screen2]: ./doc/img/2_2_device_sessions.jpg "Screen 2"
|
||||
[screen3]: ./doc/img/2_3_device_presence.jpg "Screen 3"
|
||||
[screen4]: ./doc/img/3_presence.jpg "Screen 4"
|
||||
[report1]: ./doc/img/4_report_1.jpg "Report sample 1"
|
||||
[report2]: ./doc/img/4_report_2.jpg "Report sample 2"
|
||||
[main]: ./docs/img/1_devices.jpg "Main screen"
|
||||
[screen1]: ./docs/img/2_1_device_details.jpg "Screen 1"
|
||||
[screen2]: ./docs/img/2_2_device_sessions.jpg "Screen 2"
|
||||
[screen3]: ./docs/img/2_3_device_presence.jpg "Screen 3"
|
||||
[screen4]: ./docs/img/3_presence.jpg "Screen 4"
|
||||
[report1]: ./docs/img/4_report_1.jpg "Report sample 1"
|
||||
[report2]: ./docs/img/4_report_2.jpg "Report sample 2"
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
VERSION = '2.50'
|
||||
VERSION_YEAR = '2020'
|
||||
VERSION_DATE = '2020-12-30'
|
||||
|
||||
DB_PATH = '/home/pi/pialert/db/pialert.db'
|
||||
LOG_PATH = '/home/pi/pialert/log'
|
||||
VENDORS_DB = '/usr/share/arp-scan/ieee-oui.txt'
|
||||
PA_FRONT_URL = 'http://pi.alert/deviceDetails.php?mac='
|
||||
PRINT_LOG = False
|
||||
|
||||
SMTP_SERVER = 'smtp.gmail.com'
|
||||
SMTP_PORT = 587
|
||||
SMTP_USER = 'user@gmail.com'
|
||||
SMTP_PASS = 'password'
|
||||
|
||||
REPORT_MAIL = False
|
||||
REPORT_FROM = 'Pi.Alert <' + SMTP_USER +'>'
|
||||
REPORT_TO = 'user@gmail.com'
|
||||
|
||||
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?'
|
||||
|
||||
PIHOLE_ACTIVE = False
|
||||
PIHOLE_DB = '/etc/pihole/pihole-FTL.db'
|
||||
DHCP_ACTIVE = False
|
||||
DHCP_LEASES = '/etc/pihole/dhcp.leases'
|
||||
@@ -1,7 +0,0 @@
|
||||
#
|
||||
# Pi.Alert cron
|
||||
#
|
||||
0 3 * * 1 python ~/pialert/back/pialert.py update_vendors >~/pialert/log/pialert.vendors.log 2>&1
|
||||
*/1 * * * * python ~/pialert/back/pialert.py internet_IP >~/pialert/log/pialert.IP.log 2>&1
|
||||
*/5 * * * * python ~/pialert/back/pialert.py 1 >~/pialert/log/pialert.1.log 2>&1
|
||||
*/15 * * * * python ~/pialert/back/pialert.py 15 >~/pialert/log/pialert.15.log 2>&1
|
||||
144
back/pialert.py
@@ -1,8 +1,13 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Pi.Alert v2.50 / 2020-12-30
|
||||
# Puche 2020
|
||||
# GNU GPLv3
|
||||
#-------------------------------------------------------------------------------
|
||||
# Pi.Alert v2.61 / 2021-01-25
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# pialert.py - Back module. Network scanner
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#===============================================================================
|
||||
@@ -27,8 +32,15 @@ import csv
|
||||
#===============================================================================
|
||||
# CONFIG CONSTANTS
|
||||
#===============================================================================
|
||||
PIALERT_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
execfile (PIALERT_PATH + "/pialert.conf")
|
||||
PIALERT_BACK_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
PIALERT_PATH = PIALERT_BACK_PATH + "/.."
|
||||
|
||||
if (sys.version_info > (3,0)):
|
||||
exec(open(PIALERT_PATH + "/config/version.conf").read())
|
||||
exec(open(PIALERT_PATH + "/config/pialert.conf").read())
|
||||
else:
|
||||
execfile (PIALERT_PATH + "/config/version.conf")
|
||||
execfile (PIALERT_PATH + "/config/pialert.conf")
|
||||
|
||||
|
||||
#===============================================================================
|
||||
@@ -46,7 +58,6 @@ def main ():
|
||||
print ('---------------------------------------------------------')
|
||||
|
||||
# Initialize global variables
|
||||
# PIALERT_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
log_timestamp = datetime.datetime.now()
|
||||
|
||||
# DB
|
||||
@@ -68,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()
|
||||
|
||||
@@ -152,16 +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)
|
||||
|
||||
# Using 'curl' instead of 'dig'
|
||||
curl_args = ['curl', '-s', 'https://diagnostic.opendns.com/myip']
|
||||
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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -237,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_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']
|
||||
@@ -292,9 +309,12 @@ def update_devices_MAC_vendors ():
|
||||
#-------------------------------------------------------------------------------
|
||||
def query_MAC_vendor (pMAC):
|
||||
try :
|
||||
# BUGFIX #6 - Fix pMAC parameter as numbers
|
||||
pMACstr = str(pMAC)
|
||||
|
||||
# Check MAC parameter
|
||||
mac = pMAC.replace (':','')
|
||||
if len(pMAC) != 17 or len(mac) != 12 :
|
||||
mac = pMACstr.replace (':','')
|
||||
if len(pMACstr) != 17 or len(mac) != 12 :
|
||||
return -2
|
||||
|
||||
# Search vendor in HW Vendors DB
|
||||
@@ -447,8 +467,28 @@ def execute_arpscan (pRetries):
|
||||
devices_list = [device.groupdict()
|
||||
for device in re.finditer (re_pattern, arpscan_output)]
|
||||
|
||||
# Bugfix #5 - Delete duplicated MAC's with different IP's
|
||||
# TEST - Force duplicated device
|
||||
# devices_list.append(devices_list[0])
|
||||
# Delete duplicate MAC
|
||||
unique_mac = []
|
||||
unique_devices = []
|
||||
|
||||
for device in devices_list :
|
||||
if device['mac'] not in unique_mac:
|
||||
unique_mac.append(device['mac'])
|
||||
unique_devices.append(device)
|
||||
|
||||
# DEBUG
|
||||
# print (devices_list)
|
||||
# print (unique_mac)
|
||||
# print (unique_devices)
|
||||
# print (len(devices_list))
|
||||
# print (len(unique_mac))
|
||||
# print (len(unique_devices))
|
||||
|
||||
# return list
|
||||
return devices_list
|
||||
return unique_devices
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
def copy_pihole_network ():
|
||||
@@ -486,10 +526,17 @@ def read_DHCP_leases ():
|
||||
return
|
||||
|
||||
# Read DHCP Leases
|
||||
with open(DHCP_LEASES) as f:
|
||||
reader = csv.reader(f, delimiter=' ')
|
||||
data = [(col1, col2, col3, col4, col5)
|
||||
for col1, col2, col3, col4, col5 in reader]
|
||||
# Bugfix #1 - dhcp.leases: lines with different number of columns (5 col)
|
||||
data = []
|
||||
with open(DHCP_LEASES, 'r') as f:
|
||||
for line in f:
|
||||
row = line.rstrip().split()
|
||||
if len(row) == 5 :
|
||||
data.append (row)
|
||||
# with open(DHCP_LEASES) as f:
|
||||
# reader = csv.reader(f, delimiter=' ')
|
||||
# data = [(col1, col2, col3, col4, col5)
|
||||
# for col1, col2, col3, col4, col5 in reader]
|
||||
|
||||
# Insert into PiAlert table
|
||||
sql.execute ("DELETE FROM DHCP_Leases")
|
||||
@@ -638,11 +685,12 @@ def create_new_devices ():
|
||||
|
||||
# Pi-hole - Insert events for new devices
|
||||
# NOT STRICYLY NECESARY (Devices can be created through Current_Scan)
|
||||
# Bugfix #2 - Pi-hole devices w/o IP
|
||||
print_log ('New devices - 3 Pi-hole Events')
|
||||
sql.execute ("""INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime,
|
||||
eve_EventType, eve_AdditionalInfo,
|
||||
eve_PendingAlertEmail)
|
||||
SELECT PH_MAC, PH_IP, ?, 'New Device',
|
||||
SELECT PH_MAC, IFNULL (PH_IP,'-'), ?, 'New Device',
|
||||
'(Pi-Hole) ' || PH_Vendor, 1
|
||||
FROM PiHole_Network
|
||||
WHERE NOT EXISTS (SELECT 1 FROM Devices
|
||||
@@ -650,13 +698,14 @@ def create_new_devices ():
|
||||
(startTime, ) )
|
||||
|
||||
# Pi-hole - Create New Devices
|
||||
# Bugfix #2 - Pi-hole devices w/o IP
|
||||
print_log ('New devices - 4 Pi-hole Create devices')
|
||||
sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor,
|
||||
dev_LastIP, dev_FirstConnection, dev_LastConnection,
|
||||
dev_ScanCycle, dev_AlertEvents, dev_AlertDeviceDown,
|
||||
dev_PresentLastScan)
|
||||
SELECT PH_MAC, PH_Name, PH_Vendor, PH_IP, ?, ?,
|
||||
1, 1, 0, 1
|
||||
SELECT PH_MAC, PH_Name, PH_Vendor, IFNULL (PH_IP,'-'),
|
||||
?, ?, 1, 1, 0, 1
|
||||
FROM PiHole_Network
|
||||
WHERE NOT EXISTS (SELECT 1 FROM Devices
|
||||
WHERE dev_MAC = PH_MAC) """,
|
||||
@@ -675,16 +724,39 @@ def create_new_devices ():
|
||||
|
||||
# DHCP Leases - Create New Devices
|
||||
print_log ('New devices - 6 DHCP Leases Create devices')
|
||||
sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor,
|
||||
dev_LastIP, dev_FirstConnection, dev_LastConnection,
|
||||
# BUGFIX #23 - Duplicated MAC in DHCP.Leases
|
||||
# TEST - Force Duplicated MAC
|
||||
# sql.execute ("""INSERT INTO DHCP_Leases VALUES
|
||||
# (1610700000, 'TEST1', '10.10.10.1', 'Test 1', '*')""")
|
||||
# sql.execute ("""INSERT INTO DHCP_Leases VALUES
|
||||
# (1610700000, 'TEST2', '10.10.10.2', 'Test 2', '*')""")
|
||||
sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_LastIP,
|
||||
dev_Vendor, dev_FirstConnection, dev_LastConnection,
|
||||
dev_ScanCycle, dev_AlertEvents, dev_AlertDeviceDown,
|
||||
dev_PresentLastScan)
|
||||
SELECT DHCP_MAC, DHCP_Name, '(unknown)', DHCP_IP, ?, ?,
|
||||
1, 1, 0, 1
|
||||
FROM DHCP_Leases
|
||||
SELECT DISTINCT DHCP_MAC,
|
||||
(SELECT DHCP_Name FROM DHCP_Leases AS D2
|
||||
WHERE D2.DHCP_MAC = D1.DHCP_MAC
|
||||
ORDER BY DHCP_DateTime DESC LIMIT 1),
|
||||
(SELECT DHCP_IP FROM DHCP_Leases AS D2
|
||||
WHERE D2.DHCP_MAC = D1.DHCP_MAC
|
||||
ORDER BY DHCP_DateTime DESC LIMIT 1),
|
||||
'(unknown)', ?, ?, 1, 1, 0, 1
|
||||
FROM DHCP_Leases AS D1
|
||||
WHERE NOT EXISTS (SELECT 1 FROM Devices
|
||||
WHERE dev_MAC = DHCP_MAC) """,
|
||||
(startTime, startTime) )
|
||||
|
||||
# sql.execute ("""INSERT INTO Devices (dev_MAC, dev_name, dev_Vendor,
|
||||
# dev_LastIP, dev_FirstConnection, dev_LastConnection,
|
||||
# dev_ScanCycle, dev_AlertEvents, dev_AlertDeviceDown,
|
||||
# dev_PresentLastScan)
|
||||
# SELECT DHCP_MAC, DHCP_Name, '(unknown)', DHCP_IP, ?, ?,
|
||||
# 1, 1, 0, 1
|
||||
# FROM DHCP_Leases
|
||||
# WHERE NOT EXISTS (SELECT 1 FROM Devices
|
||||
# WHERE dev_MAC = DHCP_MAC) """,
|
||||
# (startTime, startTime) )
|
||||
print_log ('New Devices end')
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -984,12 +1056,12 @@ def email_reporting ():
|
||||
openDB()
|
||||
|
||||
# Open text Template
|
||||
template_file = open(PIALERT_PATH + '/report_template.txt', 'r')
|
||||
template_file = open(PIALERT_BACK_PATH + '/report_template.txt', 'r')
|
||||
mail_text = template_file.read()
|
||||
template_file.close()
|
||||
|
||||
# Open html Template
|
||||
template_file = open(PIALERT_PATH + '/report_template.html', 'r')
|
||||
template_file = open(PIALERT_BACK_PATH + '/report_template.html', 'r')
|
||||
mail_html = template_file.read()
|
||||
template_file.close()
|
||||
|
||||
@@ -1034,7 +1106,7 @@ def email_reporting ():
|
||||
eventAlert['eve_EventType'], eventAlert['eve_DateTime'],
|
||||
eventAlert['eve_IP'], eventAlert['eve_AdditionalInfo'])
|
||||
mail_html_Internet += html_line_template.format (
|
||||
PA_FRONT_URL, eventAlert['eve_MAC'],
|
||||
REPORT_DEVICE_URL, eventAlert['eve_MAC'],
|
||||
eventAlert['eve_EventType'], eventAlert['eve_DateTime'],
|
||||
eventAlert['eve_IP'], eventAlert['eve_AdditionalInfo'])
|
||||
|
||||
@@ -1062,7 +1134,7 @@ def email_reporting ():
|
||||
eventAlert['eve_IP'], eventAlert['dev_Name'],
|
||||
eventAlert['eve_AdditionalInfo'])
|
||||
mail_html_new_devices += html_line_template.format (
|
||||
PA_FRONT_URL, eventAlert['eve_MAC'], eventAlert['eve_MAC'],
|
||||
REPORT_DEVICE_URL, eventAlert['eve_MAC'], eventAlert['eve_MAC'],
|
||||
eventAlert['eve_DateTime'], eventAlert['eve_IP'],
|
||||
eventAlert['dev_Name'], eventAlert['eve_AdditionalInfo'])
|
||||
|
||||
@@ -1089,7 +1161,7 @@ def email_reporting ():
|
||||
eventAlert['eve_MAC'], eventAlert['eve_DateTime'],
|
||||
eventAlert['eve_IP'], eventAlert['dev_Name'])
|
||||
mail_html_devices_down += html_line_template.format (
|
||||
PA_FRONT_URL, eventAlert['eve_MAC'], eventAlert['eve_MAC'],
|
||||
REPORT_DEVICE_URL, eventAlert['eve_MAC'], eventAlert['eve_MAC'],
|
||||
eventAlert['eve_DateTime'], eventAlert['eve_IP'],
|
||||
eventAlert['dev_Name'])
|
||||
|
||||
@@ -1119,7 +1191,7 @@ def email_reporting ():
|
||||
eventAlert['eve_IP'], eventAlert['eve_EventType'],
|
||||
eventAlert['dev_Name'], eventAlert['eve_AdditionalInfo'])
|
||||
mail_html_events += html_line_template.format (
|
||||
PA_FRONT_URL, eventAlert['eve_MAC'], eventAlert['eve_MAC'],
|
||||
REPORT_DEVICE_URL, eventAlert['eve_MAC'], eventAlert['eve_MAC'],
|
||||
eventAlert['eve_DateTime'], eventAlert['eve_IP'],
|
||||
eventAlert['eve_EventType'], eventAlert['dev_Name'],
|
||||
eventAlert['eve_AdditionalInfo'])
|
||||
@@ -1201,7 +1273,7 @@ def write_file (pPath, pText):
|
||||
file.close()
|
||||
else:
|
||||
file = open (pPath, 'w', encoding='utf-8')
|
||||
file.write (ptext)
|
||||
file.write (pText)
|
||||
file.close()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
<!-- ---------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# repot_template.html - Back module. Template to email reporting in HTML format
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#--------------------------------------------------------------------------- -->
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
@@ -101,9 +110,9 @@
|
||||
<td>
|
||||
<table width=100% border=0 bgcolor=#70AD47 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 12px; font-weight: bold; color:#385723">
|
||||
<tr>
|
||||
<td width=25% style="text-align:Left"> Puche <PIALERT_YEAR></td>
|
||||
<td width=50% style="text-align:center"> Pi.Alert <PIALERT_VERSION> / <PIALERT_VERSION_DATE> </td>
|
||||
<td width=25% style="text-align:right"> GNU GPLv3</td>
|
||||
<td width=25% style="text-align:Left"> <span style="display:inline-block; transform: rotate(180deg)">©</span> <PIALERT_YEAR> Puche</td>
|
||||
<td width=50% style="text-align:center"> Pi.Alert <PIALERT_VERSION> (<PIALERT_VERSION_DATE>) </td>
|
||||
<td width=25% style="text-align:right"> GNU GPLv3</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
|
||||
@@ -24,4 +24,4 @@ Events
|
||||
<TABLE_EVENTS>
|
||||
</SECTION_EVENTS>
|
||||
----------------------------------------------------------------------
|
||||
Puche <PIALERT_YEAR> Pi.Alert <PIALERT_VERSION> / <PIALERT_VERSION_DATE> GNU GPLv3
|
||||
(?) <PIALERT_YEAR> Puche Pi.Alert <PIALERT_VERSION> (<PIALERT_VERSION_DATE>) GNU GPLv3
|
||||
|
||||
62
back/update_vendors.sh
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/bin/sh
|
||||
# ------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# vendors_db_update.sh - Back module. IEEE Vendors db update
|
||||
# ------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Main directories to update:
|
||||
# /usr/share/arp-scan
|
||||
# /usr/share/ieee-data
|
||||
# /var/lib/ieee-data
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
echo Updating... /usr/share/ieee-data/
|
||||
cd /usr/share/ieee-data/
|
||||
|
||||
sudo mkdir -p 2_backup
|
||||
sudo cp *.txt 2_backup
|
||||
sudo cp *.csv 2_backup
|
||||
|
||||
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 $1 -# -O http://standards-oui.ieee.org/oui28/mam.csv
|
||||
sudo curl $1 -# -O http://standards-oui.ieee.org/oui28/mam.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 $1 -# -O http://standards-oui.ieee.org/oui/oui.csv
|
||||
sudo curl $1 -# -O http://standards-oui.ieee.org/oui/oui.txt
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
echo ""
|
||||
echo Updating... /usr/share/arp-scan/
|
||||
cd /usr/share/arp-scan
|
||||
|
||||
sudo mkdir -p 2_backup
|
||||
sudo cp *.txt 2_backup
|
||||
|
||||
# Update from /usb/lib/ieee-data
|
||||
sudo get-iab -v
|
||||
sudo get-oui -v
|
||||
|
||||
# Update from ieee website
|
||||
# sudo get-iab -v -u http://standards-oui.ieee.org/iab/iab.txt
|
||||
# sudo get-oui -v -u http://standards-oui.ieee.org/oui/oui.txt
|
||||
|
||||
# Update from ieee website develop
|
||||
# sudo get-iab -v -u http://standards.ieee.org/develop/regauth/iab/iab.txt
|
||||
# sudo get-oui -v -u http://standards.ieee.org/develop/regauth/oui/oui.txt
|
||||
|
||||
# Update from Sanitized oui (linuxnet.ca)
|
||||
# sudo get-oui -v -u https://linuxnet.ca/ieee/oui.txt
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Update MAC Vendor DB
|
||||
#
|
||||
# /usr/share/arp-scan
|
||||
# /usr/share/ieee-data
|
||||
# /var/lib/ieee-data
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
echo Updating... /usr/share/ieee-data/
|
||||
cd /usr/share/ieee-data/
|
||||
|
||||
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 -# -O http://standards-oui.ieee.org/oui28/mam.csv
|
||||
sudo curl -# -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 -# -O http://standards-oui.ieee.org/oui/oui.csv
|
||||
sudo curl -# -O http://standards-oui.ieee.org/oui/oui.txt
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
echo ""
|
||||
echo Updating... /usr/share/arp-scan/
|
||||
cd /usr/share/arp-scan
|
||||
|
||||
sudo mkdir -p 2_backup
|
||||
sudo cp *.txt 2_backup
|
||||
|
||||
# Update from /usb/lib/ieee-data
|
||||
sudo get-iab -v
|
||||
sudo get-oui -v
|
||||
|
||||
# Update from ieee website
|
||||
# sudo get-iab -v -u http://standards-oui.ieee.org/iab/iab.txt
|
||||
# sudo get-oui -v -u http://standards-oui.ieee.org/oui/oui.txt
|
||||
|
||||
# Update from ieee website develop
|
||||
# sudo get-iab -v -u http://standards.ieee.org/develop/regauth/iab/iab.txt
|
||||
# sudo get-oui -v -u http://standards.ieee.org/develop/regauth/oui/oui.txt
|
||||
|
||||
# Update from Sanitized oui (linuxnet.ca)
|
||||
# sudo get-oui -v -u https://linuxnet.ca/ieee/oui.txt
|
||||
|
||||
37
config/pialert.conf
Normal file
@@ -0,0 +1,37 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# pialert.conf - Back module. Configuration file
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
PIALERT_PATH = '/home/pi/pialert'
|
||||
DB_PATH = PIALERT_PATH + '/db/pialert.db'
|
||||
LOG_PATH = PIALERT_PATH + '/log'
|
||||
VENDORS_DB = '/usr/share/arp-scan/ieee-oui.txt'
|
||||
PRINT_LOG = False
|
||||
|
||||
SMTP_SERVER = 'smtp.gmail.com'
|
||||
SMTP_PORT = 587
|
||||
SMTP_USER = 'user@gmail.com'
|
||||
SMTP_PASS = 'password'
|
||||
|
||||
REPORT_MAIL = False
|
||||
REPORT_FROM = 'Pi.Alert <' + SMTP_USER +'>'
|
||||
REPORT_TO = 'user@gmail.com'
|
||||
REPORT_DEVICE_URL = 'http://pi.alert/deviceDetails.php?mac='
|
||||
|
||||
# QUERY_MYIP_SERVER = 'https://diagnostic.opendns.com/myip'
|
||||
QUERY_MYIP_SERVER = 'http://ipv4.icanhazip.com'
|
||||
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?'
|
||||
|
||||
PIHOLE_ACTIVE = False
|
||||
PIHOLE_DB = '/etc/pihole/pihole-FTL.db'
|
||||
DHCP_ACTIVE = False
|
||||
DHCP_LEASES = '/etc/pihole/dhcp.leases'
|
||||
3
config/version.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
VERSION = '2.61'
|
||||
VERSION_YEAR = '2021'
|
||||
VERSION_DATE = '2021-01-25'
|
||||
BIN
db/pialert.db
192
doc/INSTALL.md
@@ -1,192 +0,0 @@
|
||||
# Pi.Alert Installation
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
Initially designed to run on a Raspberry PI, probably it can run on many other
|
||||
Linux distributions.
|
||||
|
||||
Stimated time: 20'
|
||||
|
||||
### Dependencies
|
||||
| Dependency | Comments |
|
||||
| ---------- | -------------------------------------------------------- |
|
||||
| Lighttpd | Probably works on other webservers / not tested |
|
||||
| arp-scan | Required for Scan Method 1 |
|
||||
| Pi.hole | Optional. Scan Method 2. Check devices doing DNS queries |
|
||||
| dnsmasq | Optional. Scan Method 3. Check devices using DHCP server |
|
||||
| IEEE HW DB | Necessary to identified Device vendor |
|
||||
|
||||
# Installation process
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
|
||||
## Raspberry Setup
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
1 - Install 'Raspberry Pi OS'
|
||||
- Instructions https://www.raspberrypi.org/documentation/installation/installing-images/
|
||||
- *Lite version (without Descktop) is enough for Pi.Alert*
|
||||
|
||||
2 - Activate ssh
|
||||
- Create a empty file with name 'ssh' in the boot partition of the SD
|
||||
|
||||
3 - Start the raspberry
|
||||
|
||||
4 - Login to the system with pi user
|
||||
```
|
||||
user: pi
|
||||
password: raspberry
|
||||
```
|
||||
|
||||
5 - Change de default password of pi user
|
||||
```
|
||||
passwd
|
||||
```
|
||||
|
||||
6 - Setup the basic configuration
|
||||
```
|
||||
sudo raspi-config
|
||||
```
|
||||
|
||||
7 - Optionally, configure a static IP in raspi-config
|
||||
|
||||
8 - Update the OS
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get upgrade
|
||||
sudo reboot
|
||||
```
|
||||
|
||||
## Pi-hole Setup
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
1- Links & Doc
|
||||
- https://pi-hole.net/
|
||||
- https://github.com/pi-hole/pi-hole
|
||||
- https://github.com/pi-hole/pi-hole/#one-step-automated-install
|
||||
|
||||
2 - Login to the system with pi user
|
||||
|
||||
3 - Install Pi-hole
|
||||
```
|
||||
curl -sSL https://install.pi-hole.net | bash
|
||||
```
|
||||
- Mark "Install web admin interface"
|
||||
- Mark "Install web server lighttpd"
|
||||
|
||||
4 - Configure Pi-hole admin password
|
||||
```
|
||||
pihole -a -p PASSWORD
|
||||
```
|
||||
|
||||
5 - Connect to web admin panel
|
||||
- http://192.168.1.x/admin/
|
||||
- (*replace the 192.168.1.x with your Raspberry IP*)
|
||||
|
||||
6 - Activate DHCP server
|
||||
- Pi-hole -> Settings -> DHCP -> Mark "DHCP server enabled"
|
||||
|
||||
7 - Add pi.alert DNS Record
|
||||
- Pi-hole -> Local DNS -> DNS Records -> Add new domain /IP
|
||||
- pi.alert 192.168.1.x
|
||||
- (*replace the 192.168.1.x with your Raspberry IP*)
|
||||
|
||||
8 - Deactivate your current DHCP Server (*Normaly at your router or AP*)
|
||||
|
||||
9 - Renew your computer IP to unsure you are using the new DHCP and DNS server
|
||||
- Windows: cmd -> ipconfig /renew
|
||||
- Linux: shell -> sudo dhclient -r; sudo dhclient
|
||||
- Mac: Apple menu -> System Preferences -> Network -> Select the network -> Advanced -> TCP/IP -> Renew DHCP Lease
|
||||
|
||||
## arp-scan & Python
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
1 - Install arp-scan utility and test
|
||||
```
|
||||
sudo apt-get install arp-scan
|
||||
sudo arp-scan -l
|
||||
```
|
||||
|
||||
2 - Install Python & packages
|
||||
```
|
||||
sudo apt-get install python-setuptools
|
||||
sudo apt install python-pip
|
||||
|
||||
pip install netaddr
|
||||
pip install dpkt
|
||||
pip install MacLookup
|
||||
```
|
||||
|
||||
|
||||
## Pi.Alert
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
1- Download Pi.Alert and uncmompress
|
||||
```
|
||||
curl -LO https://github.com/pucherot/Pi.Alert/raw/main/install/pialert_latest.tar
|
||||
tar xvf pialert_latest.tar
|
||||
rm pialert_latest.tar
|
||||
```
|
||||
|
||||
2 - Public the front portal
|
||||
```
|
||||
sudo ln -s /home/pi/pialert/front /var/www/html/pialert
|
||||
```
|
||||
|
||||
3 - Update lighttp config
|
||||
```
|
||||
sudo sh -c "printf '\n\n\$HTTP[\"host\"] == \"pi.alert\" {\n server.document-root = \"/var/www/html/pialert/\"\n}\n' >> /etc/lighttpd/external.conf"
|
||||
sudo /etc/init.d/lighttpd restart
|
||||
```
|
||||
|
||||
4 - If you want to use email reporting with gmail
|
||||
- Go to your Google Account https://myaccount.google.com/
|
||||
- On the left navigation panel, click Security
|
||||
- On the bottom of the page, in the Less secure app access panel, click Turn on access
|
||||
- Click Save button
|
||||
|
||||
5 - Config Pialert parameters
|
||||
```
|
||||
nano ~/pialert/back/pialert.conf
|
||||
```
|
||||
- if you want to use email reporting, configure this parameters
|
||||
```
|
||||
REPORT_MAIL = True
|
||||
SMTP_USER = 'user@gmail.com'
|
||||
SMTP_PASS = 'password'
|
||||
REPORT_TO = 'user@gmail.com'
|
||||
```
|
||||
|
||||
- if you want to update yout Dynamic DNS, configure this parameters
|
||||
```
|
||||
DDNS_ACTIVE = True
|
||||
DDNS_DOMAIN = 'your_domain.freeddns.org'
|
||||
DDNS_USER = 'dynu_user'
|
||||
DDNS_PASSWORD = 'A0000000B0000000C0000000D0000000'
|
||||
DDNS_UPDATE_URL = 'https://api.dynu.com/nic/update?'
|
||||
```
|
||||
|
||||
- if you have installed Pi.hole and DHCP, activate this parameters
|
||||
```
|
||||
PIHOLE_ACTIVE = True
|
||||
DHCP_ACTIVE = True
|
||||
```
|
||||
|
||||
6 - Update vendors DB
|
||||
```
|
||||
python ~/pialert/back/pialert.py update_vendors
|
||||
```
|
||||
|
||||
7 - Test Pi.Alert Scan
|
||||
```
|
||||
python ~/pialert/back/pialert.py internet_IP
|
||||
python ~/pialert/back/pialert.py 1
|
||||
```
|
||||
|
||||
8 - Add crontab jobs
|
||||
```
|
||||
(crontab -l 2>/dev/null; cat ~/pialert/back/pialert.cron) | crontab -
|
||||
```
|
||||
|
||||
9 - Use admin panel to configure the devices
|
||||
- http://pi.alert/
|
||||
|
||||
### License
|
||||
GPL 3.0
|
||||
[Read more here](LICENSE.txt)
|
||||
|
||||
### Contact
|
||||
pi.alert.application@gmail.com
|
||||
95
docs/DEVICE_MANAGEMENT.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# Pi.Alert - Device Management
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
To edit device information:
|
||||
- Select "Devices" in the menu on the left of the screen
|
||||
- Find the device you want to edit in the central table
|
||||
- Go to the device page by clicking on the device name or status
|
||||
- Press "Details" tab of the device
|
||||
- Edit the device data
|
||||
- Press the "Save" button
|
||||
|
||||
|
||||
![Device Details][screen1]
|
||||
|
||||
|
||||
## Main Info
|
||||
- **MAC**: MAC addres of the device. Not editable.
|
||||
- **Name**: Friendly device name
|
||||
- **Owner**: Device owner (The list is self-populated with existing owners)
|
||||
- **Type**: Select a device type from the dropdown list (Smartphone, Table,
|
||||
Laptop, TV, router, ....) or type a new device type
|
||||
- **Vendor**: Automatically updated by Pi.Alert
|
||||
- **Favorite**: Mark the device as favorite and then it will appears at the
|
||||
begining of the device list
|
||||
- **Group**: Select a grouper ('Always on', 'Personal', Friends') or type
|
||||
your own Group name
|
||||
- **Comments**: Type any comments for the device
|
||||
|
||||
## Session Info
|
||||
- **Status**: Show device status : On-line / Off-Line
|
||||
- **First Session**: Date and time of the first connection
|
||||
- **Last Session**: Date and time of the last connection
|
||||
- **Last IP**: Last known IP used during the last connection
|
||||
- **Static IP**: Check this box to identify devices that always use the
|
||||
same IP
|
||||
|
||||
## Events & Alerts config
|
||||
- **Scan Cycle**: Select the scan cycle: 0, 1', 15'
|
||||
- Some devices do not respond to all ARP packets, for this cases is better
|
||||
to use a 15' cycle.
|
||||
- **For Apple devices I recommend using 15' cycle**
|
||||
- **Alert All Events**: Send a notification in each event (connection,
|
||||
disconnection, IP Changed, ...)
|
||||
- **Alert Down**: Send a notification when the device is down
|
||||
- *(Userful with "always connected" devices: Router, AP, Camera, Alexa,
|
||||
...)*
|
||||
- **Skip repeated notifications during**: Do not send more than one
|
||||
notification to this device for X hours
|
||||
- *(Useful to avoid notification saturation on devices that frequently
|
||||
connects and disconnects)*
|
||||
|
||||
# Privacy & Random MAC's
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
|
||||
The latest versions of some operating systems (IOS and Android) incorporate a
|
||||
new & interesting functionality to improve privacy: **Random MACs**.
|
||||
|
||||
This functionality allows you to **hide the true MAC** of the device and
|
||||
**assign a random MAC** when we connect to WIFI networks.
|
||||
|
||||
This behavior is especially useful when connecting to WIFI's that we do not
|
||||
know, but it **is totally useless when connecting to our own WIFI's** or known
|
||||
networks.
|
||||
|
||||
**I recommend disabling this operation when connecting our devices to our own
|
||||
WIFI's**, in this way, Pi.Alert will be able to identify the device, and it
|
||||
will not identify it as a new device every so often (every time IOS or Android
|
||||
decides to change the MAC).
|
||||
|
||||
### IOS
|
||||
![ios][ios]
|
||||
|
||||
- [Use private Wi-Fi addresses in iOS 14](https://support.apple.com/en-us/HT211227)
|
||||
|
||||
### Android
|
||||
![Android][Android]
|
||||
|
||||
- [How to Disable MAC Randomization in Android 10](https://support.boingo.com/s/article/How-to-Disable-MAC-Randomization-in-Android-10-Android-Q)
|
||||
- [How do I disable random Wi-Fi MAC address on Android 10](https://support.plume.com/hc/en-gb/articles/360052070714-How-do-I-disable-random-Wi-Fi-MAC-address-on-Android-10-)
|
||||
|
||||
### License
|
||||
GPL 3.0
|
||||
[Read more here](../LICENSE.txt)
|
||||
|
||||
### Contact
|
||||
pi.alert.application@gmail.com
|
||||
|
||||
***Suggestions and comments are welcome***
|
||||
|
||||
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
[main]: ./img/1_devices.jpg "Main screen"
|
||||
[screen1]: ./img/2_1_device_details.jpg "Screen 1"
|
||||
[ios]: https://9to5mac.com/wp-content/uploads/sites/6/2020/08/how-to-use-private-wifi-mac-address-iphone-ipad.png?resize=2048,1009 "ios"
|
||||
[Android]: ./img/android_random_mac.jpg "Android"
|
||||
|
||||
302
docs/INSTALL.md
Normal file
@@ -0,0 +1,302 @@
|
||||
# Pi.Alert Installation Guide
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
Initially designed to run on a Raspberry PI, probably it can run on many other
|
||||
Linux distributions.
|
||||
|
||||
Estimated time: 20'
|
||||
|
||||
### Dependencies
|
||||
| Dependency | Comments |
|
||||
| ---------- | -------------------------------------------------------- |
|
||||
| Lighttpd | Probably works on other webservers / not tested |
|
||||
| arp-scan | Required for Scan Method 1 |
|
||||
| Pi.hole | Optional. Scan Method 2. Check devices doing DNS queries |
|
||||
| dnsmasq | Optional. Scan Method 3. Check devices using DHCP server |
|
||||
| IEEE HW DB | Necessary to identified Device vendor |
|
||||
|
||||
# One-step Automated Install:
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
### `curl -sSL https://github.com/pucherot/Pi.Alert/raw/main/install/pialert_install.sh | bash`
|
||||
|
||||
# Installation process (step by step)
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
|
||||
## Raspberry Setup
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
1.1 - Install 'Raspberry Pi OS'
|
||||
- Instructions https://www.raspberrypi.org/documentation/installation/installing-images/
|
||||
- *Lite version (without Descktop) is enough for Pi.Alert*
|
||||
|
||||
1.2 - Activate ssh
|
||||
- Create a empty file with name 'ssh' in the boot partition of the SD
|
||||
|
||||
1.3 - Start the raspberry
|
||||
|
||||
1.4 - Login to the system with pi user
|
||||
```
|
||||
user: pi
|
||||
password: raspberry
|
||||
```
|
||||
|
||||
1.5 - Change the default password of pi user
|
||||
```
|
||||
passwd
|
||||
```
|
||||
|
||||
1.6 - Setup the basic configuration
|
||||
```
|
||||
sudo raspi-config
|
||||
```
|
||||
|
||||
1.7 - Optionally, configure a static IP in raspi-config
|
||||
|
||||
1.8 - Update the OS
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get upgrade
|
||||
sudo shutdown -r now
|
||||
```
|
||||
|
||||
|
||||
## Pi-hole Setup (optional)
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
2.1 - Links & Doc
|
||||
- https://pi-hole.net/
|
||||
- https://github.com/pi-hole/pi-hole
|
||||
- https://github.com/pi-hole/pi-hole/#one-step-automated-install
|
||||
|
||||
2.2 - Login to the system with pi user
|
||||
|
||||
2.3 - Install Pi-hole
|
||||
```
|
||||
curl -sSL https://install.pi-hole.net | bash
|
||||
```
|
||||
- Select "Install web admin interface"
|
||||
- Select "Install web server lighttpd"
|
||||
|
||||
2.4 - Configure Pi-hole admin password
|
||||
```
|
||||
pihole -a -p PASSWORD
|
||||
```
|
||||
|
||||
2.5 - Connect to web admin panel
|
||||
```
|
||||
hostname -I
|
||||
```
|
||||
- http://192.168.1.x/admin/
|
||||
- (*replace 192.168.1.x with your Raspberry IP*)
|
||||
|
||||
2.6 - Activate DHCP server
|
||||
- Pi-hole admin portal -> Settings -> DHCP -> Mark "DHCP server enabled"
|
||||
|
||||
2.7 - Add pi.alert DNS Record
|
||||
```
|
||||
hostname -I
|
||||
```
|
||||
- Pi-hole admin portal -> Local DNS -> DNS Records -> Add new domain /IP
|
||||
- pi.alert 192.168.1.x
|
||||
- (*replace 192.168.1.x with your Raspberry IP*)
|
||||
|
||||
2.8 - Deactivate your current DHCP Server (*Normaly at your router or AP*)
|
||||
|
||||
2.9 - Renew your computer IP to unsure you are using the new DHCP and DNS server
|
||||
- Windows: cmd -> ipconfig /renew
|
||||
- Linux: shell -> sudo dhclient -r; sudo dhclient
|
||||
- Mac: Apple menu -> System Preferences -> Network -> Select the network
|
||||
-> Advanced -> TCP/IP -> Renew DHCP Lease
|
||||
|
||||
|
||||
## Lighttpd & PHP
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
If you have installed Pi.hole, lighttpd and PHP are already installed and this
|
||||
block is not necessary
|
||||
|
||||
3.1 - Install lighttpd
|
||||
```
|
||||
sudo apt-get install lighttpd -y
|
||||
```
|
||||
|
||||
3.2 - If Pi.Alert will be the only site available in this webserver, you can
|
||||
redirect the default server page to pialert subfolder
|
||||
```
|
||||
sudo mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.html.old
|
||||
sudo ln -s ~/pialert/install/index.html /var/www/html/index.html
|
||||
```
|
||||
|
||||
3.3 - Install PHP
|
||||
```
|
||||
sudo apt-get install php php-cgi php-fpm php-sqlite3 -y
|
||||
```
|
||||
|
||||
3.4 - Activate PHP
|
||||
```
|
||||
sudo lighttpd-enable-mod fastcgi-php
|
||||
sudo /etc/init.d/lighttpd restart
|
||||
```
|
||||
|
||||
|
||||
## arp-scan & Python
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
4.1 - Install arp-scan utility and test
|
||||
```
|
||||
sudo apt-get install arp-scan -y
|
||||
sudo arp-scan -l
|
||||
```
|
||||
|
||||
4.2 - Test Python
|
||||
|
||||
New versions of 'Raspberry Pi OS' includes Python. You can check that
|
||||
Python is installed with the command:
|
||||
```
|
||||
python -V
|
||||
```
|
||||
|
||||
New versions of Ubuntu includes Python 3. You can choose between use `python3`
|
||||
command or to install Python 2 (that includes `python` command).
|
||||
|
||||
|
||||
If you prefer to use Python 3, in the next installation block, you must update
|
||||
`pialert.cron` file with the correct command: `python3` instead of `python`.
|
||||
```
|
||||
python3 -V
|
||||
```
|
||||
|
||||
4.3 - If Python is not installed in your system, you can install it with this
|
||||
command:
|
||||
```
|
||||
sudo apt-get install python
|
||||
```
|
||||
Or this one if you prefer Python 3:
|
||||
```
|
||||
sudo apt-get install python3
|
||||
```
|
||||
|
||||
## Pi.Alert
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
5.1 - Download Pi.Alert and uncompress
|
||||
```
|
||||
cd
|
||||
curl -LO https://github.com/pucherot/Pi.Alert/raw/main/tar/pialert_latest.tar
|
||||
tar xvf pialert_latest.tar
|
||||
rm pialert_latest.tar
|
||||
```
|
||||
|
||||
5.2 - Public the front portal
|
||||
```
|
||||
sudo ln -s ~/pialert/front /var/www/html/pialert
|
||||
```
|
||||
|
||||
5.3 - Configure web server redirection
|
||||
|
||||
If you have configured your DNS server (Pi.hole or other) to resolve pi.alert
|
||||
with the IP of your raspberry, youy must configure lighttpd to redirect these
|
||||
requests to the correct pialert web folder
|
||||
```
|
||||
sudo cp ~/pialert/install/pialert_front.conf /etc/lighttpd/conf-available
|
||||
sudo ln -s ../conf-available/pialert_front.conf /etc/lighttpd/conf-enabled/pialert_front.conf
|
||||
sudo /etc/init.d/lighttpd restart
|
||||
```
|
||||
|
||||
5.4 - If you want to use email reporting with gmail
|
||||
- Go to your Google Account https://myaccount.google.com/
|
||||
- On the left navigation panel, click Security
|
||||
- On the bottom of the page, in the Less secure app access panel,
|
||||
click Turn on access
|
||||
- Click Save button
|
||||
|
||||
5.5 - Config Pialert parameters
|
||||
```
|
||||
sed -i "s,'/home/pi/pialert','$HOME/pialert'," ~/pialert/config/pialert.conf
|
||||
nano ~/pialert/config/pialert.conf
|
||||
```
|
||||
- If you want to use email reporting, configure this parameters
|
||||
```ini
|
||||
REPORT_MAIL = True
|
||||
SMTP_USER = 'user@gmail.com'
|
||||
SMTP_PASS = 'password'
|
||||
REPORT_TO = 'user@gmail.com'
|
||||
```
|
||||
|
||||
- If you want to update your Dynamic DNS, configure this parameters
|
||||
```ini
|
||||
DDNS_ACTIVE = True
|
||||
DDNS_DOMAIN = 'your_domain.freeddns.org'
|
||||
DDNS_USER = 'dynu_user'
|
||||
DDNS_PASSWORD = 'A0000000B0000000C0000000D0000000'
|
||||
DDNS_UPDATE_URL = 'https://api.dynu.com/nic/update?'
|
||||
```
|
||||
|
||||
- If you have installed Pi.hole and DHCP, activate this parameters
|
||||
```ini
|
||||
PIHOLE_ACTIVE = True
|
||||
DHCP_ACTIVE = True
|
||||
```
|
||||
|
||||
5.6 - Update vendors DB
|
||||
```
|
||||
python ~/pialert/back/pialert.py update_vendors
|
||||
```
|
||||
or
|
||||
```
|
||||
python3 ~/pialert/back/pialert.py update_vendors
|
||||
```
|
||||
|
||||
5.7 - Test Pi.Alert Scan
|
||||
```
|
||||
python ~/pialert/back/pialert.py internet_IP
|
||||
python ~/pialert/back/pialert.py 1
|
||||
```
|
||||
or
|
||||
```
|
||||
python3 ~/pialert/back/pialert.py internet_IP
|
||||
python3 ~/pialert/back/pialert.py 1
|
||||
```
|
||||
|
||||
5.8 - Update crontab template with python3
|
||||
|
||||
If you prefer to use Python 3 (installed in the previous block), you must
|
||||
update `pialert.cron` file with the correct command: `python3` instead of
|
||||
`python`
|
||||
```
|
||||
sed -i 's/python/python3/g' ~/pialert/install/pialert.cron
|
||||
```
|
||||
|
||||
5.9 - Add crontab jobs
|
||||
```
|
||||
(crontab -l 2>/dev/null; cat ~/pialert/install/pialert.cron) | crontab -
|
||||
```
|
||||
|
||||
5.10 - Add permissions to the web-server user
|
||||
```
|
||||
sudo chgrp -R www-data ~/pialert/db
|
||||
chmod -R 770 ~/pialert/db
|
||||
```
|
||||
|
||||
5.11 - Check DNS record for pi.alert (explained in point 2.7 of Pi.hole
|
||||
installation)
|
||||
- Add pi.alert DNS Record
|
||||
```
|
||||
hostname -I
|
||||
```
|
||||
- Pi-hole admin portal -> Local DNS -> DNS Records -> Add new domain /IP
|
||||
- pi.alert 192.168.1.x
|
||||
- (*replace 192.168.1.x with your Raspberry IP*)
|
||||
|
||||
5.12 - Use admin panel to configure the devices
|
||||
- http://pi.alert/
|
||||
- http://192.168.1.x/pialert/
|
||||
- (*replace 192.168.1.x with your Raspberry IP*)
|
||||
|
||||
|
||||
## Device Management
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
|
||||
- [Device Management instructions](./DEVICE_MANAGEMENT.md)
|
||||
|
||||
|
||||
### License
|
||||
GPL 3.0
|
||||
[Read more here](../LICENSE.txt)
|
||||
|
||||
### Contact
|
||||
pi.alert.application@gmail.com
|
||||
44
docs/RAMDOM_MAC.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Privacy & Random MAC's
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
|
||||
The latest versions of some operating systems (IOS and Android) incorporate a
|
||||
new & interesting functionality to improve privacy: **Random MACs**.
|
||||
|
||||
This functionality allows you to **hide the true MAC** of the device and
|
||||
**assign a random MAC** when we connect to WIFI networks.
|
||||
|
||||
This behavior is especially useful when connecting to WIFI's that we do not
|
||||
know, but it **is totally useless when connecting to our own WIFI's** or known
|
||||
networks.
|
||||
|
||||
**I recommend disabling this operation when connecting our devices to our own
|
||||
WIFI's**, in this way, Pi.Alert will be able to identify the device, and it
|
||||
will not identify it as a new device every so often (every time IOS or Android
|
||||
decides to change the MAC).
|
||||
|
||||
## IOS
|
||||
![ios][ios]
|
||||
|
||||
- [Use private Wi-Fi addresses in iOS 14](https://support.apple.com/en-us/HT211227)
|
||||
|
||||
## Android
|
||||
![Android][Android]
|
||||
|
||||
- [How to Disable MAC Randomization in Android 10](https://support.boingo.com/s/article/How-to-Disable-MAC-Randomization-in-Android-10-Android-Q)
|
||||
- [How do I disable random Wi-Fi MAC address on Android 10](https://support.plume.com/hc/en-gb/articles/360052070714-How-do-I-disable-random-Wi-Fi-MAC-address-on-Android-10-)
|
||||
|
||||
|
||||
### License
|
||||
GPL 3.0
|
||||
[Read more here](../LICENSE.txt)
|
||||
|
||||
### Contact
|
||||
pi.alert.application@gmail.com
|
||||
|
||||
***Suggestions and comments are welcome***
|
||||
|
||||
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
[ios]: https://9to5mac.com/wp-content/uploads/sites/6/2020/08/how-to-use-private-wifi-mac-address-iphone-ipad.png?resize=2048,1009 "ios"
|
||||
[Android]: ./img/android_random_mac.jpg "Android"
|
||||
|
||||
28
docs/VERSIONS_HISTORY.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Pi.Alert Version History
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
|
||||
| Version | Description |
|
||||
| ------- | --------------------------------------------------------------- |
|
||||
| v2.60 | Improved the compability of installation process (Ubuntu) |
|
||||
| v2.56 | Bug fixing |
|
||||
| v2.55 | Bug fixing |
|
||||
| v2.52 | Bug fixing |
|
||||
| v2.51 | Bug fixing |
|
||||
| v2.50 | First public release |
|
||||
|
||||
|
||||
## Pi.Alert v2.60
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
- `pialert.conf` moved from `back` to `config` folder
|
||||
- `pialert.conf` splitted in two files: `pialert.conf` and `version.conf`
|
||||
- Added compatibility with Python 3 (default version installed with Ubuntu)
|
||||
- Added compatibility in the Installation guide with Ubuntu server
|
||||
- Eliminated some unnecessary packages from the installation
|
||||
|
||||
|
||||
### License
|
||||
GPL 3.0
|
||||
[Read more here](../LICENSE.txt)
|
||||
|
||||
### Contact
|
||||
pi.alert.application@gmail.com
|
||||
|
Before Width: | Height: | Size: 168 KiB After Width: | Height: | Size: 168 KiB |
|
Before Width: | Height: | Size: 129 KiB After Width: | Height: | Size: 129 KiB |
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 135 KiB After Width: | Height: | Size: 135 KiB |
|
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 136 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
BIN
docs/img/android_random_mac.jpg
Normal file
|
After Width: | Height: | Size: 551 KiB |
@@ -1,3 +1,12 @@
|
||||
<!-- ---------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# repot_sample.html - Back module. Sample email reporting in HTML format
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#--------------------------------------------------------------------------- -->
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
@@ -16,7 +25,7 @@
|
||||
<td>
|
||||
<table width=100% border=0 bgcolor=#FFD966 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 16px; text-align:center; color:#5F5000">
|
||||
<tr>
|
||||
<td width=33%> Report Date: <b>2021-01-02 08:20</b> </td>
|
||||
<td width=33%> Report Date: <b>2021-01-01 08:00</b> </td>
|
||||
<td width=34%> Scan Cycle: <b>Internet</b> </td>
|
||||
<td width=33%> Server: <b>pi4</b> </td>
|
||||
</tr>
|
||||
@@ -39,7 +48,7 @@
|
||||
|
||||
<tr>
|
||||
<td> Internet IP Changed </td>
|
||||
<td> 2021-01-02 08:20:00 </td>
|
||||
<td> 2021-01-01 08:00:00 </td>
|
||||
<td style="font-size: 24px; color:#D02020"> 1.1.1.0 </td>
|
||||
<td> Previous Internet IP: 1.1.0.0 </td>
|
||||
</tr>
|
||||
@@ -58,8 +67,8 @@
|
||||
<td>
|
||||
<table width=100% border=0 bgcolor=#70AD47 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 12px; font-weight: bold; color:#385723">
|
||||
<tr>
|
||||
<td width=25% style="text-align:Left"> Puche 2020</td>
|
||||
<td width=50% style="text-align:center"> Pi.Alert 2.50 / 2020-12-30 </td>
|
||||
<td width=25% style="text-align:Left"> Puche 2021</td>
|
||||
<td width=50% style="text-align:center"> Pi.Alert 2.50 / 2021-01-01 </td>
|
||||
<td width=25% style="text-align:right"> GNU GPLv3</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -1,3 +1,12 @@
|
||||
<!-- ---------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# repot_sample.html - Back module. Sample email reporting in HTML format
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#--------------------------------------------------------------------------- -->
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
@@ -16,7 +25,7 @@
|
||||
<td>
|
||||
<table width=100% border=0 bgcolor=#FFD966 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 16px; text-align:center; color:#5F5000">
|
||||
<tr>
|
||||
<td width=33%> Report Date: <b>2021-01-02 08:20</b> </td>
|
||||
<td width=33%> Report Date: <b>2021-01-01 08:00</b> </td>
|
||||
<td width=34%> Scan Cycle: <b>1</b> </td>
|
||||
<td width=33%> Server: <b>pi4</b> </td>
|
||||
</tr>
|
||||
@@ -43,13 +52,13 @@
|
||||
|
||||
<tr>
|
||||
<td> f8:d0:27:00:00:00 </td>
|
||||
<td> 2021-01-02 08:20:00 </td>
|
||||
<td> 2021-01-01 08:00:00 </td>
|
||||
<td> 192.168.1.20 </td>
|
||||
<td> Seiko Epson Corporation </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> c8:6c:3d:00:00:00 </td>
|
||||
<td> 2021-01-02 08:20:00 </td>
|
||||
<td> 2021-01-01 08:00:00 </td>
|
||||
<td> 192.168.1.181 </td>
|
||||
<td> Amazon Technologies Inc. </td>
|
||||
</tr>
|
||||
@@ -72,7 +81,7 @@
|
||||
|
||||
<tr>
|
||||
<td> 0c:ee:99:00:00:00 </td>
|
||||
<td> 2021-01-02 08:20:00 </td>
|
||||
<td> 2021-01-01 08:00:00 </td>
|
||||
<td> 192.168.1.171 </td>
|
||||
<td> Alexa - Echo </td>
|
||||
</tr>
|
||||
@@ -97,7 +106,7 @@
|
||||
|
||||
<tr>
|
||||
<td> 94:0c:98:00:00:00 </td>
|
||||
<td> 2021-01-02 08:20:00 </td>
|
||||
<td> 2021-01-01 08:00:00 </td>
|
||||
<td> 192.168.1.132 </td>
|
||||
<td> Connected </td>
|
||||
<td> Person 1 - iPhone 11 </td>
|
||||
@@ -105,7 +114,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td> 5c:41:5a:00:00:00 </td>
|
||||
<td> 2021-01-02 08:20:00 </td>
|
||||
<td> 2021-01-01 08:00:00 </td>
|
||||
<td> 192.168.1.170 </td>
|
||||
<td> IP Changed </td>
|
||||
<td> Alexa Dot </td>
|
||||
@@ -121,8 +130,8 @@
|
||||
<td>
|
||||
<table width=100% border=0 bgcolor=#70AD47 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 12px; font-weight: bold; color:#385723">
|
||||
<tr>
|
||||
<td width=25% style="text-align:Left"> Puche 2020</td>
|
||||
<td width=50% style="text-align:center"> Pi.Alert 2.50 / 2020-12-30 </td>
|
||||
<td width=25% style="text-align:Left"> Puche 2021</td>
|
||||
<td width=50% style="text-align:center"> Pi.Alert 2.50 / 2021-01-01 </td>
|
||||
<td width=25% style="text-align:right"> GNU GPLv3</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 139 KiB |
@@ -1,10 +1,36 @@
|
||||
<!-- ---------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# footer.php - Front module. Common footer to all the front pages
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#--------------------------------------------------------------------------- -->
|
||||
|
||||
<!-- Main Footer -->
|
||||
<footer class="main-footer">
|
||||
<!-- Default to the left -->
|
||||
|
||||
<!--
|
||||
© 2020 Puche
|
||||
-->
|
||||
<?php
|
||||
$conf_file = '../config/version.conf';
|
||||
$conf_data = parse_ini_file($conf_file);
|
||||
echo '<span style="display:inline-block; transform: rotate(180deg)">©</span> '. $conf_data['VERSION_YEAR'] .' Puche';
|
||||
?>
|
||||
|
||||
<!-- To the right -->
|
||||
<div class="pull-right no-hidden-xs">
|
||||
Pi.alert  2.50  <small>(2019-12-30)</small>
|
||||
|
||||
<!--
|
||||
Pi.Alert  2.50  <small>(2019-12-30)</small>
|
||||
-->
|
||||
<?php
|
||||
$conf_file = '../config/version.conf';
|
||||
$conf_data = parse_ini_file($conf_file);
|
||||
echo 'Pi.Alert  '. $conf_data['VERSION'] .'  <small>('. $conf_data['VERSION_DATE'] .')</small>';
|
||||
?>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
<!-- ---------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# header.php - Front module. Common header to all the front pages
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#--------------------------------------------------------------------------- -->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Pi.alert</title>
|
||||
<title>Pi.Alert</title>
|
||||
<!-- Tell the browser to be responsive to screen width -->
|
||||
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
|
||||
<!-- Bootstrap 3.3.7 -->
|
||||
@@ -21,7 +30,7 @@
|
||||
<link rel="stylesheet" href="lib/AdminLTE/dist/css/skins/skin-yellow-light.min.css">
|
||||
|
||||
|
||||
<!-- Pi.alert CSS -->
|
||||
<!-- Pi.Alert CSS -->
|
||||
<link rel="stylesheet" href="css/pialert.css">
|
||||
|
||||
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||
@@ -40,7 +49,7 @@
|
||||
</head>
|
||||
|
||||
<!-- Layout Boxed Yellow -->
|
||||
<body class="hold-transition skin-yellow-light layout-boxed sidebar-mini" style="background-image: url('img/backgroud.png');">
|
||||
<body class="hold-transition skin-yellow-light layout-boxed sidebar-mini" style="background-image: url('img/background.png');">
|
||||
<!-- Site wrapper -->
|
||||
<div class="wrapper">
|
||||
|
||||
@@ -52,7 +61,7 @@
|
||||
<!-- mini logo for sidebar mini 50x50 pixels -->
|
||||
<span class="logo-mini">P<b>a</b></span>
|
||||
<!-- logo for regular state and mobile devices -->
|
||||
<span class="logo-lg">Pi<b>.alert</b></span>
|
||||
<span class="logo-lg">Pi<b>.Alert</b></span>
|
||||
</a>
|
||||
|
||||
<!-- Header Navbar -->
|
||||
@@ -73,14 +82,14 @@
|
||||
<!-- Menu Toggle Button -->
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<!-- The user image in the navbar-->
|
||||
<img src="img/pialertLogoWhite.png" class="user-image" style="border-radius: initial" alt="Pi.alert Logo">
|
||||
<img src="img/pialertLogoWhite.png" class="user-image" style="border-radius: initial" alt="Pi.Alert Logo">
|
||||
<!-- hidden-xs hides the username on small devices so only the image appears. -->
|
||||
<span class="hidden-xs">Pi.alert</span>
|
||||
<span class="hidden-xs">Pi.Alert</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- The user image in the menu -->
|
||||
<li class="user-header">
|
||||
<img src="img/pialertLogoWhite.png" class="img-circle" alt="Pi.alert Logo" style="border-color:transparent">
|
||||
<img src="img/pialertLogoWhite.png" class="img-circle" alt="Pi.Alert Logo" style="border-color:transparent">
|
||||
|
||||
<p>
|
||||
Open Source Network Guard
|
||||
@@ -91,15 +100,19 @@
|
||||
<li class="user-body">
|
||||
<div class="row">
|
||||
<div class="col-xs-4 text-center">
|
||||
<a href="https://github.com/pucherot/Pi.Alert">GitHub</a>
|
||||
<a target="_blank" href="https://github.com/pucherot/Pi.Alert">GitHub Pi.Alert</a>
|
||||
</div>
|
||||
<div class="col-xs-4 text-center">
|
||||
<a href="https://github.com/pucherot/Pi.Alert">Pi.Alert</a>
|
||||
<!-- <a href="#">Website</a> -->
|
||||
<a href="mailto:pi.alert.application@gmail.com">email Support</a>
|
||||
</div>
|
||||
<div class="col-xs-4 text-center">
|
||||
<a target="_blank" href="https://github.com/pucherot/Pi.Alert/blob/main/LICENSE.txt">GNU GPLv3</a>
|
||||
</div>
|
||||
<!--
|
||||
<div class="col-xs-4 text-center">
|
||||
<a href="#">Updates</a>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
</li>
|
||||
@@ -118,11 +131,11 @@
|
||||
<!-- Sidebar user panel (optional) -->
|
||||
<div class="user-panel">
|
||||
<a href="/" class="logo">
|
||||
<img src="img/pialertLogoGray80.png" class="img-responsive" alt="Pi.alert Logo"/>
|
||||
<img src="img/pialertLogoGray80.png" class="img-responsive" alt="Pi.Alert Logo"/>
|
||||
</a>
|
||||
<div class="pull-left image">
|
||||
<!--
|
||||
<br><img src="img/pialertLogoBlack.png" class="img-responsive" alt="Pi.alert Logo" style="display: table; table-layout: fixed;" />
|
||||
<br><img src="img/pialertLogoBlack.png" class="img-responsive" alt="Pi.Alert Logo" style="display: table; table-layout: fixed;" />
|
||||
-->
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
rm pialert/install/pialert_2.50.tar
|
||||
tar cvf pialert/install/pialert_2.50.tar -h --exclude="pialert/install" --exclude="pialert/.git" pialert
|
||||
|
||||
11
install/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!-- ---------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# index.html - Redirect file to pialert subdirectory
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#--------------------------------------------------------------------------- -->
|
||||
|
||||
<meta http-equiv="refresh" content="0; url=pialert"/>
|
||||
<meta http-equiv="Cache-Control" content="no-store" />
|
||||
13
install/pialert.cron
Normal file
@@ -0,0 +1,13 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# pialert.cron - Back module. Crontab jobs
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
0 3 * * 1 python ~/pialert/back/pialert.py update_vendors >~/pialert/log/pialert.vendors.log 2>&1
|
||||
*/1 * * * * python ~/pialert/back/pialert.py internet_IP >~/pialert/log/pialert.IP.log 2>&1
|
||||
*/5 * * * * python ~/pialert/back/pialert.py 1 >~/pialert/log/pialert.1.log 2>&1
|
||||
*/15 * * * * python ~/pialert/back/pialert.py 15 >~/pialert/log/pialert.15.log 2>&1
|
||||
12
install/pialert_front.conf
Normal file
@@ -0,0 +1,12 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# index.html - Redirect file to pialert subdirectory
|
||||
# ------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
$HTTP["host"] == "pi.alert" {
|
||||
server.document-root = "/var/www/html/pialert/"
|
||||
}
|
||||
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
|
||||
@@ -1 +1,10 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# IP_changes.log - Back module. Logfile for Internet IP changes
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
2021-01-01 00:00:00 0.0.0.0
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
<!-- ---------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# repot_template.html - Back module. Template to email reporting in HTML format
|
||||
#-------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#--------------------------------------------------------------------------- -->
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
@@ -16,7 +25,7 @@
|
||||
<td>
|
||||
<table width=100% border=0 bgcolor=#FFD966 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 16px; text-align:center; color:#5F5000">
|
||||
<tr>
|
||||
<td width=33%> Report Date: <b>2021-01-04 18:08</b> </td>
|
||||
<td width=33%> Report Date: <b>2021-01-01 08:00</b> </td>
|
||||
<td width=34%> Scan Cycle: <b>1</b> </td>
|
||||
<td width=33%> Server: <b>pi4</b> </td>
|
||||
</tr>
|
||||
@@ -34,8 +43,8 @@
|
||||
<td>
|
||||
<table width=100% border=0 bgcolor=#70AD47 cellpadding=5px cellspacing=0 style="border-collapse: collapse; font-size: 12px; font-weight: bold; color:#385723">
|
||||
<tr>
|
||||
<td width=25% style="text-align:Left"> Puche 2020</td>
|
||||
<td width=50% style="text-align:center"> Pi.Alert DEV 2.50 / 2020-12-30 </td>
|
||||
<td width=25% style="text-align:Left"> Puche 2021</td>
|
||||
<td width=50% style="text-align:center"> Pi.Alert 2.50 / 2021-01-01 </td>
|
||||
<td width=25% style="text-align:right"> GNU GPLv3</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Pi.Alert Report
|
||||
========================================
|
||||
|
||||
Report Date: 2021-01-01 00:00
|
||||
Report Date: 2021-01-01 08:00
|
||||
Scan Cycle: 1
|
||||
Server: pi4
|
||||
|
||||
@@ -12,4 +12,4 @@ Events
|
||||
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Puche 2020 Pi.Alert 2.50 / 2020-12-30 GNU GPLv3
|
||||
Puche 2021 Pi.Alert 2.50 / 2021-01-01 GNU GPLv3
|
||||
|
||||
28
tar/create_tar.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
# ------------------------------------------------------------------------------
|
||||
# Pi.Alert
|
||||
# Open Source Network Guard / WIFI & LAN intrusion detector
|
||||
#
|
||||
# create_tar.sh - Create the installation file
|
||||
# ------------------------------------------------------------------------------
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
PIALERT_VERSION=`awk '$1=="VERSION" { print $3 }' ../config/version.conf | tr -d \'`
|
||||
PIALERT_DEV_PATH=/media/WD_4TB/dev
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
cd $PIALERT_DEV_PATH
|
||||
pwd
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
ls -l pialert/tar/pialert*.tar
|
||||
tar tvf pialert/tar/pialert_latest.tar | wc -l
|
||||
rm pialert/tar/pialert_*.tar
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
tar cvf pialert/tar/pialert_$PIALERT_VERSION.tar --exclude="pialert/tar" --exclude="pialert/.git" pialert | wc -l
|
||||
|
||||
ln -s pialert_$PIALERT_VERSION.tar pialert/tar/pialert_latest.tar
|
||||
ls -l pialert/tar/pialert*.tar
|
||||
|
||||