Compare commits
11 Commits
709ba501d3
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| f45a94622e | |||
| 9b59c36974 | |||
| 031d3006d8 | |||
| affe71d6dd | |||
| 6f54924a1f | |||
| 0d3515ad07 | |||
| 5288323831 | |||
| a3ec2fada7 | |||
| fe3b33a58d | |||
| 888581c807 | |||
| b1e836f96a |
@@ -0,0 +1,14 @@
|
|||||||
|
root = "."
|
||||||
|
tmp_dir = "tmp"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
cmd = "go build -o ./tmp/main ./src"
|
||||||
|
bin = "./tmp/main"
|
||||||
|
include_ext = ["go", "html", "sql", "css", "js"]
|
||||||
|
include_dir = ["src", "templates", "static"]
|
||||||
|
exclude_dir = ["tmp", "scrap", ".git", ".vscode"]
|
||||||
|
delay = 1000
|
||||||
|
stop_on_error = true
|
||||||
|
|
||||||
|
[misc]
|
||||||
|
clean_on_exit = true
|
||||||
@@ -8,3 +8,9 @@ test.py
|
|||||||
binary
|
binary
|
||||||
tmp/
|
tmp/
|
||||||
scrap/
|
scrap/
|
||||||
|
*.sqlite3
|
||||||
|
*.db
|
||||||
|
init.sql
|
||||||
|
.prettierignore
|
||||||
|
.vscode/
|
||||||
|
query.sql
|
||||||
|
|||||||
+9
-2
@@ -1,10 +1,17 @@
|
|||||||
FROM golang:alpine AS builder
|
FROM golang:alpine AS builder
|
||||||
|
|
||||||
|
# go-sqlite3 is a cgo package, so it needs a C toolchain
|
||||||
|
RUN apk add --no-cache gcc musl-dev
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY go.mod ./
|
COPY go.mod go.sum ./
|
||||||
COPY *.go ./
|
RUN go mod download
|
||||||
|
|
||||||
|
COPY src/*.go ./
|
||||||
|
COPY src/seed.sql ./
|
||||||
|
|
||||||
|
ENV CGO_ENABLED=1
|
||||||
RUN go build -o server .
|
RUN go build -o server .
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
services:
|
services:
|
||||||
website:
|
website:
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_PATH: /app/data/zum.db
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
@@ -8,4 +10,6 @@ services:
|
|||||||
container_name: acidarchon.com
|
container_name: acidarchon.com
|
||||||
ports:
|
ports:
|
||||||
- 8088:8080
|
- 8088:8080
|
||||||
|
volumes:
|
||||||
|
- /dockers/acidarchon:/app/data
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -2,4 +2,7 @@ module acidburnmonkey/acidarchon
|
|||||||
|
|
||||||
go 1.26.2
|
go 1.26.2
|
||||||
|
|
||||||
require github.com/joho/godotenv v1.5.1 // indirect
|
require (
|
||||||
|
github.com/joho/godotenv v1.5.1
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.44
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.44 h1:3VSe+xafpbzsLbdr2AWlAZk9yRHiBhTBakioXaCKTF8=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.44/go.mod h1:pjEuOr8IwzLJP2MfGeTb0A35jauH+C2kbHKBr7yXKVQ=
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ipResponse struct {
|
|
||||||
IP string `json:"ip"`
|
|
||||||
Asn string `json:"asn"`
|
|
||||||
AsName string `json:"as_name"`
|
|
||||||
AsDomain string `json:"as_domain"`
|
|
||||||
CountryCode string `json:"country_code"`
|
|
||||||
Country string `json:"country"`
|
|
||||||
ContinentCode string `json:"continent_code"`
|
|
||||||
Continent string `json:"continent"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
|
|
||||||
godotenv.Load()
|
|
||||||
|
|
||||||
// routes
|
|
||||||
mux.HandleFunc("/", handleRoot)
|
|
||||||
mux.HandleFunc("/robots.txt", serveRobots)
|
|
||||||
mux.HandleFunc("/*", handleRoot)
|
|
||||||
|
|
||||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
|
||||||
|
|
||||||
fmt.Println("listening on 8080")
|
|
||||||
http.ListenAndServe(":8080", mux)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleRoot(w http.ResponseWriter, r *http.Request) {
|
|
||||||
templ, err := template.ParseFiles("templates/home.html")
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "template not found", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
|
||||||
if err != nil {
|
|
||||||
host = r.RemoteAddr
|
|
||||||
}
|
|
||||||
|
|
||||||
dox, err := callApi(host)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "api call failed", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
templ.Execute(w, dox)
|
|
||||||
}
|
|
||||||
|
|
||||||
func serveRobots(w http.ResponseWriter, r *http.Request) {
|
|
||||||
robots, err := os.ReadFile("templates/robots.txt")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(w, "sucks to suck")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprint(w, string(robots))
|
|
||||||
}
|
|
||||||
|
|
||||||
func callApi(ip string) (ipResponse, error) {
|
|
||||||
api := os.Getenv("IPAPI")
|
|
||||||
fmt.Printf("api: %v\n", api)
|
|
||||||
|
|
||||||
var values ipResponse
|
|
||||||
|
|
||||||
if api == " " {
|
|
||||||
return values, errors.New("No api key")
|
|
||||||
}
|
|
||||||
|
|
||||||
url := fmt.Sprintf("https://api.ipinfo.io/lite/%s?token=%s", ip, api)
|
|
||||||
|
|
||||||
request, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
return values, errors.New("request failed")
|
|
||||||
}
|
|
||||||
defer request.Body.Close()
|
|
||||||
|
|
||||||
body, _ := io.ReadAll(request.Body)
|
|
||||||
|
|
||||||
err = json.Unmarshal(body, &values)
|
|
||||||
|
|
||||||
return values, nil
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
_ "embed"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed seed.sql
|
||||||
|
var seedSQL string
|
||||||
|
|
||||||
|
// logs level=('debug', 'info', 'warning', 'error')
|
||||||
|
type logs struct {
|
||||||
|
level string
|
||||||
|
ip string
|
||||||
|
traceback string
|
||||||
|
date time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type dbStruct struct {
|
||||||
|
db *sql.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seed runs the schema in seed.sql. Idempotent via CREATE TABLE IF NOT EXISTS,
|
||||||
|
func (app *dbStruct) Seed() error {
|
||||||
|
_, err := app.db.Exec(seedSQL)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// InsertLog() : database method, only inserts level + traceback
|
||||||
|
func (app *dbStruct) InsertLog(lg logs) error {
|
||||||
|
query := `INSERT INTO logs (level, traceback) VALUES (?, ?)`
|
||||||
|
|
||||||
|
_, err := app.db.Exec(query, lg.level, lg.traceback)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogIp() : database method, logs level + Ip
|
||||||
|
func (app *dbStruct) LogIp(lg logs) error {
|
||||||
|
query := `INSERT INTO logs (level, ip) VALUES (?, ?)`
|
||||||
|
|
||||||
|
_, err := app.db.Exec(query, lg.level, lg.ip)
|
||||||
|
return err
|
||||||
|
}
|
||||||
+174
@@ -0,0 +1,174 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log/slog"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ipResponse struct {
|
||||||
|
IP string `json:"ip"`
|
||||||
|
Asn string `json:"asn"`
|
||||||
|
AsName string `json:"as_name"`
|
||||||
|
AsDomain string `json:"as_domain"`
|
||||||
|
CountryCode string `json:"country_code"`
|
||||||
|
Country string `json:"country"`
|
||||||
|
ContinentCode string `json:"continent_code"`
|
||||||
|
Continent string `json:"continent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type IPInfo struct {
|
||||||
|
Query string `json:"query"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Country string `json:"country"`
|
||||||
|
CountryCode string `json:"countryCode"`
|
||||||
|
Region string `json:"region"`
|
||||||
|
RegionName string `json:"regionName"`
|
||||||
|
City string `json:"city"`
|
||||||
|
Zip string `json:"zip"`
|
||||||
|
Lat float64 `json:"lat"`
|
||||||
|
Lon float64 `json:"lon"`
|
||||||
|
Timezone string `json:"timezone"`
|
||||||
|
ISP string `json:"isp"`
|
||||||
|
Org string `json:"org"`
|
||||||
|
AS string `json:"as"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TemolateData struct {
|
||||||
|
Ip ipResponse
|
||||||
|
IP2 IPInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
godotenv.Load()
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
dbPath := os.Getenv("DB_PATH")
|
||||||
|
if dbPath == "" {
|
||||||
|
dbPath = "zum.db"
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := sql.Open("sqlite3", dbPath)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("err opening db")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
database := &dbStruct{db: db}
|
||||||
|
|
||||||
|
if err := database.Seed(); err != nil {
|
||||||
|
slog.Error("seeding db", "err", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// routes
|
||||||
|
mux.HandleFunc("/", database.handleRoot)
|
||||||
|
mux.HandleFunc("/robots.txt", serveRobots)
|
||||||
|
mux.HandleFunc("/*", database.handleRoot)
|
||||||
|
|
||||||
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||||
|
|
||||||
|
fmt.Println("listening on 8080")
|
||||||
|
http.ListenAndServe(":8080", mux)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Routes
|
||||||
|
|
||||||
|
// handleRoot() : part of dbStruct
|
||||||
|
func (app *dbStruct) handleRoot(w http.ResponseWriter, r *http.Request) {
|
||||||
|
templ, err := template.ParseFiles("templates/home.html")
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "template not found", http.StatusInternalServerError)
|
||||||
|
if logErr := app.InsertLog(logs{level: "error", traceback: "template not found"}); logErr != nil {
|
||||||
|
slog.Error("failed to write log", "err", logErr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
host := r.Header.Get("CF-Connecting-IP")
|
||||||
|
if host == "" {
|
||||||
|
host = r.Header.Get("X-Real-IP")
|
||||||
|
}
|
||||||
|
if host == "" {
|
||||||
|
host = r.Header.Get("X-Forwarded-For")
|
||||||
|
}
|
||||||
|
if host == "" {
|
||||||
|
host, _, _ = net.SplitHostPort(r.RemoteAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
dox := callApi(host)
|
||||||
|
dox2 := secondApi(host)
|
||||||
|
|
||||||
|
if logErr := app.LogIp(logs{level: "info", ip: dox.IP}); logErr != nil {
|
||||||
|
slog.Error("failed to write log", "err", logErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
templ.Execute(w, TemolateData{Ip: dox, IP2: *dox2})
|
||||||
|
}
|
||||||
|
|
||||||
|
func serveRobots(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.ServeFile(w, r, ("templates/robots.txt"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// utils
|
||||||
|
func callApi(ip string) ipResponse {
|
||||||
|
api := os.Getenv("IPAPI")
|
||||||
|
|
||||||
|
slog.Info("client called", "ip", ip)
|
||||||
|
|
||||||
|
var values ipResponse
|
||||||
|
|
||||||
|
if api == " " {
|
||||||
|
slog.Error("No api provided")
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("https://api.ipinfo.io/lite/%s?token=%s", ip, api)
|
||||||
|
|
||||||
|
request, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("callApi Error")
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
defer request.Body.Close()
|
||||||
|
|
||||||
|
body, _ := io.ReadAll(request.Body)
|
||||||
|
|
||||||
|
err = json.Unmarshal(body, &values)
|
||||||
|
|
||||||
|
slog.Debug("Api1 res:", "ip", values.IP, "country", values.Country, "continent:", values.ContinentCode,
|
||||||
|
"ISP", values.AsName)
|
||||||
|
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
||||||
|
func secondApi(ip string) *IPInfo {
|
||||||
|
url := fmt.Sprintf("http://ip-api.com/json/%s", ip)
|
||||||
|
|
||||||
|
var res IPInfo
|
||||||
|
|
||||||
|
response, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("secondApi err")
|
||||||
|
return &res
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
body, _ := io.ReadAll(response.Body)
|
||||||
|
|
||||||
|
json.Unmarshal(body, &res)
|
||||||
|
|
||||||
|
slog.Debug("secondApi", "city", res.City, "lat", res.Lat, "lon", res.Lon, "status", res.Status)
|
||||||
|
|
||||||
|
return &res
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS logs (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
level TEXT NOT NULL CHECK(level IN ('debug', 'info', 'warning', 'error')),
|
||||||
|
ip TEXT,
|
||||||
|
traceback TEXT,
|
||||||
|
date DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||||
|
);
|
||||||
@@ -13,6 +13,26 @@ h1 {
|
|||||||
font-family: GlitchGoblin;
|
font-family: GlitchGoblin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.layout {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
padding: 0 40px;
|
||||||
|
gap: 40px;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#map {
|
||||||
|
width: 400px;
|
||||||
|
height: 400px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
.info {
|
.info {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-10
@@ -1,24 +1,60 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
|
||||||
|
<head>
|
||||||
<link rel="icon" type="image/x-icon" href="/static/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="/static/favicon.ico" />
|
||||||
<link rel="stylesheet" href="/static/styles.css" />
|
<link rel="stylesheet" href="/static/styles.css" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
||||||
<meta charset="UTF-8">
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
|
<meta charset="UTF-8" />
|
||||||
<title>Who are you?</title>
|
<title>Who are you?</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
|
||||||
|
<body>
|
||||||
<h1>
|
<h1>
|
||||||
U HAVE THREAD <br />
|
U HAVE THREAD <br />
|
||||||
UPON MY DOMAIN <br />
|
UPON MY DOMAIN <br />
|
||||||
& MUST SUFFER <br />
|
& MUST SUFFER <br />
|
||||||
WHO R U?
|
WHO R U?
|
||||||
</h1>
|
</h1>
|
||||||
|
<div class="layout">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="info"><h2>IP Address:</h2><p>{{.IP}}</p></div>
|
<div class="info">
|
||||||
<div class="info"><h2>Country:</h2><p>{{.Country}}</p></div>
|
<h2>IP Address:</h2>
|
||||||
<div class="info"><h2>Continent:</h2><p>{{.Continent}}</p></div>
|
<p>{{.Ip.IP}}</p>
|
||||||
<div class="info"><h2>Internet Provider:</h2><p>{{.AsName}}</p></div>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
<div class="info">
|
||||||
|
<h2>Country:</h2>
|
||||||
|
<p>{{.Ip.Country}}</p>
|
||||||
|
</div>
|
||||||
|
<div class="info">
|
||||||
|
<h2>Continent:</h2>
|
||||||
|
<p>{{.Ip.Continent}}</p>
|
||||||
|
</div>
|
||||||
|
<div class="info">
|
||||||
|
<h2>Internet Provider:</h2>
|
||||||
|
<p>{{.Ip.AsName}}</p>
|
||||||
|
</div>
|
||||||
|
<div class="info">
|
||||||
|
<h2>City:</h2>
|
||||||
|
<p>{{.IP2.City}}</p>
|
||||||
|
</div>
|
||||||
|
<div class="info">
|
||||||
|
<h2>Coordinates:</h2>
|
||||||
|
<p>{{.IP2.Lat}}, {{.IP2.Lon}}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="map"></div>
|
||||||
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
<script>
|
||||||
|
var map = L.map('map', { maxZoom: 10 }).setView([{{.IP2.Lat}}, {{.IP2.Lon}}], 8);
|
||||||
|
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
|
attribution: '© OpenStreetMap'
|
||||||
|
}).addTo(map);
|
||||||
|
L.marker([{{.IP2.Lat}}, {{.IP2.Lon}}]).addTo(map);
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user