Add VPN client users with inbound access and subscription links.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
orohi
2026-07-29 04:49:32 +03:00
co-authored by Cursor
parent 4991b313d7
commit c0e78ce949
16 changed files with 930 additions and 11 deletions
+32
View File
@@ -129,6 +129,30 @@ CREATE TABLE IF NOT EXISTS node_inbounds (
enabled BOOLEAN NOT NULL DEFAULT TRUE,
PRIMARY KEY (node_id, inbound_id)
);
CREATE TABLE IF NOT EXISTS clients (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
username TEXT NOT NULL UNIQUE,
email TEXT NOT NULL DEFAULT '',
uuid UUID NOT NULL UNIQUE DEFAULT gen_random_uuid(),
status TEXT NOT NULL DEFAULT 'active',
traffic_limit_bytes BIGINT NOT NULL DEFAULT 0,
traffic_used_bytes BIGINT NOT NULL DEFAULT 0,
expire_at TIMESTAMPTZ,
sub_token TEXT NOT NULL UNIQUE,
note TEXT NOT NULL DEFAULT '',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_clients_status ON clients(status);
CREATE INDEX IF NOT EXISTS idx_clients_sub_token ON clients(sub_token);
CREATE TABLE IF NOT EXISTS client_inbounds (
client_id UUID NOT NULL REFERENCES clients(id) ON DELETE CASCADE,
inbound_id UUID NOT NULL REFERENCES inbounds(id) ON DELETE CASCADE,
PRIMARY KEY (client_id, inbound_id)
);
`
if _, err := db.Exec(schema); err != nil {
return err
@@ -266,5 +290,13 @@ func GetStats(db *sql.DB) (models.DashboardStats, error) {
return s, err
}
err = db.QueryRow(`SELECT COUNT(*) FROM config_profiles`).Scan(&s.ProfilesTotal)
if err != nil {
return s, err
}
err = db.QueryRow(`SELECT COUNT(*) FROM clients`).Scan(&s.ClientsTotal)
if err != nil {
return s, err
}
err = db.QueryRow(`SELECT COUNT(*) FROM clients WHERE status = 'active'`).Scan(&s.ClientsActive)
return s, err
}