mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Compare commits
11 Commits
00a47ab5d3
...
next_relea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfd2cf9e20 | ||
|
|
61824abb9f | ||
|
|
33c5548fe1 | ||
|
|
fd41c395ae | ||
|
|
1a980844f0 | ||
|
|
82e018e284 | ||
|
|
e0e1233b1c | ||
|
|
74677f940e | ||
|
|
21a4d20579 | ||
|
|
9634e4e0f7 | ||
|
|
59b417705e |
12
.github/workflows/docker_prod.yml
vendored
12
.github/workflows/docker_prod.yml
vendored
@@ -32,6 +32,18 @@ jobs:
|
|||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
# --- Previous approach Get release version from tag
|
||||||
|
- name: Set up dynamic build ARGs
|
||||||
|
id: getargs
|
||||||
|
run: echo "version=$(cat ./stable/VERSION)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Get release version
|
||||||
|
id: get_version_prev
|
||||||
|
run: echo "::set-output name=version::${GITHUB_REF#refs/tags/}"
|
||||||
|
|
||||||
|
- name: Create .VERSION file
|
||||||
|
run: echo "${{ steps.get_version.outputs.version }}" >> .VERSION_PREV
|
||||||
|
|
||||||
# --- Get release version from tag
|
# --- Get release version from tag
|
||||||
- name: Get release version
|
- name: Get release version
|
||||||
id: get_version
|
id: get_version
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@ nohup.out
|
|||||||
config/*
|
config/*
|
||||||
.ash_history
|
.ash_history
|
||||||
.VERSION
|
.VERSION
|
||||||
|
.VERSION_PREV
|
||||||
config/pialert.conf
|
config/pialert.conf
|
||||||
config/app.conf
|
config/app.conf
|
||||||
db/*
|
db/*
|
||||||
|
|||||||
29
Dockerfile
29
Dockerfile
@@ -1,16 +1,16 @@
|
|||||||
# The NetAlertX Dockerfile has 3 stages:
|
# The NetAlertX Dockerfile has 3 stages:
|
||||||
#
|
#
|
||||||
# Stage 1. Builder - NetAlertX Requires special tools and packages to build our virtual environment, but
|
# Stage 1. Builder - NetAlertX Requires special tools and packages to build our virtual environment, but
|
||||||
# which are not needed in future stages. We build the builder and extract the venv for runner to use as
|
# which are not needed in future stages. We build the builder and extract the venv for runner to use as
|
||||||
# a base.
|
# a base.
|
||||||
#
|
#
|
||||||
# Stage 2. Runner builds the bare minimum requirements to create an operational NetAlertX. The primary
|
# Stage 2. Runner builds the bare minimum requirements to create an operational NetAlertX. The primary
|
||||||
# reason for breaking at this stage is it leaves the system in a proper state for devcontainer operation
|
# reason for breaking at this stage is it leaves the system in a proper state for devcontainer operation
|
||||||
# This image also provides a break-out point for uses who wish to execute the anti-pattern of using a
|
# This image also provides a break-out point for uses who wish to execute the anti-pattern of using a
|
||||||
# docker container as a VM for experimentation and various development patterns.
|
# docker container as a VM for experimentation and various development patterns.
|
||||||
#
|
#
|
||||||
# Stage 3. Hardened removes root, sudoers, folders, permissions, and locks the system down into a read-only
|
# Stage 3. Hardened removes root, sudoers, folders, permissions, and locks the system down into a read-only
|
||||||
# compatible image. While NetAlertX does require some read-write operations, this image can guarantee the
|
# compatible image. While NetAlertX does require some read-write operations, this image can guarantee the
|
||||||
# code pushed out by the project is the only code which will run on the system after each container restart.
|
# code pushed out by the project is the only code which will run on the system after each container restart.
|
||||||
# It reduces the chance of system hijacking and operates with all modern security protocols in place as is
|
# It reduces the chance of system hijacking and operates with all modern security protocols in place as is
|
||||||
# expected from a security appliance.
|
# expected from a security appliance.
|
||||||
@@ -29,7 +29,7 @@ COPY requirements.txt /tmp/requirements.txt
|
|||||||
RUN apk add --no-cache bash shadow python3 python3-dev gcc musl-dev libffi-dev openssl-dev git \
|
RUN apk add --no-cache bash shadow python3 python3-dev gcc musl-dev libffi-dev openssl-dev git \
|
||||||
&& python -m venv /opt/venv
|
&& python -m venv /opt/venv
|
||||||
|
|
||||||
# Create virtual environment owned by root, but readable by everyone else. This makes it easy to copy
|
# Create virtual environment owned by root, but readable by everyone else. This makes it easy to copy
|
||||||
# into hardened stage without worrying about permissions and keeps image size small. Keeping the commands
|
# into hardened stage without worrying about permissions and keeps image size small. Keeping the commands
|
||||||
# together makes for a slightly smaller image size.
|
# together makes for a slightly smaller image size.
|
||||||
RUN pip install --no-cache-dir -r /tmp/requirements.txt && \
|
RUN pip install --no-cache-dir -r /tmp/requirements.txt && \
|
||||||
@@ -95,11 +95,11 @@ ENV READ_WRITE_FOLDERS="${NETALERTX_DATA} ${NETALERTX_CONFIG} ${NETALERTX_DB} ${
|
|||||||
${SYSTEM_SERVICES_ACTIVE_CONFIG}"
|
${SYSTEM_SERVICES_ACTIVE_CONFIG}"
|
||||||
|
|
||||||
#Python environment
|
#Python environment
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
ENV VIRTUAL_ENV=/opt/venv
|
ENV VIRTUAL_ENV=/opt/venv
|
||||||
ENV VIRTUAL_ENV_BIN=/opt/venv/bin
|
ENV VIRTUAL_ENV_BIN=/opt/venv/bin
|
||||||
ENV PYTHONPATH=${NETALERTX_APP}:${NETALERTX_SERVER}:${NETALERTX_PLUGINS}:${VIRTUAL_ENV}/lib/python3.12/site-packages
|
ENV PYTHONPATH=${NETALERTX_APP}:${NETALERTX_SERVER}:${NETALERTX_PLUGINS}:${VIRTUAL_ENV}/lib/python3.12/site-packages
|
||||||
ENV PATH="${SYSTEM_SERVICES}:${VIRTUAL_ENV_BIN}:$PATH"
|
ENV PATH="${SYSTEM_SERVICES}:${VIRTUAL_ENV_BIN}:$PATH"
|
||||||
|
|
||||||
# App Environment
|
# App Environment
|
||||||
ENV LISTEN_ADDR=0.0.0.0
|
ENV LISTEN_ADDR=0.0.0.0
|
||||||
@@ -110,7 +110,7 @@ ENV VENDORSPATH_NEWEST=${SYSTEM_SERVICES_RUN_TMP}/ieee-oui.txt
|
|||||||
ENV ENVIRONMENT=alpine
|
ENV ENVIRONMENT=alpine
|
||||||
ENV READ_ONLY_USER=readonly READ_ONLY_GROUP=readonly
|
ENV READ_ONLY_USER=readonly READ_ONLY_GROUP=readonly
|
||||||
ENV NETALERTX_USER=netalertx NETALERTX_GROUP=netalertx
|
ENV NETALERTX_USER=netalertx NETALERTX_GROUP=netalertx
|
||||||
ENV LANG=C.UTF-8
|
ENV LANG=C.UTF-8
|
||||||
|
|
||||||
|
|
||||||
RUN apk add --no-cache bash mtr libbsd zip lsblk tzdata curl arp-scan iproute2 iproute2-ss nmap \
|
RUN apk add --no-cache bash mtr libbsd zip lsblk tzdata curl arp-scan iproute2 iproute2-ss nmap \
|
||||||
@@ -138,6 +138,7 @@ RUN install -d -o ${NETALERTX_USER} -g ${NETALERTX_GROUP} -m 700 ${READ_WRITE_FO
|
|||||||
|
|
||||||
# Copy version information into the image
|
# Copy version information into the image
|
||||||
COPY --chown=${NETALERTX_USER}:${NETALERTX_GROUP} .[V]ERSION ${NETALERTX_APP}/.VERSION
|
COPY --chown=${NETALERTX_USER}:${NETALERTX_GROUP} .[V]ERSION ${NETALERTX_APP}/.VERSION
|
||||||
|
COPY --chown=${NETALERTX_USER}:${NETALERTX_GROUP} .[V]ERSION ${NETALERTX_APP}/.VERSION_PREV
|
||||||
|
|
||||||
# Copy the virtualenv from the builder stage
|
# Copy the virtualenv from the builder stage
|
||||||
COPY --from=builder --chown=20212:20212 ${VIRTUAL_ENV} ${VIRTUAL_ENV}
|
COPY --from=builder --chown=20212:20212 ${VIRTUAL_ENV} ${VIRTUAL_ENV}
|
||||||
@@ -147,12 +148,12 @@ COPY --from=builder --chown=20212:20212 ${VIRTUAL_ENV} ${VIRTUAL_ENV}
|
|||||||
# This is done after the copy of the venv to ensure the venv is in place
|
# This is done after the copy of the venv to ensure the venv is in place
|
||||||
# although it may be quicker to do it before the copy, it keeps the image
|
# although it may be quicker to do it before the copy, it keeps the image
|
||||||
# layers smaller to do it after.
|
# layers smaller to do it after.
|
||||||
RUN if [ -f '.VERSION' ]; then \
|
RUN for vfile in .VERSION .VERSION_PREV; do \
|
||||||
cp '.VERSION' "${NETALERTX_APP}/.VERSION"; \
|
if [ ! -f "${NETALERTX_APP}/${vfile}" ]; then \
|
||||||
else \
|
echo "DEVELOPMENT 00000000" > "${NETALERTX_APP}/${vfile}"; \
|
||||||
echo "DEVELOPMENT 00000000" > "${NETALERTX_APP}/.VERSION"; \
|
fi; \
|
||||||
fi && \
|
chown 20212:20212 "${NETALERTX_APP}/${vfile}"; \
|
||||||
chown 20212:20212 "${NETALERTX_APP}/.VERSION" && \
|
done && \
|
||||||
apk add --no-cache libcap && \
|
apk add --no-cache libcap && \
|
||||||
setcap cap_net_raw+ep /bin/busybox && \
|
setcap cap_net_raw+ep /bin/busybox && \
|
||||||
setcap cap_net_raw,cap_net_admin+eip /usr/bin/nmap && \
|
setcap cap_net_raw,cap_net_admin+eip /usr/bin/nmap && \
|
||||||
@@ -180,7 +181,7 @@ ENV UMASK=0077
|
|||||||
|
|
||||||
# Create readonly user and group with no shell access.
|
# Create readonly user and group with no shell access.
|
||||||
# Readonly user marks folders that are created by NetAlertX, but should not be modified.
|
# Readonly user marks folders that are created by NetAlertX, but should not be modified.
|
||||||
# AI may claim this is stupid, but it's actually least possible permissions as
|
# AI may claim this is stupid, but it's actually least possible permissions as
|
||||||
# read-only user cannot login, cannot sudo, has no write permission, and cannot even
|
# read-only user cannot login, cannot sudo, has no write permission, and cannot even
|
||||||
# read the files it owns. The read-only user is ownership-as-a-lock hardening pattern.
|
# read the files it owns. The read-only user is ownership-as-a-lock hardening pattern.
|
||||||
RUN addgroup -g 20212 "${READ_ONLY_GROUP}" && \
|
RUN addgroup -g 20212 "${READ_ONLY_GROUP}" && \
|
||||||
|
|||||||
@@ -253,11 +253,11 @@ docker run -it --rm --name netalertx --user "0" \
|
|||||||
ghcr.io/jokob-sk/netalertx:latest
|
ghcr.io/jokob-sk/netalertx:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
..or alternatively execute:
|
...or alternatively execute:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo chown -R 20211:20211 /local_data_dir
|
sudo chown -R 20211:20211 /local_data_dir
|
||||||
sudo chmod -R a+rwx /local_data_dir/
|
sudo chmod -R a+rwx /local_data_dir
|
||||||
```
|
```
|
||||||
|
|
||||||
7. Stop the container
|
7. Stop the container
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ There is also an in-app Help / FAQ section that should be answering frequently a
|
|||||||
|
|
||||||
#### 🐳 Docker (Fully supported)
|
#### 🐳 Docker (Fully supported)
|
||||||
|
|
||||||
- The main installation method is as a [docker container - follow these instructions here](./DOCKER_INSTALLATION.md).
|
- The main installation method is as a [docker container - follow these instructions here](./DOCKER_INSTALLATION.md).
|
||||||
|
|
||||||
#### 💻 Bare-metal / On-server (Experimental/community supported 🧪)
|
#### 💻 Bare-metal / On-server (Experimental/community supported 🧪)
|
||||||
|
|
||||||
- [(Experimental 🧪) On-hardware instructions](./HW_INSTALL.md)
|
- [(Experimental 🧪) On-hardware instructions](./HW_INSTALL.md)
|
||||||
|
|
||||||
- Alternative bare-metal install forks:
|
- Alternative bare-metal install forks:
|
||||||
- [leiweibau's fork](https://github.com/leiweibau/Pi.Alert/) (maintained)
|
- [leiweibau's fork](https://github.com/leiweibau/Pi.Alert/) (maintained)
|
||||||
- [pucherot's original code](https://github.com/pucherot/Pi.Alert/) (un-maintained)
|
- [pucherot's original code](https://github.com/pucherot/Pi.Alert/) (un-maintained)
|
||||||
|
|
||||||
@@ -63,7 +63,6 @@ There is also an in-app Help / FAQ section that should be answering frequently a
|
|||||||
|
|
||||||
#### ♻ Misc
|
#### ♻ Misc
|
||||||
|
|
||||||
- [Version history (legacy)](./VERSIONS_HISTORY.md)
|
|
||||||
- [Reverse proxy (Nginx, Apache, SWAG)](./REVERSE_PROXY.md)
|
- [Reverse proxy (Nginx, Apache, SWAG)](./REVERSE_PROXY.md)
|
||||||
- [Installing Updates](./UPDATES.md)
|
- [Installing Updates](./UPDATES.md)
|
||||||
- [Setting up Authelia](./AUTHELIA.md) (DRAFT)
|
- [Setting up Authelia](./AUTHELIA.md) (DRAFT)
|
||||||
@@ -80,27 +79,27 @@ There is also an in-app Help / FAQ section that should be answering frequently a
|
|||||||
- [Frontend development tips](./FRONTEND_DEVELOPMENT.md)
|
- [Frontend development tips](./FRONTEND_DEVELOPMENT.md)
|
||||||
- [Webhook secrets](./WEBHOOK_SECRET.md)
|
- [Webhook secrets](./WEBHOOK_SECRET.md)
|
||||||
|
|
||||||
Feel free to suggest or submit new docs via a PR.
|
Feel free to suggest or submit new docs via a PR.
|
||||||
|
|
||||||
## 👨💻 Development priorities
|
## 👨💻 Development priorities
|
||||||
|
|
||||||
Priorities from highest to lowest:
|
Priorities from highest to lowest:
|
||||||
|
|
||||||
* 🔼 Fixing core functionality bugs not solvable with workarounds
|
* 🔼 Fixing core functionality bugs not solvable with workarounds
|
||||||
* 🔵 New core functionality unlocking other opportunities (e.g.: plugins)
|
* 🔵 New core functionality unlocking other opportunities (e.g.: plugins)
|
||||||
* 🔵 Refactoring enabling faster implementation of future functionality
|
* 🔵 Refactoring enabling faster implementation of future functionality
|
||||||
* 🔽 (low) UI functionality & improvements (PRs welcome 😉)
|
* 🔽 (low) UI functionality & improvements (PRs welcome 😉)
|
||||||
|
|
||||||
Design philosophy: Focus on core functionality and leverage existing apps and tools to make NetAlertX integrate into other workflows.
|
Design philosophy: Focus on core functionality and leverage existing apps and tools to make NetAlertX integrate into other workflows.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
1. Supporting apprise makes more sense than implementing multiple individual notification gateways
|
1. Supporting apprise makes more sense than implementing multiple individual notification gateways
|
||||||
2. Implementing regular expression support across settings for validation makes more sense than validating one setting with a specific expression.
|
2. Implementing regular expression support across settings for validation makes more sense than validating one setting with a specific expression.
|
||||||
|
|
||||||
UI-specific requests are a low priority as the framework picked by the original developer is not very extensible (and afaik doesn't support components) and has limited mobile support. Also, I argue the value proposition is smaller than working on something else.
|
UI-specific requests are a low priority as the framework picked by the original developer is not very extensible (and afaik doesn't support components) and has limited mobile support. Also, I argue the value proposition is smaller than working on something else.
|
||||||
|
|
||||||
Feel free to submit PRs if interested. try to **keep the PRs small/on-topic** so they are easier to review and approve.
|
Feel free to submit PRs if interested. try to **keep the PRs small/on-topic** so they are easier to review and approve.
|
||||||
|
|
||||||
That being said, I'd reconsider if more people and or recurring sponsors file a request 😉.
|
That being said, I'd reconsider if more people and or recurring sponsors file a request 😉.
|
||||||
|
|
||||||
@@ -112,8 +111,8 @@ Please be as detailed as possible with **workarounds** you considered and why a
|
|||||||
|
|
||||||
If you submit a PR please:
|
If you submit a PR please:
|
||||||
|
|
||||||
1. Check that your changes are backward compatible with existing installations and with a blank setup.
|
1. Check that your changes are backward compatible with existing installations and with a blank setup.
|
||||||
2. Existing features should always be preserved.
|
2. Existing features should always be preserved.
|
||||||
3. Keep the PR small, on-topic and don't change code that is not necessary for the PR to work
|
3. Keep the PR small, on-topic and don't change code that is not necessary for the PR to work
|
||||||
4. New features code should ideally be re-usable for different purposes, not for a very narrow use case.
|
4. New features code should ideally be re-usable for different purposes, not for a very narrow use case.
|
||||||
5. New functionality should ideally be implemented via the Plugins system, if possible.
|
5. New functionality should ideally be implemented via the Plugins system, if possible.
|
||||||
@@ -131,13 +130,13 @@ Suggested test cases:
|
|||||||
Some additional context:
|
Some additional context:
|
||||||
|
|
||||||
* Permanent settings/config is stored in the `app.conf` file
|
* Permanent settings/config is stored in the `app.conf` file
|
||||||
* Currently temporary (session?) settings are stored in the `Parameters` DB table as key-value pairs. This table is wiped during a container rebuild/restart and its values are re-initialized from cookies/session data from the browser.
|
* Currently temporary (session?) settings are stored in the `Parameters` DB table as key-value pairs. This table is wiped during a container rebuild/restart and its values are re-initialized from cookies/session data from the browser.
|
||||||
|
|
||||||
## 🐛 Submitting an issue or bug
|
## 🐛 Submitting an issue or bug
|
||||||
|
|
||||||
Before submitting a new issue please spend a couple of minutes on research:
|
Before submitting a new issue please spend a couple of minutes on research:
|
||||||
|
|
||||||
* Check [🛑 Common issues](./DEBUG_TIPS.md#common-issues)
|
* Check [🛑 Common issues](./DEBUG_TIPS.md#common-issues)
|
||||||
* Check [💡 Closed issues](https://github.com/jokob-sk/NetAlertX/issues?q=is%3Aissue+is%3Aclosed) if a similar issue was solved in the past.
|
* Check [💡 Closed issues](https://github.com/jokob-sk/NetAlertX/issues?q=is%3Aissue+is%3Aclosed) if a similar issue was solved in the past.
|
||||||
* When submitting an issue ❗[enable debug](./DEBUG_TIPS.md)❗
|
* When submitting an issue ❗[enable debug](./DEBUG_TIPS.md)❗
|
||||||
|
|
||||||
|
|||||||
@@ -378,7 +378,7 @@ function localizeTimestamp(input) {
|
|||||||
let tz = getSetting("TIMEZONE") || 'Europe/Berlin';
|
let tz = getSetting("TIMEZONE") || 'Europe/Berlin';
|
||||||
input = String(input || '').trim();
|
input = String(input || '').trim();
|
||||||
|
|
||||||
// ✅ 1. Unix timestamps (10 or 13 digits)
|
// 1. Unix timestamps (10 or 13 digits)
|
||||||
if (/^\d+$/.test(input)) {
|
if (/^\d+$/.test(input)) {
|
||||||
const ms = input.length === 10 ? parseInt(input, 10) * 1000 : parseInt(input, 10);
|
const ms = input.length === 10 ? parseInt(input, 10) * 1000 : parseInt(input, 10);
|
||||||
return new Intl.DateTimeFormat('default', {
|
return new Intl.DateTimeFormat('default', {
|
||||||
@@ -389,39 +389,53 @@ function localizeTimestamp(input) {
|
|||||||
}).format(new Date(ms));
|
}).format(new Date(ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ 2. European DD/MM/YYYY
|
// 2. European DD/MM/YYYY
|
||||||
let match = input.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})(?:[ ,]+(\d{1,2}:\d{2}(?::\d{2})?))?(.*)$/);
|
let match = input.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})(?:[ ,]+(\d{1,2}:\d{2}(?::\d{2})?))?(.*)$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
let [ , d, m, y, t = "00:00:00", tzPart = "" ] = match;
|
let [, d, m, y, t = "00:00:00", tzPart = ""] = match;
|
||||||
const iso = `${y}-${m.padStart(2,'0')}-${d.padStart(2,'0')}T${t.length===5?t+":00":t}${tzPart}`;
|
const iso = `${y}-${m.padStart(2,'0')}-${d.padStart(2,'0')}T${t.length===5?t+":00":t}${tzPart}`;
|
||||||
return formatSafe(iso, tz);
|
return formatSafe(iso, tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ 3. US MM/DD/YYYY
|
// 3. US MM/DD/YYYY
|
||||||
match = input.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})(?:[ ,]+(\d{1,2}:\d{2}(?::\d{2})?))?(.*)$/);
|
match = input.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})(?:[ ,]+(\d{1,2}:\d{2}(?::\d{2})?))?(.*)$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
let [ , m, d, y, t = "00:00:00", tzPart = "" ] = match;
|
let [, m, d, y, t = "00:00:00", tzPart = ""] = match;
|
||||||
const iso = `${y}-${m.padStart(2,'0')}-${d.padStart(2,'0')}T${t.length===5?t+":00":t}${tzPart}`;
|
const iso = `${y}-${m.padStart(2,'0')}-${d.padStart(2,'0')}T${t.length===5?t+":00":t}${tzPart}`;
|
||||||
return formatSafe(iso, tz);
|
return formatSafe(iso, tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ 4. ISO-style (with T, Z, offsets)
|
// 4. ISO YYYY-MM-DD with optional Z/+offset
|
||||||
match = input.match(/^(\d{4}-\d{1,2}-\d{1,2})[ T](\d{1,2}:\d{2}(?::\d{2})?)(Z|[+-]\d{2}:?\d{2})?$/);
|
match = input.match(/^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])[ T](\d{1,2}:\d{2}(?::\d{2})?)(Z|[+-]\d{2}:?\d{2})?$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
let [ , ymd, time, offset = "" ] = match;
|
let [, y, m, d, time, offset = ""] = match;
|
||||||
// normalize to YYYY-MM-DD
|
|
||||||
let [y, m, d] = ymd.split('-').map(x => x.padStart(2,'0'));
|
|
||||||
const iso = `${y}-${m}-${d}T${time.length===5?time+":00":time}${offset}`;
|
const iso = `${y}-${m}-${d}T${time.length===5?time+":00":time}${offset}`;
|
||||||
return formatSafe(iso, tz);
|
return formatSafe(iso, tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ 5. RFC2822 / "25 Aug 2025 13:45:22 +0200"
|
// 5. RFC2822 / "25 Aug 2025 13:45:22 +0200"
|
||||||
match = input.match(/^\d{1,2} [A-Za-z]{3,} \d{4}/);
|
match = input.match(/^\d{1,2} [A-Za-z]{3,} \d{4}/);
|
||||||
if (match) {
|
if (match) {
|
||||||
return formatSafe(input, tz);
|
return formatSafe(input, tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ 6. Fallback (whatever Date() can parse)
|
// 6. DD-MM-YYYY with optional time
|
||||||
|
match = input.match(/^(\d{1,2})-(\d{1,2})-(\d{4})(?:[ T](\d{1,2}:\d{2}(?::\d{2})?))?$/);
|
||||||
|
if (match) {
|
||||||
|
let [, d, m, y, time = "00:00:00"] = match;
|
||||||
|
const iso = `${y}-${m.padStart(2,'0')}-${d.padStart(2,'0')}T${time.length===5?time+":00":time}`;
|
||||||
|
return formatSafe(iso, tz);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. Strict YYYY-DD-MM with optional time
|
||||||
|
match = input.match(/^(\d{4})-(0[1-9]|[12]\d|3[01])-(0[1-9]|1[0-2])(?:[ T](\d{1,2}:\d{2}(?::\d{2})?))?$/);
|
||||||
|
if (match) {
|
||||||
|
let [, y, d, m, time = "00:00:00"] = match;
|
||||||
|
const iso = `${y}-${m}-${d}T${time.length === 5 ? time + ":00" : time}`;
|
||||||
|
return formatSafe(iso, tz);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8. Fallback
|
||||||
return formatSafe(input, tz);
|
return formatSafe(input, tz);
|
||||||
|
|
||||||
function formatSafe(str, tz) {
|
function formatSafe(str, tz) {
|
||||||
@@ -440,6 +454,7 @@ function localizeTimestamp(input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* Replaces double quotes within single-quoted strings, then converts all single quotes to double quotes,
|
* Replaces double quotes within single-quoted strings, then converts all single quotes to double quotes,
|
||||||
@@ -1629,7 +1644,7 @@ async function executeOnce() {
|
|||||||
await cacheSettings();
|
await cacheSettings();
|
||||||
await cacheStrings();
|
await cacheStrings();
|
||||||
|
|
||||||
console.log("✅ All AJAX callbacks have completed");
|
console.log("All AJAX callbacks have completed");
|
||||||
onAllCallsComplete();
|
onAllCallsComplete();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
require 'php/templates/header.php';
|
require 'php/templates/header.php';
|
||||||
require 'php/templates/modals.php';
|
require 'php/templates/modals.php';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// show spinning icon
|
// show spinning icon
|
||||||
showSpinner()
|
showSpinner()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Page ------------------------------------------------------------------ -->
|
<!-- Page ------------------------------------------------------------------ -->
|
||||||
<div class="content-wrapper">
|
<div class="content-wrapper">
|
||||||
<span class="helpIcon">
|
<span class="helpIcon">
|
||||||
<a target="_blank" href="https://github.com/jokob-sk/NetAlertX/blob/main/docs/NETWORK_TREE.md">
|
<a target="_blank" href="https://github.com/jokob-sk/NetAlertX/blob/main/docs/NETWORK_TREE.md">
|
||||||
<i class="fa fa-circle-question"></i>
|
<i class="fa fa-circle-question"></i>
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div id="toggleFilters" class="">
|
<div id="toggleFilters" class="">
|
||||||
<div class="checkbox icheck col-xs-12">
|
<div class="checkbox icheck col-xs-12">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" name="showOffline" checked>
|
<input type="checkbox" name="showOffline" checked>
|
||||||
<div style="margin-left: 10px; display: inline-block; vertical-align: top;">
|
<div style="margin-left: 10px; display: inline-block; vertical-align: top;">
|
||||||
<?= lang('Network_ShowOffline');?>
|
<?= lang('Network_ShowOffline');?>
|
||||||
<span id="showOfflineNumber">
|
<span id="showOfflineNumber">
|
||||||
<!-- placeholder -->
|
<!-- placeholder -->
|
||||||
@@ -31,14 +31,14 @@
|
|||||||
<div class="checkbox icheck col-xs-12">
|
<div class="checkbox icheck col-xs-12">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" name="showArchived">
|
<input type="checkbox" name="showArchived">
|
||||||
<div style="margin-left: 10px; display: inline-block; vertical-align: top;">
|
<div style="margin-left: 10px; display: inline-block; vertical-align: top;">
|
||||||
<?= lang('Network_ShowArchived');?>
|
<?= lang('Network_ShowArchived');?>
|
||||||
<span id="showArchivedNumber">
|
<span id="showArchivedNumber">
|
||||||
<!-- placeholder -->
|
<!-- placeholder -->
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="networkTree" class="drag">
|
<div id="networkTree" class="drag">
|
||||||
@@ -55,8 +55,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<!-- Placeholder -->
|
<!-- Placeholder -->
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section id="unassigned-devices-wrapper">
|
<section id="unassigned-devices-wrapper">
|
||||||
<!-- Placeholder -->
|
<!-- Placeholder -->
|
||||||
</section>
|
</section>
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
require 'php/templates/footer.php';
|
require 'php/templates/footer.php';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<script src="lib/treeviz/bundle.js"></script>
|
<script src="lib/treeviz/bundle.js"></script>
|
||||||
|
|
||||||
<script defer>
|
<script defer>
|
||||||
|
|
||||||
@@ -78,12 +78,12 @@
|
|||||||
|
|
||||||
// Create Top level tabs (List of network devices), explanation of the terminology below:
|
// Create Top level tabs (List of network devices), explanation of the terminology below:
|
||||||
//
|
//
|
||||||
// Switch 1 (node)
|
// Switch 1 (node)
|
||||||
// /(p1) \ (p2) <----- port numbers
|
// /(p1) \ (p2) <----- port numbers
|
||||||
// / \
|
// / \
|
||||||
// Smart TV (leaf) Switch 2 (node (for the PC) and leaf (for Switch 1))
|
// Smart TV (leaf) Switch 2 (node (for the PC) and leaf (for Switch 1))
|
||||||
// \
|
// \
|
||||||
// PC (leaf) <------- leafs are not included in this SQL query
|
// PC (leaf) <------- leafs are not included in this SQL query
|
||||||
const rawSql = `
|
const rawSql = `
|
||||||
SELECT node_name, node_mac, online, node_type, node_ports_count, parent_mac, node_icon, node_alert
|
SELECT node_name, node_mac, online, node_type, node_ports_count, parent_mac, node_icon, node_alert
|
||||||
FROM (
|
FROM (
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
|
|
||||||
const portLabel = node.node_ports_count ? ` (${node.node_ports_count})` : '';
|
const portLabel = node.node_ports_count ? ` (${node.node_ports_count})` : '';
|
||||||
const icon = atob(node.node_icon);
|
const icon = atob(node.node_icon);
|
||||||
const id = node.node_mac.replace(/:/g, '_');
|
const id = node.node_mac.replace(/:/g, '_');
|
||||||
|
|
||||||
html += `
|
html += `
|
||||||
<li class="networkNodeTabHeaders ${i === 0 ? 'active' : ''}">
|
<li class="networkNodeTabHeaders ${i === 0 ? 'active' : ''}">
|
||||||
@@ -137,13 +137,13 @@
|
|||||||
renderNetworkTabContent(nodes);
|
renderNetworkTabContent(nodes);
|
||||||
|
|
||||||
// init selected (first) tab
|
// init selected (first) tab
|
||||||
initTab();
|
initTab();
|
||||||
|
|
||||||
// init selected node highlighting
|
// init selected node highlighting
|
||||||
initSelectedNodeHighlighting()
|
initSelectedNodeHighlighting()
|
||||||
|
|
||||||
// Register events on tab change
|
// Register events on tab change
|
||||||
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||||
initSelectedNodeHighlighting()
|
initSelectedNodeHighlighting()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -205,10 +205,10 @@
|
|||||||
<hr/>
|
<hr/>
|
||||||
<div class="box box-aqua box-body" id="connected">
|
<div class="box box-aqua box-body" id="connected">
|
||||||
<h5>
|
<h5>
|
||||||
<i class="fa fa-sitemap fa-rotate-270"></i>
|
<i class="fa fa-sitemap fa-rotate-270"></i>
|
||||||
${getString('Network_Connected')}
|
${getString('Network_Connected')}
|
||||||
</h5>
|
</h5>
|
||||||
|
|
||||||
<div id="leafs_${id}" class="table-responsive"></div>
|
<div id="leafs_${id}" class="table-responsive"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -234,9 +234,9 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$container.html(wrapperHtml);
|
$container.html(wrapperHtml);
|
||||||
|
|
||||||
const $table = $(`#${tableId}`);
|
const $table = $(`#${tableId}`);
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
@@ -298,7 +298,7 @@
|
|||||||
title: getString('Device_TableHead_Vendor'),
|
title: getString('Device_TableHead_Vendor'),
|
||||||
data: 'devVendor',
|
data: 'devVendor',
|
||||||
width: '20%'
|
width: '20%'
|
||||||
}
|
}
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
||||||
|
|
||||||
@@ -356,7 +356,7 @@
|
|||||||
function loadConnectedDevices(node_mac) {
|
function loadConnectedDevices(node_mac) {
|
||||||
const sql = `
|
const sql = `
|
||||||
SELECT devName, devMac, devLastIP, devVendor, devPresentLastScan, devAlertDown, devParentPort,
|
SELECT devName, devMac, devLastIP, devVendor, devPresentLastScan, devAlertDown, devParentPort,
|
||||||
CASE
|
CASE
|
||||||
WHEN devIsNew = 1 THEN 'New'
|
WHEN devIsNew = 1 THEN 'New'
|
||||||
WHEN devPresentLastScan = 1 THEN 'On-line'
|
WHEN devPresentLastScan = 1 THEN 'On-line'
|
||||||
WHEN devPresentLastScan = 0 AND devAlertDown != 0 THEN 'Down'
|
WHEN devPresentLastScan = 0 AND devAlertDown != 0 THEN 'Down'
|
||||||
@@ -371,7 +371,7 @@
|
|||||||
|
|
||||||
const wrapperHtml = `
|
const wrapperHtml = `
|
||||||
<table class="table table-bordered table-striped node-leafs-table " id="table_leafs_${id}" data-node-mac="${node_mac}">
|
<table class="table table-bordered table-striped node-leafs-table " id="table_leafs_${id}" data-node-mac="${node_mac}">
|
||||||
|
|
||||||
</table>`;
|
</table>`;
|
||||||
|
|
||||||
loadDeviceTable({
|
loadDeviceTable({
|
||||||
@@ -414,12 +414,12 @@
|
|||||||
$.get(apiUrl, function (data) {
|
$.get(apiUrl, function (data) {
|
||||||
|
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
const parsed = JSON.parse(data);
|
const parsed = JSON.parse(data);
|
||||||
const allDevices = parsed;
|
const allDevices = parsed;
|
||||||
|
|
||||||
console.log(allDevices);
|
console.log(allDevices);
|
||||||
|
|
||||||
|
|
||||||
if (!allDevices || allDevices.length === 0) {
|
if (!allDevices || allDevices.length === 0) {
|
||||||
showModalOK(getString('Gen_Warning'), getString('Network_NoDevices'));
|
showModalOK(getString('Gen_Warning'), getString('Network_NoDevices'));
|
||||||
@@ -439,7 +439,7 @@
|
|||||||
{
|
{
|
||||||
$('#showArchivedNumber').text(`(${archivedCount})`);
|
$('#showArchivedNumber').text(`(${archivedCount})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(offlineCount > 0)
|
if(offlineCount > 0)
|
||||||
{
|
{
|
||||||
$('#showOfflineNumber').text(`(${offlineCount})`);
|
$('#showOfflineNumber').text(`(${offlineCount})`);
|
||||||
@@ -501,7 +501,7 @@ var visibleNodesCount = 0;
|
|||||||
var parentNodesCount = 0;
|
var parentNodesCount = 0;
|
||||||
var hiddenMacs = []; // hidden children
|
var hiddenMacs = []; // hidden children
|
||||||
var hiddenChildren = [];
|
var hiddenChildren = [];
|
||||||
var deviceListGlobal = null;
|
var deviceListGlobal = null;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Recursively get children nodes and build a tree
|
// Recursively get children nodes and build a tree
|
||||||
@@ -521,13 +521,17 @@ function getChildren(node, list, path, visited = [])
|
|||||||
|
|
||||||
// Loop through all items to find children of the current node
|
// Loop through all items to find children of the current node
|
||||||
for (var i in list) {
|
for (var i in list) {
|
||||||
if (list[i].devParentMAC.toLowerCase() == node.devMac.toLowerCase() && !hiddenMacs.includes(list[i].devParentMAC)) {
|
const item = list[i];
|
||||||
|
const parentMac = item.devParentMAC || ""; // null-safe
|
||||||
|
const nodeMac = node.devMac || ""; // null-safe
|
||||||
|
|
||||||
visibleNodesCount++;
|
if (parentMac != "" && parentMac.toLowerCase() == nodeMac.toLowerCase() && !hiddenMacs.includes(parentMac)) {
|
||||||
|
|
||||||
// Process children recursively, passing a copy of the visited list
|
visibleNodesCount++;
|
||||||
children.push(getChildren(list[i], list, path + ((path == "") ? "" : '|') + list[i].devParentMAC, visited));
|
|
||||||
}
|
// Process children recursively, passing a copy of the visited list
|
||||||
|
children.push(getChildren(list[i], list, path + ((path == "") ? "" : '|') + parentMac, visited));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track leaf and parent node counts
|
// Track leaf and parent node counts
|
||||||
@@ -537,7 +541,7 @@ function getChildren(node, list, path, visited = [])
|
|||||||
parentNodesCount++;
|
parentNodesCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: node.devName,
|
name: node.devName,
|
||||||
path: path,
|
path: path,
|
||||||
mac: node.devMac,
|
mac: node.devMac,
|
||||||
@@ -562,19 +566,32 @@ function getChildren(node, list, path, visited = [])
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
function getHierarchy()
|
function getHierarchy()
|
||||||
{
|
{
|
||||||
|
let internetNode = null;
|
||||||
|
|
||||||
for(i in deviceListGlobal)
|
for(i in deviceListGlobal)
|
||||||
{
|
{
|
||||||
if(deviceListGlobal[i].devMac == 'Internet')
|
if(deviceListGlobal[i].devMac == 'Internet')
|
||||||
{
|
{
|
||||||
return (getChildren(deviceListGlobal[i], deviceListGlobal, ''))
|
internetNode = deviceListGlobal[i];
|
||||||
|
|
||||||
|
return (getChildren(internetNode, deviceListGlobal, ''))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!internetNode) {
|
||||||
|
showModalOk(
|
||||||
|
getString('Network_Configuration_Error'),
|
||||||
|
getString('Network_Root_Not_Configured')
|
||||||
|
);
|
||||||
|
console.error("getHierarchy(): Internet node not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
function toggleSubTree(parentMac, treePath)
|
function toggleSubTree(parentMac, treePath)
|
||||||
{
|
{
|
||||||
@@ -593,33 +610,33 @@ function toggleSubTree(parentMac, treePath)
|
|||||||
myTree.refresh(updatedTree);
|
myTree.refresh(updatedTree);
|
||||||
|
|
||||||
// re-attach any onclick events
|
// re-attach any onclick events
|
||||||
attachTreeEvents();
|
attachTreeEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
function attachTreeEvents()
|
function attachTreeEvents()
|
||||||
{
|
{
|
||||||
// toggle subtree functionality
|
// toggle subtree functionality
|
||||||
$("div[data-mytreemac]").each(function(){
|
$("div[data-mytreemac]").each(function(){
|
||||||
$(this).attr('onclick', 'toggleSubTree("'+$(this).attr('data-mytreemac')+'","'+ $(this).attr('data-mytreepath')+'")')
|
$(this).attr('onclick', 'toggleSubTree("'+$(this).attr('data-mytreemac')+'","'+ $(this).attr('data-mytreepath')+'")')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Handle network node click - select correct tab in the bottom table
|
// Handle network node click - select correct tab in the bottom table
|
||||||
function handleNodeClick(el)
|
function handleNodeClick(el)
|
||||||
{
|
{
|
||||||
|
|
||||||
isNetworkDevice = $(el).data("devisnetworknodedynamic") == 1;
|
isNetworkDevice = $(el).data("devisnetworknodedynamic") == 1;
|
||||||
targetTabMAC = ""
|
targetTabMAC = ""
|
||||||
thisDevMac= $(el).data("mac");
|
thisDevMac= $(el).data("mac");
|
||||||
|
|
||||||
if (isNetworkDevice == false)
|
if (isNetworkDevice == false)
|
||||||
{
|
{
|
||||||
targetTabMAC = $(el).data("parentmac");
|
targetTabMAC = $(el).data("parentmac");
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
targetTabMAC = thisDevMac;
|
targetTabMAC = thisDevMac;
|
||||||
}
|
}
|
||||||
|
|
||||||
var targetTab = $(`a[data-mytabmac="${targetTabMAC}"]`);
|
var targetTab = $(`a[data-mytabmac="${targetTabMAC}"]`);
|
||||||
@@ -628,8 +645,8 @@ function handleNodeClick(el)
|
|||||||
// Simulate a click event on the target tab
|
// Simulate a click event on the target tab
|
||||||
targetTab.click();
|
targetTab.click();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNetworkDevice) {
|
if (isNetworkDevice) {
|
||||||
// Smooth scroll to the tab content
|
// Smooth scroll to the tab content
|
||||||
@@ -639,7 +656,7 @@ function handleNodeClick(el)
|
|||||||
} else {
|
} else {
|
||||||
$("tr.selected").removeClass("selected");
|
$("tr.selected").removeClass("selected");
|
||||||
$(`tr[data-mac="${thisDevMac}"]`).addClass("selected");
|
$(`tr[data-mac="${thisDevMac}"]`).addClass("selected");
|
||||||
|
|
||||||
const tableId = "table_leafs_" + targetTabMAC.replace(/:/g, '_');
|
const tableId = "table_leafs_" + targetTabMAC.replace(/:/g, '_');
|
||||||
const $table = $(`#${tableId}`).DataTable();
|
const $table = $(`#${tableId}`).DataTable();
|
||||||
|
|
||||||
@@ -669,10 +686,8 @@ function handleNodeClick(el)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
var myTree;
|
var myTree;
|
||||||
|
|
||||||
|
|
||||||
var emSize;
|
var emSize;
|
||||||
var nodeHeight;
|
var nodeHeight;
|
||||||
// var sizeCoefficient = 1.4
|
// var sizeCoefficient = 1.4
|
||||||
@@ -689,140 +704,139 @@ function emToPx(em, element) {
|
|||||||
|
|
||||||
function initTree(myHierarchy)
|
function initTree(myHierarchy)
|
||||||
{
|
{
|
||||||
// calculate the drawing area based on teh tree width and available screen size
|
if(myHierarchy && myHierarchy.type !== "")
|
||||||
|
|
||||||
let baseFontSize = parseFloat($('html').css('font-size'));
|
|
||||||
let treeAreaHeight = ($(window).height() - 155); ;
|
|
||||||
// calculate the font size of the leaf nodes to fit everything into the tree area
|
|
||||||
leafNodesCount == 0 ? 1 : leafNodesCount;
|
|
||||||
|
|
||||||
emSize = pxToEm((treeAreaHeight/(leafNodesCount)).toFixed(2));
|
|
||||||
|
|
||||||
let screenWidthEm = pxToEm($('.networkTable').width()-15);
|
|
||||||
|
|
||||||
// init the drawing area size
|
|
||||||
$("#networkTree").attr('style', `height:${treeAreaHeight}px; width:${emToPx(screenWidthEm)}px`)
|
|
||||||
|
|
||||||
if(myHierarchy.type == "")
|
|
||||||
{
|
{
|
||||||
showModalOk(getString('Network_Configuration_Error'), getString('Network_Root_Not_Configured'))
|
// calculate the drawing area based on the tree width and available screen size
|
||||||
|
let baseFontSize = parseFloat($('html').css('font-size'));
|
||||||
return;
|
let treeAreaHeight = ($(window).height() - 155); ;
|
||||||
|
|
||||||
|
// calculate the font size of the leaf nodes to fit everything into the tree area
|
||||||
|
leafNodesCount == 0 ? 1 : leafNodesCount;
|
||||||
|
|
||||||
|
emSize = pxToEm((treeAreaHeight/(leafNodesCount)).toFixed(2));
|
||||||
|
|
||||||
|
let screenWidthEm = pxToEm($('.networkTable').width()-15);
|
||||||
|
|
||||||
|
// init the drawing area size
|
||||||
|
$("#networkTree").attr('style', `height:${treeAreaHeight}px; width:${emToPx(screenWidthEm)}px`)
|
||||||
|
|
||||||
|
// handle canvas and node size if only a few nodes
|
||||||
|
emSize > 1 ? emSize = 1 : emSize = emSize;
|
||||||
|
|
||||||
|
let nodeHeightPx = emToPx(emSize*1);
|
||||||
|
let nodeWidthPx = emToPx(screenWidthEm / (parentNodesCount));
|
||||||
|
|
||||||
|
// handle if only a few nodes
|
||||||
|
nodeWidthPx > 160 ? nodeWidthPx = 160 : nodeWidthPx = nodeWidthPx;
|
||||||
|
|
||||||
|
console.log(Treeviz);
|
||||||
|
|
||||||
|
myTree = Treeviz.create({
|
||||||
|
htmlId: "networkTree",
|
||||||
|
renderNode: nodeData => {
|
||||||
|
|
||||||
|
(!emptyArr.includes(nodeData.data.port )) ? port = nodeData.data.port : port = "";
|
||||||
|
|
||||||
|
(port == "" || port == 0 || port == 'None' ) ? portBckgIcon = `<i class="fa fa-wifi"></i>` : portBckgIcon = `<i class="fa fa-ethernet"></i>`;
|
||||||
|
|
||||||
|
portHtml = (port == "" || port == 0 || port == 'None' ) ? "   " : port;
|
||||||
|
|
||||||
|
// Build HTML for individual nodes in the network diagram
|
||||||
|
deviceIcon = (!emptyArr.includes(nodeData.data.icon )) ?
|
||||||
|
`<div class="netIcon">
|
||||||
|
${atob(nodeData.data.icon)}
|
||||||
|
</div>` : "";
|
||||||
|
devicePort = `<div class="netPort"
|
||||||
|
style="width:${emSize}em;height:${emSize}em">
|
||||||
|
${portHtml}</div>
|
||||||
|
<div class="portBckgIcon"
|
||||||
|
style="margin-left:-${emSize*0.7}em;">
|
||||||
|
${portBckgIcon}
|
||||||
|
</div>`;
|
||||||
|
collapseExpandIcon = nodeData.data.hiddenChildren ?
|
||||||
|
"square-plus" : "square-minus";
|
||||||
|
|
||||||
|
// generate +/- icon if node has children nodes
|
||||||
|
collapseExpandHtml = nodeData.data.hasChildren ?
|
||||||
|
`<div class="netCollapse"
|
||||||
|
style="font-size:${nodeHeightPx/2}px;top:${Math.floor(nodeHeightPx / 4)}px"
|
||||||
|
data-mytreepath="${nodeData.data.path}"
|
||||||
|
data-mytreemac="${nodeData.data.mac}">
|
||||||
|
<i class="fa fa-${collapseExpandIcon} pointer"></i>
|
||||||
|
</div>` : "";
|
||||||
|
|
||||||
|
selectedNodeMac = $(".nav-tabs-custom .active a").attr('data-mytabmac')
|
||||||
|
|
||||||
|
highlightedCss = nodeData.data.mac == selectedNodeMac ?
|
||||||
|
" highlightedNode " : "";
|
||||||
|
cssNodeType = nodeData.data.devIsNetworkNodeDynamic ?
|
||||||
|
" node-network-device " : " node-standard-device ";
|
||||||
|
|
||||||
|
networkHardwareIcon = nodeData.data.devIsNetworkNodeDynamic ? `<span class="network-hw-icon">
|
||||||
|
<i class="fa-solid fa-hard-drive"></i>
|
||||||
|
</span>` : "";
|
||||||
|
|
||||||
|
const badgeConf = getStatusBadgeParts(nodeData.data.presentLastScan, nodeData.data.alertDown, nodeData.data.mac, statusText = '')
|
||||||
|
|
||||||
|
return result = `<div
|
||||||
|
class="node-inner hover-node-info box pointer ${highlightedCss} ${cssNodeType}"
|
||||||
|
style="height:${nodeHeightPx}px;font-size:${nodeHeightPx-5}px;"
|
||||||
|
onclick="handleNodeClick(this)"
|
||||||
|
data-mac="${nodeData.data.mac}"
|
||||||
|
data-parentMac="${nodeData.data.parentMac}"
|
||||||
|
data-name="${nodeData.data.name}"
|
||||||
|
data-ip="${nodeData.data.ip}"
|
||||||
|
data-mac="${nodeData.data.mac}"
|
||||||
|
data-vendor="${nodeData.data.vendor}"
|
||||||
|
data-type="${nodeData.data.type}"
|
||||||
|
data-devIsNetworkNodeDynamic="${nodeData.data.devIsNetworkNodeDynamic}"
|
||||||
|
data-lastseen="${nodeData.data.lastseen}"
|
||||||
|
data-firstseen="${nodeData.data.firstseen}"
|
||||||
|
data-relationship="${nodeData.data.relType}"
|
||||||
|
data-status="${nodeData.data.status}"
|
||||||
|
data-present="${nodeData.data.presentLastScan}"
|
||||||
|
data-alert="${nodeData.data.alertDown}"
|
||||||
|
data-icon="${nodeData.data.icon}"
|
||||||
|
>
|
||||||
|
<div class="netNodeText">
|
||||||
|
<strong><span>${devicePort} <span class="${badgeConf.cssText}">${deviceIcon}</span></span>
|
||||||
|
<span class="spanNetworkTree anonymizeDev" style="width:${nodeWidthPx-50}px">${nodeData.data.name}</span>
|
||||||
|
${networkHardwareIcon}
|
||||||
|
</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
${collapseExpandHtml}`;
|
||||||
|
},
|
||||||
|
mainAxisNodeSpacing: 'auto',
|
||||||
|
// secondaryAxisNodeSpacing: 0.3,
|
||||||
|
nodeHeight: nodeHeightPx,
|
||||||
|
nodeWidth: nodeWidthPx,
|
||||||
|
marginTop: '5',
|
||||||
|
isHorizontal : true,
|
||||||
|
hasZoom: true,
|
||||||
|
hasPan: true,
|
||||||
|
marginLeft: '10',
|
||||||
|
marginRight: '10',
|
||||||
|
idKey: "mac",
|
||||||
|
hasFlatData: false,
|
||||||
|
relationnalField: "children",
|
||||||
|
linkWidth: (nodeData) => 2,
|
||||||
|
linkColor: (nodeData) => {
|
||||||
|
relConf = getRelationshipConf(nodeData.data.relType)
|
||||||
|
return relConf.color;
|
||||||
|
}
|
||||||
|
// onNodeClick: (nodeData) => handleNodeClick(nodeData),
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(deviceListGlobal);
|
||||||
|
myTree.refresh(myHierarchy);
|
||||||
|
|
||||||
|
// hide spinning icon
|
||||||
|
hideSpinner()
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
console.error("getHierarchy() not returning expected result");
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle canvas and node size if only a few nodes
|
|
||||||
emSize > 1 ? emSize = 1 : emSize = emSize;
|
|
||||||
|
|
||||||
let nodeHeightPx = emToPx(emSize*1);
|
|
||||||
let nodeWidthPx = emToPx(screenWidthEm / (parentNodesCount));
|
|
||||||
|
|
||||||
// handle if only a few nodes
|
|
||||||
nodeWidthPx > 160 ? nodeWidthPx = 160 : nodeWidthPx = nodeWidthPx;
|
|
||||||
|
|
||||||
console.log(Treeviz);
|
|
||||||
|
|
||||||
myTree = Treeviz.create({
|
|
||||||
htmlId: "networkTree",
|
|
||||||
renderNode: nodeData => {
|
|
||||||
|
|
||||||
(!emptyArr.includes(nodeData.data.port )) ? port = nodeData.data.port : port = "";
|
|
||||||
|
|
||||||
(port == "" || port == 0 || port == 'None' ) ? portBckgIcon = `<i class="fa fa-wifi"></i>` : portBckgIcon = `<i class="fa fa-ethernet"></i>`;
|
|
||||||
|
|
||||||
portHtml = (port == "" || port == 0 || port == 'None' ) ? "   " : port;
|
|
||||||
|
|
||||||
// Build HTML for individual nodes in the network diagram
|
|
||||||
deviceIcon = (!emptyArr.includes(nodeData.data.icon )) ?
|
|
||||||
`<div class="netIcon">
|
|
||||||
${atob(nodeData.data.icon)}
|
|
||||||
</div>` : "";
|
|
||||||
devicePort = `<div class="netPort"
|
|
||||||
style="width:${emSize}em;height:${emSize}em">
|
|
||||||
${portHtml}</div>
|
|
||||||
<div class="portBckgIcon"
|
|
||||||
style="margin-left:-${emSize*0.7}em;">
|
|
||||||
${portBckgIcon}
|
|
||||||
</div>`;
|
|
||||||
collapseExpandIcon = nodeData.data.hiddenChildren ?
|
|
||||||
"square-plus" : "square-minus";
|
|
||||||
|
|
||||||
// generate +/- icon if node has children nodes
|
|
||||||
collapseExpandHtml = nodeData.data.hasChildren ?
|
|
||||||
`<div class="netCollapse"
|
|
||||||
style="font-size:${nodeHeightPx/2}px;top:${Math.floor(nodeHeightPx / 4)}px"
|
|
||||||
data-mytreepath="${nodeData.data.path}"
|
|
||||||
data-mytreemac="${nodeData.data.mac}">
|
|
||||||
<i class="fa fa-${collapseExpandIcon} pointer"></i>
|
|
||||||
</div>` : "";
|
|
||||||
|
|
||||||
selectedNodeMac = $(".nav-tabs-custom .active a").attr('data-mytabmac')
|
|
||||||
|
|
||||||
highlightedCss = nodeData.data.mac == selectedNodeMac ?
|
|
||||||
" highlightedNode " : "";
|
|
||||||
cssNodeType = nodeData.data.devIsNetworkNodeDynamic ?
|
|
||||||
" node-network-device " : " node-standard-device ";
|
|
||||||
|
|
||||||
networkHardwareIcon = nodeData.data.devIsNetworkNodeDynamic ? `<span class="network-hw-icon">
|
|
||||||
<i class="fa-solid fa-hard-drive"></i>
|
|
||||||
</span>` : "";
|
|
||||||
|
|
||||||
const badgeConf = getStatusBadgeParts(nodeData.data.presentLastScan, nodeData.data.alertDown, nodeData.data.mac, statusText = '')
|
|
||||||
|
|
||||||
return result = `<div
|
|
||||||
class="node-inner hover-node-info box pointer ${highlightedCss} ${cssNodeType}"
|
|
||||||
style="height:${nodeHeightPx}px;font-size:${nodeHeightPx-5}px;"
|
|
||||||
onclick="handleNodeClick(this)"
|
|
||||||
data-mac="${nodeData.data.mac}"
|
|
||||||
data-parentMac="${nodeData.data.parentMac}"
|
|
||||||
data-name="${nodeData.data.name}"
|
|
||||||
data-ip="${nodeData.data.ip}"
|
|
||||||
data-mac="${nodeData.data.mac}"
|
|
||||||
data-vendor="${nodeData.data.vendor}"
|
|
||||||
data-type="${nodeData.data.type}"
|
|
||||||
data-devIsNetworkNodeDynamic="${nodeData.data.devIsNetworkNodeDynamic}"
|
|
||||||
data-lastseen="${nodeData.data.lastseen}"
|
|
||||||
data-firstseen="${nodeData.data.firstseen}"
|
|
||||||
data-relationship="${nodeData.data.relType}"
|
|
||||||
data-status="${nodeData.data.status}"
|
|
||||||
data-present="${nodeData.data.presentLastScan}"
|
|
||||||
data-alert="${nodeData.data.alertDown}"
|
|
||||||
data-icon="${nodeData.data.icon}"
|
|
||||||
>
|
|
||||||
<div class="netNodeText">
|
|
||||||
<strong><span>${devicePort} <span class="${badgeConf.cssText}">${deviceIcon}</span></span>
|
|
||||||
<span class="spanNetworkTree anonymizeDev" style="width:${nodeWidthPx-50}px">${nodeData.data.name}</span>
|
|
||||||
${networkHardwareIcon}
|
|
||||||
</strong>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
${collapseExpandHtml}`;
|
|
||||||
},
|
|
||||||
mainAxisNodeSpacing: 'auto',
|
|
||||||
// secondaryAxisNodeSpacing: 0.3,
|
|
||||||
nodeHeight: nodeHeightPx,
|
|
||||||
nodeWidth: nodeWidthPx,
|
|
||||||
marginTop: '5',
|
|
||||||
isHorizontal : true,
|
|
||||||
hasZoom: true,
|
|
||||||
hasPan: true,
|
|
||||||
marginLeft: '10',
|
|
||||||
marginRight: '10',
|
|
||||||
idKey: "mac",
|
|
||||||
hasFlatData: false,
|
|
||||||
relationnalField: "children",
|
|
||||||
linkWidth: (nodeData) => 2,
|
|
||||||
linkColor: (nodeData) => {
|
|
||||||
relConf = getRelationshipConf(nodeData.data.relType)
|
|
||||||
return relConf.color;
|
|
||||||
}
|
|
||||||
// onNodeClick: (nodeData) => handleNodeClick(nodeData),
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(deviceListGlobal);
|
|
||||||
myTree.refresh(myHierarchy);
|
|
||||||
|
|
||||||
// hide spinning icon
|
|
||||||
hideSpinner()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -839,11 +853,11 @@ function initTab()
|
|||||||
selectedTab = "Internet_id"
|
selectedTab = "Internet_id"
|
||||||
|
|
||||||
// the #target from the url
|
// the #target from the url
|
||||||
target = getQueryString('mac')
|
target = getQueryString('mac')
|
||||||
|
|
||||||
// update cookie if target specified
|
// update cookie if target specified
|
||||||
if(target != "")
|
if(target != "")
|
||||||
{
|
{
|
||||||
setCache(key, target.replaceAll(":","_")+'_id') // _id is added so it doesn't conflict with AdminLTE tab behavior
|
setCache(key, target.replaceAll(":","_")+'_id') // _id is added so it doesn't conflict with AdminLTE tab behavior
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -860,12 +874,12 @@ function initTab()
|
|||||||
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||||
setCache(key, $(e.target).attr('id'))
|
setCache(key, $(e.target).attr('id'))
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
function initSelectedNodeHighlighting()
|
function initSelectedNodeHighlighting()
|
||||||
{
|
{
|
||||||
|
|
||||||
var currentNodeMac = $(".networkNodeTabHeaders.active a").data("mytabmac");
|
var currentNodeMac = $(".networkNodeTabHeaders.active a").data("mytabmac");
|
||||||
|
|
||||||
@@ -882,7 +896,7 @@ function initSelectedNodeHighlighting()
|
|||||||
newSelNode = $("#networkTree div[data-mac='"+currentNodeMac+"']")[0]
|
newSelNode = $("#networkTree div[data-mac='"+currentNodeMac+"']")[0]
|
||||||
|
|
||||||
console.log(newSelNode)
|
console.log(newSelNode)
|
||||||
|
|
||||||
$(newSelNode).attr('class', $(newSelNode).attr('class') + ' highlightedNode')
|
$(newSelNode).attr('class', $(newSelNode).attr('class') + ' highlightedNode')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -913,7 +927,7 @@ function updateLeaf(leafMac, action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// showing icons or device names in tabs depending on available screen size
|
// showing icons or device names in tabs depending on available screen size
|
||||||
function checkTabsOverflow() {
|
function checkTabsOverflow() {
|
||||||
const $ul = $('.nav-tabs');
|
const $ul = $('.nav-tabs');
|
||||||
const $lis = $ul.find('li');
|
const $lis = $ul.find('li');
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ if ! awk '$2 == "/" && $4 ~ /ro/ {found=1} END {exit !found}' /proc/mounts; then
|
|||||||
══════════════════════════════════════════════════════════════════════════════
|
══════════════════════════════════════════════════════════════════════════════
|
||||||
⚠️ Warning: Container is running as read-write, not in read-only mode.
|
⚠️ Warning: Container is running as read-write, not in read-only mode.
|
||||||
|
|
||||||
Please mount the root filesystem as --read-only or use read-only: true
|
Please mount the root filesystem as --read-only or use read_only: true
|
||||||
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/read-only-filesystem.md
|
https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/read-only-filesystem.md
|
||||||
══════════════════════════════════════════════════════════════════════════════
|
══════════════════════════════════════════════════════════════════════════════
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user