File: nagzillac2.pl

package info (click to toggle)
nagzilla 2.0-1.1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 504 kB
  • sloc: perl: 272; sh: 191; makefile: 17
file content (112 lines) | stat: -rwxr-xr-x 2,599 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl -w

#(c)2007-2009 Hurricane Labs
#Author: Billford
#License: See LICENSE file GPL v2
#Nagzilla Jabber Relay Client

use strict;
require Config::Simple;
require Data::Dumper;
use IO::Socket;
use IO::Socket::INET;
use Getopt::Long;
use Pod::Usage;

#bring in our configuration variables
my $CONFDIR = "/etc/nagzillac";

# DO NOT EDIT ANYTHING BEYOND THIS POINT!!

##################Begin Config Setup########################
our %Config;
Config::Simple->import_from('nagzillac.cfg', \%Config);
my $cfg = new Config::Simple("$CONFDIR/nagzillac.cfg");

#Nagzillac Nagzilla Server Settings

my $nagzillaserver = $cfg->param("NagzillaServer");
my $nagzillaport  = $cfg->param("NagzillaPort");

##################End Config Setup##########################

##################Get Some Options and set up pod2usage#####

my ($opt_type, $opt_room, $opt_mess, $opt_color, $opt_help, $opt_man);

GetOptions (

	't=s'	=> \$opt_type,
	'r=s'	=> \$opt_room,
	'm=s'	=> \$opt_mess,
	'c:s'	=> \$opt_color,
	'help|?'		=> \$opt_help,
	'man!'	=> \$opt_man

) or pod2usage(-verbose =>1) && exit; #End GetOptions

no warnings 'uninitialized'; 

pod2usage(-verbose => 1) && exit if defined $opt_help;
pod2usage(-verbose => 1) && exit if ($opt_type eq '' || $opt_room eq '' || $opt_mess eq '');
pod2usage(-verbose => 2) && exit if defined $opt_man;




##################End Options###############################

my $send2nagd;
if ($opt_color eq '') {	
$send2nagd = "$opt_type^$opt_room^$opt_mess";
} else {
	$send2nagd = "$opt_type^$opt_room^$opt_mess^$opt_color";
}

print "$send2nagd \n";


##################Make socket connection###############################

#Let's make us a socket connection
my $remote = IO::Socket::INET->new(
   Proto    => 'tcp',
   PeerAddr => "$nagzillaserver",
   PeerPort => "$nagzillaport",
   Reuse    => 1
) or die "$!";

$remote->autoflush(1);

print $remote $send2nagd;

close $remote;

##################End socket stuff###############################

=head1 NAME

 nagzillac2.pl

=head1 SYNOPSIS

 Nagzillac connects to and sends messages to nagzillad which relays them to Jabber

=head1 ARGUMENTS
 
 -t	Type: either groupchat or chat REQUIRED
 -r	Room: Either chatroom name or JID of an individual REQUIRED
 -m	Message: The messages you would like to send enclosed in quotes REQUIRED
 -c	Color: The color of your message (currently only red, yellow and green work) OPTIONAL
 -h	Prints this message

=head1 AUTHOR

 Billford@Hurricane Labs

=head1 CREDITS

 McMaster@Hurricane Labs - some code and sounding board
 Steve@Hurricane Labs - some stupid checking 

=cut