-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttpDialer.groovy
executable file
·64 lines (56 loc) · 1.96 KB
/
HttpDialer.groovy
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
#!/usr/bin/env groovy
import java.util.concurrent.Executors;
import org.asteriskjava.manager.ManagerConnection;
import org.asteriskjava.manager.ManagerConnectionFactory;
import org.asteriskjava.manager.action.OriginateAction;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
/**
* A small httpserver that works with chrome plugins like sipcaller
* to initiate calls from your browser.
*/
@SuppressWarnings("restriction")
class HttpDialer {
def port
def user
def pass
ManagerConnectionFactory factory
public listen() {
factory = new ManagerConnectionFactory("localhost", user, pass)
def server = HttpServer.create(new InetSocketAddress("localhost", port), 0)
server.with {
createContext('/', handle as HttpHandler)
setExecutor(Executors.newCachedThreadPool())
start()
}
}
def handle =
{ HttpExchange exchange ->
def query = exchange.requestURI.query
if (query.matches(/pn=\d+/)) {
def number = query.split(/\=/)[1]
def connection = factory.createManagerConnection()
connection.login()
OriginateAction action = new OriginateAction();
action.with {
channel = "SIP/100"
context = "from-internal"
exten = number
callerId = number
priority = 1
}
println connection.sendAction(action, 30000)
}
exchange.sendResponseHeaders(200, 0)
exchange.responseBody.closeQuietly()
}
public static main(String[] args) {
new HttpDialer().with {
port = 8091
user = 'user'
pass = 'letmein'
listen()
}
}
}