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
|
package main
import (
"config"
"datax"
"flag"
"fmt"
"os"
"runtime"
"syscon"
"syslog"
"time"
)
func main() {
if runtime.GOOS != "linux" {
fmt.Println("this application is supposed to run on linux, there is nothing to do in here... \nexiting with status 0")
return
}
defer syslog.HandlePan()
fixDaemon := flag.NewFlagSet("daemon", flag.ExitOnError)
confPath := fixDaemon.String("config", "fixrate.conf", "gnu config file for fixrate service")
fixDaemon.Usage = fixRateUsage
fixUser := flag.NewFlagSet("users", flag.ExitOnError)
fixUser.Usage = addUserUsage
confPathforUser := fixUser.String("config", "fixrate.conf", "gnu config file for fixrate service")
userName := fixUser.String("username", "sina@snix.ir", "a username to add/modify in database")
userRate := fixUser.Int("userrate", 10, "how many e-mails user should be able to send")
userReset := fixUser.Int("counter", 120, "time interval between user counter reset")
flag.Usage = globUsage
if len(os.Args) < 2 {
fmt.Println("expected 'daemon' or 'users' commands")
flag.Usage()
os.Exit(1)
}
switch os.Args[1] {
case "daemon":
fixDaemon.Parse(os.Args[2:])
conf := config.ReadConfigFromFile(*confPath)
syscon.StartNewService(conf)
case "users":
fixUser.Parse(os.Args[2:])
if len(os.Args[2:]) == 0 {
fmt.Println("expect more options -- use --h for information")
fixUser.Usage()
os.Exit(1)
}
conf := config.ReadConfigFromFile(*confPathforUser)
if err := datax.SQLInit(conf); err != nil {
panic(syslog.BigError{Why: err, Cod: 1})
}
defer datax.DBClose()
temp := &datax.UserAccount{
Username: *userName,
UserType: true,
LastReset: time.Now(),
Limit: *userRate,
Reset: *userReset,
}
if err := datax.CreateNewUser(temp); err != nil {
panic(syslog.BigError{Why: err, Cod: 1})
}
fmt.Printf("\033[32minfo:\033[0m username: %v with %v e-mails per %v seconds added to database.\n", *userName, *userRate, *userReset)
default:
fmt.Println("expected 'daemon' or 'users' commands")
flag.Usage()
os.Exit(1)
}
}
func globUsage() {
fmt.Printf(`usage of fixrate postfix module snix.ir LLC:
%v commands... [ OPTIONS ] ...
commands:
daemon starting fixrate daemon, should be used by systemd
--config pass a file to read configuration from. default: ./fixrate.conf
users add or modify users and attributes in database
--config pass a file to read configuration from. default: ./fixrate.conf
--username a username to add/modify in database. default is sina@snix.ir
--counter time interval (seconds) between user counter reset. default is 120
--userrate how many e-mails user should be able to send. default is 10
example:
---- adding name@domain.com ---- 100 e-mail per 10 minutes:
%v users --username name@domain.com -- userrate 100 --counter 600
Copyright (c) 2021 git.snix.ir, All rights reserved.
Developed BY sina@snix.ir --> Sina Ghaderi
This work is licensed under the terms of the MIT license.
`, os.Args[0], os.Args[0])
}
func fixRateUsage() {
fmt.Printf(`usage of fixrate postfix module snix.ir LLC:
%v daemon [ OPTIONS ] ...
options:
--config pass a file to read configuration from. default: ./fixrate.conf
--h print this banner and exit.
Copyright (c) 2021 git.snix.ir, All rights reserved.
Developed BY sina@snix.ir --> Sina Ghaderi
This work is licensed under the terms of the MIT license.
`, os.Args[0])
}
func addUserUsage() {
fmt.Printf(`usage of fixrate postfix module snix.ir LLC:
%v users [ OPTIONS ] ...
options:
--config pass a file to read configuration from. default: ./fixrate.conf
--username a username to add/modify in database. default is sina@snix.ir
--counter time interval (seconds) between user counter reset. default is 120
--userrate how many e-mails user should be able to send. default is 10
example:
---- adding name@domain.com ---- 100 e-mail per 10 minutes:
%v users --username name@domain.com -- userrate 100 --counter 600
Copyright (c) 2021 git.snix.ir, All rights reserved.
Developed BY sina@snix.ir --> Sina Ghaderi
This work is licensed under the terms of the MIT license.
`, os.Args[0], os.Args[0])
}
|