backing off of xmldb D:
git-svn-id: file:///home/shish/svn/shimmie2/trunk@852 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
e7b7fc0d24
commit
9026856a91
@ -37,7 +37,7 @@ class IPBan extends Extension {
|
||||
|
||||
if(is_a($event, 'InitExtEvent')) {
|
||||
global $config;
|
||||
if($config->get_int("ext_ipban_version") < 5) {
|
||||
if($config->get_int("ext_ipban_version") < 3) {
|
||||
$this->install();
|
||||
}
|
||||
|
||||
@ -95,8 +95,46 @@ class IPBan extends Extension {
|
||||
global $database;
|
||||
global $config;
|
||||
|
||||
if($config->get_int("ext_ipban_version") < 3) {
|
||||
$database->upgrade_schema("ext/ipban/schema.xml");
|
||||
// shortcut to latest
|
||||
if($config->get_int("ext_ipban_version") < 1) {
|
||||
$database->execute("
|
||||
CREATE TABLE bans (
|
||||
id {$database->engine->auto_increment},
|
||||
banner_id INTEGER NOT NULL,
|
||||
ip CHAR(15) NOT NULL,
|
||||
end DATETIME NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
INDEX (end)
|
||||
) {$database->engine->create_table_extras};
|
||||
");
|
||||
$config->set_int("ext_ipban_version", 3);
|
||||
}
|
||||
|
||||
// ===
|
||||
|
||||
if($config->get_int("ext_ipban_version") < 1) {
|
||||
$database->Execute("CREATE TABLE bans (
|
||||
id int(11) NOT NULL auto_increment,
|
||||
ip char(15) default NULL,
|
||||
date datetime default NULL,
|
||||
end datetime default NULL,
|
||||
reason varchar(255) default NULL,
|
||||
PRIMARY KEY (id)
|
||||
)");
|
||||
$config->set_int("ext_ipban_version", 1);
|
||||
}
|
||||
|
||||
if($config->get_int("ext_ipban_version") == 1) {
|
||||
$database->execute("ALTER TABLE bans ADD COLUMN banner_id INTEGER NOT NULL AFTER id");
|
||||
$config->set_int("ext_ipban_version", 2);
|
||||
}
|
||||
|
||||
if($config->get_int("ext_ipban_version") == 2) {
|
||||
$database->execute("ALTER TABLE bans DROP COLUMN date");
|
||||
$database->execute("ALTER TABLE bans CHANGE ip ip CHAR(20) NOT NULL");
|
||||
$database->execute("ALTER TABLE bans CHANGE reason reason TEXT NOT NULL");
|
||||
$database->execute("CREATE INDEX bans__end ON bans(end)");
|
||||
$config->set_int("ext_ipban_version", 3);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
@ -127,33 +165,29 @@ class IPBan extends Extension {
|
||||
// database {{{
|
||||
private function get_bans() {
|
||||
global $database;
|
||||
$bans = $database->get_all("SELECT * FROM bans ORDER BY date");
|
||||
$bans = $database->get_all("SELECT * FROM bans ORDER BY end, id");
|
||||
if($bans) {return $bans;}
|
||||
else {return array();}
|
||||
}
|
||||
|
||||
private function get_active_bans() {
|
||||
global $database;
|
||||
$bans = $database->get_all("SELECT * FROM bans WHERE (date < now()) AND (end > now() OR isnull(end))");
|
||||
$bans = $database->get_all("SELECT * FROM bans WHERE (end > now() OR isnull(end))");
|
||||
if($bans) {return $bans;}
|
||||
else {return array();}
|
||||
}
|
||||
|
||||
private function get_ip_ban($ip) {
|
||||
global $database;
|
||||
return $database->db->GetRow("SELECT * FROM bans WHERE ip = ? AND date < now() AND (end > now() OR isnull(end))", array($ip));
|
||||
}
|
||||
|
||||
private function add_ip_ban($ip, $reason, $end, $user) {
|
||||
global $database;
|
||||
if(preg_match("/^\d+ (day|week|month)$/i", $end)) {
|
||||
$sql = "INSERT INTO bans (ip, reason, date, end, banner_id)
|
||||
VALUES (?, ?, now(), now() + interval $end, ?)";
|
||||
$parts = array();
|
||||
if(preg_match("/^(\d+) (day|week|month)s?$/i", $end, $parts)) {
|
||||
$sql = "INSERT INTO bans (ip, reason, end, banner_id)
|
||||
VALUES (?, ?, now() + interval {$parts[1]} {$parts[2]}, ?)";
|
||||
$database->Execute($sql, array($ip, $reason, $user->id));
|
||||
}
|
||||
else {
|
||||
$sql = "INSERT INTO bans (ip, reason, date, end, banner_id)
|
||||
VALUES (?, ?, now(), ?, ?)";
|
||||
$sql = "INSERT INTO bans (ip, reason, end, banner_id)
|
||||
VALUES (?, ?, ?, ?)";
|
||||
$database->Execute($sql, array($ip, $reason, $end, $user->id));
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<schema version="0.3">
|
||||
<!-- FIXME: mysql utf8ness -->
|
||||
<table name="bans">
|
||||
<field name="id" type="I"><key/><autoincrement/></field>
|
||||
<field name="banner_id" type="I"><notnull/></field>
|
||||
<field name="ip" type="C" size="20"><notnull/></field>
|
||||
<field name="date" type="D"><notnull/></field>
|
||||
<field name="end" type="D"><notnull/></field>
|
||||
<field name="reason" type="C" size="255"><notnull/></field>
|
||||
<index name="bans__ip"><col>ip</col></index>
|
||||
<opt platform="mysql">DEFAULT CHARSET='utf8'</opt>
|
||||
</table>
|
||||
|
||||
<sql>
|
||||
<query>DELETE FROM config WHERE name='ext_ipban_version'</query>
|
||||
<query>INSERT INTO config(name, value) VALUES('ext_ipban_version', 5)</query>
|
||||
</sql>
|
||||
</schema>
|
Loading…
x
Reference in New Issue
Block a user