-
Notifications
You must be signed in to change notification settings - Fork 4
/
cmdInteractiveMain.go
82 lines (66 loc) · 1.69 KB
/
cmdInteractiveMain.go
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
package cmd
import (
"time"
"github.com/manifoldco/promptui"
"github.com/moorada/neferpitool/pkg/changes"
"github.com/moorada/neferpitool/pkg/configuration"
"github.com/moorada/neferpitool/pkg/db"
"github.com/moorada/neferpitool/pkg/log"
"github.com/moorada/neferpitool/pkg/stats"
"github.com/robfig/cron/v3"
)
var changesToSend changes.ChangeList
func MonitorCmd() {
for true {
prompt := promptui.Select{
Label: "Monitor mode",
Items: []string{"Domains", "Show all Typodomains in Expiration", "Check for changes", "Active changes in background", "Stats", "Test"},
}
_, result, err := prompt.Run()
if err != nil {
log.Error("Prompt failed %v\n", err)
return
}
switch result {
case "Domains":
manageDomains()
case "Show all Typodomains in Expiration":
showTypoDomainsInExpiration()
case "Check for changes":
checkForChanges()
case "Active changes in background":
background()
case "Stats":
stats.PrintWhoisStats()
case "Test":
test()
}
}
}
func test() {
parser := cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow)
for _, c := range configuration.GetConf().REPORTFREQUENCY {
cronSpec, _ := parser.Parse(c)
log.Info("%s", cronSpec.Next(time.Now()))
}
cronSpec, _ := parser.Parse("*/30 * * * *")
log.Info("%s", cronSpec.Next(time.Now()))
}
func manageDomains() {
mds := db.GetMainDomainListFromDB()
var mdsnames []string
for _, d := range mds {
mdsnames = append(mdsnames, d.Name)
}
prompt := promptui.Select{
Label: "Domains",
Items: mdsnames,
}
_, result, err := prompt.Run()
if err != nil {
log.Error("Prompt failed %v\n", err)
return
}
log.Info("Manage %s", result)
SingleDomainMode(result)
}