Fix settings handler build

This commit is contained in:
redtea committed 2026-10-15 22:48:03 +03:00
1 parent ce7c417884
commit b272aed8fd
13 files changed
+458 -60

No files matched your search

+10 -14
View File
@@ -11,7 +11,7 @@ import (
// DB wraps the SQLite connection and all queries used by the server.
type DB struct {
sql *sql.DB
sql *dbx
path string // the file; the key of saved secrets sits beside it
}
@@ -31,7 +31,7 @@ func OpenDB(path string) (*DB, error) {
if err := sdb.Ping(); err != nil {
return nil, err
}
db := &DB{sql: sdb, path: path}
db := &DB{sql: &dbx{DB: sdb}, path: path}
if err := db.migrate(); err != nil {
return nil, err
}
@@ -131,7 +131,7 @@ CREATE TABLE IF NOT EXISTS forward_rules (
`CREATE TABLE IF NOT EXISTS ssh_hosts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
admin_id INTEGER NOT NULL REFERENCES admins(id) ON DELETE CASCADE,
label TEXT NOT NULL, host TEXT NOT NULL, port INTEGER NOT NULL, user TEXT NOT NULL,
label TEXT NOT NULL, host TEXT NOT NULL, port INTEGER NOT NULL, login TEXT NOT NULL,
auth TEXT NOT NULL, secret TEXT NOT NULL)`,
`CREATE TABLE IF NOT EXISTS admin_agents (
admin_id INTEGER NOT NULL REFERENCES admins(id) ON DELETE CASCADE,
@@ -142,6 +142,10 @@ CREATE TABLE IF NOT EXISTS forward_rules (
return err
}
}
// ssh_hosts.user (a word PostgreSQL keeps for itself) became login.
if !db.sql.pg {
_, _ = db.sql.Exec(`ALTER TABLE ssh_hosts RENAME COLUMN user TO login`)
}
return nil
}
@@ -178,13 +182,9 @@ func (db *DB) CreateAdmin(username, passHash string) error {
// CreateUser adds a panel user with the role given and returns its id.
func (db *DB) CreateUser(username, passHash, role string) (int64, error) {
res, err := db.sql.Exec(
return db.sql.insert(
`INSERT INTO admins(username, pass_hash, created_at, role) VALUES(?, ?, ?, ?)`,
username, passHash, time.Now().Unix(), role)
if err != nil {
return 0, err
}
return res.LastInsertId()
}
// Roles of panel users: an admin sees and runs everything; a user only the
@@ -595,14 +595,10 @@ func (db *DB) CreateForwardRule(r ForwardRule) (int64, error) {
if r.Proto == "" {
r.Proto = "http"
}
res, err := db.sql.Exec(
return db.sql.insert(
`INSERT INTO forward_rules(agent_id, client_port, host_port, listen_addr, proto, no_ufw, label, created_at)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)`,
r.AgentID, r.ClientPort, r.HostPort, r.ListenAddr, r.Proto, r.NoUfw, r.Label, time.Now().Unix())
if err != nil {
return 0, err
}
return res.LastInsertId()
r.AgentID, r.ClientPort, r.HostPort, r.ListenAddr, r.Proto, boolInt(r.NoUfw), r.Label, time.Now().Unix())
}
func (db *DB) ListForwardRules() ([]ForwardRule, error) {