mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-06 17:15:38 -08:00
all debugging online.
This commit is contained in:
@@ -14,7 +14,7 @@ RUN apk add --no-cache bash shadow python3 python3-dev gcc musl-dev libffi-dev o
|
||||
# Enable venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
RUN pip install openwrt-luci-rpc asusrouter asyncio aiohttp graphene flask flask-cors unifi-sm-api tplink-omada-client wakeonlan pycryptodome requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet python-nmap dnspython librouteros yattag zeroconf git+https://github.com/foreign-sub/aiofreepybox.git
|
||||
RUN pip install openwrt-luci-rpc asusrouter asyncio aiohttp graphene flask flask-cors unifi-sm-api tplink-omada-client wakeonlan pycryptodome requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet python-nmap dnspython librouteros yattag zeroconf simplejson future six urllib3 httplib2 git+https://github.com/foreign-sub/aiofreepybox.git
|
||||
|
||||
RUN chmod -R u-rwx,g-rwx /opt
|
||||
|
||||
|
||||
@@ -1,27 +1,49 @@
|
||||
{
|
||||
"name": "NetAlertX DevContainer",
|
||||
"remoteUser": "netalertx",
|
||||
"workspaceFolder": "/workspaces/NetAlertX",
|
||||
"build": {
|
||||
"dockerfile": "./Dockerfile",
|
||||
"context": "../",
|
||||
"dockerfile": "./Dockerfile", // Dockerfile generated by script
|
||||
"context": "../", // Context is the root of the repository
|
||||
"target": "netalertx-devcontainer"
|
||||
},
|
||||
"workspaceFolder": "/workspaces/NetAlertX",
|
||||
"runArgs": [
|
||||
"--add-host=host.docker.internal:host-gateway",
|
||||
"--security-opt", "apparmor=unconfined" // for alowing ramdisk mounts
|
||||
],
|
||||
|
||||
"capAdd": [
|
||||
"SYS_ADMIN", // For mounting ramdisks
|
||||
"NET_ADMIN", // For network interface configuration
|
||||
"NET_RAW" // For raw packet manipulation
|
||||
"NET_RAW" // For raw packet manipulation
|
||||
],
|
||||
|
||||
|
||||
|
||||
"runArgs": [
|
||||
"--security-opt",
|
||||
"apparmor=unconfined" // for allowing ramdisk mounts
|
||||
|
||||
// Uncomment --network=host to run full NetAlertX scanning capabilities of network scanning in
|
||||
// container. This runs too slowly in a large network to be practical for development purposes.
|
||||
// You can start services such as avahi on the host, in other containers within the network, or
|
||||
// even within this container and connect to them as needed.
|
||||
// "--network=host",
|
||||
],
|
||||
// ATTENTION: If running with --network=host, COMMENT `forwardPorts` OR ELSE THERE WILL BE NO WEBUI!
|
||||
"forwardPorts": [20211, 20212, 9003, 9000, 5678],
|
||||
"portsAttributes": { // the ports we care about
|
||||
"20211": {
|
||||
"label": "Frontend:Nginx+PHP"
|
||||
},
|
||||
"20212": {
|
||||
"label": "Backend:GraphQL"
|
||||
},
|
||||
"9003": {
|
||||
"label": "PHP Debug:Xdebug"
|
||||
},
|
||||
"9000": {
|
||||
"label": "PHP-FPM:FastCGI"
|
||||
},
|
||||
"5678": {
|
||||
"label": "Python Debug:debugpy"
|
||||
}
|
||||
},
|
||||
|
||||
"postStartCommand": "${containerWorkspaceFolder}/.devcontainer/scripts/setup.sh",
|
||||
|
||||
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
@@ -43,16 +65,13 @@
|
||||
"eamodio.gitlens",
|
||||
"alexcvzz.vscode-sqlite",
|
||||
"yzhang.markdown-all-in-one"
|
||||
]
|
||||
,
|
||||
],
|
||||
"settings": {
|
||||
"terminal.integrated.cwd": "${containerWorkspaceFolder}",
|
||||
// Python testing configuration
|
||||
"python.testing.pytestEnabled": true,
|
||||
"python.testing.unittestEnabled": false,
|
||||
"python.testing.pytestArgs": [
|
||||
"test"
|
||||
],
|
||||
"python.testing.pytestArgs": ["test"],
|
||||
// Make sure we discover tests and import server correctly
|
||||
"python.analysis.extraPaths": [
|
||||
"/workspaces/NetAlertX",
|
||||
@@ -63,26 +82,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"forwardPorts": [5678, 9000, 9003, 20211, 20212],
|
||||
|
||||
"portsAttributes": {
|
||||
"20211": {
|
||||
"label": "Frontend:Nginx+PHP"
|
||||
},
|
||||
"20212": {
|
||||
"label": "Backend:GraphQL"
|
||||
},
|
||||
"9003": {
|
||||
"label": "PHP Debug:Xdebug"
|
||||
},
|
||||
"9000": {
|
||||
"label": "PHP-FPM:FastCGI"
|
||||
},
|
||||
"5678": {
|
||||
"label": "Python Debug:debugpy"
|
||||
}
|
||||
},
|
||||
|
||||
// Optional: ensures compose services are stopped when you close the window
|
||||
"shutdownAction": "stopContainer"
|
||||
}
|
||||
"shutdownAction": "stopContainer" // stop container when VSCode is closed
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ extension_dir="/services/php/modules"
|
||||
xdebug.mode=develop,debug
|
||||
xdebug.log=/app/log/xdebug.log
|
||||
xdebug.log_level=7
|
||||
xdebug.client_host=host.docker.internal
|
||||
xdebug.client_host=127.0.0.1
|
||||
xdebug.client_port=9003
|
||||
xdebug.start_with_request=yes
|
||||
xdebug.discover_client_host=1
|
||||
|
||||
@@ -2,7 +2,7 @@ zend_extension="xdebug.so"
|
||||
[xdebug]
|
||||
xdebug.mode=develop,debug
|
||||
xdebug.log_level=0
|
||||
xdebug.client_host=host.docker.internal
|
||||
xdebug.client_host=127.0.0.1
|
||||
xdebug.client_port=9003
|
||||
xdebug.start_with_request=yes
|
||||
xdebug.discover_client_host=1
|
||||
|
||||
@@ -5,4 +5,4 @@ if [ ! -d /workspaces/NetAlertX/.devcontainer ]; then
|
||||
echo "Not in a devcontainer, exiting..."
|
||||
echo ---------------------------------------------------
|
||||
exit 255
|
||||
fi
|
||||
fi
|
||||
|
||||
23
.venv_import_check.py
Normal file
23
.venv_import_check.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import sys, importlib
|
||||
mods = [
|
||||
'json', 'simplejson',
|
||||
'httplib', 'http.client',
|
||||
'urllib2', 'urllib.request',
|
||||
'Queue', 'queue',
|
||||
'cStringIO', 'StringIO', 'io',
|
||||
'md5', 'hashlib',
|
||||
'ssl'
|
||||
]
|
||||
print('PYTHON_EXE:' + sys.executable)
|
||||
print('PYTHON_VER:' + sys.version.replace('\n', ' '))
|
||||
for m in mods:
|
||||
try:
|
||||
mod = importlib.import_module(m)
|
||||
ver = getattr(mod, '__version__', None)
|
||||
if ver is None:
|
||||
# try common attributes
|
||||
ver = getattr(mod, 'version', None)
|
||||
info = (' version=' + str(ver)) if ver is not None else ''
|
||||
print('OK %s%s' % (m, info))
|
||||
except Exception as e:
|
||||
print('MISSING %s %s: %s' % (m, e.__class__.__name__, e))
|
||||
19
.vscode/tasks.json
vendored
19
.vscode/tasks.json
vendored
@@ -146,6 +146,25 @@
|
||||
"id": "debug-stop",
|
||||
"color": "terminal.ansiRed"
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "[Dev Container] List NetAlertX Ports",
|
||||
"type": "shell",
|
||||
"command": "./scripts/list-ports.sh",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder:NetAlertX}"
|
||||
},
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"reveal": "always",
|
||||
"panel": "shared",
|
||||
"showReuseMessage": false
|
||||
},
|
||||
"problemMatcher": [],
|
||||
"icon": {
|
||||
"id": "output",
|
||||
"color": "terminal.ansiBlue"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ RUN apk add --no-cache bash shadow python3 python3-dev gcc musl-dev libffi-dev o
|
||||
# Enable venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
RUN pip install openwrt-luci-rpc asusrouter asyncio aiohttp graphene flask flask-cors unifi-sm-api tplink-omada-client wakeonlan pycryptodome requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet python-nmap dnspython librouteros yattag zeroconf git+https://github.com/foreign-sub/aiofreepybox.git
|
||||
RUN pip install openwrt-luci-rpc asusrouter asyncio aiohttp graphene flask flask-cors unifi-sm-api tplink-omada-client wakeonlan pycryptodome requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet python-nmap dnspython librouteros yattag zeroconf simplejson future six urllib3 httplib2 git+https://github.com/foreign-sub/aiofreepybox.git
|
||||
|
||||
RUN chmod -R u-rwx,g-rwx /opt
|
||||
|
||||
|
||||
@@ -957,7 +957,8 @@ class SpeedtestResults(object):
|
||||
self.client = client or {}
|
||||
|
||||
self._share = None
|
||||
self.timestamp = '%sZ' % datetime.datetime.utcnow().isoformat()
|
||||
# Use timezone-aware UTC datetime (utcnow() deprecated for removal)
|
||||
self.timestamp = datetime.datetime.now(datetime.timezone.utc).isoformat().replace('+00:00', 'Z')
|
||||
self.bytes_received = 0
|
||||
self.bytes_sent = 0
|
||||
|
||||
|
||||
44
docs/DEV_PORTS_HOST_MODE.md
Normal file
44
docs/DEV_PORTS_HOST_MODE.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Dev Ports in Host Network Mode
|
||||
|
||||
When using `"--network=host"` in the devcontainer, VS Code's normal port forwarding model doesn't apply. All container ports are already on the host network namespace, so:
|
||||
|
||||
- Listing ports in `forwardPorts` can cause VS Code to pre-bind or reserve them (conflicts with startup scripts waiting for a free port).
|
||||
- The PORTS panel will not auto-detect services reliably, because forwarding isn't occurring.
|
||||
- Debugger ports (e.g. Xdebug `9003`, Python debugpy `5678`) can still be listed safely.
|
||||
|
||||
## Recommended Pattern
|
||||
|
||||
1. Only include debugger ports in `forwardPorts`:
|
||||
```jsonc
|
||||
"forwardPorts": [5678, 9003]
|
||||
```
|
||||
2. Do NOT list application service ports (e.g. 20211, 20212) there when in host mode.
|
||||
3. Use the helper task to enumerate current bindings:
|
||||
- Run task: `> Tasks: Run Task` → `[Dev Container] List NetAlertX Ports`
|
||||
|
||||
## Port Enumeration Script
|
||||
Script: `scripts/list-ports.sh`
|
||||
Outputs binding address, PID (if resolvable) and process name for key ports.
|
||||
|
||||
You can edit the PORTS variable inside that script to add/remove watched ports.
|
||||
|
||||
## Xdebug Notes
|
||||
Set in `99-xdebug.ini`:
|
||||
```ini
|
||||
xdebug.client_host=127.0.0.1
|
||||
xdebug.client_port=9003
|
||||
xdebug.discover_client_host=1
|
||||
```
|
||||
Ensure your IDE is listening on 9003.
|
||||
|
||||
## Troubleshooting
|
||||
| Symptom | Cause | Fix |
|
||||
|---------|-------|-----|
|
||||
| `Waiting for port 20211 to free...` repeats | VS Code pre-bound the port via `forwardPorts` | Remove the port from `forwardPorts`, rebuild, retry |
|
||||
| PHP request hangs at start | Xdebug trying to connect to unresolved host (`host.docker.internal`) | Use `127.0.0.1` or rely on discovery |
|
||||
| PORTS panel empty | Expected in host mode | Use the port enumeration task |
|
||||
|
||||
## Future Improvements
|
||||
- Optional: add a small web status endpoint summarizing runtime ports.
|
||||
- Optional: detect host mode in `setup.sh` and skip the wait loop if the PID using port is the intended process.
|
||||
|
||||
19
scripts/list-ports.sh
Executable file
19
scripts/list-ports.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
# Quick port/service enumerator for host-network dev container.
|
||||
# Shows which processes are bound to key NetAlertX ports.
|
||||
PORTS="20211 20212 9003 9000 5678"
|
||||
printf "%-8s %-22s %-8s %s\n" PORT BIND LISTEN_PID COMMAND
|
||||
for p in $PORTS; do
|
||||
line=$(ss -ltnp 2>/dev/null | awk -v P=":${p}" '$4 ~ P {print $0; exit}')
|
||||
if [ -n "$line" ]; then
|
||||
addr=$(echo "$line" | awk '{print $4}')
|
||||
pid=$(echo "$line" | sed -n 's/.*pid=\([0-9]*\).*/\1/p')
|
||||
cmd="$( [ -n "$pid" ] && ps -o comm= -p "$pid" 2>/dev/null)"
|
||||
printf "%-8s %-22s %-8s %s\n" "$p" "$addr" "${pid:-?}" "${cmd:-?}"
|
||||
else
|
||||
printf "%-8s %-22s %-8s %s\n" "$p" "(not listening)" "-" "-"
|
||||
fi
|
||||
done
|
||||
|
||||
# Show any other NetAlertX-related listeners (nginx, php-fpm, python backend)
|
||||
ss -ltnp 2>/dev/null | egrep 'nginx|php-fpm|python' || true
|
||||
Reference in New Issue
Block a user