- Deleted version comparison logic from `pkg/plugin/sign/version.go`. - Removed unused types and constants from `pkg/plugin/types.go`. - Updated `pkg/protocol/message.go` to remove plugin-related message types. - Enhanced `pkg/proxy/http.go` and `pkg/proxy/socks5.go` to include username/password authentication for HTTP and SOCKS5 proxies. - Modified `pkg/proxy/server.go` to pass authentication parameters to server constructors. - Added new API endpoint to generate installation commands with a token for clients. - Created database functions to manage installation tokens in `internal/server/db/install_token.go`. - Implemented the installation command generation logic in `internal/server/router/handler/install.go`. - Updated web frontend to support installation command generation and display in `web/src/views/ClientsView.vue`.
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package db
|
|
|
|
// CreateInstallToken 创建安装token
|
|
func (s *SQLiteStore) CreateInstallToken(token *InstallToken) error {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
_, err := s.db.Exec(`INSERT INTO install_tokens (token, client_id, created_at, used) VALUES (?, ?, ?, ?)`,
|
|
token.Token, token.ClientID, token.CreatedAt, 0)
|
|
return err
|
|
}
|
|
|
|
// GetInstallToken 获取安装token
|
|
func (s *SQLiteStore) GetInstallToken(token string) (*InstallToken, error) {
|
|
s.mu.RLock()
|
|
defer s.mu.RUnlock()
|
|
|
|
var t InstallToken
|
|
var used int
|
|
err := s.db.QueryRow(`SELECT token, client_id, created_at, used FROM install_tokens WHERE token = ?`, token).
|
|
Scan(&t.Token, &t.ClientID, &t.CreatedAt, &used)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
t.Used = used == 1
|
|
return &t, nil
|
|
}
|
|
|
|
// MarkTokenUsed 标记token已使用
|
|
func (s *SQLiteStore) MarkTokenUsed(token string) error {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
_, err := s.db.Exec(`UPDATE install_tokens SET used = 1 WHERE token = ?`, token)
|
|
return err
|
|
}
|
|
|
|
// DeleteExpiredTokens 删除过期token
|
|
func (s *SQLiteStore) DeleteExpiredTokens(expireTime int64) error {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
_, err := s.db.Exec(`DELETE FROM install_tokens WHERE created_at < ?`, expireTime)
|
|
return err
|
|
}
|