~ubuntu-branches/ubuntu/gutsy/amsn/gutsy

« back to all changes in this revision

Viewing changes to utils/amsnctl.pl

  • Committer: Bazaar Package Importer
  • Author(s): Theodore Karkoulis
  • Date: 2006-01-04 15:26:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060104152602-ipe1yg00rl3nlklv
Tags: 0.95-1
New Upstream Release (closes: #345052, #278575).

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
print;
125
125
close $sock2;
126
126
 
127
 
#!/usr/bin/perl -w
128
 
 
129
 
###
130
 
###
131
 
### This program is free software; you can redistribute it and/or modify
132
 
### it under the terms of the GNU General Public License as published by
133
 
### the Free Software Foundation; version 2 of the License
134
 
###
135
 
### This program is distributed in the hope that it will be useful,
136
 
### but WITHOUT ANY WARRANTY; without even the implied warranty of
137
 
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
138
 
### GNU General Public License for more details.
139
 
###
140
 
### You should have received a copy of the GNU General Public License
141
 
### along with this program; if not, write to the Free Software
142
 
### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
143
 
###
144
 
###
145
 
### amsnctl.pl
146
 
### amsn remote control
147
 
###
148
 
### just another way to control amsn 
149
 
### you can use this program in your scripts in an easier way 
150
 
### than using amsn-remote-CLI
151
 
###
152
 
### written by David Mu�oz ( voise at tiscali.es )
153
 
###
154
 
###
155
 
 
156
 
### ./amsnctl.pl [stuff] 
157
 
###
158
 
### [stuff] are:
159
 
###
160
 
###   --cmd    [cmd]  : amsn remote command   (mandatory)
161
 
###   --login  [user] : session login         (mandatory)
162
 
###   --passwd [pass] : amsn server password  (mandatory)
163
 
###   --host   [IP]   : ip, default 127.0.0.1 
164
 
###   --port   [port] : port, default 63251   
165
 
###
166
 
###
167
 
### Example (notice the use of " and \" in command)
168
 
###
169
 
### ./amsnctl.pl --login me@hotmail.com --passwd mypasswd --cmd "setnick \"me - programming in perl\""
170
 
###
171
 
 
172
 
###
173
 
### IMPORTANT:
174
 
###
175
 
###   you MUST install Perl-HMAC package
176
 
### 
177
 
 
178
 
use Digest::HMAC_MD5;  
179
 
use IO::Socket;        
180
 
use Getopt::Long;      
181
 
 
182
 
### do you think i like commenting code? 
183
 
 
184
 
GetOptions("host=s" => \$host,
185
 
           "port=s" => \$port,
186
 
           "login=s" => \$acc,
187
 
           "passwd=s" => \$pass,
188
 
           "cmd=s" => \$cmd);
189
 
 
190
 
if (!defined($host)) {
191
 
    $host = '127.0.0.1';
192
 
}
193
 
 
194
 
if (!defined($port)) {
195
 
    $port = '63251';
196
 
}
197
 
 
198
 
if (!defined($acc)) {
199
 
    die "You must scpecify a login name\n";
200
 
}
201
 
 
202
 
if (!defined($pass)) {
203
 
    die "You must specify a password\n";
204
 
}
205
 
 
206
 
if (!defined($cmd)) {
207
 
    die "You must specify a command\n";
208
 
}
209
 
 
210
 
my $sock = new IO::Socket::INET (
211
 
                                 PeerAddr => $host,
212
 
                                 PeerPort => $port,
213
 
                                 Proto => 'tcp',
214
 
                                );
215
 
 
216
 
die "Amsn server closed?\n" unless $sock;
217
 
 
218
 
$sock->autoflush(1);
219
 
print $sock "$acc\n";
220
 
 
221
 
$_ = <$sock>;
222
 
chomp($_);
223
 
s/\r//;
224
 
$port2 = $_;
225
 
close($sock);
226
 
 
227
 
my $sock2 = new IO::Socket::INET (
228
 
                                 PeerAddr => $host,
229
 
                                 PeerPort => $port2,
230
 
                                 Proto => 'tcp',
231
 
                                );
232
 
die "Amsn server closed?\n" unless $sock;
233
 
 
234
 
$sock2->autoflush(1);
235
 
print $sock2 "auth\n";
236
 
 
237
 
$_ = <$sock2>;
238
 
s/(\d+\.\d+)//;
239
 
$reto = $1;
240
 
$hmac = Digest::HMAC_MD5->new($reto);
241
 
$hmac->add($pass);
242
 
$digest = $hmac->hexdigest;
243
 
 
244
 
print $sock2 "auth2 $digest\n";
245
 
$_= <$sock2>;
246
 
 
247
 
print $sock2 $cmd."\n";
248
 
print $sock2 "quit\n";
249
 
$_=<$sock2>;
250
 
print;
251
 
close $sock2;
252
 
 
253
 
#!/usr/bin/perl -w
254
 
 
255
 
###
256
 
###
257
 
### This program is free software; you can redistribute it and/or modify
258
 
### it under the terms of the GNU General Public License as published by
259
 
### the Free Software Foundation; version 2 of the License
260
 
###
261
 
### This program is distributed in the hope that it will be useful,
262
 
### but WITHOUT ANY WARRANTY; without even the implied warranty of
263
 
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
264
 
### GNU General Public License for more details.
265
 
###
266
 
### You should have received a copy of the GNU General Public License
267
 
### along with this program; if not, write to the Free Software
268
 
### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
269
 
###
270
 
###
271
 
### amsnctl.pl
272
 
### amsn remote control
273
 
###
274
 
### just another way to control amsn 
275
 
### you can use this program in your scripts in an easier way 
276
 
### than using amsn-remote-CLI
277
 
###
278
 
### written by David Mu�oz ( voise at tiscali.es )
279
 
###
280
 
###
281
 
 
282
 
### ./amsnctl.pl [stuff] 
283
 
###
284
 
### [stuff] are:
285
 
###
286
 
###   --cmd    [cmd]  : amsn remote command   (mandatory)
287
 
###   --login  [user] : session login         (mandatory)
288
 
###   --passwd [pass] : amsn server password  (mandatory)
289
 
###   --host   [IP]   : ip, default 127.0.0.1 
290
 
###   --port   [port] : port, default 63251   
291
 
###
292
 
###
293
 
### Example (notice the use of " and \" in command)
294
 
###
295
 
### ./amsnctl.pl --login me@hotmail.com --passwd mypasswd --cmd "setnick \"me - programming in perl\""
296
 
###
297
 
 
298
 
###
299
 
### IMPORTANT:
300
 
###
301
 
###   you MUST install Perl-HMAC package
302
 
### 
303
 
 
304
 
use Digest::HMAC_MD5;  
305
 
use IO::Socket;        
306
 
use Getopt::Long;      
307
 
 
308
 
### do you think i like commenting code? 
309
 
 
310
 
GetOptions("host=s" => \$host,
311
 
           "port=s" => \$port,
312
 
           "login=s" => \$acc,
313
 
           "passwd=s" => \$pass,
314
 
           "cmd=s" => \$cmd);
315
 
 
316
 
if (!defined($host)) {
317
 
    $host = '127.0.0.1';
318
 
}
319
 
 
320
 
if (!defined($port)) {
321
 
    $port = '63251';
322
 
}
323
 
 
324
 
if (!defined($acc)) {
325
 
    die "You must scpecify a login name\n";
326
 
}
327
 
 
328
 
if (!defined($pass)) {
329
 
    die "You must specify a password\n";
330
 
}
331
 
 
332
 
if (!defined($cmd)) {
333
 
    die "You must specify a command\n";
334
 
}
335
 
 
336
 
my $sock = new IO::Socket::INET (
337
 
                                 PeerAddr => $host,
338
 
                                 PeerPort => $port,
339
 
                                 Proto => 'tcp',
340
 
                                );
341
 
 
342
 
die "Amsn server closed?\n" unless $sock;
343
 
 
344
 
$sock->autoflush(1);
345
 
print $sock "$acc\n";
346
 
 
347
 
$_ = <$sock>;
348
 
chomp($_);
349
 
s/\r//;
350
 
$port2 = $_;
351
 
close($sock);
352
 
 
353
 
my $sock2 = new IO::Socket::INET (
354
 
                                 PeerAddr => $host,
355
 
                                 PeerPort => $port2,
356
 
                                 Proto => 'tcp',
357
 
                                );
358
 
die "Amsn server closed?\n" unless $sock;
359
 
 
360
 
$sock2->autoflush(1);
361
 
print $sock2 "auth\n";
362
 
 
363
 
$_ = <$sock2>;
364
 
s/(\d+\.\d+)//;
365
 
$reto = $1;
366
 
$hmac = Digest::HMAC_MD5->new($reto);
367
 
$hmac->add($pass);
368
 
$digest = $hmac->hexdigest;
369
 
 
370
 
print $sock2 "auth2 $digest\n";
371
 
$_= <$sock2>;
372
 
 
373
 
print $sock2 $cmd."\n";
374
 
print $sock2 "quit\n";
375
 
$_=<$sock2>;
376
 
print;
377
 
close $sock2;
378