/
main.go
105 lines (78 loc) · 2.12 KB
/
main.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"bytes"
"flag"
"io/ioutil"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/telapi/flumine/logger"
)
var (
uri = flag.String("uri", "", "URI you wish to use to access smpp dumps. By default it's autogenerated.")
iface = flag.String("i", "any", "Interface you wish to invoke. Use ifconfig to figure out which one. Default is any.")
srvkill = make(chan os.Signal, 1)
packets = make(chan []string)
)
func main() {
flag.Parse()
signal.Notify(srvkill, os.Interrupt)
signal.Notify(srvkill, syscall.SIGTERM)
furi := *uri
if err := ValidateUri(*uri); err != nil {
// If lenght of uri is empty we are going to attempt generate uri
if len(*uri) < 1 {
Debug("Provided URI is empty. We are going to generate new one now ...")
furi = GenerateUri()
} else {
Error("Got error while validating uri: %s", err)
return
}
}
tshark, err := NewTshark(*iface)
if err != nil {
Error("Could not create new Tshark due to: %s", err)
return
}
Debug("Starting SMPPd CLI for (uri: %s)", furi)
go func() {
<-srvkill
close(packets)
logger.Warning("SMPPd CLI is now stopped!")
os.Exit(0)
}()
go func() {
for {
select {
case packet := <-packets:
Debug("Got (packet: %s). Preparing post ...", packet)
//msg := ""
for _, p := range packet {
Debug("%s", p)
}
req, err := http.NewRequest("POST", "http://webhookr.com/3QeA51r", bytes.NewBuffer(packet))
req.Header.Set("Content-Type", "text/plain")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
Error("Could not send POST request due to: %s", err)
return
}
defer resp.Body.Close()
Debug("Got Response Status: %s", resp.Status)
Debug("Got Response Headers: %v", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
Debug("Got Response Body: %s", string(body))
if resp.Status == "200 OK" {
Notice("Packet successfully published! (data: %s)", string(packet))
}
}
}
}()
if err := tshark.Capture(packets); err != nil {
Error("Could not start tshark due to: %s", err)
return
}
Notice("Tshark consumer successfully started!")
}