summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-10-31 13:03:10 -0400
committerAdam <Adam@anope.org>2010-10-31 13:03:10 -0400
commit011582ff3c0d69e6b426b744b1abf30bb175e019 (patch)
treeeae6ce0568a8dd8dacc6eecca24547a2b2139ca4
parent98bdd9749a0e7d8d9e34d584233c99533066aa26 (diff)
Fixed bug #1197 - Store vhosts in MySQL
-rw-r--r--data/example.conf34
-rw-r--r--data/mysql/tables.sql58
-rw-r--r--modules/extra/db_mysql.cpp34
3 files changed, 89 insertions, 37 deletions
diff --git a/data/example.conf b/data/example.conf
index 5439be554..0a3a7e398 100644
--- a/data/example.conf
+++ b/data/example.conf
@@ -1649,11 +1649,11 @@ module { name = "m_ssl" }
#module { name = "m_mysql" }
mysql
{
- database = "anope";
- server = "127.0.0.1";
- username = "anope";
- password = "mypassword";
- port = 3306;
+ database = "anope"
+ server = "127.0.0.1"
+ username = "anope"
+ password = "mypassword"
+ port = 3306
}
/*
@@ -1757,28 +1757,28 @@ m_dnsbl
* This is not recommended, and on large networks will open a very large amount of DNS queries.
* While services are not drastically affected by this, your nameserver/DNSBL might care.
*/
- check_on_connect = no;
+ check_on_connect = no
/*
* If set, Services will check clients when coming back from a netsplit. This can cause a large number
* of DNS queries open at once. While services are not drastically affected by this, your nameserver/DNSBL
* might care.
*/
- check_on_netburst = no;
+ check_on_netburst = no
/*
* If set, OperServ will add clients found in the DNSBL to the akill list. Without it, OperServ simply sends
* a timed G/K-line to the IRCd and forgets about it. Can be useful if your akill list is being fill up by bots.
*/
- add_to_akill = yes;
+ add_to_akill = yes
}
blacklist
{
/* Name of the blacklist */
- name = "rbl.efnetrbl.org";
+ name = "rbl.efnetrbl.org"
/* How long to set the akill for */
- time = 4h;
+ time = 4h
/* Reason for akill.
* %n is the nick of the user
@@ -1791,17 +1791,17 @@ blacklist
reason = "You are listed in the efnet RBL, visit http://rbl.efnetrbl.org/?i=%i for info"
/* Replies to ban and their reason. If this is totally ommited all replies get banned */
- 1 = "Open Proxy";
+ 1 = "Open Proxy"
/* Don't ban for result 2 or 3 */
- #2 = "spamtrap666";
- #3 = "spamtrap50";
- 4 = "TOR";
- 5 = "Drones / Flooding";
+ #2 = "spamtrap666"
+ #3 = "spamtrap50"
+ 4 = "TOR"
+ 5 = "Drones / Flooding"
}
blacklist
{
- name = "dnsbl.dronebl.org";
- time = 4h;
+ name = "dnsbl.dronebl.org"
+ time = 4h
reason = "You have a host listed in the DroneBL. For more information, visit http://dronebl.org/lookup.do?ip=%i"
}
diff --git a/data/mysql/tables.sql b/data/mysql/tables.sql
index a26153a50..d1f83f730 100644
--- a/data/mysql/tables.sql
+++ b/data/mysql/tables.sql
@@ -3,9 +3,9 @@
-- http://www.phpmyadmin.net
--
-- Host: localhost
--- Generation Time: Oct 12, 2010 at 06:36 PM
+-- Generation Time: Oct 31, 2010 at 03:02 AM
-- Server version: 5.1.50
--- PHP Version: 5.2.14-pl0-gentoo
+-- PHP Version: 5.3.3-pl1-gentoo
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
@@ -175,6 +175,21 @@ CREATE TABLE IF NOT EXISTS `anope_extra` (
-- --------------------------------------------------------
--
+-- Table structure for table `anope_hs_core`
+--
+
+CREATE TABLE IF NOT EXISTS `anope_hs_core` (
+ `nick` varchar(255) NOT NULL,
+ `vident` varchar(64) NOT NULL,
+ `vhost` varchar(255) NOT NULL,
+ `creator` varchar(255) NOT NULL,
+ `time` int(11) NOT NULL,
+ KEY `FK_anope_hs_core_nick` (`nick`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+-- --------------------------------------------------------
+
+--
-- Table structure for table `anope_info`
--
@@ -358,8 +373,8 @@ CREATE TABLE IF NOT EXISTS `anope_os_xlines` (
-- Constraints for table `anope_bs_badwords`
--
ALTER TABLE `anope_bs_badwords`
- ADD CONSTRAINT `FK_anope_bs_badwords_channel` FOREIGN KEY (`channel`) REFERENCES `anope_cs_info` (`name`) ON DELETE
-CASCADE ON UPDATE CASCADE;
+ ADD CONSTRAINT `FK_anope_bs_badwords_channel` FOREIGN KEY (`channel`) REFERENCES `anope_cs_info` (`name`) ON DELETE CASCADE
+ON UPDATE CASCADE;
--
-- Constraints for table `anope_bs_info_metadata`
@@ -372,15 +387,15 @@ CASCADE ON UPDATE CASCADE;
-- Constraints for table `anope_cs_access`
--
ALTER TABLE `anope_cs_access`
- ADD CONSTRAINT `FK_anope_cs_access_channel` FOREIGN KEY (`channel`) REFERENCES `anope_cs_info` (`name`) ON DELETE CASCADE
-ON UPDATE CASCADE;
+ ADD CONSTRAINT `FK_anope_cs_access_channel` FOREIGN KEY (`channel`) REFERENCES `anope_cs_info` (`name`) ON DELETE CASCADE ON
+UPDATE CASCADE;
--
-- Constraints for table `anope_cs_akick`
--
ALTER TABLE `anope_cs_akick`
- ADD CONSTRAINT `FK_anope_cs_akick_channel` FOREIGN KEY (`channel`) REFERENCES `anope_cs_info` (`name`) ON DELETE CASCADE
-ON UPDATE CASCADE;
+ ADD CONSTRAINT `FK_anope_cs_akick_channel` FOREIGN KEY (`channel`) REFERENCES `anope_cs_info` (`name`) ON DELETE CASCADE ON
+UPDATE CASCADE;
--
-- Constraints for table `anope_cs_info_metadata`
@@ -393,8 +408,8 @@ CASCADE ON UPDATE CASCADE;
-- Constraints for table `anope_cs_levels`
--
ALTER TABLE `anope_cs_levels`
- ADD CONSTRAINT `FK_anope_cs_levels_channel` FOREIGN KEY (`channel`) REFERENCES `anope_cs_info` (`name`) ON DELETE CASCADE
-ON UPDATE CASCADE;
+ ADD CONSTRAINT `FK_anope_cs_levels_channel` FOREIGN KEY (`channel`) REFERENCES `anope_cs_info` (`name`) ON DELETE CASCADE ON
+UPDATE CASCADE;
--
-- Constraints for table `anope_cs_ttb`
@@ -404,30 +419,37 @@ ALTER TABLE `anope_cs_ttb`
UPDATE CASCADE;
--
+-- Constraints for table `anope_hs_core`
+--
+ALTER TABLE `anope_hs_core`
+ ADD CONSTRAINT `FK_anope_hs_core_nick` FOREIGN KEY (`nick`) REFERENCES `anope_ns_alias` (`nick`) ON DELETE CASCADE ON UPDATE
+CASCADE;
+
+--
-- Constraints for table `anope_ms_info`
--
ALTER TABLE `anope_ms_info`
- ADD CONSTRAINT `FK_anope_ms_info_receiver` FOREIGN KEY (`receiver`) REFERENCES `anope_ns_alias` (`nick`) ON DELETE CASCADE
-ON UPDATE CASCADE;
+ ADD CONSTRAINT `FK_anope_ms_info_receiver` FOREIGN KEY (`receiver`) REFERENCES `anope_ns_alias` (`nick`) ON DELETE CASCADE ON
+UPDATE CASCADE;
--
-- Constraints for table `anope_ns_access`
--
ALTER TABLE `anope_ns_access`
- ADD CONSTRAINT `FK_anope_ns_access_display` FOREIGN KEY (`display`) REFERENCES `anope_ns_core` (`display`) ON DELETE
-CASCADE ON UPDATE CASCADE;
+ ADD CONSTRAINT `FK_anope_ns_access_display` FOREIGN KEY (`display`) REFERENCES `anope_ns_core` (`display`) ON DELETE CASCADE
+ON UPDATE CASCADE;
--
-- Constraints for table `anope_ns_alias`
--
ALTER TABLE `anope_ns_alias`
- ADD CONSTRAINT `FK_anope_ns_alias_display` FOREIGN KEY (`display`) REFERENCES `anope_ns_core` (`display`) ON DELETE
-CASCADE ON UPDATE CASCADE;
+ ADD CONSTRAINT `FK_anope_ns_alias_display` FOREIGN KEY (`display`) REFERENCES `anope_ns_core` (`display`) ON DELETE CASCADE
+ON UPDATE CASCADE;
--
-- Constraints for table `anope_ns_alias_metadata`
--
ALTER TABLE `anope_ns_alias_metadata`
- ADD CONSTRAINT `FK_anope_ns_alias_metadata_nick` FOREIGN KEY (`nick`) REFERENCES `anope_ns_alias` (`nick`) ON DELETE
-CASCADE ON UPDATE CASCADE;
+ ADD CONSTRAINT `FK_anope_ns_alias_metadata_nick` FOREIGN KEY (`nick`) REFERENCES `anope_ns_alias` (`nick`) ON DELETE CASCADE
+ON UPDATE CASCADE;
diff --git a/modules/extra/db_mysql.cpp b/modules/extra/db_mysql.cpp
index f430502a4..fa8ede0d4 100644
--- a/modules/extra/db_mysql.cpp
+++ b/modules/extra/db_mysql.cpp
@@ -410,9 +410,11 @@ class DBMySQL : public Module
I_OnMemoSend, I_OnMemoDel,
/* OperServ */
I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel,
- I_OnAddXLine, I_OnDelXLine
+ I_OnAddXLine, I_OnDelXLine,
+ /* HostServ */
+ I_OnSetVhost, I_OnDeleteVhost
};
- ModuleManager::Attach(i, this, 39);
+ ModuleManager::Attach(i, this, 41);
}
EventReturn OnLoadDatabase()
@@ -525,6 +527,20 @@ class DBMySQL : public Module
FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(na, na->nick, Params));
}
+ r = SQL->RunQuery("SELECT * FROM `anope_hs_core`");
+ for (int i = 0; i < r.Rows(); ++i)
+ {
+ NickAlias *na = findnick(r.Get(i, "nick"));
+ if (!na)
+ {
+ Log() << "MySQL: Got vhost entry for nonexistant nick " << r.Get(i, "nick");
+ continue;
+ }
+
+ time_t creation = r.Get(i, "time").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "time")) : Anope::CurTime;
+ na->hostinfo.SetVhost(r.Get(i, "vident"), r.Get(i, "vhost"), r.Get(i, "creator"), creation);
+ }
+
r = SQL->RunQuery("SELECT * FROM `anope_bs_core`");
for (int i = 0; i < r.Rows(); ++i)
{
@@ -1360,6 +1376,16 @@ class DBMySQL : public Module
else
this->RunQuery(Anope::string("DELETE FROM `anope_os_xlines` WHERE `type` = '") + (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) + "'");
}
+
+ void OnDeleteVhost(NickAlias *na)
+ {
+ this->RunQuery("DELETE FROM `anope_hs_core` WHERE `nick` = '" + na->nick + "'");
+ }
+
+ void OnSetVhost(NickAlias *na)
+ {
+ this->RunQuery("INSERT INTO `anope_hs_core` (nick, vident, vhost, creator, time) VALUES('" + na->nick + "', '" + na->hostinfo.GetIdent() + "', '" + na->hostinfo.GetHost() + "', '" + na->hostinfo.GetCreator() + "', " + stringify(na->hostinfo.GetTime()) + ")");
+ }
};
void MySQLInterface::OnResult(const SQLResult &r)
@@ -1418,7 +1444,11 @@ static void SaveDatabases()
me->RunQuery("TRUNCATE TABLE `anope_ns_alias`");
for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
+ {
me->InsertAlias(it->second);
+ if (it->second->hostinfo.HasVhost())
+ me->OnSetVhost(it->second);
+ }
me->RunQuery("TRUNCATE TABLE `anope_ns_core`");
me->RunQuery("TRUNCATE TABLE `anope_ms_info`");