-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvms
315 lines (293 loc) · 7.36 KB
/
vms
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/usr/bin/perl
# Copyright (c) 2016 Todd T. Fries <todd@fries.net>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
use strict;
use warnings;
use Data::Dumper;
#use OpenBSD::Getopt;
use Getopt::Std;
use VOIP::MS;
# -n quiet, just facts no labels
our $opt_n = 0;
our $opt_p;
our $opt_c = $ENV{'HOME'}."/.voipms.conf";
our $opt_f; # CDR/sendsms
our $opt_s; # ratecentersusa
our $opt_t; # CDR/sendsms
our $opt_m; # sendsms
getopts('c:np:f:m:s:t:');
my ($user,$pass);
my $d;
my $conffile=$opt_c;
my $config = { };
if (-f $conffile) {
if (!open(CF,"$conffile")) {
print "open of $conffile failed, aborting\n";
exit(1);
}
my $line;
while(<CF>) {
chomp($line = $_);
if ($line =~ /^([a-zA-Z][a-zA-Z_0-9]*)\s*=\s*(.*)$/) {
my ($var, $val) = ($1,$2);
$config->{$var} = $val;
#printf "config: '%s' = '%s'\n",$var,$val;
}
}
} else {
die("config file $conffile does not exist, need user and pass from it, bailing");
}
if (!defined($config->{user}) || !defined($config->{pass})) {
print "User or Pass is Null and void, bailing for now\n";
exit(1);
}
my $voip = VOIP::MS->new(username => $config->{user},
password => $config->{pass});
if ($opt_p eq "balance") {
my $balinfo= $voip->getBalance();
my $fmt = "Balance = %0.8f\n";
if ($opt_n > 0) {
$fmt = "%0.8f\n";
}
printf $fmt, $balinfo;
exit(0);
}
if ($opt_p eq "getlang") {
my $langinfo = $voip->getLanguages();
$d = Data::Dumper->new([$langinfo]);
print $d->Dump();
exit(0);
}
# the following 'if (0)' bits work, they're just verbose; enable if desired
# this is a wip anyway, will get re-done once enough apis are implemented
if ($opt_p eq "CDR") {
if (!defined($opt_f)) {
$opt_f = "2016-08-01";
}
if (!defined($opt_t)) {
$opt_t = "2016-10-01";
}
my $cdr = $voip->getCDR( {
date_from => $opt_f,
date_to => $opt_t,
} );
$d = Data::Dumper->new([$cdr]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "servers") {
my $slist = $voip->getServersInfo(); # optional: server_pop => 1
$d = Data::Dumper->new([$slist]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "transactionhistory") {
my $thist = $voip->getTransactionHistory( {
date_from => $opt_f,
date_to => $opt_t,
} );
$d = Data::Dumper->new([$thist]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "allowedcodecs") {
my $acodecs = $voip->getAllowedCodecs;
$d = Data::Dumper->new([$acodecs]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "lockinternational") {
my $res = $voip->getLockInternational;
$d = Data::Dumper->new([$res]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "protocols") {
my $res = $voip->getProtocols;
$d = Data::Dumper->new([$res]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "routes") {
my $res = $voip->getRoutes;
$d = Data::Dumper->new([$res]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "subaccounts") {
my $res = $voip->getSubAccounts;
$d = Data::Dumper->new([$res]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "clients") {
my $res = $voip->getClients;
$d = Data::Dumper->new([$res]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "ratecentersusa") {
my $state = $opt_s;
my $res = $voip->getRateCentersUSA({ state => $state });
$d = Data::Dumper->new([$res]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "internationalinfo") {
my $tret = $voip->getInternationalTypes();
foreach my $it (@$tret) {
printf "%12s %s\n", $it->{value}, $it->{description};
my $ret = $voip->getDIDCountries(type => $it->{value});
my $i=0;
foreach my $ctry (@$ret) {
if ($ctry->{value} eq $ctry->{description}) {
$ctry->{description} = "";
}
printf "%2d. %12s %s\n", $i++, $ctry->{value}, $ctry->{description};
if ($ctry->{value} eq "all") {
next;
}
my $r;
eval {
$r = $voip->getDIDsInternationalGeographic(
country_id => $ctry->{value});
$d = Data::Dumper->new([$r]);
print "International Geographic:\n";
print $d->Dump();
};
if ($@) {
print $@;
}
eval {
$r = $voip->getDIDsInternationalNational(
country_id => $ctry->{value});
$d = Data::Dumper->new([$r]);
print "International National:\n";
print $d->Dump();
};
if ($@) {
print $@;
}
eval {
$r = $voip->getDIDsInternationalTollFree(
country_id => $ctry->{value});
$d = Data::Dumper->new([$r]);
print "International TollFree:\n";
print $d->Dump();
};
if ($@) {
print $@;
}
}
}
exit(0);
}
if ($opt_p eq "callaccounts") {
my $ret = $voip->getCallAccounts(); # optional: client => 56115
my $i=0;
foreach my $acct (@$ret) {
if ($acct->{value} eq $acct->{description}) {
$acct->{description} = "";
}
printf "%2d. %12s %s\n", $i++, $acct->{value}, $acct->{description};
if ($acct->{value} eq "all") {
next;
}
my $r = $voip->getRegistrationStatus(account => $acct->{value});
$d = Data::Dumper->new([$r]);
print $d->Dump();
}
}
if ($opt_p eq "billing") {
my $ret = $voip->getCallBilling();
$d = Data::Dumper->new([$ret]);
print $d->Dump();
}
if ($opt_p eq "calltypes") {
my $ret = $voip->getCallTypes(); # optional: client => 56115
$d = Data::Dumper->new([$ret]);
print $d->Dump();
}
if ($opt_p eq "regstatus") {
my $ret = $voip->getRegistrationStatus(account => $config->{account0});
$d = Data::Dumper->new([$ret]);
print $d->Dump();
}
if (0) { # hmmm, what is a callback exactly?
my $cb = { };
$cb->{description} = 'testing 1 2 3';
$cb->{number} = '14057791633';
$cb->{delay_before} = '30';
$cb->{response_timeout} = '30';
$cb->{digit_timeout} = '5';
# optional
$cb->{callerid_number} = '14058267307';
my $cdr = $voip->setCallback( $cb );
$d = Data::Dumper->new([$cdr]);
print $d->Dump();
}
if ($opt_p eq "packages") { # how to create a package?
my $ret = $voip->getPackages(); # optional: package => 8378
$d = Data::Dumper->new([$ret]);
print $d->Dump();
}
if ($opt_p eq "dids") {
# optional: client => '' || '5615' || '5615_VoIP'
# optional: did => 1231231234
my $ret = $voip->getDIDsInfo();
$d = Data::Dumper->new([$ret]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "sendsms") {
if (!defined($opt_f)) {
$opt_f = $config->{mySMSdid};
}
if (!defined($opt_t)) {
$opt_t = $config->{mySMSdst};
}
if (!defined($opt_m)) {
die("cannot send a sms without a message! use -m <message>");
}
my %p;
$p{did} = $opt_f;
$p{dst} = $opt_t;
#$p{message} = 'testing 1 2 3½¹°';
#$p{message} = 'The quick brown fox jumped over the lazy dogs';
#$p{message} = 'Receiving SMS on a MiFi for an old owner of the number 4057795424, please stop.';
$p{message} = $opt_m;
my $did = $opt_f;
my $dst = $opt_t;
printf "did='%s', dst='%s'\n", $did, $dst;
my $ret = $voip->sendSMS(
did => $did,
dst => $dst,
message => $opt_m,
);
$d = Data::Dumper->new([$ret]);
print $d->Dump();
exit(0);
}
if ($opt_p eq "smslist") {
if (!defined($opt_f)) {
$opt_f = "2016-08-01";
}
if (!defined($opt_t)) {
$opt_t = "2016-10-01";
}
my $cdr = $voip->getSMS( { from => $opt_f, to => $opt_t } );
$d = Data::Dumper->new([$cdr]);
print $d->Dump();
exit(0);
}