1
|
|
|
package main |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"fmt" |
5
|
|
|
"log" |
6
|
|
|
"net" |
7
|
|
|
"os" |
8
|
|
|
|
9
|
|
|
"github.com/staskobzar/goagi" |
10
|
|
|
) |
11
|
|
|
|
12
|
|
|
func Serve(conn net.Conn) { |
|
|
|
|
13
|
|
|
defer conn.Close() |
14
|
|
|
|
15
|
|
|
dbg := log.New(os.Stdout, "fastagi example: ", log.Lmicroseconds) |
16
|
|
|
agi, err := goagi.New(conn, conn, dbg) |
17
|
|
|
if err != nil { |
18
|
|
|
panic(err) |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
resp, err := agi.Verbose("Hello World!") |
22
|
|
|
if err != nil { |
23
|
|
|
dbg.Printf("Failed verbose command: %s", err) |
24
|
|
|
return |
25
|
|
|
} |
26
|
|
|
dbg.Printf("Verbose response code: %d", resp.Code()) |
27
|
|
|
|
28
|
|
|
resp, _ = agi.GetVariable("CHANNEL") |
29
|
|
|
dbg.Printf("Asterisk channel variable: %s", resp.Value()) |
30
|
|
|
|
31
|
|
|
resp, err = agi.GetData("welcome", 0, 2) |
32
|
|
|
if err != nil { |
33
|
|
|
panic(err) |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
dbg.Printf("Get Data response code: %d", resp.Code()) |
37
|
|
|
dbg.Printf("Get Data response result: %d", resp.Result()) |
38
|
|
|
dbg.Printf("Get Data response value: %s", resp.Value()) |
39
|
|
|
dbg.Printf("Get Data response data: %s", resp.Data()) |
40
|
|
|
|
41
|
|
|
resp, err = agi.GetVariable("CDR(duration)") |
42
|
|
|
if err != nil { |
43
|
|
|
panic(err) |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
dbg.Printf("CDR duration value: %s", resp.Value()) |
47
|
|
|
|
48
|
|
|
agi.Verbose("Goodbye!") |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
func main() { |
52
|
|
|
fmt.Println("[x] Starting FastAGI script") |
53
|
|
|
ln, err := net.Listen("tcp", "127.0.0.1:4575") |
54
|
|
|
if err != nil { |
55
|
|
|
panic(err) |
56
|
|
|
} |
57
|
|
|
for { |
58
|
|
|
conn, err := ln.Accept() |
59
|
|
|
if err != nil { |
60
|
|
|
panic(err) |
61
|
|
|
} |
62
|
|
|
go Serve(conn) |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|