2024-11-21 06:16:20 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2024-12-06 20:24:56 +00:00
|
|
|
var (
|
|
|
|
Paths []string
|
|
|
|
)
|
|
|
|
|
2024-11-21 06:16:20 +00:00
|
|
|
func Readfile(filename string, out chan<- string) error {
|
|
|
|
file, err := os.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
out <- line
|
|
|
|
}
|
|
|
|
|
|
|
|
return scanner.Err()
|
|
|
|
}
|
2024-12-06 20:24:56 +00:00
|
|
|
|
|
|
|
func ReadPaths() ([]string, error) {
|
|
|
|
if Conf.Pathlist == "" {
|
|
|
|
// default fallback paths, some of the most common opendir uris
|
|
|
|
return []string{"/", "/files", "/ftp", "/backup", "/backups", "/config", "/dev", "/archive", "/old", "/scripts", "/logs", "/data", "/uploads", "/temp", "/tmp", "/static"}, nil
|
|
|
|
}
|
|
|
|
var paths []string
|
|
|
|
|
|
|
|
file, err := os.Open(Conf.Pathlist)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
|
|
|
paths = append(paths, strings.TrimSpace(scanner.Text()))
|
|
|
|
}
|
|
|
|
|
|
|
|
return paths, scanner.Err()
|
|
|
|
}
|