forked from barbodar/KABOOK-RADIUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kabook-auth.php
95 lines (74 loc) · 3.23 KB
/
kabook-auth.php
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
#!/usr/bin/php -q
<?php
require('libs/config/defines.php');
require('libs/helper/radius.php');
require('libs/helper/database.php');
require('libs/helper/randomizer.php');
require('libs/helper/logger.php');
require('libs/phpagi/phpagi.php');
$moduleName = "KABOOK RADIUS - AUTH";
//Create a new AGI Class
$agi = new AGI();
//Create Logger
$logger = new LOGGER();
$logger->agi = $agi;
$logger->moduleName = $moduleName;
//Create Database Connection
$db = new DB();
$db->assignConfig(DB_TYPE_MYSQL);
$dbConn = $db->connect();
//CREAT Randomizer
$randomizer = new RANDOMIZER();
//User Details Catcher
$data['direction'] = 'outbound';
$data['time'] = time();
$data['channel'] = $agi->request['agi_channel'];
$data['uniqueid'] = $agi->request['agi_uniqueid'];
$data['callerid'] = $agi->request['agi_callerid'];
$data['calleridname'] = $agi->request['agi_calleridname'];
$data['dnid'] = $agi->request['agi_dnid'];
$data['rdnis'] = $agi->request['agi_rdnis'];
$data['context'] = $agi->request['agi_context'];
$data['extension'] = $agi->request['agi_extension'];
$data['accountcode'] = $agi->request['agi_accountcode'];
$data['threadid'] = $agi->request['agi_threadid'];
$data['nasPort'] = substr(rand(1000,$data['threadid']), 0, 5);
$confId[0] = $randomizer->randomHash(8);
$confId[1] = $randomizer->randomHash(8);
$confId[2] = $randomizer->randomHash(8);
$confId[3] = $randomizer->randomHash(8);
$data['confId'] = "{$confId[0]} {$confId[1]} {$confId[2]} {$confId[3]}";
$data['clientAddress'] = $agi->get_variable("USERIP")["data"];
$userURI = $agi->get_variable("SIPURI", true);
$sipusername = $agi->get_variable("SIP_HEADER(From)", true);
$dbResult = $db->insertNewCall($dbConn, $data);
$logger->sendLog("Insert new call result : {$dbResult[0]}");
if( $dbResult[0] === MYSQL_SUCCESS_RESULT ) {
$logger->sendLog("Call inserted successfully, going to send RADIUS AUTH packet");
$radClient = new RADIUS();
$radClient->h323_conf_id = "h323-conf-id={$data['confId']}";
$radClient->eventTime = $data['time'];
$radClient->acctSessionId = $data['uniqueid'];
$radClient->nasPort = $data['nasPort'];
$radAccessResponse = $radClient->authenticate($data['callerid'], $data['callerid'], $data['extension']);
if( $radAccessResponse[RADIUS_ACCESS_REQUEST] == RADIUS_ACCESS_ACCEPT && $radAccessResponse[RADIUS_CISCO_H323_RETURN_CODE] == H323_RETURN_CODE_SUCCESS ) {
$logger->sendLog("AUTH Response: {$radAccessResponse[RADIUS_CLASS]}");
$agi->set_variable("AUTHRESULT", "######## RADIUSAUTH Call From {$data['callerid']} to {$data['extension']} ACCEPTED ########");
$agi->exec("Goto", "MAIN-OUT,{$data['extension']},1");
} else {
$logger->sendLog("AUTH Response: Radius Access Rejected [Code: {$radAccessResponse[RADIUS_ACCESS_REQUEST]}] [h323-return-code : {$radAccessResponse[RADIUS_CISCO_H323_RETURN_CODE]}]");
$agi->set_variable("AUTHRESULT", "######## RADIUSATUH Call From {$data['callerid']} to {$data['extension']} REJECTED ########");
//$agi->exec("Goto", "MAIN-OUT,{$data['extension']},1");
$agi->hangup();
}
} else {
$agi->hangup();
}
//Free up the resources
$db->close($dbConn);
$db = NULL;
$radClient = NULL;
$agi = NULL;
$logger = NULL;
$randomizer = NULL;
exit();