mirror of
https://github.com/coalaura/up.git
synced 2025-07-17 21:44:35 +00:00
improve logging
This commit is contained in:
@ -156,7 +156,7 @@ func NewPinnedClient(store *CertificateStore) *http.Client {
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Printf("Server fingerprint (%s): %s\n", name, fingerprint)
|
||||
log.Printf("Server fingerprint for %s: %s\n", name, fingerprint)
|
||||
log.Print("Accept? [y/N]: ")
|
||||
|
||||
var confirm string
|
||||
|
@ -54,7 +54,7 @@ func main() {
|
||||
}
|
||||
|
||||
func run(_ context.Context, cmd *cli.Command) error {
|
||||
log.Println("loading certificate store")
|
||||
log.Println("Loading certificate store...")
|
||||
|
||||
store, err := LoadCertificateStore()
|
||||
if err != nil {
|
||||
@ -73,7 +73,7 @@ func run(_ context.Context, cmd *cli.Command) error {
|
||||
return fmt.Errorf("failed to get key path: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("using key %s\n", kPath)
|
||||
log.Printf("Using key: %s\n", kPath)
|
||||
|
||||
path = cmd.String("file")
|
||||
if path == "" {
|
||||
@ -85,7 +85,7 @@ func run(_ context.Context, cmd *cli.Command) error {
|
||||
return fmt.Errorf("failed to get file path: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("using file %s\n", fPath)
|
||||
log.Printf("Using file: %s\n", fPath)
|
||||
|
||||
file, err := os.OpenFile(fPath, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
@ -101,9 +101,9 @@ func run(_ context.Context, cmd *cli.Command) error {
|
||||
|
||||
target = fmt.Sprintf("https://%s", target)
|
||||
|
||||
log.Printf("using target %s\n", target)
|
||||
log.Printf("Using target: %s\n", target)
|
||||
|
||||
log.Printf("loading key")
|
||||
log.Printf("Loading key...")
|
||||
|
||||
private, err := LoadPrivateKey(kPath)
|
||||
if err != nil {
|
||||
@ -112,14 +112,14 @@ func run(_ context.Context, cmd *cli.Command) error {
|
||||
|
||||
public := base64.StdEncoding.EncodeToString(private.PublicKey().Marshal())
|
||||
|
||||
log.Println("requesting challenge")
|
||||
log.Println("Requesting challenge...")
|
||||
|
||||
challenge, err := RequestChallenge(client, target, public)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("completing challenge")
|
||||
log.Println("Completing challenge...")
|
||||
|
||||
response, err := CompleteChallenge(client, target, public, private, challenge)
|
||||
if err != nil {
|
||||
|
@ -25,7 +25,7 @@ func (pr *ProgressReader) Read(p []byte) (int, error) {
|
||||
pr.read += int64(n)
|
||||
|
||||
percentage := float64(pr.read) / float64(pr.total) * 100
|
||||
log.Printf("\r%s %.1f%%", pr.label, percentage)
|
||||
log.Printf("\r%s: %.1f%%", pr.label, percentage)
|
||||
|
||||
return n, err
|
||||
}
|
||||
|
@ -38,8 +38,6 @@ func main() {
|
||||
|
||||
r.Post("/receive", HandleReceiveRequest)
|
||||
|
||||
log.Println("Listening on :7966")
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: ":7966",
|
||||
Handler: r,
|
||||
@ -48,5 +46,6 @@ func main() {
|
||||
},
|
||||
}
|
||||
|
||||
log.Println("Server listening on :7966")
|
||||
srv.ListenAndServeTLS("cert.pem", "key.pem")
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ func IsSignatureFormatValid(format string) bool {
|
||||
}
|
||||
|
||||
func HandleChallengeRequest(w http.ResponseWriter, r *http.Request, authorized map[string]ssh.PublicKey) {
|
||||
log.Printf("request: new request from %s\n", r.RemoteAddr)
|
||||
log.Printf("request: received new request from %s\n", r.RemoteAddr)
|
||||
|
||||
var request internal.AuthRequest
|
||||
|
||||
if err := msgpack.NewDecoder(r.Body).Decode(&request); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
log.Warning("request: failed to decode request")
|
||||
log.Warning("request: failed to decode request payload")
|
||||
log.WarningE(err)
|
||||
|
||||
return
|
||||
@ -49,7 +49,7 @@ func HandleChallengeRequest(w http.ResponseWriter, r *http.Request, authorized m
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
log.Warning("request: failed to parse/authorize public key")
|
||||
log.Warning("request: failed to parse or authorize public key")
|
||||
log.WarningE(err)
|
||||
|
||||
return
|
||||
@ -77,14 +77,14 @@ func HandleChallengeRequest(w http.ResponseWriter, r *http.Request, authorized m
|
||||
}
|
||||
|
||||
func HandleCompleteRequest(w http.ResponseWriter, r *http.Request, authorized map[string]ssh.PublicKey) {
|
||||
log.Printf("complete: new completion from %s\n", r.RemoteAddr)
|
||||
log.Printf("complete: received completion from %s\n", r.RemoteAddr)
|
||||
|
||||
var response internal.AuthResponse
|
||||
|
||||
if err := msgpack.NewDecoder(r.Body).Decode(&response); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
log.Warning("complete: failed to decode response")
|
||||
log.Warning("complete: failed to decode response payload")
|
||||
log.WarningE(err)
|
||||
|
||||
return
|
||||
@ -94,7 +94,7 @@ func HandleCompleteRequest(w http.ResponseWriter, r *http.Request, authorized ma
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
log.Warning("complete: failed to parse/authorize public key")
|
||||
log.Warning("complete: failed to parse or authorize public key")
|
||||
log.WarningE(err)
|
||||
|
||||
return
|
||||
@ -170,7 +170,7 @@ func HandleCompleteRequest(w http.ResponseWriter, r *http.Request, authorized ma
|
||||
PublicKey: public,
|
||||
}, cache.DefaultExpiration)
|
||||
|
||||
log.Printf("complete: completed auth for %s\n", r.RemoteAddr)
|
||||
log.Printf("complete: authentication completed for %s\n", r.RemoteAddr)
|
||||
|
||||
w.Header().Set("Content-Type", "application/msgpack")
|
||||
msgpack.NewEncoder(w).Encode(internal.AuthResult{
|
||||
@ -179,7 +179,7 @@ func HandleCompleteRequest(w http.ResponseWriter, r *http.Request, authorized ma
|
||||
}
|
||||
|
||||
func HandleReceiveRequest(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("receive: request from %s\n", r.RemoteAddr)
|
||||
log.Printf("receive: received request from %s\n", r.RemoteAddr)
|
||||
|
||||
token := r.Header.Get("Authorization")
|
||||
if token == "" {
|
||||
@ -250,12 +250,12 @@ func HandleReceiveRequest(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
log.Warning("receive: failed to copy sent file")
|
||||
log.Warning("receive: failed to save uploaded file")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("receive: stored %s from %s (%d bytes)\n", name, r.RemoteAddr, read)
|
||||
log.Printf("receive: stored file %s from %s (%d bytes)\n", name, r.RemoteAddr, read)
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
Reference in New Issue
Block a user