diff --git a/clavitor.ai/admin/main.go b/clavitor.ai/admin/main.go index 0d97cf6..5a784dd 100644 --- a/clavitor.ai/admin/main.go +++ b/clavitor.ai/admin/main.go @@ -17,6 +17,7 @@ import ( ) var db *sql.DB +var isSandboxMode bool func main() { var err error @@ -26,6 +27,14 @@ func main() { } defer db.Close() + // Detect sandbox mode by IP + isSandboxMode = !isProductionServer() + if isSandboxMode { + fmt.Println("🧪 SANDBOX MODE DETECTED (non-production IP)") + } else { + fmt.Println("🏭 PRODUCTION MODE (running on clavitor.ai)") + } + initDB() r := chi.NewRouter() @@ -114,9 +123,9 @@ func handleDynamicHome(w http.ResponseWriter, r *http.Request) { html := ` -Clavitor Dynamic Admin +Clavitor Dynamic Admin{{if .IsSandbox}} [SANDBOX]{{end}} +{{if .IsSandbox}}
🧪 SANDBOX MODE Test environment - not production
{{end}} -

Clavitor Corporate Admin

-

Auto-generated from SQLite schema • 95% Paddle + 5% Extensions

+

Clavitor Corporate Admin{{if .IsSandbox}} [SANDBOX]{{end}}

+

Auto-generated from SQLite schema • 95% Paddle + 5% Extensions{{if .IsSandbox}} • TEST ENVIRONMENT{{end}}

{{range .Cards}} @@ -152,6 +174,20 @@ h1 { margin-bottom: 10px; }
{{end}} + + +
+

💰 USD Pricing (from database)

+
+{{range .Prices}} +
+

{{.ProductName}}

+
{{.Amount}} {{.Currency}}
+
+{{end}} +
+
+ ` @@ -167,10 +203,56 @@ h1 { margin-bottom: 10px; } cards = append(cards, Card{Name: t, Count: count}) } + // Fetch USD prices from database (Paddle JSON format) + type PriceInfo struct { + ProductName string + Amount string + Currency string + } + var prices []PriceInfo + rows, err := db.Query(` + SELECT p.name, pr.unit_price + FROM products p + JOIN prices pr ON p.id = pr.product_id + WHERE pr.unit_price LIKE '%USD%' + ORDER BY p.name + `) + if err == nil { + defer rows.Close() + for rows.Next() { + var name, unitPrice string + rows.Scan(&name, &unitPrice) + // Parse Paddle JSON: {"amount": "1200", "currency_code": "USD"} + amount := "0" + currency := "USD" + if idx := strings.Index(unitPrice, `"amount":`); idx >= 0 { + after := unitPrice[idx+9:] + if q1 := strings.Index(after, `"`); q1 >= 0 { + valStart := q1 + 1 + if q2 := strings.Index(after[valStart:], `"`); q2 >= 0 { + amount = after[valStart : valStart+q2] + } + } + } + if idx := strings.Index(unitPrice, `"currency_code":`); idx >= 0 { + after := unitPrice[idx+17:] + if q1 := strings.Index(after, `"`); q1 >= 0 { + valStart := q1 + 1 + if q2 := strings.Index(after[valStart:], `"`); q2 >= 0 { + currency = after[valStart : valStart+q2] + } + } + } + prices = append(prices, PriceInfo{ProductName: name, Amount: amount, Currency: currency}) + } + } + tmpl := template.Must(template.New("home").Parse(html)) tmpl.Execute(w, map[string]interface{}{ - "Tables": tables, - "Cards": cards, + "Tables": tables, + "Cards": cards, + "Prices": prices, + "IsSandbox": isSandboxMode, }) } @@ -222,9 +304,9 @@ func handleDynamicList(w http.ResponseWriter, r *http.Request) { htmlTemplate := ` -{{.Table}} - List +{{.Table}} - List{{if .IsSandbox}} [SANDBOX]{{end}} +{{if .IsSandbox}}
🧪 SANDBOX MODE - Test environment
{{end}}