summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarWilliam Heimbigner <william.heimbigner@gmail.com>2007-06-26 09:19:42 +0000
committerLibravatarWilliam Heimbigner <william.heimbigner@gmail.com>2007-06-26 09:19:42 +0000
commitc3d5aad1a6d2b84994682fbd0e07597fdb680a00 (patch)
tree57118ebd32c78663f9dc36aea49726e45e5b88a3
parent14bd999ada56e20ffc355ef32d7a8a0bbf9d1032 (diff)
Whoops, forgot to add the mysql files
-rw-r--r--config-default/mysql.xml8
-rw-r--r--modules/mysql.pl48
2 files changed, 56 insertions, 0 deletions
diff --git a/config-default/mysql.xml b/config-default/mysql.xml
new file mode 100644
index 0000000..3f66147
--- /dev/null
+++ b/config-default/mysql.xml
@@ -0,0 +1,8 @@
+<mysql>
+ <user>USER</user>
+ <pass>PASS</pass>
+ <db>asm_main</db>
+ <table>alertlog</table>
+ <host>localhost</host>
+ <port>3307</port>
+</mysql>
diff --git a/modules/mysql.pl b/modules/mysql.pl
new file mode 100644
index 0000000..7a5da7c
--- /dev/null
+++ b/modules/mysql.pl
@@ -0,0 +1,48 @@
+use warnings;
+use strict;
+use DBI;
+
+sub sql_connect
+{
+ $::dbh = DBI->connect("DBI:mysql:database=$::mysql->{db};host=$::mysql->{host};port=$::mysql->{port}",
+ $::mysql->{user}, $::mysql->{pass});
+}
+
+sub sql_record
+{
+ my ($channel, $nick, $user, $host, $level, $id, $reason) = @_;
+ $::dbh->do("INSERT INTO $::mysql->{table} (channel, nick, user, host, level, id, reason) VALUES (" .
+ $::dbh->quote($channel) . ", " . $::dbh->quote($nick) . ", " . $::dbh->quote($user) .
+ ", " . $::dbh->quote($host) . ", " . $::dbh->quote($level) . ", " .
+ $::dbh->quote($id) . ", " . $::dbh->quote($reason) . ");");
+}
+
+sub sql_query
+{
+ my ($channel, $nick, $user, $host) = @_;
+ $channel = $::dbh->quote($channel);
+ $nick = $::dbh->quote($nick);
+ $user = $::dbh->quote($user);
+ $host = $::dbh->quote($host);
+
+ $nick =~ s/\*/%/g;
+ $nick =~ s/_/\\_/g;
+ $nick =~ s/\?/_/g;
+
+ $user =~ s/\*/%/g;
+ $user =~ s/_/\\_/g;
+ $user =~ s/\?/_/g;
+
+ $host =~ s/\*/%/g;
+ $host =~ s/_/\\_/g;
+ $host =~ s/\?/_/g;
+ my $sth = $::dbh->prepare("SELECT * from $::mysql->{table} WHERE channel = $channel and nick like $nick and user like $user and host like $host;");
+ $sth->execute;
+ my $i = 0;
+ while (my $ref = $sth->fetchrow_arrayref) {
+ $i++;
+ }
+ return $i;
+}
+
+1;