Remote Server Get CDR from GSM Gateway by AMI
Introduction:
OpenVox GSM Gateway can support AMI(Asterisk Manager Interface,if you want to get the CDR from remote server,you can use the AMI to do it!
Step 1:
Set the AMI in OpenVox GSM Gateway,follows:
Step 2:Write a Program to get the CDR like follows:
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
#include< stdio.h > #include< string.h > #include< stdlib.h > #include< sys /socket.h> #include< netinet /in.h> #include< unistd.h > //Login void login_fun(int sock_fd) { char username[20]; char secret[20]; int login_len=0; int secret_len=0; int res = 0; char receive_buf[4096]; char login_buf[40]; memset(username,'\0',20); memset(secret,'\0',20); printf("please input your username\n"); scanf("%s",username); fflush(stdin); printf("please input your secret\n"); scanf("%s",secret); fflush(stdin); memset(login_buf,'\0',40); sprintf(login_buf,"action:Login\r\nusername:%s\r\nsecret:%s\r\n\r\n",username,secret); login_len = strlen(login_buf); if(res = write(sock_fd,login_buf,login_len) == login_len) { sleep(1); memset(receive_buf,'\0',4096); if(res = read(sock_fd,receive_buf,sizeof(receive_buf))<0) { perror("login failed\n"); return; } printf("%s\n",receive_buf); if(NULL != strstr(receive_buf,"Authentication accepted")) { printf("login success\n"); } } } void read_cdr(int sock_fd) { char receive_buf[4096]; int res=0; char *receive_Data; char temp_buf[1024]; char *temp = NULL; struct CDR { char CallerID[512]; char CalleeID[512]; char From[512]; char To[512]; char StartTime[512]; char Duration[512]; char Result[512]; }; struct CDR cdr_buff; int i =0; int j =0; while(1) { memset(receive_buf,'\0',4096); memset(cdr_buff.CallerID,'\0',512); memset(cdr_buff.CalleeID,'\0',512); memset(cdr_buff.From,'\0',512); memset(cdr_buff.To,'\0',512); memset(cdr_buff.StartTime,'\0',512); memset(cdr_buff.Duration,'\0',512); memset(cdr_buff.Result,'\0',512); if(res = read(sock_fd,receive_buf,sizeof(receive_buf))<0) { perror("read failed\n"); } else { //memset(receive_buf,'\0',4096); if((receive_Data = strstr(receive_buf,"Application: WriteCDR"))!=NULL) { //printf("111111111111111111111111111111111111111111111%s\n",receive_Data); i=0; j=0; if((temp=strstr(receive_Data,"AppData:"))!=NULL) { for(i=0;i<strlen(temp);i++) { if(temp[i]!=':') { j++; } else { break; } } temp=temp+j+2; for(i=0;i<strlen(temp);i++) { if(temp[i]!=',') { cdr_buff.CallerID[i]=temp[i]; } else { break; } } temp=temp+i+1; for(i=0;i<strlen(temp);i++) { if(temp[i]!=',') { cdr_buff.CalleeID[i]=temp[i]; } else { break; } } temp=temp+i+1; for(i=0;i<strlen(temp);i++) { if(temp[i]!=',') { cdr_buff.From[i]=temp[i]; } else { break; } } temp=temp+i+1; for(i=0;i<strlen(temp);i++) { if(temp[i]!=',') { cdr_buff.To[i]=temp[i]; } else { break; } } temp=temp+i+1; for(i=0;i<strlen(temp);i++) { if(temp[i]!=',') { cdr_buff.StartTime[i]=temp[i]; } else { break; } } temp=temp+i+1; for(i=0;i<strlen(temp);i++) { if(temp[i]!=',') { cdr_buff.Duration[i]=temp[i]; } else { break; } } temp=temp+i+1; for(i=0;i<strlen(temp);i++) { if(temp[i]!='\n') { cdr_buff.Result[i]=temp[i]; } else { break; } } printf("Callerid==============%s\n",cdr_buff.CallerID); printf("Calleeid==============%s\n",cdr_buff.CalleeID); printf("From==============%s\n",cdr_buff.From); printf("To==============%s\n",cdr_buff.To); printf("StartTime==============%s\n",cdr_buff.StartTime); printf("Duration==============%s\n",cdr_buff.Duration); printf("Result==============%s\n",cdr_buff.Result); // break; } } } } } int main(void) { int client_socket; struct sockaddr_in client_addr; char ServerIp[20]; memset(ServerIp,'\0',20); printf("Please input your server ip address\n"); scanf("%s",ServerIp); fflush(stdin); client_socket = socket(AF_INET,SOCK_STREAM,0); if(client_socket < 0) { perror("create socket error\n"); return -1; } client_addr.sin_family = AF_INET; client_addr.sin_port = htons(5038); client_addr.sin_addr.s_addr = inet_addr(ServerIp); //connect if(connect(client_socket,(struct sockaddr *)&client_addr,sizeof(client_addr))<0) { perror("connect error\n"); return -1; } else { printf("connect to %s success\n",ServerIp); } login_fun(client_socket); read_cdr(client_socket); return 0; } |
Step 3:compile and run the app
Notice: This just a test program,just use for refer it!
Thanks!