-
Notifications
You must be signed in to change notification settings - Fork 7
/
universal.pl
executable file
·141 lines (138 loc) · 4.61 KB
/
universal.pl
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
#!/usr/bin/perl
use strict;
################################################################################
# a universal bot for multiple personalities
#
# all the $ENV varibles should be loaded from /etc/{default,sysconfig}/jarivs
# by the init script before running this script
#
$ENV{'PATH'}='/usr/local/bin:/usr/bin:/bin';
$ENV{'IFS'}=' \t\n';
################################################################################
# Add local libraries (we install them under us)
BEGIN {
use Cwd;
my $path=$0;
$path=~s/\/[^\/]*$//;
chdir($path);
my $libdir=cwd()."/lib";
my $cpanlib=cwd()."/cpan";
my $libdirs= [
"$cpanlib/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi",
"$cpanlib/lib/perl5/5.8.8/i386-linux-thread-multi/",
"$cpanlib/lib/perl5/site_perl/5.8.8/",
"$cpanlib/lib/perl5/5.8.8/",
"$libdir",
];
# add all of these to our library search path
foreach my $dir (@{$libdirs}){ unshift @INC, $dir if -d $dir; };
}
################################################################################
# Include our dependencies
use POSIX 'setsid';
use local::lib;
use Data::Dumper;
use Jarvis::IRC;
use Jarvis::Jabber;
use Jarvis::Persona::System;
use Jarvis::Persona::Crunchy;
use Jarvis::Persona::Jarvis;
use POE::Builder;
use Sys::Hostname::Long;
use Cwd;
################################################################################
#sub daemonize {
# defined( my $pid = fork() ) or die "Can't fork: $!\n";
# exit if $pid;
# setsid() or die "Can't start a new session: $!\n";
#}
################################################################################
$|++;
################################################################################
# disable jabber if we have no xmpp creds
my $enable_jabber=1;
if(!defined($ENV{'XMPP_PASSWORD'})){
$enable_jabber=0;
print STDERR "no XMPP_PASSWORD, disabling XMPP\n";
}
################################################################################
# get a handle for our builder
my $poe = new POE::Builder({ 'debug' => '0','trace' => '0' });
exit unless $poe;
################################################################################
# get our fqd, hostname, domain name, and base dn (our assumptions)
my $fqdn = hostname_long;
my $hostname = $fqdn; $hostname=~s/\..*$//;
my $domain = $fqdn; $domain=~s/^[^\.]*\.//;
my $basedn = "dc=".join(",dc=",split(/\./,$domain));
################################################################################
# This is the base (system) persona that controls the other personas
my $persona = YAML::Load(<< "...");
persona:
class: Jarvis::Persona::System
init:
alias: system
trace: 0
debug: 0
peer_group: cn=bot_managed
ldap_bindpw: $ENV{'SECRET'}
connectors:
- class: Jarvis::IRC
init:
alias: ${hostname}_irc
nickname: ${hostname}
ircname: ${fqdn}
server: 127.0.0.1
domain: ${domain}
channel_list:
- #asgard
persona: system
...
################################################################################
# a list of the personas I can spawn goes into known_personas
$persona->{'persona'}->{'init'}->{'known_personas'} = YAML::Load(<< "...");
---
- name: crunchy
persona:
persist: 1
class: Jarvis::Persona::Crunchy
init:
alias: crunchy
ldap_domain: ${domain}
ldap_binddn: cn=${hostname},ou=Hosts,${basedn}
ldap_bindpw: $ENV{'LDAP_PASSWORD'}
dbi_connect: dbi:mysql:tumble:tumbledb.vpn.websages.com
dbi_user: tumble
start_twitter_enabled: 0
twitter_name: capncrunchbot
password: $ENV{'TWITTER_PASSWORD'}
retry: 150
connectors:
- class: Jarvis::IRC
init:
alias: crunchy_irc
nickname: crunchy
ircname: "Cap'n Crunchbot"
server: 127.0.0.1
port: 8080
usessl: 1
username: $ENV{'IRC_ACCOUNT'}
password: $ENV{'IRC_PASSWORD'}
domain: ${domain}
channel_list:
- #soggies
persona: crunchy
...
###############################################################################
# Start the system persona
#
$poe->yaml_sess(YAML::Dump( $persona->{'persona'} ));
#
# add it's connectors
#
foreach my $connector (@{ $persona->{'persona'}->{'connectors'} }){
$poe->yaml_sess(YAML::Dump($connector));
}
################################################################################
# fire up the kernel
POE::Kernel->run();