-
Notifications
You must be signed in to change notification settings - Fork 10
/
openfpc-cx2db
executable file
·729 lines (590 loc) · 20.3 KB
/
openfpc-cx2db
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper;
use POSIX qw(setsid);
use DateTime;
use Getopt::Long qw/:config auto_version auto_help/;
use DBI;
use Sys::Syslog;
use Privileges::Drop;
use File::Path qw(mkpath make_path);
=head1 NAME
openfpc-cx2db.pl - Load session metadata from cxtracker into a db
=head1 VERSION
0.1
=head1 SYNOPSIS
$ openfpc-cx2db.pl [options]
OPTIONS:
--dir : set the dir to monitor for session files
--daemon : enables daemon mode
--debug : enable debug messages (default: 0 (disabled))
--help : this help message
--version : show openfpc-cx2db.pl version
--config : specify the OpenFPC Config file
=cut
our $VERSION = 0.1;
our $DEBUG = 0;
our $DAEMON = 0;
our $NOT_ESTABLISHED = 1;
our $TIMEOUT = 5;
our $HOSTNAME = q(default);
our $CONFFILE = 0;
my $SDIR = "/nsm_data/$HOSTNAME/session/";
my $LOGFILE = q(/var/log/openfpc-cx2db.log);
my $PIDFILE = q(/var/run/openfpc-cx2db.pid);
our $DB_NAME = "openfpc";
our $DB_HOST = "127.0.0.1";
our $DB_PORT = "3306";
our $DB_USERNAME = "openfpc";
our $DB_PASS = "openfpc";
our $DROP_USER = "openfpc";
our $AUTOCOMMIT = 0;
my $SANCP_DB = {};
my %CONFIG = ( NODENAME => "No_Name", );
my $starttime = 0;
my $FDIR = "$SDIR/failed";
my $openfpcver = "0.9";
GetOptions(
'dir=s' => \$SDIR,
'debug' => \$DEBUG,
'daemon' => \$DAEMON,
'config=s' => \$CONFFILE,
);
# Signal handlers
use vars qw(%sources);
$SIG{"HUP"} = \&recreate_merge_table;
$SIG{"INT"} = sub { game_over() };
$SIG{"TERM"} = sub { game_over() };
$SIG{"QUIT"} = sub { game_over() };
$SIG{"KILL"} = sub { game_over() };
#$SIG{"ALRM"} = sub { dir_watch(); alarm $TIMEOUT; };
# Read in the openfpc config file (generated by openfpc-setup.pl)
# and override the default hard-coded values if specified.
# -Leon
if ($CONFFILE) {
warn "[*] Reading config file\n" if ($DEBUG);
open my $CONFIG, '<', $CONFFILE or ldie("Unable to open config file $CONFFILE $!");
while (<$CONFIG>) {
chomp;
if ( $_ =~ m/^[a-zA-Z]/ ) {
( my $key, my @value ) = split /=/, $_;
$CONFIG{$key} = join '=', @value;
}
}
$HOSTNAME = $CONFIG{'NODENAME'} if ( defined $CONFIG{'NODENAME'} );
# $PIDFILE = "/var/run/openfpc-cx2db-" . $CONFIG{'NODENAME'} . ".pid" if (defined $CONFIG{'NODENAME'});
$PIDFILE = "/var/run/openfpc-" . $CONFIG{'NODENAME'} . "/openfpc-cx2db.pid" if ( defined $CONFIG{'NODENAME'} );
$DB_NAME = $CONFIG{'SESSION_DB_NAME'} if ( defined $CONFIG{'SESSION_DB_NAME'} );
$DB_USERNAME = $CONFIG{'SESSION_DB_USER'} if ( defined $CONFIG{'SESSION_DB_USER'} );
$DB_PASS = $CONFIG{'SESSION_DB_PASS'} if ( defined $CONFIG{'SESSION_DB_PASS'} );
$SDIR = $CONFIG{'SESSION_DIR'} if ( defined $CONFIG{'SESSION_DIR'} );
$DROP_USER = $CONFIG{'DROP_USER'} if ( defined $CONFIG{'DROP_USER'} );
$FDIR = "$SDIR/failed";
$LOGFILE = "/var/log/openfpc-cx2db-$CONFIG{'NODENAME'}.log" if ( defined $CONFIG{'NODENAME'} );
close $CONFIG;
}
else {
warn "[-] No config file specified. Using defaults.\n" if ($DEBUG);
}
our $DBI = "DBI:mysql:$DB_NAME:$DB_HOST:$DB_PORT";
# Show config if debug is enabled.
if ($DEBUG) {
print "[-] Config \n" . " Session DB : $DB_NAME\n" . " DB User : $DB_USERNAME\n" . " DB Pass : $DB_PASS\n" . " Session Dir: $SDIR\n" . " Failed Dir : $FDIR\n" . " Drop user : $DROP_USER\n" . " Log file : $LOGFILE\n";
}
# Check that SDIR exists, if not, create and own as DROP_USER
unless ( -d "$SDIR/failed" ) {
my $FDIR = $SDIR . "/failed";
make_path $FDIR,
{
owner => $DROP_USER,
group => $DROP_USER
}
or ldie("Session dir $SDIR doesn't exist, and I failed to create it");
warn "[-] Created session dir $SDIR\n";
}
# Create blank logfile for use by DROP_USER
unless ( -e $LOGFILE ) {
system("touch $LOGFILE");
system("chown $DROP_USER.$DROP_USER $LOGFILE");
}
# If Failed subfolder doesn't exist, lets add it
wlog("[*] Starting openfpc-cx2db.pl ver $openfpcver...");
#my $dbh = DBI->connect($DBI,$DB_USERNAME,$DB_PASS, {AutoCommit => 0, RaiseError => 1}) or die "$DBI::errstr";
unless ( my $dbt = DBI->connect( $DBI, $DB_USERNAME, $DB_PASS, { AutoCommit => 0, PrintError => 0, } ) ) {
wlog("DB Test connection failed: $DBI::errstr");
exit(255);
}
else {
wlog("Test connection to DB succeeded. Logging sessions.");
$dbt->disconnect;
}
# Prepare to meet the world of Daemons
if ($DAEMON) {
wlog("[*] Daemonizing...");
chdir("/") or die "chdir /: $!\n";
open( STDIN, "/dev/null" ) or die "open /dev/null: $!\n";
open( STDOUT, "> $LOGFILE" ) or ldie("Error: Unable to open log file $LOGFILE: $!\n");
defined( my $dpid = fork ) or die "fork: $!\n";
if ($dpid) {
# Write PID file
wlog("Using pid file $PIDFILE");
open( PID, "> $PIDFILE" ) or ldie("Unable to open pid file: $PIDFILE: $!\n");
print PID $dpid, "\n";
close(PID);
exit 0;
}
setsid();
open( STDERR, ">&STDOUT" );
}
# Drop privs to DROP_USER
warn("Dropping Privileges to user $DROP_USER") if $DEBUG;
my $cuser = `whoami`;
warn("Process Started by user $cuser") if $DEBUG;
drop_privileges($DROP_USER);
$cuser = `whoami`;
warn("Now running as user $cuser") if $DEBUG;
unless ( -w "$SDIR" ) {
ldie("Error: Session directory $SDIR isn't writable as current user $cuser");
}
warn "[*] Connecting to database...\n";
# HERE
my $dbh = DBI->connect( $DBI, $DB_USERNAME, $DB_PASS, { AutoCommit => 0, RaiseError => 1 } ) or die "$DBI::errstr";
my $sth;
# Make todays table, and initialize the session merged table
setup_db();
# Start dir_watch() which looks for new session files and put them into db
warn "[*] Looking for session data in: $SDIR \n" if $DEBUG;
dir_watch();
exit;
=head1 FUNCTIONS
=head2 wlog
Write the string passed to the function as a log
e.g. wlog("Something just went down");
=cut
sub wlog {
my $msg = shift;
chomp $msg;
my $gmtime = gmtime();
my $logdata = "$CONFIG{'NODENAME'} " . $msg;
unless ($DAEMON) {
print "$gmtime GMT: $logdata\n";
}
syslog( "info", $logdata );
}
=head2 ldie
Write a log message, and then die.
Helps find start up problems in daemon mode
=cut
sub ldie {
my $msg = shift;
wlog($msg);
die($msg);
}
=head2 dir_watch
This sub looks for new session data in a dir.
Takes $dir to watch as input.
=cut
sub dir_watch {
#infinite loop
while (1) {
my @FILES;
# Open the directory
if ( opendir( DIR, $SDIR ) ) {
# Find session files in dir (stats.eth0.1229062136)
while ( my $FILE = readdir(DIR) ) {
next if ( ( "." eq $FILE ) || ( ".." eq $FILE ) );
next unless ( $FILE =~ /^stats\..*\.\d{10}$/ );
push( @FILES, $FILE ) if ( -f "$SDIR/$FILE" );
}
closedir(DIR);
}
foreach my $FILE (@FILES) {
print "[*] Found file: $SDIR/$FILE\n" if ($DEBUG);
my $result = get_session("$SDIR/$FILE");
if ( $result >= 1 ) {
rename( "$SDIR/$FILE", "$FDIR/$FILE" ) or warn "[*] Couldn't move $SDIR/$FILE to $FDIR/$FILE: $!\n";
warn "[*] Error while processing file: $SDIR/$FILE\n";
}
my $endtime = time();
my $processtime = $endtime - $starttime;
print "[*] File $SDIR/$FILE processed in $processtime seconds\n" if ($DEBUG);
unlink("$SDIR/$FILE") if $result == 0;
}
# Dont pool files to often, or to seldom...
sleep $TIMEOUT;
}
}
=head2 get_session
This sub extracts the session data from a session data file.
Takes $file as input parameter.
=cut
sub get_session {
my $SFILE = shift;
my $tablename = get_table_name();
my $result = 0;
my %signatures;
# Check if table exists, if not create and make new session merge table
if ( !checkif_table_exist($tablename) ) {
new_session_table($tablename);
$sth->finish if $sth;
recreate_merge_table();
}
if ( open( FILE, $SFILE ) ) {
$starttime = time();
my $filelen = `wc -l $SFILE |awk '{print \$1'}`;
my $filesize = `ls -lh $SFILE |awk '{print \$5}'`;
chomp $filelen;
chomp $filesize;
print "[*] File:$SFILE, Lines:$filelen, Size:$filesize\n" if $DEBUG;
# Verify the data in the session files
LINE:
while ( my $line = readline FILE ) {
chomp $line;
$line =~ /^\d{19}/;
unless ($line) {
warn "[*] Error: Not valid session start format in: '$SFILE'";
next LINE;
}
my @elements = split /\|/, $line;
unless ( @elements == 15 ) {
warn "[*] Error: Not valid Nr. of session args format in: '$SFILE'";
next LINE;
}
# Things should be OK now to send to the DB
$result += put_session2db( $line, $tablename );
}
close FILE;
eval {
$dbh->commit;
$sth->finish();
};
if ($@) {
# Failed
return 1;
}
}
return $result;
}
=head2 ip_is_ipv6
Check if an IP address is version 6
returns 1 if true, 0 if false
=cut
sub ip_is_ipv6 {
my $ip = shift;
# Count octets
my $n = ( $ip =~ tr/:/:/ );
return (0) unless ( $n > 0 and $n < 8 );
# $k is a counter
my $k;
foreach ( split /:/, $ip ) {
$k++;
# Empty octet ?
next if ( $_ eq '' );
# Normal v6 octet ?
next if (/^[a-f\d]{1,4}$/i);
# Last octet - is it IPv4 ?
if ( $k == $n + 1 ) {
next if ( ip_is_ipv4($_) );
}
print "[*] Invalid IP address $ip";
return 0;
}
# Does the IP address start with : ?
if ( $ip =~ m/^:[^:]/ ) {
print "[*] Invalid address $ip (starts with :)";
return 0;
}
# Does the IP address finish with : ?
if ( $ip =~ m/[^:]:$/ ) {
print "[*] Invalid address $ip (ends with :)";
return 0;
}
# Does the IP address have more than one '::' pattern ?
if ( $ip =~ s/:(?=:)//g > 1 ) {
print "[*] Invalid address $ip (More than one :: pattern)";
return 0;
}
return 1;
}
=head2 expand_ipv6
Expands a IPv6 address from short notation
=cut
sub expand_ipv6 {
my $ip = shift;
# Keep track of ::
$ip =~ s/::/:!:/;
# IP as an array
my @ip = split /:/, $ip;
# Number of octets
my $num = scalar(@ip);
# Now deal with '::' ('000!')
foreach ( 0 .. ( scalar(@ip) - 1 ) ) {
# Find the pattern
next unless ( $ip[$_] eq '!' );
# @empty is the IP address 0
my @empty = map { $_ = '0' x 4 } ( 0 .. 7 );
# Replace :: with $num '0000' octets
$ip[$_] = join ':', @empty[ 0 .. 8 - $num ];
last;
}
# Now deal with octets where there are less then 4 enteries
my @ip_long = split /:/, ( lc( join ':', @ip ) );
foreach ( 0 .. ( scalar(@ip_long) - 1 ) ) {
# Next if we have our 4 enteries
next if ( $ip_long[$_] =~ /^[a-f\d]{4}$/ );
# Push '0' until we match
while ( !( $ip_long[$_] =~ /[a-f\d]{4,}/ ) ) {
$ip_long[$_] =~ s/^/0/;
}
}
return ( lc( join ':', @ip_long ) );
}
=head2 put_session2db
takes a session line as input and stores it in DB
=cut
sub put_session2db {
my $SESSION = shift;
my $tablename = shift;
my $ip_version = 2; # AF_INET
my ( $cx_id, $s_t, $e_t, $tot_time, $ip_type, $src_dip, $src_port, $dst_dip, $dst_port, $src_packets, $src_byte, $dst_packets, $dst_byte, $src_flags, $dst_flags ) = split /\|/, $SESSION, 15;
if ( $NOT_ESTABLISHED && $ip_type == 6 ) {
if ( $tot_time <= 1 ) { # Do we need this ?
if ( $src_packets == 0 || $dst_packets == 0 ) { # What if a reset is sent?
# $src_flags & $dst_flags ?
warn "Skipping record: Only established TCP sessions are recorded\n" if $DEBUG;
return 0;
}
}
}
if ( ip_is_ipv6($src_dip) || ip_is_ipv6($dst_dip) ) {
if ( $CONFIG{'ENABLE_IP_V6'} ) {
# We should verify that src and dst are both ipv6! else b0rk!
$src_dip = expand_ipv6($src_dip);
$dst_dip = expand_ipv6($dst_dip);
$src_dip = "INET_ATON6(\'$src_dip\')";
$dst_dip = "INET_ATON6(\'$dst_dip\')";
$ip_version = 10; # AF_INET6
}
else {
warn "[*] Skipping record: IPv6 disabled\n" if $DEBUG;
return 0;
}
}
my $sql;
eval {
$sql =
qq[INSERT INTO $tablename (
sid,sessionid,start_time,end_time,duration,ip_proto,
src_ip,src_port,dst_ip,dst_port,src_pkts,src_bytes,
dst_pkts,dst_bytes,src_flags,dst_flags,ip_version
) VALUES (
?,?,?,?,?,
?,?,?,?,?,
?,?,?,?,?,
?,?
)];
$sth = $dbh->prepare_cached($sql);
$sth->execute( $HOSTNAME, $cx_id, $s_t, $e_t, $tot_time, $ip_type, $src_dip, $src_port, $dst_dip, $dst_port, $src_packets, $src_byte, $dst_packets, $dst_byte, $src_flags, $dst_flags, $ip_version );
};
if ($@) {
# Failed
return 1;
}
return 0;
}
=head2 setup_db
Create todays table if it dont exist (session_hostname_date).
Make a new merge of all session_% tables.
=cut
sub setup_db {
my $tablename = get_table_name();
new_session_table($tablename);
delete_merged_session_table();
my $sessiontables = find_session_tables();
merge_session_tables($sessiontables);
return;
}
=head2 new_session_table
Creates a new session_$hostname_$date table
Takes $hostname and $date as input.
=cut
sub new_session_table {
my ($tablename) = shift;
my ( $sql, $sth1 );
eval {
$sql =
" \
CREATE TABLE IF NOT EXISTS $tablename \
( \
sid INT(10) UNSIGNED NOT NULL, \
sessionid BIGINT(20) UNSIGNED NOT NULL, \
start_time DATETIME NOT NULL, \
end_time DATETIME NOT NULL, \
duration INT(10) UNSIGNED NOT NULL, \
ip_proto TINYINT UNSIGNED NOT NULL, \
ip_version TINYINT UNSIGNED NOT NULL, \
src_ip DECIMAL(39,0) UNSIGNED, \
src_port SMALLINT UNSIGNED, \
dst_ip DECIMAL(39,0) UNSIGNED, \
dst_port SMALLINT UNSIGNED, \
src_pkts INT UNSIGNED NOT NULL, \
src_bytes INT UNSIGNED NOT NULL, \
dst_pkts INT UNSIGNED NOT NULL, \
dst_bytes INT UNSIGNED NOT NULL, \
src_flags TINYINT UNSIGNED NOT NULL, \
dst_flags TINYINT UNSIGNED NOT NULL, \
PRIMARY KEY (sid,sessionid), \
INDEX src_ip (src_ip), \
INDEX dst_ip (dst_ip), \
INDEX dst_port (dst_port), \
INDEX src_port (src_port), \
INDEX start_time (start_time) \
) ENGINE=MyISAM \
";
$sth1 = $dbh->prepare($sql);
$sth1->execute;
$sth1->finish;
};
if ($@) {
# Failed
return 1;
}
return 0;
}
=head2 find_session_tables
Find all session_% tables
=cut
sub find_session_tables {
my ( $sql, $sth );
my $tables = q();
$sql = q(SHOW TABLES LIKE 'session_%');
$sth = $dbh->prepare($sql);
$sth->execute;
while ( my @array = $sth->fetchrow_array ) {
my $table = $array[0];
$tables = "$tables $table,";
}
$sth->finish;
$tables =~ s/,$//;
return $tables;
}
=head2 delete_merged_session_table
Deletes the session merged table if it exists.
=cut
sub delete_merged_session_table {
my ( $sql, $sth );
eval {
$sql = "DROP TABLE IF EXISTS session";
$sth = $dbh->prepare($sql);
$sth->execute;
$sth->finish;
};
if ($@) {
# Failed
warn "[*] Drop table session failed...\n" if $DEBUG;
return 1;
}
warn "[*] Dropped table session...\n" if $DEBUG;
return 0;
}
=head2 merge_session_tables
Creates a new session merge table
=cut
sub merge_session_tables {
my $tables = shift;
my ( $sql, $sth );
eval {
# check for != MRG_MyISAM - exit
warn "[*] Creating session MERGE table\n" if $DEBUG;
my $sql = " \
CREATE TABLE session \
( \
sid INT(0) UNSIGNED NOT NULL, \
sessionid BIGINT(20) UNSIGNED NOT NULL, \
start_time DATETIME NOT NULL, \
end_time DATETIME NOT NULL, \
duration INT(10) UNSIGNED NOT NULL, \
ip_proto TINYINT(3) UNSIGNED NOT NULL, \
ip_version TINYINT(3) UNSIGNED NOT NULL, \
src_ip DECIMAL(39,0) UNSIGNED, \
src_port SMALLINT UNSIGNED, \
dst_ip DECIMAL(39,0) UNSIGNED, \
dst_port SMALLINT UNSIGNED, \
src_pkts INT UNSIGNED NOT NULL, \
src_bytes INT UNSIGNED NOT NULL, \
dst_pkts INT UNSIGNED NOT NULL, \
dst_bytes INT UNSIGNED NOT NULL, \
src_flags TINYINT UNSIGNED NOT NULL, \
dst_flags TINYINT UNSIGNED NOT NULL, \
INDEX p_key (sid,sessionid), \
INDEX src_ip (src_ip), \
INDEX dst_ip (dst_ip), \
INDEX dst_port (dst_port), \
INDEX src_port (src_port), \
INDEX start_time (start_time) \
) ENGINE=MERGE UNION=($tables) \
";
$sth = $dbh->prepare($sql);
$sth->execute;
$sth->finish;
};
if ($@) {
# Failed
warn "[*] Create session MERGE table failed!\n" if $DEBUG;
return 1;
}
return 0;
}
=head2 get_table_name
makes a table name, format: session_$HOSTNAME_$DATE
=cut
sub get_table_name {
my $DATE = `date --iso`;
$DATE =~ s/\-//g;
$DATE =~ s/\n$//;
my $tablename = "session_" . "$HOSTNAME" . "_" . "$DATE";
return $tablename;
}
=head2 checkif_table_exist
Checks if a table exists. Takes $tablename as input and
returns 1 if $tablename exists, and 0 if not.
=cut
sub checkif_table_exist {
my $tablename = shift;
my ( $sql, $sth );
eval {
$sql = "select count(*) from $tablename where 1=0";
$dbh->do($sql);
};
if ( $dbh->err ) {
warn "Table $tablename does not exist.\n" if $DEBUG;
return 0;
}
else {
return 1;
}
}
=head2 recreate_merge_table
Recreates the merge table.
=cut
sub recreate_merge_table {
my $sessiontables = find_session_tables();
delete_merged_session_table();
merge_session_tables($sessiontables);
}
=head2 game_over
Terminates the program in a sainfull way.
=cut
sub game_over {
warn "[*] Terminating...\n";
$dbh->disconnect;
unlink($PIDFILE);
exit 0;
}
=head1 AUTHOR
Edward Fjellskaal
=head1 COPYRIGHT
This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut