Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: evijayan2/nginxproxymanagerGraf
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: zimmra/nginxproxymanagerGraf
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Mar 23, 2023

  1. Copy the full SHA
    ab55500 View commit details
  2. Ignore local IPs

    zimmra authored Mar 23, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    cac5e9d View commit details
  3. influxdb2 rewrite

    zimmra committed Mar 23, 2023
    Copy the full SHA
    f46abec View commit details
Showing with 44 additions and 91 deletions.
  1. +23 −13 .github/workflows/docker-image.yml
  2. +13 −70 Getipinfo.py
  3. +8 −8 sendips.sh
36 changes: 23 additions & 13 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Docker Image CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
release:
types: [published]

jobs:

@@ -13,13 +11,25 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file Dockerfile --tag nginx-proxy-manager-graf:$(date +%s)
- name: Dockerize
if: success()
uses: manusa/actions-publish-docker@v1.1.2
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
name: evijayan2/nginx-proxy-manager-graf
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: pzubuntu593/nginx-proxy-manager-graf:latest,pzubuntu593/nginx-proxy-manager-graf:${{ github.ref_name }}
83 changes: 13 additions & 70 deletions Getipinfo.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/python3

import sys
#import geoip2.webservice
print ('*************************************')
print (sys.argv[1])

#print str(sys.argv[1])
import geoip2.database
import socket
import datetime
import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS
import os

print(socket.gethostname())

print ('*************************************')
print (sys.argv[1])

print(socket.gethostname())

reader = geoip2.database.Reader('/GeoLite2-City.mmdb')
response = reader.city(str(sys.argv[1]).strip())
@@ -26,85 +26,29 @@
IP = str(sys.argv[1]).strip()
Domain = str(sys.argv[2]).strip()
duration = int(sys.argv[3])
# print (Country)
# print (State)
# print (City)
# print (Zip)
# print (Long)
# print (Lat)
# print (ISO)
# print (IP)
reader.close()


import datetime
import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS

## get env vars and use

import os
# influx configuration - edit these
reader.close()

npmhome = "/root/.config/NPMGRAF"
npmhome = os.getenv('NPMGRAF_HOME')
ifuser = os.getenv('INFLUX_USER')
ifpass = os.getenv('INFLUX_PW')
ifdb = os.getenv('INFLUX_DB')
# Get environment variables
ifhost = os.getenv('INFLUX_HOST')
ifport = os.getenv('INFLUX_PORT')
ifbucket = os.getenv('INFLUX_BUCKET')
iforg = os.getenv('INFLUX_ORG')
iftoken = os.getenv('INFLUX_TOKEN')

print(ifbucket, iforg, ifhost, ifport)

print(ifbucket, iforg, ifuser, ifpass)
hostname = socket.gethostname()
measurement_name = ("ReverseProxyConnections")
print ('*************************************')
# take a timestamp for this measurement
time = datetime.datetime.utcnow()

# format the data as a single measurement for influx
# body = [
# {
# "measurement": measurement_name,
# "time": time,
# "tags": {
# "key": ISO,
# "latitude": Lat,
# "longitude": Long,
# "Domain": Domain,
# "City": City,
# "State": State,
# "name": Country,
# "IP": IP
# },
# "fields": {
# "Domain": Domain,
# "latitude": Lat,
# "longitude": Long,
# "State": State,
# "City": City,
# "key": ISO,
# "IP": IP,
# "name": Country,
# "duration": duration,
# "metric": 1
# }
# }
# ]

# connect to influx
# ifclient = InfluxDBClient(ifhost,ifport,ifuser,ifpass,ifdb)
ifclient = influxdb_client.InfluxDBClient(
url=ifhost,
url=f"http://{ifhost}:{ifport}",
org=iforg,
username=ifuser,
password=ifpass
token=iftoken
)

# write the measurement
write_api = ifclient.write_api(write_options=SYNCHRONOUS)

point = influxdb_client.Point(measurement_name)
@@ -128,5 +72,4 @@
point.field("duration", duration)
point.field("metric", 1)

write_api.write(bucket=ifbucket, org=iforg, record=point)

write_api.write(bucket=ifbucket, org=iforg, record=point)
16 changes: 8 additions & 8 deletions sendips.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/sh
# " /bin/sh /Shared/nginx/shtail.sh & " needs to be added to /startapp.sh as the second line
# for ipv6 and ipv4 grep -E -o "(([0-9]{1,3}[\.]){3}[0-9]{1,3}|([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))" file.txt
# for ipv6 and ipv4 exluding homeips grep -E -o "(([0-9]{1,3}[\.]){3}[0-9]{1,3}|([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))" | grep -v "192.168.0.*\| 69.0.0.* \| 5.0.0.*" file.txt
# for domains grep -E -o "[a-z0-9]*\.[a-z0-9]*\.(de|net|org|com)" file.txt #working for domains

tail -f /logs/proxy-host*_access.log | grep -E " ([0-9]{1,3}[\.]){3}[0-9]{1,3}" | while read line;
do
domain=`echo ${line} | grep -m 1 -o -E " [a-z0-9\-]*\.[a-z0-9]*\.(de|net|org|com)"`
ipaddressnumber=`echo $line | grep -o -m 1 -E " (([0-9]{1,3}[\.]){3}[0-9]{1,3}|([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"` ##UPDATE grep -v with local network
ipaddressnumber=$(echo $line | grep -o -m 1 -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | head -n 1 | grep -E -v "^10\.|^172\.(1[6-9]|2[0-9]|3[0-1])\.|^192\.168\.")
length=`echo $line | awk -F ' ' '{print$14}' | grep -m 1 -o '[[:digit:]]*'`

if [ -z "$domain" ]; then
domain="empty"
fi
echo "$length = $ipaddressnumber = $domain"
python /root/.config/NPMGRAF/Getipinfo.py "$ipaddressnumber" "$domain" "$length"

if [ ! -z "$ipaddressnumber" ]; then
echo "$length = $ipaddressnumber = $domain"
python /root/.config/NPMGRAF/Getipinfo.py "$ipaddressnumber" "$domain" "$length"
fi
done
reboot
reboot