-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
434 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.dockerignore | ||
.git | ||
.gitignore | ||
__pycache__ | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
*plamen* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM python:3.11-slim | ||
|
||
WORKDIR /ipget | ||
|
||
COPY ipget/ /ipget | ||
COPY requirements.txt /ipget | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
EXPOSE 5000 | ||
|
||
ENV WORKERS 2 | ||
ENV IP_API false | ||
ENV FLASK_ENV production | ||
|
||
RUN chmod +x ipget.sh | ||
|
||
ENTRYPOINT ["./ipget.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: '3.8' | ||
|
||
services: | ||
ipget: | ||
image: prestigen/ipget:0.0.1 | ||
hostname: ipget | ||
environment: | ||
- WORKERS=4 | ||
- IP_API=false | ||
- FLASK_ENV=production | ||
restart: always | ||
|
||
nginx: | ||
image: nginx:latest | ||
hostname: ipget-nginx | ||
ports: | ||
- "80:80" | ||
- "443:443" | ||
volumes: | ||
- ./resources/nginx.conf:/etc/nginx/nginx.conf:ro | ||
- $HOME/.nginx/cert.pem:/etc/nginx/cert.pem:ro | ||
- $HOME/.nginx/key.pem:/etc/nginx/key.pem:ro | ||
depends_on: | ||
- ipget | ||
restart: always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from flask import Flask, request, render_template | ||
from urllib.parse import urlparse | ||
from version import __version__ as ipget_version | ||
import os | ||
import requests | ||
|
||
|
||
ipget = Flask(__name__) | ||
ip_api = os.getenv("IP_API", "False").lower() == "true" | ||
|
||
|
||
def format_headers(headers): | ||
return "<br>".join(f"{key}: {value}" for key, value in headers.items()) | ||
|
||
|
||
# TODO: Store all ip-api.com json fields in a dictionary | ||
def get_country(ip): | ||
ip_api_location = None | ||
try: | ||
if ip_api: | ||
response = requests.get(f"http://ip-api.com/json/{ip}") | ||
json_response = response.json() | ||
country = json_response.get("country") | ||
region_name = json_response.get("regionName") | ||
city = json_response.get("city") | ||
ip_api_location = ( | ||
f"{country}, {region_name}, {city}" if country is not None else None | ||
) | ||
|
||
return ip_api_location | ||
except requests.RequestException: | ||
return "N/A" | ||
|
||
|
||
@ipget.route("/") | ||
def home(): | ||
client_ip = request.headers.get("X-Real-IP", request.remote_addr) | ||
user_agent = request.headers.get("User-Agent", "").lower() | ||
|
||
if "mozilla" in user_agent or "chrome" in user_agent or "safari" in user_agent: | ||
client_info = { | ||
"ip": client_ip, | ||
"remote_hostname": urlparse("//" + request.headers.get("Host")).hostname, | ||
"x_forwarded_for": request.headers.get("X-Forwarded-For"), | ||
"country": get_country(client_ip), | ||
"user_agent": request.user_agent.string, | ||
"headers": format_headers(request.headers), | ||
} | ||
return render_template( | ||
"index.html", | ||
client_info=client_info, | ||
ip_api=ip_api, | ||
ipget_version=ipget_version | ||
) | ||
else: | ||
return f"{client_ip}\n" | ||
|
||
|
||
@ipget.route("/ip") | ||
def return_ip(): | ||
return f"{request.headers.get('X-Real-IP', request.remote_addr)}\n" | ||
|
||
|
||
@ipget.route("/host") | ||
def return_host(): | ||
return f"{request.headers.get('Host')}\n" | ||
|
||
|
||
@ipget.route("/xff") | ||
def return_xff(): | ||
return f"{request.headers.get('X-Forwarded-For')}\n" | ||
|
||
|
||
@ipget.route("/country") | ||
def return_country(): | ||
return f"{get_country(request.headers.get('X-Real-IP', request.remote_addr))}\n" | ||
|
||
|
||
@ipget.route("/ua") | ||
def return_ua(): | ||
return f"{request.user_agent.string}\n" | ||
|
||
|
||
@ipget.route("/headers") | ||
def return_headers(): | ||
return dict(request.headers) | ||
|
||
|
||
@ipget.errorhandler(404) | ||
def page_not_found(e): | ||
return "Error 404: Resource does not exist.\n", 404 | ||
|
||
|
||
if __name__ == "__main__": | ||
ipget.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
exec gunicorn -w ${WORKERS:-2} -b 0.0.0.0:5000 ipget:ipget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
body { | ||
font-family: 'Roboto Mono', monospace; | ||
background-color: #1e1e1e; /* Dark background */ | ||
color: #ccffcc; /* Very light pastel green text */ | ||
margin: 0; | ||
padding: 20px; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.container { | ||
background-color: #252526; /* Slightly lighter dark background */ | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); | ||
width: 80%; /* Adjust as needed */ | ||
} | ||
|
||
h1 { | ||
color: #98fb98; /* Pastel green color for headers */ | ||
} | ||
|
||
table { | ||
width: 100%; | ||
/* table-layout: fixed; */ | ||
margin-left: auto; | ||
margin-right: auto; | ||
border-collapse: collapse; | ||
/* border: 1px solid #3c3c3c; /* Dark border for the table */ | ||
border: 2px solid #4c4c4c; /* Thicker and darker border for the table */ | ||
} | ||
|
||
th, td { | ||
flex: 1; | ||
text-align: left; | ||
padding: 8px; | ||
color: #ccffcc; /* Very light pastel green text for table data */ | ||
border: 2px solid #4c4c4c; /* Thicker and darker border for cells */ | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
|
||
tr:nth-child(even) { | ||
background-color: #2d2d2d; /* Darker row background */ | ||
} | ||
|
||
tr:nth-child(odd) { | ||
background-color: #1e1e1e; /* Dark row background */ | ||
} | ||
|
||
th { | ||
background-color: #98fb98; /* Pastel green background for table headers */ | ||
color: #1e1e1e; /* Dark text for better contrast */ | ||
text-align: left; | ||
} | ||
|
||
th:nth-child(1), td:nth-child(1), | ||
th:nth-child(2), td:nth-child(2) { | ||
overflow: hidden; | ||
white-space: nowrap; | ||
} | ||
|
||
th:nth-child(3), td:nth-child(3) { | ||
word-wrap: break-word; | ||
word-break: break-all; | ||
overflow-wrap: break-word; | ||
} | ||
|
||
|
||
footer { | ||
text-align: center; /* Center align text */ | ||
padding: 5px 0; /* Some padding */ | ||
margin-top: 20px; /* Space from content above */ | ||
background-color: #1e1e1e; /* Background color */ | ||
position: fixed; /* Fix to bottom */ | ||
left: 0; | ||
bottom: 0; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
body { | ||
font-family: 'Roboto Mono', monospace; | ||
background-color: #1e1e1e; /* Dark background */ | ||
color: #ccffcc; /* Very light pastel green text */ | ||
margin: 0; | ||
padding: 20px; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.container { | ||
background-color: #252526; /* Slightly lighter dark background */ | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); | ||
width: 80%; /* Adjust as needed */ | ||
} | ||
|
||
h1 { | ||
color: #98fb98; /* Pastel green color for headers */ | ||
} | ||
|
||
table { | ||
width: 80%; | ||
max-width: 80%; | ||
table-layout: auto; | ||
margin-left: auto; | ||
margin-right: auto; | ||
border-collapse: collapse; | ||
/* border: 1px solid #3c3c3c; /* Dark border for the table */ | ||
border: 2px solid #4c4c4c; /* Thicker and darker border for the table */ | ||
} | ||
|
||
th, td { | ||
text-align: left; | ||
padding: 8px; | ||
color: #ccffcc; /* Very light pastel green text for table data */ | ||
overflow: hidden; /* Prevent overflow */ | ||
border: 2px solid #4c4c4c; /* Thicker and darker border for cells */ | ||
white-space: normal; | ||
} | ||
|
||
tr:nth-child(even) { | ||
background-color: #2d2d2d; /* Darker row background */ | ||
} | ||
|
||
tr:nth-child(odd) { | ||
background-color: #1e1e1e; /* Dark row background */ | ||
} | ||
|
||
th { | ||
background-color: #98fb98; /* Pastel green background for table headers */ | ||
color: #1e1e1e; /* Dark text for better contrast */ | ||
text-align: left; | ||
} | ||
|
||
th:nth-child(1), td:nth-child(1), | ||
th:nth-child(2), td:nth-child(2) { | ||
width: 20%; /* Reduce the width; adjust this value as needed */ | ||
max-width: 300px; /* Optional: you can set a maximum width */ | ||
overflow: hidden; | ||
white-space: nowrap; | ||
} | ||
|
||
th:nth-child(3), td:nth-child(3) { | ||
width: 60%; /* Allows the third column to resize */ | ||
white-space: normal; | ||
} | ||
|
||
footer { | ||
text-align: center; /* Center align text */ | ||
padding: 5px 0; /* Some padding */ | ||
margin-top: 20px; /* Space from content above */ | ||
background-color: #1e1e1e; /* Background color */ | ||
position: fixed; /* Fix to bottom */ | ||
left: 0; | ||
bottom: 0; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>IP Get</title> | ||
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap" rel="stylesheet"> | ||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<table> | ||
<tr> | ||
<th colspan="3">[root@{{ client_info.remote_hostname }}]: ~># ipget</th> | ||
</tr> | ||
<tr> | ||
<td>curl {{ client_info.remote_hostname }}<br>curl {{ client_info.remote_hostname }}/ip</td> | ||
<td>IP Address</td> | ||
<td><b>{{ client_info.ip }}</b></td> | ||
</tr> | ||
<tr> | ||
<td>curl {{ client_info.remote_hostname }}/xff</td> | ||
<td>X-Forwarded-For</td> | ||
<td>{{ client_info.x_forwarded_for }}</td> | ||
</tr> | ||
{% if ip_api %} | ||
<tr> | ||
<td></td> | ||
<td>Location</td> | ||
<td>{{ client_info.country }}</td> | ||
</tr> | ||
{% endif %} | ||
<tr> | ||
<td>curl {{ client_info.remote_hostname }}/xff</td> | ||
<td>User Agent</td> | ||
<td>{{ client_info.user_agent }}</td> | ||
</tr> | ||
<tr> | ||
<td>curl {{ client_info.remote_hostname }}/headers</td> | ||
<td>Headers</td> | ||
<td>{{ client_info.headers|safe }}</td> | ||
</tr> | ||
<!-- Add more rows if needed --> | ||
</table> | ||
<footer> | ||
<p>© <span id="current-year"></span> IP Get v{{ ipget_version }}</p> | ||
</footer> | ||
<script> | ||
document.getElementById('current-year').textContent = new Date().getFullYear(); | ||
</script> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Flask | ||
requests | ||
gunicorn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
# Directory where the certificate and key will be stored | ||
CERT_DIR="$HOME/.nginx" | ||
|
||
# Certificate and key configuration | ||
ALG_NAME="rsa" | ||
ALG_SIZE="4096" | ||
DAYS="3650" | ||
CN="ip.aumaton.com" | ||
|
||
|
||
# Check if the directory exists, create if not | ||
if [ ! -d "$CERT_DIR" ]; then | ||
mkdir -p "$CERT_DIR" | ||
fi | ||
|
||
# Set the filenames | ||
CERT_FILE="$CERT_DIR/cert.pem" | ||
KEY_FILE="$CERT_DIR/key.pem" | ||
|
||
# Generate the key and certificate | ||
openssl req -x509 -newkey $ALG_NAME:$ALG_SIZE -keyout "$KEY_FILE" -out "$CERT_FILE" -days $DAYS -nodes -subj "/CN=$CN" | ||
|
||
echo "Certificate and key have been generated in $CERT_DIR" |
Oops, something went wrong.