Compare commits
13 Commits
main
...
680b0f46e5
| Author | SHA1 | Date | |
|---|---|---|---|
| 680b0f46e5 | |||
| 6bc46e73c5 | |||
| cacbd7620a | |||
| 581c5bdb62 | |||
| a80330622e | |||
| 3e8f611cd3 | |||
| c420534639 | |||
| 68b862fe6f | |||
| 55ad4fa4ed | |||
| e3590b8a93 | |||
| 47fad37675 | |||
| b1db95bd2e | |||
| e46554e5dd |
@@ -9,42 +9,22 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Unit tests
|
|
||||||
run: |
|
|
||||||
python3 -m unittest discover -s tests
|
|
||||||
|
|
||||||
- name: Install jq
|
|
||||||
run: |
|
|
||||||
apt-get update -y
|
|
||||||
apt-get install -y jq
|
|
||||||
|
|
||||||
- name: Deploy via SSH
|
- name: Deploy via SSH
|
||||||
env:
|
env:
|
||||||
VPN_HOST: ${{ secrets.VPN_HOST }}
|
VPN_HOST: ${{ secrets.VPN_HOST }}
|
||||||
VPN_USER: ${{ secrets.VPN_USER }}
|
VPN_USER: ${{ secrets.VPN_USER }}
|
||||||
VPN_SSH_KEY: ${{ secrets.TEST_KEY }}
|
VPN_SSH_KEY_B64: ${{ secrets.TEST_KEY_B64 }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
chmod 700 ~/.ssh
|
chmod 700 ~/.ssh
|
||||||
printf '%s' "$VPN_SSH_KEY" > ~/.ssh/id_ci_runner
|
printf '%s' "$VPN_SSH_KEY_B64" | base64 -d > ~/.ssh/id_ci_runner
|
||||||
chmod 600 ~/.ssh/id_ci_runner
|
chmod 600 ~/.ssh/id_ci_runner
|
||||||
VPN_USER="$(printf '%s' "$VPN_USER" | tr -d '\r\n')"
|
VPN_USER="$(printf '%s' "$VPN_USER" | tr -d '\r\n')"
|
||||||
VPN_HOST="$(printf '%s' "$VPN_HOST" | tr -d '\r\n')"
|
VPN_HOST="$(printf '%s' "$VPN_HOST" | tr -d '\r\n')"
|
||||||
echo "using user=${VPN_USER} host=${VPN_HOST}"
|
echo "using user=${VPN_USER} host=${VPN_HOST}"
|
||||||
ssh-keyscan -H "$VPN_HOST" >> ~/.ssh/known_hosts || true
|
ssh-keyscan -H "$VPN_HOST" >> ~/.ssh/known_hosts || true
|
||||||
ssh-keygen -lf ~/.ssh/id_ci_runner
|
ssh-keygen -lf ~/.ssh/id_ci_runner
|
||||||
ssh -o BatchMode=yes -o ConnectTimeout=10 -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/id_ci_runner "${VPN_USER}@${VPN_HOST}" "echo ok"
|
ssh -vvv -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/id_ci_runner "${VPN_USER}@${VPN_HOST}" "echo ok"
|
||||||
|
|
||||||
ssh -o BatchMode=yes -o ConnectTimeout=10 -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/id_ci_runner "${VPN_USER}@${VPN_HOST}" "cd /srv/ip-ua && git fetch --all && git reset --hard origin/main && bash deploy/my-vpn/deploy.sh"
|
ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/id_ci_runner "${VPN_USER}@${VPN_HOST}" "cd /srv/ip-ua && git fetch --all && git reset --hard origin/main && bash deploy/my-vpn/deploy.sh"
|
||||||
for i in $(seq 1 10); do
|
|
||||||
if curl -fsS "http://${VPN_HOST}" -o /tmp/resp.json; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
jq -e '.ip and .user_agent and .method and .path and .timestamp' /tmp/resp.json >/dev/null
|
|
||||||
echo "smoke ok"
|
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -3,3 +3,19 @@
|
|||||||
ok
|
ok
|
||||||
|
|
||||||
# ci test
|
# ci test
|
||||||
|
|
||||||
|
# ci test 2
|
||||||
|
|
||||||
|
# ci test 3
|
||||||
|
|
||||||
|
# ci test 4
|
||||||
|
|
||||||
|
# ci test 5
|
||||||
|
|
||||||
|
# ci test 6
|
||||||
|
|
||||||
|
# ci test 7
|
||||||
|
|
||||||
|
# ci test 8
|
||||||
|
|
||||||
|
# ci test 9
|
||||||
|
|||||||
36
app.py
36
app.py
@@ -5,32 +5,20 @@ from datetime import datetime, timezone
|
|||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
|
||||||
|
|
||||||
def build_payload(headers, client_ip, method, path, now=None):
|
|
||||||
if now is None:
|
|
||||||
now = datetime.now(timezone.utc)
|
|
||||||
|
|
||||||
forwarded = headers.get("X-Forwarded-For", "")
|
|
||||||
ip = forwarded.split(",")[0].strip() if forwarded else client_ip
|
|
||||||
|
|
||||||
return {
|
|
||||||
"ip": ip,
|
|
||||||
"user_agent": headers.get("User-Agent", ""),
|
|
||||||
"method": method,
|
|
||||||
"path": path,
|
|
||||||
"timestamp": now.isoformat(),
|
|
||||||
"headers": dict(headers),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class Handler(BaseHTTPRequestHandler):
|
class Handler(BaseHTTPRequestHandler):
|
||||||
def _write_json(self, status=200):
|
def _write_json(self, status=200):
|
||||||
headers = {k: v for k, v in self.headers.items()}
|
client_ip = self.headers.get("X-Forwarded-For", "").split(",")[0].strip()
|
||||||
payload = build_payload(
|
if not client_ip:
|
||||||
headers=headers,
|
client_ip = self.client_address[0]
|
||||||
client_ip=self.client_address[0],
|
|
||||||
method=self.command,
|
payload = {
|
||||||
path=self.path,
|
"ip": client_ip,
|
||||||
)
|
"user_agent": self.headers.get("User-Agent", ""),
|
||||||
|
"method": self.command,
|
||||||
|
"path": self.path,
|
||||||
|
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||||
|
"headers": {k: v for k, v in self.headers.items()},
|
||||||
|
}
|
||||||
|
|
||||||
data = json.dumps(payload, ensure_ascii=False).encode("utf-8")
|
data = json.dumps(payload, ensure_ascii=False).encode("utf-8")
|
||||||
self.send_response(status)
|
self.send_response(status)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
for push
|
|
||||||
for push
|
|
||||||
for push
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
h
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
import unittest
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
|
|
||||||
from app import build_payload
|
|
||||||
|
|
||||||
|
|
||||||
class TestBuildPayload(unittest.TestCase):
|
|
||||||
def test_uses_forwarded_ip(self):
|
|
||||||
now = datetime(2026, 2, 6, 0, 0, 0, tzinfo=timezone.utc)
|
|
||||||
payload = build_payload(
|
|
||||||
headers={"X-Forwarded-For": "10.0.0.1, 10.0.0.2", "User-Agent": "ua"},
|
|
||||||
client_ip="192.168.0.10",
|
|
||||||
method="GET",
|
|
||||||
path="/",
|
|
||||||
now=now,
|
|
||||||
)
|
|
||||||
self.assertEqual(payload["ip"], "10.0.0.1")
|
|
||||||
self.assertEqual(payload["user_agent"], "ua")
|
|
||||||
self.assertEqual(payload["method"], "GET")
|
|
||||||
self.assertEqual(payload["path"], "/")
|
|
||||||
self.assertEqual(payload["timestamp"], "2026-02-06T00:00:00+00:00")
|
|
||||||
|
|
||||||
def test_falls_back_to_client_ip(self):
|
|
||||||
now = datetime(2026, 2, 6, 0, 0, 0, tzinfo=timezone.utc)
|
|
||||||
payload = build_payload(
|
|
||||||
headers={"User-Agent": "ua"},
|
|
||||||
client_ip="192.168.0.10",
|
|
||||||
method="POST",
|
|
||||||
path="/submit",
|
|
||||||
now=now,
|
|
||||||
)
|
|
||||||
self.assertEqual(payload["ip"], "192.168.0.10")
|
|
||||||
self.assertEqual(payload["user_agent"], "ua")
|
|
||||||
self.assertEqual(payload["method"], "POST")
|
|
||||||
self.assertEqual(payload["path"], "/submit")
|
|
||||||
self.assertEqual(payload["timestamp"], "2026-02-06T00:00:00+00:00")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
Reference in New Issue
Block a user