PUSHPROD default db and conf file for new installs

This commit is contained in:
Jokob-sk
2022-12-24 13:12:23 +11:00
parent f651d9336a
commit da3ac55122
4 changed files with 63 additions and 27 deletions

View File

@@ -35,7 +35,11 @@ RUN rm /etc/nginx/sites-available/default \
&& ln -s /home/pi/pialert/install/default /etc/nginx/sites-available/default \ && ln -s /home/pi/pialert/install/default /etc/nginx/sites-available/default \
&& sed -ie 's/listen 80/listen '${PORT}'/g' /etc/nginx/sites-available/default \ && sed -ie 's/listen 80/listen '${PORT}'/g' /etc/nginx/sites-available/default \
# run the hardware vendors update # run the hardware vendors update
&& /home/pi/pialert/back/update_vendors.sh && /home/pi/pialert/back/update_vendors.sh \
# Create a backup of the pialert.conf to be used if the user didn't supply a configuration file
&& cp /home/pi/pialert/config/pialert.conf /home/pi/pialert/back/pialert.conf_bak \
# Create a backup of the pialert.db to be used if the user didn't supply a database
&& cp /home/pi/pialert/db/pialert.db /home/pi/pialert/back/pialert.db_bak
ENTRYPOINT ["tini", "--"] ENTRYPOINT ["tini", "--"]

View File

