-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_packetfilter.go
56 lines (47 loc) · 1.04 KB
/
create_packetfilter.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
package main
import (
"fmt"
"log"
"os"
"github.com/esurdam/go-sophos"
types "github.com/esurdam/go-sophos/api/v1.3.0/objects"
)
//noinspection ALL
var (
endpoint, token string
)
func init() {
if len(os.Args) == 3 {
endpoint = os.Args[1]
token = os.Args[2]
}
if endpoint == "" {
endpoint = os.Getenv("ENDPOINT")
}
if token == "" {
token = os.Getenv("TOKEN")
}
if endpoint == "" || token == "" {
panic("need endpoint and token as args or from env ($ENDPOINT, $TOKEN)")
}
}
func main() {
client, err := sophos.New(endpoint, sophos.WithAPIToken(token))
if err != nil {
log.Fatal(err)
}
p := types.PacketfilterPacketfilter{
Action: "accept",
Destinations: []string{sophos.RefNetworkAny},
Direction: "in",
Log: true,
Services: []string{sophos.RefServiceAny},
Sources: []string{sophos.RefNetworkAny},
Status: true,
}
err = client.PostObject(&p, sophos.WithRestdInsert("packetfilter.rules", 0), sophos.WithSessionClose)
if err != nil {
log.Fatal(err)
}
fmt.Println(p.Reference)
}