One-step Automated Install |
---|
35 | 36 | ``` 37 | bash -c "$(wget -qLO - https://github.com/leiweibau/Pi.Alert-Satellite/raw/main/install/pialert_satellite_install.sh)" 38 | ``` 39 | |
One-step Automated Update |
---|
61 | 62 | ``` 63 | bash -c "$(wget -qLO - https://github.com/leiweibau/Pi.Alert-Satellite/raw/main/install/pialert_satellite_update.sh)" 64 | ``` 65 | |
The requested URL was not found on this server.
69 | '; 70 | 71 | // Check whether mode or token is set, otherwise HTTP 404 72 | if ($_REQUEST['mode'] == "" || $_REQUEST['token'] == "") { 73 | header('HTTP/1.0 404 Not Found', true, 404); 74 | echo $http_response; 75 | die(); 76 | } 77 | // Check if payload is set when usingg direct or proxy mode, otherwise HTTP 404 78 | if (($_REQUEST['mode'] == "direct" || $_REQUEST['mode'] == "proxy") && !isset($_FILES['encrypted_data'])) { 79 | header('HTTP/1.0 404 Not Found', true, 404); 80 | echo $http_response; 81 | die(); 82 | } 83 | 84 | $incomming_token = $_REQUEST['token']; 85 | 86 | // Procedure for direct API call (Pi.Alert) 87 | if ($_REQUEST['mode'] == "direct") { 88 | // Query from the database 89 | $satellite_list = get_all_satellites(); 90 | $satellite_tokens = array(); 91 | $satellite_passwords = array(); 92 | 93 | for($x=0;$xThe threshold for repeated transmission errors from the satellite to the API has been reached.
1163 | 1164 | 1165 | """ 1166 | send_email (notiTEXT, notiHTML, True) 1167 | # create a file that recognizes that a mail has been sent 1168 | notification_stop('start') 1169 | else: 1170 | print(' Nothing to report') 1171 | else: 1172 | print(' Reporting stopped because a mail has already been sent') 1173 | 1174 | else: 1175 | print(' Satellite error reporting is disabled') 1176 | #------------------------------------------------------------------------------- 1177 | def send_email(pText, pHTML, logs): 1178 | # Compose email 1179 | msg = MIMEMultipart() 1180 | msg['Subject'] = FRIENDLY_NAME + ' - Pi.Alert Satellite Message ' 1181 | msg['From'] = MAIL_FROM 1182 | msg['To'] = MAIL_TO 1183 | alternative = MIMEMultipart('alternative') 1184 | alternative.attach(MIMEText(pText, 'plain')) 1185 | alternative.attach(MIMEText(pHTML, 'html')) 1186 | msg.attach(alternative) 1187 | 1188 | if logs: 1189 | existing_files = [ 1190 | f for f in sorted_alphanumeric(os.listdir(SATELLITE_LOG_PATH)) 1191 | if f.endswith(".txt") and "_error_" in f and len(f.split('_error_')[1].replace('.txt', '')) == report_timestamp 1192 | ] 1193 | 1194 | for file_name in existing_files: 1195 | file_path = os.path.join(SATELLITE_LOG_PATH, file_name) 1196 | with open(file_path, 'rb') as file: 1197 | part = MIMEBase('application', 'octet-stream') 1198 | part.set_payload(file.read()) 1199 | encoders.encode_base64(part) 1200 | part.add_header('Content-Disposition', f'attachment; filename="{file_name}"') 1201 | msg.attach(part) 1202 | 1203 | # Send mail 1204 | try: 1205 | smtp_connection = smtplib.SMTP (SMTP_SERVER, SMTP_PORT) 1206 | smtp_connection.ehlo() 1207 | if not SafeParseGlobalBool("SMTP_SKIP_TLS"): 1208 | smtp_connection.starttls() 1209 | smtp_connection.ehlo() 1210 | if not SafeParseGlobalBool("SMTP_SKIP_LOGIN"): 1211 | escaped_password = repr(SMTP_PASS)[1:-1] 1212 | smtp_connection.login (SMTP_USER, escaped_password) 1213 | smtp_connection.sendmail (MAIL_FROM, MAIL_TO, msg.as_string()) 1214 | except Exception as e: 1215 | print(f" Error sending the e-mail") 1216 | finally: 1217 | smtp_connection.quit() 1218 | print(f" Message sent") 1219 | 1220 | 1221 | #------------------------------------------------------------------------------- 1222 | def SafeParseGlobalBool(boolVariable): 1223 | return eval(boolVariable) if boolVariable in globals() else False 1224 | 1225 | #=============================================================================== 1226 | # UTIL 1227 | #=============================================================================== 1228 | def print_log (pText): 1229 | global log_timestamp 1230 | 1231 | # Check LOG actived 1232 | if not PRINT_LOG : 1233 | return 1234 | 1235 | # Current Time 1236 | log_timestamp2 = datetime.datetime.now() 1237 | 1238 | # Print line + time + elapsed time + text 1239 | print('--------------------> ', 1240 | log_timestamp2, ' ', 1241 | log_timestamp2 - log_timestamp, ' ', 1242 | pText) 1243 | 1244 | # Save current time to calculate elapsed time until next log 1245 | log_timestamp = log_timestamp2 1246 | 1247 | #=============================================================================== 1248 | # BEGIN 1249 | #=============================================================================== 1250 | if __name__ == '__main__': 1251 | sys.exit(main()) 1252 | -------------------------------------------------------------------------------- /back/update_vendors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ------------------------------------------------------------------------------ 3 | # Pi.Alert 4 | # Open Source Network Guard / WIFI & LAN intrusion detector 5 | # 6 | # update_vendors.sh - Back module. IEEE Vendors db update 7 | # ------------------------------------------------------------------------------ 8 | # Puche 2021 pi.alert.application@gmail.com GNU GPLv3 9 | # ------------------------------------------------------------------------------ 10 | 11 | # ---------------------------------------------------------------------- 12 | # Main directories to update: 13 | # /usr/share/arp-scan 14 | # /usr/share/ieee-data 15 | # /var/lib/ieee-data 16 | # ---------------------------------------------------------------------- 17 | 18 | # ---------------------------------------------------------------------- 19 | echo "Updating... /usr/share/ieee-data/" 20 | cd /usr/share/ieee-data/ 21 | 22 | sudo aria2c --dir=/usr/share/ieee-data --max-connection-per-server=3 --allow-overwrite=true --quiet=true "https://standards-oui.ieee.org/oui/oui.csv" 23 | sudo aria2c --dir=/usr/share/ieee-data --max-connection-per-server=3 --allow-overwrite=true --quiet=true "https://standards-oui.ieee.org/oui/oui.txt" 24 | sudo aria2c --dir=/usr/share/ieee-data --max-connection-per-server=3 --allow-overwrite=true --quiet=true "https://standards-oui.ieee.org/oui36/oui36.csv" 25 | sudo aria2c --dir=/usr/share/ieee-data --max-connection-per-server=3 --allow-overwrite=true --quiet=true "https://standards-oui.ieee.org/oui36/oui36.txt" 26 | sudo aria2c --dir=/usr/share/ieee-data --max-connection-per-server=3 --allow-overwrite=true --quiet=true "https://standards-oui.ieee.org/oui28/mam.csv" 27 | sudo aria2c --dir=/usr/share/ieee-data --max-connection-per-server=3 --allow-overwrite=true --quiet=true "https://standards-oui.ieee.org/oui28/mam.txt" 28 | sudo aria2c --dir=/usr/share/ieee-data --max-connection-per-server=3 --allow-overwrite=true --quiet=true "https://standards-oui.ieee.org/iab/iab.csv" 29 | sudo aria2c --dir=/usr/share/ieee-data --max-connection-per-server=3 --allow-overwrite=true --quiet=true "https://standards-oui.ieee.org/iab/iab.txt" 30 | 31 | # ---------------------------------------------------------------------- 32 | echo "" 33 | echo "Updating... /usr/share/arp-scan/" 34 | cd /usr/share/arp-scan 35 | 36 | # Update from /var/lib/ieee-data 37 | sudo get-oui -v 38 | 39 | # Update from ieee website 40 | # sudo get-iab -v -u https://standards-oui.ieee.org/iab/iab.txt 41 | # sudo get-oui -v -u https://standards-oui.ieee.org/oui/oui.txt 42 | 43 | # Update from Sanitized oui (linuxnet.ca) 44 | # sudo get-oui -v -u https://linuxnet.ca/ieee/oui.txt 45 | 46 | -------------------------------------------------------------------------------- /config/satellite.conf: -------------------------------------------------------------------------------- 1 | # General Settings 2 | # ---------------------- 3 | SATELLITE_PATH = '/home/pi/pialert_satellite' 4 | LOG_PATH = SATELLITE_PATH + '/log' 5 | PRINT_LOG = False 6 | VENDORS_DB = '/usr/share/arp-scan/ieee-oui.txt' 7 | QUERY_MYIP_SERVER = 'https://myipv4.p1.opendns.com/get_my_ip' 8 | INTERNET_DETECTION = False 9 | SATELLITE_TOKEN = 'Demo' 10 | SATELLITE_PASSWORD = 'Demo' 11 | SATELLITE_MASTER_URL = 'http://localhost/pialert/api/satellite.php' 12 | PROXY_MODE = False 13 | SATELLITE_ERROR_REPORT = False 14 | NETWORK_DNS_SERVER = 'localhost' 15 | 16 | # Mail-Account Settings 17 | # ---------------------- 18 | SMTP_SERVER = 'smtp.gmail.com' 19 | SMTP_PORT = 587 20 | SMTP_USER = 'user@gmail.com' 21 | SMTP_PASS = 'password' 22 | SMTP_SKIP_TLS = False 23 | SMTP_SKIP_LOGIN = False 24 | FRIENDLY_NAME = 'My Satellite' 25 | MAIL_FROM = FRIENDLY_NAME + ' - Pi.Alert Satellite <' + SMTP_USER + '>' 26 | MAIL_TO = 'destination@example.com' 27 | COLLECT_REPORTS_FOR_MAIL = 12 28 | # Since a scan is performed every 5 minutes, 12 corresponds to a period of 1 hour during 29 | # which no successful transmission takes place until a notification is sent. 30 | 31 | # Arp-scan Options & Samples 32 | # ---------------------- 33 | ARPSCAN_ACTIVE = False 34 | SCAN_SUBNETS = '--localnet' 35 | # SCAN_SUBNETS = '--localnet' 36 | # SCAN_SUBNETS = '--localnet --interface=eth0' 37 | # SCAN_SUBNETS = ['192.168.1.0/24 --interface=eth0','192.168.2.0/24 --interface=eth1'] 38 | 39 | # Fritzbox Configuration 40 | # ---------------------- 41 | FRITZBOX_ACTIVE = False 42 | FRITZBOX_IP = '192.168.179.1' 43 | FRITZBOX_USER = 'admin' 44 | FRITZBOX_PASS = 'password' 45 | 46 | # Mikrotik Configuration 47 | # ---------------------- 48 | MIKROTIK_ACTIVE = False 49 | MIKROTIK_IP = '10.0.0.1' 50 | MIKROTIK_USER = 'user' 51 | MIKROTIK_PASS = 'password' 52 | 53 | # UniFi Configuration 54 | # ------------------- 55 | UNIFI_ACTIVE = False 56 | UNIFI_IP = '10.0.0.2' 57 | UNIFI_API = 'v5' 58 | UNIFI_USER = 'user' 59 | UNIFI_PASS = 'password' 60 | # Possible UNIFI APIs are v4, v5, unifiOS, UDMP-unifiOS 61 | 62 | # OpenWRT Configuration 63 | # ---------------------- 64 | OPENWRT_ACTIVE = False 65 | OPENWRT_IP = '192.168.1.1' 66 | OPENWRT_USER = 'root' 67 | OPENWRT_PASS = '' 68 | 69 | # Pi-hole Configuration 70 | # ---------------------- 71 | PIHOLE_ACTIVE = False 72 | PIHOLE_DHCP_ACTIVE = False 73 | PIHOLE6_URL = '' 74 | PIHOLE6_PASSWORD = '' 75 | PIHOLE6_API_MAXCLIENTS = 100 76 | -------------------------------------------------------------------------------- /config/version.conf: -------------------------------------------------------------------------------- 1 | VERSION = '' 2 | VERSION_YEAR = '2025' 3 | VERSION_DATE = '2025-04-13' 4 | -------------------------------------------------------------------------------- /docs/CONFIG_FILE.md: -------------------------------------------------------------------------------- 1 | ## Main Config flie parameter 2 | 3 | | PARAMETER | DESCRIPTION | 4 | | ------------------------ | ----------- | 5 | | SATELLITE_PATH | This variable is set during installation and should not be changed | 6 | | LOG_PATH | This variable is set during installation and should not be changed | 7 | | PRINT_LOG | If this entry is set to True, additional timestamps for the individual sub-functions are added to the scan log. By default this entry is set to False | 8 | | VENDORS_DB | This variable is set during installation and should not be changed | 9 | | QUERY_MYIP_SERVER | The satellite uses this URL to check the current public IP | 10 | | INTERNET_DETECTION | Activates or deactivates the public IP check (the parameter currently has no function) | 11 | | SATELLITE_TOKEN | This token (48 alphanumeric characters long) is generated by Pi.Alert and must be entered here. It uniquely identifies this satellite within the Pi.Alert instance | 12 | | SATELLITE_PASSWORD | The password (96 alphanumeric characters long) is generated by Pi.Alert individually for each satellite and must be entered here. | 13 | | SATELLITE_MASTER_URL | This is the URL of the API to which the satellite sends its scan results. This can either be Pi.Alert directly or an external web server on which the API for proxy mode has been installed. | 14 | | PROXY_MODE | Activates the proxy mode in the satellite. If the satellite informs the API that it is working in proxy mode, the API does not attempt to unpack the received data. | 15 | | SATELLITE_ERROR_REPORT | This can be used to activate notification of satellite transmission errors. | 16 | | NETWORK_DNS_SERVER | For host name resolving | 17 | 18 | 19 | #### Mail-Account Settings 20 | 21 | | Option | Description | 22 | |--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------| 23 | | SMTP_SERVER | Address of the e-mail server (e.g. smtp.gmail.com) | 24 | | SMTP_PORT | The port of the SMTP server. The port may vary depending on the server configuration. | 25 | | SMTP_USER | User name | 26 | | SMTP_PASS | Password | 27 | | SMTP_SKIP_TLS | If this entry is set to True, transport encryption of the e-mail is enabled. If the server does not support this, the entry must be set to False. | 28 | | SMTP_SKIP_LOGIN | There are SMTP servers which do not require a login. In such a case, this value can be set to True. | 29 | | MAIL_TO | destination@example.com 30 | | COLLECT_REPORTS_FOR_MAIL | This parameter defines the threshold at which notification of transmission errors takes place. The saved logs are attached to the mail. After this mail, further error notifications are stopped until a successful transmission has taken place. | 31 | 32 | #### Fritzbox Configuration 33 | 34 | | Option | Description | 35 | |-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| 36 | | FRITZBOX_ACTIVE | If a Fritzbox is used in the network, it can be used as a data source. This can be activated or deactivated at this point. | 37 | | FRITZBOX_IP | IP address of the Fritzbox. | 38 | | FRITZBOX_USER | This assumes that the Fritzbox is configured for a login with username and password, instead of password only. A login with password only is not supported. | 39 | | FRITZBOX_PASS | Password | 40 | 41 | 42 | #### Mikrotik Configuration 43 | 44 | | Option | Description | 45 | |-----------------|------------------------------------------------------------------------------------------------------------------------------| 46 | | MIKROTIK_ACTIVE | If a Mikrotik router is used in the network, it can be used as a data source. This can be enabled or disabled at this point. | 47 | | MIKROTIK_IP | IP address of the Mikrotik router. | 48 | | MIKROTIK_USER | Username | 49 | | MIKROTIK_PASS | Password | 50 | 51 | 52 | #### UniFi Configuration 53 | 54 | | Option | Description | 55 | |--------------|---------------------------------------------------------------------------------------------------------------------------| 56 | | UNIFI_ACTIVE | If a UniFi system is used in the network, it can be used as a data source. This can be enabled or disabled at this point. | 57 | | UNIFI_IP | IP address of the Unifi system. | 58 | | UNIFI_API | Possible UNIFI APIs are v4, v5, unifiOS, UDMP-unifiOS, default | 59 | | UNIFI_USER | Username | 60 | | UNIFI_PASS | Password | 61 | 62 | 63 | #### OpenWRT Configuration 64 | 65 | | Option | Description | 66 | |----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 67 | | OPENWRT_ACTIVE | The package `luci-mod-rpc`need to be installed, on your OpenWrt router. If a OpenWRT is used in the network, it can be used as a data source. This can be activated or deactivated at this point. | 68 | | OPENWRT_IP | IP address of the OpenWRT router. | 69 | | OPENWRT_USER | Username | 70 | | OPENWRT_PASS | Password 71 | 72 | #### Pi-hole Configuration 73 | 74 | | Option | Description | 75 | |--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 76 | | PIHOLE_ACTIVE | This variable is set during installation. | 77 | | PIHOLE_DHCP_ACTIVE | This variable is valid for the DHCP server of Pihole 5.x as well as for 6.x | 78 | | PIHOLE6_URL | If you want to access the Pi-hole data of version 6, enter the URL to the web interface (without the "/admin" suffix) here. | 79 | | PIHOLE6_PASSWORD | Enter the password for the Pi-hole web interface here. | 80 | | PIHOLE6_API_MAXCLIENTS | Specifies the maximum number of clients that are returned as a response from the API | 81 | 82 | [Back](https://github.com/leiweibau/Pi.Alert-Satellite?tab=readme-ov-file#pialert-satellite) -------------------------------------------------------------------------------- /docs/JSON_DEMO.md: -------------------------------------------------------------------------------- 1 | ## DEMO json 2 | 3 | Here you can see the basic structure of the unencrypted json, which is sent encrypted to the API. 4 | 5 | 6 | ```json 7 | { 8 | "satellite_meta_data": [ 9 | { 10 | "hostname": "Pialert-Satellite-Host", 11 | "satellite_version": "2024-07-03", 12 | "satellite_ip": "