removed useless networking monitoring option - release fixed 2.8
This commit is contained in:
parent
7e665152b0
commit
ccf04ede06
@ -542,10 +542,6 @@ func main() {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if conf.Server.NetworkEvents {
|
|
||||||
go monitorNetwork(ctx)
|
|
||||||
go handleNetworkEvents(ctx)
|
|
||||||
}
|
|
||||||
go updateSystemMetrics(ctx)
|
go updateSystemMetrics(ctx)
|
||||||
|
|
||||||
if conf.ClamAV.ClamAVEnabled {
|
if conf.ClamAV.ClamAVEnabled {
|
||||||
@ -1749,6 +1745,14 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// handleUpload handles PUT requests for file uploads
|
// handleUpload handles PUT requests for file uploads
|
||||||
func handleUpload(w http.ResponseWriter, r *http.Request, absFilename, fileStorePath string, a url.Values) {
|
func handleUpload(w http.ResponseWriter, r *http.Request, absFilename, fileStorePath string, a url.Values) {
|
||||||
|
clientIP := getOriginalClientIP(r)
|
||||||
|
parsedIP := net.ParseIP(clientIP)
|
||||||
|
if parsedIP == nil {
|
||||||
|
log.Warnf("Invalid client IP address: %s", clientIP)
|
||||||
|
} else {
|
||||||
|
log.Infof("Handling upload from IP: %s (%s)", parsedIP.String(), detectIPVersion(parsedIP.String()))
|
||||||
|
}
|
||||||
|
|
||||||
log.Infof("Using storage path: %s", conf.Server.StoragePath)
|
log.Infof("Using storage path: %s", conf.Server.StoragePath)
|
||||||
|
|
||||||
// HMAC validation
|
// HMAC validation
|
||||||
@ -1856,6 +1860,7 @@ func handleUpload(w http.ResponseWriter, r *http.Request, absFilename, fileStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Respond with 201 Created immediately
|
// Respond with 201 Created immediately
|
||||||
|
w.Header().Set("Content-Type", "text/plain") // Ensure correct interpretation
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
if f, ok := w.(http.Flusher); ok {
|
if f, ok := w.(http.Flusher); ok {
|
||||||
f.Flush()
|
f.Flush()
|
||||||
@ -1960,7 +1965,14 @@ func handleDownload(w http.ResponseWriter, r *http.Request, absFilename, fileSto
|
|||||||
} else {
|
} else {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
log.Infof("Initiating download for file: %s", absFilename)
|
log.Infof("Initiating download for file: %s", absFilename)
|
||||||
http.ServeFile(w, r, absFilename)
|
f, err := os.Open(absFilename)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Couldn't open file: %v", err)
|
||||||
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
http.ServeContent(w, r, filepath.Base(absFilename), fileInfo.ModTime(), f)
|
||||||
downloadDuration.Observe(time.Since(startTime).Seconds())
|
downloadDuration.Observe(time.Since(startTime).Seconds())
|
||||||
downloadSizeBytes.Observe(float64(fileInfo.Size()))
|
downloadSizeBytes.Observe(float64(fileInfo.Size()))
|
||||||
downloadsTotal.Inc()
|
downloadsTotal.Inc()
|
||||||
@ -2160,73 +2172,6 @@ func getFileInfo(absFilename string) (os.FileInfo, error) {
|
|||||||
return fileInfo, nil
|
return fileInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func monitorNetwork(ctx context.Context) {
|
|
||||||
currentIP := getCurrentIPAddress()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
log.Info("Stopping network monitor.")
|
|
||||||
return
|
|
||||||
case <-time.After(10 * time.Second):
|
|
||||||
newIP := getCurrentIPAddress()
|
|
||||||
if newIP != currentIP && newIP != "" {
|
|
||||||
currentIP = newIP
|
|
||||||
select {
|
|
||||||
case networkEvents <- NetworkEvent{Type: "IP_CHANGE", Details: currentIP}:
|
|
||||||
log.WithField("new_ip", currentIP).Info("Queued IP_CHANGE event")
|
|
||||||
default:
|
|
||||||
log.Warn("Network event channel full. Dropping IP_CHANGE event.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleNetworkEvents(ctx context.Context) {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
log.Info("Stopping network event handler.")
|
|
||||||
return
|
|
||||||
case event, ok := <-networkEvents:
|
|
||||||
if !ok {
|
|
||||||
log.Info("Network events channel closed.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
switch event.Type {
|
|
||||||
case "IP_CHANGE":
|
|
||||||
log.WithField("new_ip", event.Details).Info("Network change detected")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getCurrentIPAddress() string {
|
|
||||||
interfaces, err := net.Interfaces()
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Error("Failed to get network interfaces")
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, iface := range interfaces {
|
|
||||||
if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
addrs, err := iface.Addrs()
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Errorf("Failed to get addresses for interface %s", iface.Name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, addr := range addrs {
|
|
||||||
if ipnet, ok := addr.(*net.IPNet); ok && ipnet.IP.IsGlobalUnicast() && ipnet.IP.To4() != nil {
|
|
||||||
return ipnet.IP.String()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupGracefulShutdown(server *http.Server, cancel context.CancelFunc) {
|
func setupGracefulShutdown(server *http.Server, cancel context.CancelFunc) {
|
||||||
quit := make(chan os.Signal, 1)
|
quit := make(chan os.Signal, 1)
|
||||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||||
@ -2812,13 +2757,23 @@ func detectIPVersion(ip string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getOriginalClientIP(r *http.Request) string {
|
func getOriginalClientIP(r *http.Request) string {
|
||||||
if ip := r.Header.Get("X-Forwarded-For"); ip != "" {
|
if xff := r.Header.Get("X-Forwarded-For"); xff != "" {
|
||||||
parts := strings.Split(ip, ",")
|
parts := strings.Split(xff, ",")
|
||||||
return strings.TrimSpace(parts[0])
|
for _, part := range parts {
|
||||||
|
ip := strings.TrimSpace(part)
|
||||||
|
if net.ParseIP(ip) != nil {
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ip := r.Header.Get("X-Real-IP"); ip != "" {
|
if rip := r.Header.Get("X-Real-IP"); rip != "" {
|
||||||
return strings.TrimSpace(ip)
|
if net.ParseIP(rip) != nil {
|
||||||
|
return strings.TrimSpace(rip)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
host, _, _ := net.SplitHostPort(r.RemoteAddr)
|
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||||
return host
|
if err == nil && host != "" && net.ParseIP(host) != nil {
|
||||||
|
return host
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user