@@ -41,14 +41,16 @@ import threading
# PATHS # PATHS
#=============================================================================== #===============================================================================
PIALERT_BACK_PATH = os.path.dirname(os.path.abspath(__file__)) PIALERT_BACK_PATH = os.path.dirname(os.path.abspath(__file__))
pialertPath = PIALERT_BACK_PATH + "/.." pialertPath = PIALERT_BACK_PATH + "/.." #to fix - remove references and use pialertPath instead
logPath = pialertPath + '/front/log' logPath = pialertPath + '/front/log'
pialertPath = '/home/pi/pialert'
confPath = "/config/pialert.conf" confPath = "/config/pialert.conf"
dbPath = '/db/pialert.db' dbPath = '/db/pialert.db'
fullConfPath = pialertPath + confPath fullConfPath = pialertPath + confPath
fullDbPath = pialertPath + dbPath fullDbPath = pialertPath + dbPath
STOPARPSCAN = pialertPath + "/db/setting_stoparpscan" STOPARPSCAN = pialertPath + "/db/setting_stoparpscan"
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def file_print(*args): def file_print(*args):
@@ -61,11 +63,6 @@ def file_print(*args):
file.write(result + '\n') file.write(result + '\n')
file.close() file.close()
#===============================================================================
# USER CONFIG VARIABLES - START
#===============================================================================
# check RW access of DB and config file # check RW access of DB and config file
file_print('\n Permissions check (All should be True)') file_print('\n Permissions check (All should be True)')
file_print('------------------------------------------------') file_print('------------------------------------------------')
@@ -75,7 +72,55 @@ file_print( " " + dbPath + " | " + " READ | " + str(os.access(fullDbPath
file_print( " " + dbPath + " | " + " WRITE | " + str(os.access(fullDbPath, os.W_OK))) file_print( " " + dbPath + " | " + " WRITE | " + str(os.access(fullDbPath, os.W_OK)))
file_print('------------------------------------------------') file_print('------------------------------------------------')
pialertPath = '/home/pi/pialert' #-------------------------------------------------------------------------------
def append_file_binary (pPath, input):
file = open (pPath, 'ab')
file.write (input)
file.close()
#-------------------------------------------------------------------------------
def logResult (stdout, stderr):
if stderr != None:
append_file_binary (logPath + '/stderr.log', stderr)
if stdout != None:
append_file_binary (logPath + '/stdout.log', stdout)
def initialiseFile(pathToCheck, defaultFile):
# if file not readable (missing?) try to copy over the backed-up (default) one
if str(os.access(pathToCheck, os.R_OK)) == "False":
file_print("[Setup] The "+ pathToCheck +" file is not readable (missing?). Trying to copy over the backed-up (default) one.")
try:
# try runnning a subprocess
p = subprocess.Popen(["cp", defaultFile , pathToCheck], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = p.communicate()
if str(os.access(pathToCheck, os.R_OK)) == "False":
file_print("[Setup] Error copying the default file ("+defaultFile+") to it's destination ("+pathToCheck+"). Make sure the app has Read & Write access to the parent directory.")
else:
file_print("[Setup] Default file ("+defaultFile+") copied over successfully to ("+pathToCheck+").")
# write stdout and stderr into .log files for debugging if needed
logResult (stdout, stderr)
except subprocess.CalledProcessError as e:
# An error occured, handle it
file_print("[Setup] Error copying the default file ("+defaultFile+"). Make sure the app has Read & Write access to " + pathToCheck)
file_print(e.output)
#===============================================================================
# Basic checks and Setup
#===============================================================================
# check and initialize pialert.conf
initialiseFile(fullConfPath, "/home/pi/pialert/back/pialert.conf_bak" )
# check and initialize pialert.db
initialiseFile(fullDbPath, "/home/pi/pialert/back/pialert.db_bak")
#===============================================================================
# USER CONFIG VARIABLES - START
#===============================================================================
vendorsDB = '/usr/share/arp-scan/ieee-oui.txt' vendorsDB = '/usr/share/arp-scan/ieee-oui.txt'
piholeDB = '/etc/pihole/pihole-FTL.db' piholeDB = '/etc/pihole/pihole-FTL.db'
@@ -1824,12 +1869,6 @@ def write_file (pPath, pText):
file.write (pText) file.write (pText)
file.close() file.close()
#-------------------------------------------------------------------------------
def append_file_binary (pPath, input):
file = open (pPath, 'ab')
file.write (input)
file.close()
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def append_line_to_file (pPath, pText): def append_line_to_file (pPath, pText):
# append the line depending using the correct python version # append the line depending using the correct python version
@@ -2341,7 +2380,8 @@ def openDB ():
return return
# Log # Log
print_log ('Opening DB...') print_log ('Opening DB...')
# Open DB and Cursor # Open DB and Cursor
sql_connection = sqlite3.connect (fullDbPath, isolation_level=None) sql_connection = sqlite3.connect (fullDbPath, isolation_level=None)
@@ -2445,14 +2485,6 @@ def add_json_list (row, list):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def logResult (stdout, stderr):
if stderr != None:
append_file_binary (logPath + '/stderr.log', stderr)
if stdout != None:
append_file_binary (logPath + '/stdout.log', stdout)
#-------------------------------------------------------------------------------
def to_text(_json): def to_text(_json):
payloadData = "" payloadData = ""
if len(_json['internet']) > 0 and 'internet' in INCLUDED_SECTIONS: if len(_json['internet']) > 0 and 'internet' in INCLUDED_SECTIONS:

View File

@@ -7,7 +7,8 @@ services:
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config - ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config
- ${APP_DATA_LOCATION}/pialert/db/pialert.db:/home/pi/pialert/db/pialert.db # - ${APP_DATA_LOCATION}/pialert/db/pialert.db:/home/pi/pialert/db/pialert.db
- ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db
# (optional) map an empty file with the name 'setting_darkmode' if you want to force the dark mode on container rebuilt # (optional) map an empty file with the name 'setting_darkmode' if you want to force the dark mode on container rebuilt
- ${APP_DATA_LOCATION}/pialert/db/setting_darkmode:/home/pi/pialert/db/setting_darkmode - ${APP_DATA_LOCATION}/pialert/db/setting_darkmode:/home/pi/pialert/db/setting_darkmode
# (optional) useful for debugging if you have issues setting up the container # (optional) useful for debugging if you have issues setting up the container

View File

@@ -34,15 +34,14 @@
| | Path | Description | | | Path | Description |
| :------------- | :------------- |:-------------| | :------------- | :------------- |:-------------|
| **Required** | `:/home/pi/pialert/config` | Folder which needs to contain the `pialert.conf` file (see below for details) | | **Required** | `:/home/pi/pialert/config` | Folder which will contain the `pialert.conf` file (see below for details) |
| **Required** | `:/home/pi/pialert/db/pialert.db` | Map an empty [pialert.db file which can be downloaded from here](https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db) | | **Required** | `:/home/pi/pialert/db` | Folder which will contain the `pialert.db` file |
|Optional| `:/home/pi/pialert/db/setting_darkmode` | Map an empty file with the name `setting_darkmode` if you want to force the dark mode on container rebuilt | |Optional| `:/home/pi/pialert/db/setting_darkmode` | Map an empty file with the name `setting_darkmode` if you want to force the dark mode on container rebuilt |
|Optional| `:/home/pi/pialert/front/log` | Logs folder useful for debugging if you have issues setting up the container | |Optional| `:/home/pi/pialert/front/log` | Logs folder useful for debugging if you have issues setting up the container |
|Optional| `:/etc/pihole/pihole-FTL.db` | PiHole's `pihole-FTL.db` database file. Required if you want to use PiHole | |Optional| `:/etc/pihole/pihole-FTL.db` | PiHole's `pihole-FTL.db` database file. Required if you want to use PiHole |
|Optional| `:/etc/pihole/dhcp.leases` | PiHole's `dhcp.leases` file. Required if you want to use PiHole | |Optional| `:/etc/pihole/dhcp.leases` | PiHole's `dhcp.leases` file. Required if you want to use PiHole |
### Config (`pialert.conf`) ### Config (`pialert.conf`)
- Download [pialert.conf from here](https://github.com/jokob-sk/Pi.Alert/tree/main/config). - Download [pialert.conf from here](https://github.com/jokob-sk/Pi.Alert/tree/main/config).