-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathmain.go
More file actions
145 lines (120 loc) Β· 5 KB
/
main.go
File metadata and controls
145 lines (120 loc) Β· 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main
import (
"fmt"
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
"github.com/fatih/color"
"Montscan/agent"
"Montscan/config"
"Montscan/server"
)
func printBanner(cfg *config.Config) {
cyan := color.New(color.FgCyan).SprintFunc()
yellow := color.New(color.FgYellow).SprintFunc()
green := color.New(color.FgGreen).SprintFunc()
white := color.New(color.FgWhite).SprintFunc()
// debug print all "cfg"
fmt.Println(cfg)
if cfg.FTPEnabled {
fmt.Println(green("π‘ FTP Ingress:"))
uploadPath, _ := filepath.Abs(cfg.FTPUploadDir)
fmt.Printf(" %sββ%s Host: %s\n", white(""), white(""), cyan(cfg.FTPHost))
fmt.Printf(" %sββ%s Port: %s\n", white(""), white(""), cyan(fmt.Sprintf("%d", cfg.FTPPort)))
fmt.Printf(" %sββ%s Username: %s\n", white(""), white(""), cyan(cfg.FTPUsername))
fmt.Printf(" %sββ%s Upload Directory: %s\n", white(""), white(""), cyan(uploadPath))
} else {
fmt.Println(yellow("β οΈ FTP Ingress:"))
fmt.Printf(" %sββ%s %s\n", white(""), white(""), yellow("Disabled (FTP_ENABLED=false)"))
}
fmt.Println()
if cfg.SambaServerEnabled {
fmt.Println(green("π₯ Samba Server:"))
fmt.Printf(" %sββ%s Host: %s\n", white(""), white(""), cyan(cfg.SambaServerHost))
fmt.Printf(" %sββ%s Port: %s\n", white(""), white(""), cyan(fmt.Sprintf("%d", cfg.SambaServerPort)))
fmt.Printf(" %sββ%s Share: %s\n", white(""), white(""), cyan(cfg.SambaServerShare))
fmt.Printf(" %sββ%s Path: %s\n", white(""), white(""), cyan(cfg.SambaServerPath))
} else {
fmt.Println(yellow("β οΈ Samba Server:"))
fmt.Printf(" %sββ%s %s\n", white(""), white(""), yellow("Disabled (SAMBA_SERVER_ENABLED=false)"))
}
fmt.Println()
if cfg.WebDAVEnabled {
fmt.Println(green("βοΈ WebDAV Provider:"))
fmt.Printf(" %sββ%s URL: %s\n", white(""), white(""), cyan(cfg.WebDAVURL))
} else {
fmt.Println(yellow("β οΈ WebDAV Provider:"))
fmt.Printf(" %sββ%s %s\n", white(""), white(""), yellow("Not configured (WEBDAV_URL not set)"))
}
fmt.Println()
if cfg.SambaEnabled {
fmt.Println(green("ποΈ Samba Provider:"))
fmt.Printf(" %sββ%s Host: %s\n", white(""), white(""), cyan(cfg.SambaHost))
fmt.Printf(" %sββ%s Port: %s\n", white(""), white(""), cyan(fmt.Sprintf("%d", cfg.SambaPort)))
fmt.Printf(" %sββ%s Share: %s\n", white(""), white(""), cyan(cfg.SambaShare))
fmt.Printf(" %sββ%s Username: %s\n", white(""), white(""), cyan(cfg.SambaUsername))
fmt.Printf(" %sββ%s Path: %s\n", white(""), white(""), cyan(cfg.SambaPath))
} else {
fmt.Println(yellow("β οΈ Samba Provider:"))
fmt.Printf(" %sββ%s %s\n", white(""), white(""), yellow("Not configured (SAMBA_HOST or SAMBA_SHARE not set)"))
}
fmt.Println()
fmt.Println(green("π€ AI Processing (Ollama):"))
fmt.Printf(" %sββ%s Host: %s\n", white(""), white(""), cyan(cfg.OllamaHost))
fmt.Printf(" %sββ%s Model: %s\n", white(""), white(""), cyan(cfg.OllamaModel))
fmt.Println()
pdfTool := agent.CheckPDFTools()
if pdfTool != "" {
fmt.Println(green("π PDF Processing:"))
fmt.Printf(" %sββ%s Tool: %s\n", white(""), white(""), cyan(pdfTool))
} else {
fmt.Println(color.New(color.FgRed).Sprint("β PDF Processing:"))
fmt.Println(agent.GetPDFToolInstallInstructions())
}
fmt.Println()
fmt.Println(cyan("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"))
fmt.Println(green("β
All systems initialized - Ready to process documents!"))
fmt.Println(cyan("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"))
fmt.Println()
}
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lmsgprefix)
log.SetPrefix("[Montscan] ")
cfg := config.Load()
printBanner(cfg)
if !cfg.FTPEnabled && !cfg.SambaServerEnabled {
log.Fatal("No ingress server enabled. Enable FTP_ENABLED or SAMBA_SERVER_ENABLED.")
}
if agent.CheckPDFTools() == "" {
panic("PDF processing tools not found. Please install one of the supported tools (e.g., pdftotext, pdfinfo) and ensure it's in your system PATH.")
}
ag := agent.New(cfg)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigChan
fmt.Println()
color.Yellow("βΉοΈ Shutting down server...")
log.Println("Server stopped by user")
os.Exit(0)
}()
errCh := make(chan error, 2)
if cfg.FTPEnabled {
go func() {
errCh <- server.StartFTPServer(cfg, ag)
}()
}
if cfg.SambaServerEnabled {
go func() {
errCh <- server.StartSambaServer(cfg, ag)
}()
}
fmt.Println(color.GreenString("π Ingress services are now running! Press Ctrl+C to stop."))
fmt.Println()
if err := <-errCh; err != nil {
color.Red("β Error starting server: %v", err)
log.Fatalf("Error starting server: %v", err)
}
}