Advertisement
Guest User

Untitled

a guest
May 14th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 5.32 KB | None | 0 0
  1. #!/usr/bin/perl                                                                                      
  2. use Net::XMPP;                                                                                      
  3. use strict;                                                                                          
  4.  
  5. =bye
  6. if ($#ARGV < 4)
  7. {              
  8.     print "\nperl client.pl <server> <port> <username> <password> <resource> \n\n";
  9.     exit(0);                                                                      
  10. }                                                                                  
  11. =cut                                                                              
  12. my $server = $ARGV[0] || "hostname";                                      
  13. my $port = $ARGV[1] || "5222";                                                    
  14. my $username = $ARGV[2] || "username";                                              
  15. my $password = $ARGV[3] || "pass";                                              
  16. my $resource = $ARGV[4] || "Test";                                                
  17.  
  18. my $verbose = 0;
  19.  
  20. $SIG{HUP} = \&Stop;
  21. $SIG{KILL} = \&Stop;
  22. $SIG{TERM} = \&Stop;
  23. $SIG{INT} = \&Stop;
  24.  
  25. my $Connection = new Net::XMPP::Client();
  26.  
  27. $Connection->SetCallBacks(message=>\&InMessage,
  28.                           presence=>\&InPresence,
  29.                           iq=>\&InIQ);          
  30.  
  31. my $status = $Connection->Connect(hostname=>$server,
  32.                                   port=>$port);    
  33.  
  34. if (!(defined($status)))
  35. {                      
  36.     print "ERROR:  Jabber server is down or connection was not allowed.\n";
  37.     print "        ($!)\n";                                                
  38.     exit(0);                                                              
  39. }                                                                          
  40.  
  41. my @result = $Connection->AuthSend(username=>$username,
  42.                                    password=>$password,
  43.                                    resource=>$resource);
  44.  
  45. if ($result[0] ne "ok")
  46. {                      
  47.     print "ERROR: Authorization failed: $result[0] - $result[1]\n";
  48.     exit(0);                                                      
  49. }                                                                  
  50.  
  51. if ($verbose){
  52.         print "Logged in to $server:$port...\n";
  53. }                                              
  54.  
  55. $Connection->RosterGet();
  56.  
  57. if ($verbose){
  58.         print "Getting Roster to tell server to send presence info...\n";
  59. }                                                                        
  60.  
  61. $Connection->PresenceSend();
  62.  
  63. if ($verbose){
  64.         print "Sending presence to tell world that we are logged in...\n";
  65. }                                                                        
  66.  
  67. if (defined($Connection->Process())) {
  68.         my $Mess = new Net::XMPP::Message();
  69.         $Mess->SetMessage(                  
  70.                 to => "anderson\@dpgsipcall01.vail",
  71.                 subject => "Test",                  
  72.                 body => "this is a test"            
  73.         );                                          
  74.         print "sent message\n";                    
  75.         sleep 1;                                    
  76. }                                                  
  77.  
  78. if ($verbose){
  79.         print "ERROR: The connection was killed...\n";
  80. }                                                    
  81. exit(0);                                              
  82.  
  83.  
  84. sub Stop
  85. {      
  86.     print "Exiting...\n";
  87.     $Connection->Disconnect();
  88.     exit(0);                  
  89. }                            
  90.  
  91.  
  92. sub InMessage
  93. {            
  94.     my $sid = shift;
  95.     my $message = shift;
  96.                        
  97.     my $type = $message->GetType();
  98.     my $fromJID = $message->GetFrom("jid");
  99.                                            
  100.     my $from = $fromJID->GetUserID();      
  101.     my $resource = $fromJID->GetResource();
  102.     my $subject = $message->GetSubject();  
  103.     my $body = $message->GetBody();        
  104. =bye                                      
  105.     print "===\n";                        
  106.     print "Message ($type)\n";            
  107.     print "  From: $from ($resource)\n";  
  108.     print "  Subject: $subject\n";        
  109.     print "  Body: $body\n";              
  110.     print "===\n";                        
  111.     print $message->GetXML(),"\n";        
  112.     print "===\n";                        
  113. =cut                                      
  114. }                                          
  115.  
  116.  
  117. sub InIQ
  118. {      
  119.     my $sid = shift;
  120.     my $iq = shift;
  121.                    
  122.     my $from = $iq->GetFrom();
  123.     my $type = $iq->GetType();
  124.     my $query = $iq->GetQuery();
  125.     my $xmlns = $query->GetXMLNS();
  126. =bye
  127.     print "===\n";
  128.     print "IQ\n";
  129.     print "  From $from\n";
  130.     print "  Type: $type\n";
  131.     print "  XMLNS: $xmlns";
  132.     print "===\n";
  133.     print $iq->GetXML(),"\n";
  134.     print "===\n";
  135. =cut
  136. }
  137.  
  138. sub InPresence
  139. {
  140.     my $sid = shift;
  141.     my $presence = shift;
  142.  
  143.     my $from = $presence->GetFrom();
  144.     my $type = $presence->GetType();
  145.     my $status = $presence->GetStatus();
  146. =bye
  147.     print "===\n";
  148.     print "Presence\n";
  149.     print "  From $from\n";
  150.     print "  Type: $type\n";
  151.     print "  Status: $status\n";
  152.     print "===\n";
  153.     print $presence->GetXML(),"\n";
  154.     print "===\n";
  155. =cut
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement