Initial commit — migrated from GitHub (account suspended)
This commit is contained in:
commit
09d0ee68c8
65 files changed
+23255
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// clientIP mengambil IP klien dari X-Forwarded-For (bila ada) atau RemoteAddr.
|
||||
func clientIP(r *http.Request) string {
|
||||
if fwd := r.Header.Get("X-Forwarded-For"); fwd != "" {
|
||||
parts := strings.Split(fwd, ",")
|
||||
if ip := strings.TrimSpace(parts[0]); ip != "" {
|
||||
return ip
|
||||
}
|
||||
}
|
||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
return r.RemoteAddr
|
||||
}
|
||||
return host
|
||||
}
|
||||
|
||||
// log mencatat satu entri ke log aktivitas (audit trail).
|
||||
func (s *Server) log(actor, action, target, ip, result, detail string) {
|
||||
s.store.LogActivity(actor, action, target, ip, result, detail)
|
||||
}
|
||||
|
||||
// actorIP mengembalikan (username sesi, IP) untuk pencatatan log.
|
||||
func (s *Server) actorIP(r *http.Request) (string, string) {
|
||||
username, _ := s.sessionUser(r)
|
||||
if username == "" {
|
||||
username = "anonim"
|
||||
}
|
||||
return username, clientIP(r)
|
||||
}
|
||||
Reference in new issue
Block a user