mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8564f4dd7 | ||
|
|
78352ed5a4 | ||
|
|
bb4be279c8 | ||
|
|
9f73af8ce6 | ||
|
|
f6eedd84d8 | ||
|
|
cd9a1ac22a | ||
|
|
0e3f14dd9d | ||
|
|
dbe0a0548b | ||
|
|
e8f723d985 | ||
|
|
cc50d0f75e | ||
|
|
a473845242 | ||
|
|
bda526b202 | ||
|
|
9057e41ff8 | ||
|
|
75bb53fdd1 | ||
|
|
e7ebd9bab5 | ||
|
|
30aeab305d | ||
|
|
3e6d9847be | ||
|
|
3c34c822e7 |
@@ -1,6 +1,6 @@
|
||||
VERSION = '2.52'
|
||||
VERSION = '2.56'
|
||||
VERSION_YEAR = '2021'
|
||||
VERSION_DATE = '2021-01-11'
|
||||
VERSION_DATE = '2021-01-15'
|
||||
|
||||
DB_PATH = '/home/pi/pialert/db/pialert.db'
|
||||
LOG_PATH = '/home/pi/pialert/log'
|
||||
@@ -17,6 +17,8 @@ REPORT_MAIL = False
|
||||
REPORT_FROM = 'Pi.Alert <' + SMTP_USER +'>'
|
||||
REPORT_TO = 'user@gmail.com'
|
||||
|
||||
# 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'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Pi.Alert v2.52 / 2021-01-11
|
||||
# Puche 2020
|
||||
# Pi.Alert v2.56 / 2021-01-15
|
||||
# Puche 2021
|
||||
# GNU GPLv3
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ import csv
|
||||
# CONFIG CONSTANTS
|
||||
#===============================================================================
|
||||
PIALERT_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
if (sys.version_info > (3,0)):
|
||||
exec(open(PIALERT_PATH + "/pialert.conf").read())
|
||||
else:
|
||||
execfile (PIALERT_PATH + "/pialert.conf")
|
||||
|
||||
|
||||
@@ -156,8 +159,10 @@ def get_internet_IP ():
|
||||
# dig_args = ['dig', '+short', 'myip.opendns.com',
|
||||
# '@resolver1.opendns.com']
|
||||
|
||||
# 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', 'https://diagnostic.opendns.com/myip']
|
||||
curl_args = ['curl', '-s', QUERY_MYIP_SERVER]
|
||||
curl_output = subprocess.check_output (curl_args, universal_newlines=True)
|
||||
|
||||
# Check result is an IP
|
||||
@@ -292,9 +297,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 +455,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 ():
|
||||
@@ -684,16 +712,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')
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -1210,7 +1261,7 @@ def write_file (pPath, pText):
|
||||
file.close()
|
||||
else:
|
||||
file = open (pPath, 'w', encoding='utf-8')
|
||||
file.write (ptext)
|
||||
file.write (pText)
|
||||
file.close()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
BIN
db/pialert.db
BIN
db/pialert.db
Binary file not shown.
@@ -3,7 +3,7 @@
|
||||
Initially designed to run on a Raspberry PI, probably it can run on many other
|
||||
Linux distributions.
|
||||
|
||||
Stimated time: 20'
|
||||
Estimated time: 20'
|
||||
|
||||
### Dependencies
|
||||
| Dependency | Comments |
|
||||
@@ -34,7 +34,7 @@ Stimated time: 20'
|
||||
password: raspberry
|
||||
```
|
||||
|
||||
5 - Change de default password of pi user
|
||||
5 - Change the default password of pi user
|
||||
```
|
||||
passwd
|
||||
```
|
||||
@@ -76,7 +76,7 @@ Stimated time: 20'
|
||||
|
||||
5 - Connect to web admin panel
|
||||
- http://192.168.1.x/admin/
|
||||
- (*replace the 192.168.1.x with your Raspberry IP*)
|
||||
- (*replace 192.168.1.x with your Raspberry IP*)
|
||||
|
||||
6 - Activate DHCP server
|
||||
- Pi-hole -> Settings -> DHCP -> Mark "DHCP server enabled"
|
||||
@@ -84,7 +84,7 @@ Stimated time: 20'
|
||||
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*)
|
||||
- (*replace 192.168.1.x with your Raspberry IP*)
|
||||
|
||||
8 - Deactivate your current DHCP Server (*Normaly at your router or AP*)
|
||||
|
||||
@@ -115,7 +115,7 @@ Stimated time: 20'
|
||||
|
||||
## Pi.Alert
|
||||
<!--- --------------------------------------------------------------------- --->
|
||||
1- Download Pi.Alert and uncmompress
|
||||
1- Download Pi.Alert and uncompress
|
||||
```
|
||||
curl -LO https://github.com/pucherot/Pi.Alert/raw/main/install/pialert_latest.tar
|
||||
tar xvf pialert_latest.tar
|
||||
@@ -127,7 +127,7 @@ Stimated time: 20'
|
||||
sudo ln -s /home/pi/pialert/front /var/www/html/pialert
|
||||
```
|
||||
|
||||
3 - Update lighttp config
|
||||
3 - Update lighttpd 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
|
||||
@@ -144,7 +144,7 @@ Stimated time: 20'
|
||||
```
|
||||
nano ~/pialert/back/pialert.conf
|
||||
```
|
||||
- if you want to use email reporting, configure this parameters
|
||||
- If you want to use email reporting, configure this parameters
|
||||
```
|
||||
REPORT_MAIL = True
|
||||
SMTP_USER = 'user@gmail.com'
|
||||
@@ -152,7 +152,7 @@ Stimated time: 20'
|
||||
REPORT_TO = 'user@gmail.com'
|
||||
```
|
||||
|
||||
- if you want to update yout Dynamic DNS, configure this parameters
|
||||
- If you want to update your Dynamic DNS, configure this parameters
|
||||
```
|
||||
DDNS_ACTIVE = True
|
||||
DDNS_DOMAIN = 'your_domain.freeddns.org'
|
||||
@@ -161,7 +161,7 @@ Stimated time: 20'
|
||||
DDNS_UPDATE_URL = 'https://api.dynu.com/nic/update?'
|
||||
```
|
||||
|
||||
- if you have installed Pi.hole and DHCP, activate this parameters
|
||||
- If you have installed Pi.hole and DHCP, activate this parameters
|
||||
```
|
||||
PIHOLE_ACTIVE = True
|
||||
DHCP_ACTIVE = True
|
||||
@@ -183,8 +183,22 @@ Stimated time: 20'
|
||||
(crontab -l 2>/dev/null; cat ~/pialert/back/pialert.cron) | crontab -
|
||||
```
|
||||
|
||||
9 - Use admin panel to configure the devices
|
||||
9 - Add permissions to the web-server user
|
||||
```
|
||||
sudo chgrp -R www-data ~/pialert/back ~/pialert/back/pialert.conf ~/pialert/front ~/pialert/db
|
||||
chmod -R 770 ~/pialert/back ~/pialert/back/pialert.conf ~/pialert/front ~/pialert/db
|
||||
```
|
||||
|
||||
10 - Check DNS record por pi.alert (explained in point 7 of Pi.hole installing)
|
||||
- Add pi.alert DNS Record
|
||||
- Pi-hole -> Local DNS -> DNS Records -> Add new domain /IP
|
||||
- pi.alert 192.168.1.x
|
||||
- (*replace 192.168.1.x with your Raspberry IP*)
|
||||
|
||||
11 - 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
|
||||
|
||||
@@ -1,10 +1,28 @@
|
||||
|
||||
<!-- Main Footer -->
|
||||
<footer class="main-footer">
|
||||
<!-- Default to the left -->
|
||||
© 2021 Puche
|
||||
|
||||
<!--
|
||||
© 2020 Puche
|
||||
-->
|
||||
<?php
|
||||
$conf_file = '../back/pialert.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.52  <small>(2021-01-11)</small>
|
||||
|
||||
<!--
|
||||
Pi.alert  2.50  <small>(2019-12-30)</small>
|
||||
-->
|
||||
<?php
|
||||
$conf_file = '../back/pialert.conf';
|
||||
$conf_data = parse_ini_file($conf_file);
|
||||
echo 'Pi.alert  '. $conf_data['VERSION'] .'  <small>('. $conf_data['VERSION_DATE'] .')</small>';
|
||||
?>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
||||
@@ -91,15 +91,20 @@
|
||||
<li class="user-body">
|
||||
<div class="row">
|
||||
<div class="col-xs-4 text-center">
|
||||
<a href="https://github.com/pucherot/Pi.Alert">GitHub</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="https://github.com/pucherot/Pi.Alert">GitHub</a>
|
||||
</div>
|
||||
<!--
|
||||
<div class="col-xs-4 text-center">
|
||||
<a href="https://github.com/pucherot/Pi.Alert">Pi.Alert</a>
|
||||
</div>
|
||||
-->
|
||||
<!--
|
||||
<div class="col-xs-4 text-center">
|
||||
<a href="#">Updates</a>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
</li>
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
#
|
||||
PIALERT_VERSION=2.52
|
||||
PIALERT_VERSION=`awk '$1=="VERSION" { print $3 }' ../back/pialert.conf | tr -d \'`
|
||||
PIALERT_DEV_PATH=/media/WD_4TB/dev
|
||||
|
||||
cd $PIALERT_DEV_PATH
|
||||
pwd
|
||||
|
||||
tar tvf pialert/install/pialert_$PIALERT_VERSION.tar | wc -l
|
||||
rm pialert/install/pialert_$PIALERT_VERSION.tar
|
||||
ls -l pialert/install/pialert*.tar
|
||||
tar tvf pialert/install/pialert_latest.tar | wc -l
|
||||
rm pialert/install/pialert_*.tar
|
||||
|
||||
tar cvf pialert/install/pialert_$PIALERT_VERSION.tar --exclude="pialert/install" --exclude="pialert/.git" pialert | wc -l
|
||||
|
||||
rm pialert/install/pialert_latest.tar
|
||||
ln -s pialert_$PIALERT_VERSION.tar pialert/install/pialert_latest.tar
|
||||
ls -l pialert/install/pialert*.tar
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user