Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
248735710a | |||
c1a1bf0b03 | |||
82d07eaaf4 | |||
a2ffbad4a3 |
2
Makefile
2
Makefile
@@ -5,7 +5,7 @@ NAME = apiary
|
||||
|
||||
INSTALL_PREFIX ?= /usr/local
|
||||
|
||||
VERSION = $(shell cat version.go |grep "Version"| cut -d "=" -f2| tr -d "\" ")
|
||||
VERSION = $(shell cat version.go |grep "var Version"| cut -d "=" -f2| tr -d "\" ")
|
||||
ARCH = $(shell go env | grep GOHOSTARCH | cut -d"=" -f2 | tr -d "\"")
|
||||
OS = $(shell go env | grep GOHOSTOS | cut -d"=" -f2 | tr -d "\"")
|
||||
GIT_COMMIT := $(shell git rev-parse --short HEAD)
|
||||
|
@@ -3,6 +3,7 @@ package store
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
_ "github.com/jackc/pgx/v4/stdlib"
|
||||
"github.uio.no/torjus/apiary/models"
|
||||
@@ -161,6 +162,7 @@ func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) {
|
||||
|
||||
func (s *PostgresStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) {
|
||||
var stmt string
|
||||
queryString := query.Query
|
||||
|
||||
switch query.QueryType {
|
||||
case AttemptQueryTypeIP:
|
||||
@@ -168,15 +170,17 @@ func (s *PostgresStore) Query(query AttemptQuery) ([]models.LoginAttempt, error)
|
||||
FROM login_attempts WHERE remote_ip = $1`
|
||||
case AttemptQueryTypePassword:
|
||||
stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country
|
||||
FROM login_attempts WHERE password like '%$1%'`
|
||||
FROM login_attempts WHERE password like $1`
|
||||
queryString = fmt.Sprintf("%%%s%%", queryString)
|
||||
case AttemptQueryTypeUsername:
|
||||
stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country
|
||||
FROM login_attempts WHERE username like '%$1%'`
|
||||
FROM login_attempts WHERE username like $1`
|
||||
queryString = fmt.Sprintf("%%%s%%", queryString)
|
||||
default:
|
||||
return nil, fmt.Errorf("Invalid query type")
|
||||
}
|
||||
|
||||
rows, err := s.db.Query(stmt, query.Query)
|
||||
rows, err := s.db.Query(stmt, queryString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to query database: %w", err)
|
||||
}
|
||||
@@ -185,9 +189,11 @@ func (s *PostgresStore) Query(query AttemptQuery) ([]models.LoginAttempt, error)
|
||||
var results []models.LoginAttempt
|
||||
for rows.Next() {
|
||||
var la models.LoginAttempt
|
||||
if err := rows.Scan(&la.ID, &la.Date, &la.RemoteIP, &la.Username, &la.Password, &la.SSHClientVersion, &la.ConnectionUUID, &la.Country); err != nil {
|
||||
var ipString string
|
||||
if err := rows.Scan(&la.ID, &la.Date, &ipString, &la.Username, &la.Password, &la.SSHClientVersion, &la.ConnectionUUID, &la.Country); err != nil {
|
||||
return nil, fmt.Errorf("Unable to unmarshal data from database: %w", err)
|
||||
}
|
||||
la.RemoteIP = net.ParseIP(ipString)
|
||||
results = append(results, la)
|
||||
|
||||
}
|
||||
|
11
version.go
11
version.go
@@ -1,14 +1,17 @@
|
||||
package apiary
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var Version = "v0.1.2"
|
||||
var Version = "v0.1.3"
|
||||
var Build string
|
||||
|
||||
func FullVersion() string {
|
||||
if Build != "" {
|
||||
return fmt.Sprintf("%s-%s", Version, Build)
|
||||
return fmt.Sprintf("%s-%s (%s)", Version, Build, runtime.Version())
|
||||
}
|
||||
|
||||
return Version
|
||||
return fmt.Sprintf("%s (%s)", Version, runtime.Version())
|
||||
}
|
||||
|
Reference in New Issue
Block a user