diff --git a/main.go b/main.go index 06487fc..12196df 100644 --- a/main.go +++ b/main.go @@ -48,24 +48,18 @@ func initDB() { log.Fatalf("[DB] Failed to connect: %v", err) } - // Ensure cosmos keyspace exists - if err = sys.Query("CREATE KEYSPACE IF NOT EXISTS cosmos WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': 1}").Exec(); err != nil { - sys.Query("CREATE KEYSPACE IF NOT EXISTS cosmos WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}").Exec() + err = sys.Query("CREATE KEYSPACE IF NOT EXISTS unity WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': 1}").Exec() + if err != nil { + log.Fatalf("[DB] Failed to create keyspace: %v", err) } - // Backward compatibility keyspace alias - sys.Query("CREATE KEYSPACE IF NOT EXISTS unity WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}").Exec() sys.Close() - scyllaHost := os.Getenv("SCYLLA_HOST") - if scyllaHost == "" { - scyllaHost = "127.0.0.1" - } - kCluster := gocql.NewCluster(scyllaHost) + kCluster := gocql.NewCluster("127.0.0.1") kCluster.Keyspace = "cosmos" kCluster.Timeout = 10 * time.Second scyllaSession, err = kCluster.CreateSession() if err != nil { - log.Fatalf("[DB] Failed to connect to cosmos keyspace: %v", err) + log.Fatalf("[DB] Failed to connect to unity keyspace: %v", err) } scyllaSession.Query(`CREATE TABLE IF NOT EXISTS users ( @@ -122,8 +116,8 @@ func generateOTP() string { } func sendVerificationEmail(email, token, service string) { - msg := fmt.Sprintf("From: %s\r\nTo: %s\r\nSubject: Verify your Cosmos %s Account\r\n\r\nYour verification code is: %s\r\n\r\nEnter this 6-digit code in the portal to verify your account.\r\n", - getEmailFrom(), email, strings.ToUpper(service), token) + msg := fmt.Sprintf("From: noreply@cosmos.linuxguy.space\r\nTo: %s\r\nSubject: Verify your Cosmos %s Account\r\n\r\nYour verification code is: %s\r\n\r\nEnter this 6-digit code in the portal to verify your account.\r\n", + email, strings.ToUpper(service), token) cmd := exec.Command("msmtp", "-t") cmd.Stdin = bytes.NewBufferString(msg) if err := cmd.Run(); err != nil { @@ -225,7 +219,7 @@ func handleSignup(w http.ResponseWriter, r *http.Request, service string) { sessionID := uuid.New().String() // Store session+OTP in pending table — raw_password NOT stored in DB (security) - if err := scyllaSession.Query(`INSERT INTO cosmos.pending (service, reg_token, session_id, name, email, password_hash, username, profile_image) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, + if err := scyllaSession.Query(`INSERT INTO unity.pending (service, reg_token, session_id, name, email, password_hash, username, profile_image) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, service, regToken, sessionID, name, email, string(hash), username, profileImageBase64).Exec(); err != nil { log.Printf("[SIGNUP] DB: %v", err) http.Error(w, "Database error", 500) @@ -334,7 +328,7 @@ func handleVerify(w http.ResponseWriter, r *http.Request, service string) { } var sessionID, name, email, passwordHash, username, profileImage string // raw_password is never stored in DB — read from in-memory map only - err := scyllaSession.Query(`SELECT session_id, name, email, password_hash, username, profile_image FROM cosmos.pending WHERE service = ? AND reg_token = ?`, + err := scyllaSession.Query(`SELECT session_id, name, email, password_hash, username, profile_image FROM unity.pending WHERE service = ? AND reg_token = ?`, service, token).Scan(&sessionID, &name, &email, &passwordHash, &username, &profileImage) if err != nil { if r.Header.Get("Content-Type") == "application/x-www-form-urlencoded" { @@ -354,7 +348,7 @@ func handleVerify(w http.ResponseWriter, r *http.Request, service string) { accessKey := email secretKey := strings.ReplaceAll(uuid.New().String(), "-", "") + strings.ReplaceAll(uuid.New().String(), "-", "")[:8] - bucket := "cosmos-" + strings.ReplaceAll(uuid.New().String(), "-", "")[:8] + bucket := "unity-" + strings.ReplaceAll(uuid.New().String(), "-", "")[:8] // Store created_at for future session expiry checks createdAt := time.Now().Unix() if err = scyllaSession.Query(`INSERT INTO cosmos.users (service, email, name, password_hash, access_key, secret_key, bucket, bucket_display_name, session_id, username, profile_image, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, 'mybucket', ?, ?, ?, ?)`, @@ -367,7 +361,7 @@ func handleVerify(w http.ResponseWriter, r *http.Request, service string) { return } } - scyllaSession.Query(`DELETE FROM cosmos.pending WHERE service = ? AND reg_token = ?`, service, token).Exec() + scyllaSession.Query(`DELETE FROM unity.pending WHERE service = ? AND reg_token = ?`, service, token).Exec() // Clear raw password from memory immediately after use pendingPasswords.Delete(service + ":" + token) @@ -445,9 +439,9 @@ h1{font-size:48px;font-weight:700;margin-bottom:8px}
Access Key ID
%s
Secret Access Key
%s
Private Bucket
%s
-
S3 Endpoint
%s
+
S3 Endpoint
https://cosmos.linuxguy.space
Open Storage Console → -`, name, ak, sk, bucket, getCosmosBaseURL(), sid) +`, name, ak, sk, bucket, sid) case "git": fmt.Fprintf(w, `Git – Cosmos + + + + +
+
+ + + Cosmos Orbit + + Module 03 · App PaaS +
+
+ Forge (Git) + Oort (S3) + +
+
+ + +
+ +
+
+
Applications Fleet
+
—
+
— Running containers
+
+
+
Memory Allocation RAM
+
—
+
Across managed services
+
+
+
Container Engine Docker
+
v1.45 API
+
Direct socket integration
+
+
+
Ingress Gateway Proxy
+
:4100–:4999
+
Dynamic reverse proxy active
+
+
+ + +
+
+

Managed Applications

+

Live containers deployed from source repositories

+
+
+ +
+
+ + +
+
+ Loading your application fleet… +
+
+
+ + + + + + + +
+ + + +