DB setup details for docker + small fixes

This commit is contained in:
jokob-sk
2022-08-12 12:18:52 +10:00
parent c25fbe4cb8
commit 886a3eef9f
10 changed files with 76 additions and 22 deletions

View File

@@ -12,16 +12,16 @@ JavaScript)*
# Docker image 🐳 # Docker image 🐳
[![Docker](https://github.com/jokob-sk/Pi.Alert/actions/workflows/docker.yml/badge.svg)](https://github.com/jokob-sk/Pi.Alert/actions/workflows/docker.yml) [![Docker](https://github.com/jokob-sk/Pi.Alert/actions/workflows/docker.yml/badge.svg)](https://github.com/jokob-sk/Pi.Alert/actions/workflows/docker.yml)
<a href="https://github.com/jokob-sk/Pi.Alert">
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github">
</a>
[![Docker Image Size](https://img.shields.io/docker/image-size/jokobsk/pi.alert?logo=Docker)](https://hub.docker.com/r/jokobsk/pi.alert) [![Docker Image Size](https://img.shields.io/docker/image-size/jokobsk/pi.alert?logo=Docker)](https://hub.docker.com/r/jokobsk/pi.alert)
<a href="https://hub.docker.com/r/jokobsk/pi.alert"> <a href="https://hub.docker.com/r/jokobsk/pi.alert">
<img src="https://img.shields.io/docker/pulls/jokobsk/pi.alert?logo=docker&color=0aa8d2&logoColor=fff" alt="Docker Pulls"> <img src="https://img.shields.io/docker/pulls/jokobsk/pi.alert?logo=docker&color=0aa8d2&logoColor=fff" alt="Docker Pulls">
</a> </a>
<span> <a href="https://hub.docker.com/r/jokobsk/pi.alert">
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github&amp;style=plastic">
</span>
<span>
<img alt="Docker last pushed" src="https://img.shields.io/badge/dynamic/json?color=blue&label=Last%20pushed&query=last_updated&url=https%3A%2F%2Fhub.docker.com%2Fv2%2Frepositories%2Fjokobsk%2Fpi.alert%2F&logo=docker&?link=http://left&link=https://hub.docker.com/repository/docker/jokobsk/pi.alert"> <img alt="Docker last pushed" src="https://img.shields.io/badge/dynamic/json?color=blue&label=Last%20pushed&query=last_updated&url=https%3A%2F%2Fhub.docker.com%2Fv2%2Frepositories%2Fjokobsk%2Fpi.alert%2F&logo=docker&?link=http://left&link=https://hub.docker.com/repository/docker/jokobsk/pi.alert">
</span> </a>
🥇 Pi.Alert credit goes to [pucherot/Pi.Alert](https://github.com/pucherot/Pi.Alert). <br/> 🥇 Pi.Alert credit goes to [pucherot/Pi.Alert](https://github.com/pucherot/Pi.Alert). <br/>
🐳 Docker Image: [jokobsk/Pi.Alert](https://registry.hub.docker.com/r/jokobsk/pi.alert). <br/> 🐳 Docker Image: [jokobsk/Pi.Alert](https://registry.hub.docker.com/r/jokobsk/pi.alert). <br/>

View File

@@ -45,7 +45,6 @@ else:
execfile (PIALERT_PATH + "/config/version.conf") execfile (PIALERT_PATH + "/config/version.conf")
execfile (PIALERT_PATH + "/config/pialert.conf") execfile (PIALERT_PATH + "/config/pialert.conf")
#=============================================================================== #===============================================================================
# MAIN # MAIN
#=============================================================================== #===============================================================================
@@ -56,6 +55,10 @@ def main ():
global sql_connection global sql_connection
global sql global sql
# Empty stdout and stderr .log files for debugging if needed
write_file (LOG_PATH + '/stderr.log', '')
write_file (LOG_PATH + '/stdout.log', '')
# Header # Header
print ('\nPi.Alert ' + VERSION +' ('+ VERSION_DATE +')') print ('\nPi.Alert ' + VERSION +' ('+ VERSION_DATE +')')
print ('---------------------------------------------------------') print ('---------------------------------------------------------')
@@ -1374,9 +1377,11 @@ def email_reporting ():
'TABLE_EVENTS', mail_text_events, mail_html_events) 'TABLE_EVENTS', mail_text_events, mail_html_events)
# DEBUG - Write output emails for testing # DEBUG - Write output emails for testing
if True : #if True :
write_file (LOG_PATH + '/report_output.txt', mail_text) # write_file (LOG_PATH + '/report_output.txt', mail_text)
write_file (LOG_PATH + '/report_output.html', mail_html) # write_file (LOG_PATH + '/report_output.html', mail_html)
# Send Mail # Send Mail
if mail_section_Internet == True or mail_section_new_devices == True \ if mail_section_Internet == True or mail_section_new_devices == True \
@@ -1492,6 +1497,12 @@ 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
@@ -1553,7 +1564,16 @@ def send_webhook (_Text):
else: else:
_WEBHOOK_URL = WEBHOOK_URL _WEBHOOK_URL = WEBHOOK_URL
requests.post(_WEBHOOK_URL, json.dumps(_json_payload)) p = subprocess.Popen(["curl","-i","-X", "GET" ,"-H", "Content-Type:application/json" ,"-d", json.dumps(_json_payload), _WEBHOOK_URL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = p.communicate()
# write stdout and stderr into .log files for debugging if needed
if stderr != None:
append_file_binary (LOG_PATH + '/stderr.log', stderr)
if stdout != None:
append_file_binary (LOG_PATH + '/stdout.log', stdout)
#=============================================================================== #===============================================================================
# DB # DB

View File

@@ -40,7 +40,6 @@ WEBHOOK_URL = 'http://n8n.local:5555/webhook-test/aaaaaaaa-aaaa-aaaa
# ---------------------- # ----------------------
REPORT_NTFY = False REPORT_NTFY = False
NTFY_TOPIC = 'replace_my_secure_topicname_91h889f28' NTFY_TOPIC = 'replace_my_secure_topicname_91h889f28'
REPORT_DASHBOARD_URL = 'http://pi.alert/'
# PUSHSAFER (https://www.pushsafer.com/) settings # PUSHSAFER (https://www.pushsafer.com/) settings
# ---------------------- # ----------------------

View File

@@ -1,14 +1,14 @@
[![Docker](https://github.com/jokob-sk/Pi.Alert/actions/workflows/docker.yml/badge.svg)](https://github.com/jokob-sk/Pi.Alert/actions/workflows/docker.yml) [![Docker](https://github.com/jokob-sk/Pi.Alert/actions/workflows/docker.yml/badge.svg)](https://github.com/jokob-sk/Pi.Alert/actions/workflows/docker.yml)
<a href="https://github.com/jokob-sk/Pi.Alert">
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github">
</a>
[![Docker Image Size](https://img.shields.io/docker/image-size/jokobsk/pi.alert?logo=Docker)](https://hub.docker.com/r/jokobsk/pi.alert) [![Docker Image Size](https://img.shields.io/docker/image-size/jokobsk/pi.alert?logo=Docker)](https://hub.docker.com/r/jokobsk/pi.alert)
<a href="https://hub.docker.com/r/jokobsk/pi.alert"> <a href="https://hub.docker.com/r/jokobsk/pi.alert">
<img src="https://img.shields.io/docker/pulls/jokobsk/pi.alert?logo=docker&color=0aa8d2&logoColor=fff" alt="Docker Pulls"> <img src="https://img.shields.io/docker/pulls/jokobsk/pi.alert?logo=docker&color=0aa8d2&logoColor=fff" alt="Docker Pulls">
</a> </a>
<span> <a href="https://hub.docker.com/r/jokobsk/pi.alert">
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github&amp;style=plastic">
</span>
<span>
<img alt="Docker last pushed" src="https://img.shields.io/badge/dynamic/json?color=blue&label=Last%20pushed&query=last_updated&url=https%3A%2F%2Fhub.docker.com%2Fv2%2Frepositories%2Fjokobsk%2Fpi.alert%2F&logo=docker&?link=http://left&link=https://hub.docker.com/repository/docker/jokobsk/pi.alert"> <img alt="Docker last pushed" src="https://img.shields.io/badge/dynamic/json?color=blue&label=Last%20pushed&query=last_updated&url=https%3A%2F%2Fhub.docker.com%2Fv2%2Frepositories%2Fjokobsk%2Fpi.alert%2F&logo=docker&?link=http://left&link=https://hub.docker.com/repository/docker/jokobsk/pi.alert">
</span> </a>
# 🐳 A docker image for Pi.Alert # 🐳 A docker image for Pi.Alert
@@ -46,7 +46,10 @@ Default Port
* ... or by mapping the files individually `pialert.conf:/home/pi/pialert/config/pialert.conf` and `version.conf:/home/pi/pialert/config/version.conf` * ... or by mapping the files individually `pialert.conf:/home/pi/pialert/config/pialert.conf` and `version.conf:/home/pi/pialert/config/version.conf`
4. Set the `TZ` environment variable to your current time zone (e.g.`Europe/Paris`). Find your time zone [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). 4. Set the `TZ` environment variable to your current time zone (e.g.`Europe/Paris`). Find your time zone [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
5. Database backup 5. Database backup
* The DB is stored under `/home/pi/pialert/db/pialert.db`. Map this file to a persistent location (see [Examples](https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#page_facing_up-examples) for details). If facing issues (AJAX errors, can't write to DB, etc, make sure permissions are set correctly, alternatively check the logs under `/home/pi/pialert/log`) * Download the [original DB from GitHub](https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db).
* Map the `pialert.db` file (⚠ not folder) from above to `/home/pi/pialert/db/pialert.db` (see [Examples](https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples) for details).
* If facing issues (AJAX errors, can't write to DB, etc,) make sure permissions are set correctly, alternatively check the logs under `/home/pi/pialert/log`.
* To solve permission issues you can also try to create a DB backup and then run a DB Restore via the **Maintenance > Backup/Restore** section.
6. The container supports mapping to local User nad Group IDs. Specify the enviroment variables `HOST_USER_ID` and `HOST_USER_GID` if needed. 6. The container supports mapping to local User nad Group IDs. Specify the enviroment variables `HOST_USER_ID` and `HOST_USER_GID` if needed.
7. You can override the port by specifying the `PORT` env variable. 7. You can override the port by specifying the `PORT` env variable.

View File

@@ -65,6 +65,19 @@ if ($_SESSION["login"] != 1)
</div> </div>
</div> </div>
</div> </div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion_gen" href="#collapse102docker">
<?php echo $pia_lang['HelpFAQ_Cat_General_102docker_head'];?></a>
</h4>
</div>
<div id="collapse102docker" class="panel-collapse collapse" style="font-size: 16px;">
<div class="panel-body">
<?php echo $pia_lang['HelpFAQ_Cat_General_102docker_text'];?>
</div>
</div>
</div>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h4 class="panel-title"> <h4 class="panel-title">

View File

@@ -364,11 +364,11 @@ if (submit && isset($_POST['langselector_set'])) {
<div class="box"> <div class="box">
<div class="box-body" style="text-align: center;"> <div class="box-body" style="text-align: center;">
<h5 class="text-aqua" style="font-size: 16px;"> <h5 class="text-aqua" style="font-size: 16px;">
<span> <span id="lastCommit">
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github&amp;style=plastic">
</span> </span>
<span> <span id="lastDockerUpdate">
<img alt="Docker last pushed" src="https://img.shields.io/badge/dynamic/json?color=blue&label=Last%20pushed&query=last_updated&url=https%3A%2F%2Fhub.docker.com%2Fv2%2Frepositories%2Fjokobsk%2Fpi.alert%2F&logo=docker&?link=http://left&link=https://hub.docker.com/repository/docker/jokobsk/pi.alert">
</span> </span>
</h5> </h5>
</div> </div>
@@ -570,6 +570,18 @@ function PiaToggleArpScan()
}); });
} }
// laod footer asynchronously not to block the page load/other sections
window.onload = function asyncFooter()
{
$("#lastCommit").append('<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github&amp;style=plastic">');
$("#lastDockerUpdate").append(
'<img alt="Docker last pushed" src="https://img.shields.io/badge/dynamic/json?color=blue&label=Last%20pushed&query=last_updated&url=https%3A%2F%2Fhub.docker.com%2Fv2%2Frepositories%2Fjokobsk%2Fpi.alert%2F&logo=docker&?link=http://left&link=https://hub.docker.com/repository/docker/jokobsk/pi.alert">');
}
</script> </script>

View File

@@ -45,7 +45,7 @@ if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';}
case 'deleteDevice': deleteDevice(); break; case 'deleteDevice': deleteDevice(); break;
case 'deleteAllWithEmptyMACs': deleteAllWithEmptyMACs(); break; case 'deleteAllWithEmptyMACs': deleteAllWithEmptyMACs(); break;
case 'createBackupDB': createBackupDB(); break; case 'createBackupDB': createBackupDB(); break;
case 'restoreBackupDB': restoreBackupDB(); break;
case 'deleteAllDevices': deleteAllDevices(); break; case 'deleteAllDevices': deleteAllDevices(); break;
case 'runScan15min': runScan15min(); break; case 'runScan15min': runScan15min(); break;
case 'runScan1min': runScan1min(); break; case 'runScan1min': runScan1min(); break;

View File

@@ -361,6 +361,13 @@ $pia_lang['HelpFAQ_Cat_General_102_text'] = 'Check in the Pi.Alert directory if
chmod -R 770 ~/pialert/db chmod -R 770 ~/pialert/db
</span><br> </span><br>
If the database is still read-only, try reinstalling or restoring a database backup from the maintenance page.'; If the database is still read-only, try reinstalling or restoring a database backup from the maintenance page.';
$pia_lang['HelpFAQ_Cat_General_102docker_head'] = '(Docker only 🐳) Database issues (AJAX errors, read-only, not found)';
$pia_lang['HelpFAQ_Cat_General_102docker_text'] = 'Double-check you\'ve followed the <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles">dockerfile readme (most up-to-date info)</a>. <br/> <br/> <ul data-sourcepos="49:4-52:146" dir="auto">
<li data-sourcepos="49:4-49:106">Download the <a href="https://github.com/jokob-sk/Pi.Alert/blob/main/db/pialert.db">original DB from GitHub</a>.</li>
<li data-sourcepos="50:4-50:195">Map the <code>pialert.db</code> file (<g-emoji class="g-emoji" alias="warning" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/26a0.png">⚠</g-emoji> not folder) from above to <code>/home/pi/pialert/db/pialert.db</code> (see <a href="https://github.com/jokob-sk/Pi.Alert/tree/main/dockerfiles#-examples">Examples</a> for details).</li>
<li data-sourcepos="51:4-51:161">If facing issues (AJAX errors, can\'t write to DB, etc,) make sure permissions are set correctly, alternatively check the logs under <code>/home/pi/pialert/log</code>.</li>
<li data-sourcepos="52:4-52:146">To solve permission issues you can also try to create a DB backup and then run a DB Restore via the <strong>Maintenance &gt; Backup/Restore</strong> section.</li>
</ul>';
$pia_lang['HelpFAQ_Cat_General_103_head'] = 'The login page does not appear, even after changing the password.'; $pia_lang['HelpFAQ_Cat_General_103_head'] = 'The login page does not appear, even after changing the password.';
$pia_lang['HelpFAQ_Cat_General_103_text'] = 'In addition to the password, the configuration file must contain <span class="text-danger help_faq_code">~/pialert/config/pialert.conf</span> $pia_lang['HelpFAQ_Cat_General_103_text'] = 'In addition to the password, the configuration file must contain <span class="text-danger help_faq_code">~/pialert/config/pialert.conf</span>
also the parameter <span class="text-danger help_faq_code">PIALERT_WEB_PROTECTION</span> must set to <span class="text-danger help_faq_code">True</span>.'; also the parameter <span class="text-danger help_faq_code">PIALERT_WEB_PROTECTION</span> must set to <span class="text-danger help_faq_code">True</span>.';

0
log/stderr.log Normal file
View File

0
log/stdout.log Normal file
View File