ban by range in 2.2
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.2@747 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
47361369ff
commit
37a0aeb8ae
@ -317,6 +317,19 @@ function array_contains($array, $target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// from http://uk.php.net/network
|
||||
function ip_in_range($IP, $CIDR) {
|
||||
list ($net, $mask) = split ("/", $CIDR);
|
||||
|
||||
$ip_net = ip2long ($net);
|
||||
$ip_mask = ~((1 << (32 - $mask)) - 1);
|
||||
|
||||
$ip_ip = ip2long ($IP);
|
||||
|
||||
$ip_ip_net = $ip_ip & $ip_mask;
|
||||
|
||||
return ($ip_ip_net == $ip_net);
|
||||
}
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
|
||||
* Event API *
|
||||
|
@ -31,7 +31,7 @@ class IPBan extends Extension {
|
||||
|
||||
if(is_a($event, 'InitExtEvent')) {
|
||||
global $config;
|
||||
if($config->get_int("ext_ipban_version") < 2) {
|
||||
if($config->get_int("ext_ipban_version") < 5) {
|
||||
$this->install();
|
||||
}
|
||||
|
||||
@ -94,9 +94,13 @@ class IPBan extends Extension {
|
||||
global $config;
|
||||
global $database;
|
||||
|
||||
$remote = $_SERVER['REMOTE_ADDR'];
|
||||
$bans = $this->get_active_bans();
|
||||
foreach($bans as $row) {
|
||||
if($row['ip'] == $_SERVER['REMOTE_ADDR']) {
|
||||
if(
|
||||
(strstr($row['ip'], '/') && ip_in_range($remote, $row['ip'])) ||
|
||||
($row['ip'] == $remote)
|
||||
) {
|
||||
$admin = $database->get_user_by_id($row['banner_id']);
|
||||
print "IP <b>{$row['ip']}</b> has been banned by <b>{$admin->name}</b> because of <b>{$row['reason']}</b>";
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
<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="15"><notnull/></field>
|
||||
<field name="ip" type="C" size="20"><notnull/></field>
|
||||
<field name="date" type="T"><notnull/></field>
|
||||
<field name="end" type="T"><notnull/></field>
|
||||
<field name="reason" type="C" size="255"><notnull/></field>
|
||||
@ -14,6 +14,6 @@
|
||||
|
||||
<sql>
|
||||
<query>DELETE FROM config WHERE name='ext_ipban_version'</query>
|
||||
<query>INSERT INTO config(name, value) VALUES('ext_ipban_version', 3)</query>
|
||||
<query>INSERT INTO config(name, value) VALUES('ext_ipban_version', 5)</query>
|
||||
</sql>
|
||||
</schema>
|
||||
|
@ -12,6 +12,7 @@ class TagList extends Extension {
|
||||
$config->set_default_int("tag_list_length", 15);
|
||||
$config->set_default_int("tags_min", 3);
|
||||
$config->set_default_string("info_link", 'http://en.wikipedia.org/wiki/$tag');
|
||||
$config->set_default_string("tag_list_image_type", 'related');
|
||||
}
|
||||
|
||||
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "tags")) {
|
||||
@ -51,7 +52,12 @@ class TagList extends Extension {
|
||||
if(is_a($event, 'DisplayingImageEvent')) {
|
||||
global $config;
|
||||
if($config->get_int('tag_list_length') > 0) {
|
||||
$this->add_related_block($event->page, $event->image);
|
||||
if($config->get_string('tag_list_image_type') == 'related') {
|
||||
$this->add_related_block($event->page, $event->image);
|
||||
}
|
||||
else {
|
||||
$this->add_tags_block($event->page, $event->image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,6 +69,10 @@ class TagList extends Extension {
|
||||
$sb = new SetupBlock("Popular / Related Tag List");
|
||||
$sb->add_int_option("tag_list_length", "Show top "); $sb->add_label(" tags");
|
||||
$sb->add_text_option("info_link", "<br>Tag info link: ");
|
||||
$sb->add_choice_option("tag_list_image_type", array(
|
||||
"Image's tags only" => "tags",
|
||||
"Show related" => "related"
|
||||
), "<br>Image tag list: ");
|
||||
$sb->add_bool_option("tag_list_numbers", "<br>Show tag counts: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
@ -194,6 +204,26 @@ class TagList extends Extension {
|
||||
}
|
||||
}
|
||||
|
||||
private function add_tags_block($page, $image) {
|
||||
global $database;
|
||||
global $config;
|
||||
|
||||
$query = "
|
||||
SELECT tags.tag, tags.count
|
||||
FROM tags, image_tags
|
||||
WHERE tags.id = image_tags.tag_id
|
||||
AND image_tags.image_id = ?
|
||||
ORDER BY count DESC
|
||||
LIMIT ?
|
||||
";
|
||||
$args = array($image->id, $config->get_int('tag_list_length'));
|
||||
|
||||
$tags = $database->get_all($query, $args);
|
||||
if(count($tags) > 0) {
|
||||
$this->theme->display_related_block($page, $tags);
|
||||
}
|
||||
}
|
||||
|
||||
private function add_popular_block($page) {
|
||||
global $database;
|
||||
global $config;
|
||||
|
Loading…
x
Reference in New Issue
Block a user