=$from and $ip<=$to); } } /* ------------------------------------------------------------- Name: easyban_mysql_install Purpose: Creates database table if it doesnt exist Receive: $wpdb, $table_prefix Return: -none- ------------------------------------------------------------- */ function easyban_mysql_install($wpdb) { require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); $table_name = $wpdb->prefix . "banned"; $sql = "CREATE TABLE ".$table_name." ( id mediumint(8) unsigned NOT NULL auto_increment, address varchar(18) NOT NULL default '', reason varchar(255) NOT NULL default '', thetime int(15) NOT NULL, timespan int(15) NOT NULL, redireto varchar(255) NOT NULL default '', PRIMARY KEY (id) );"; dbDelta($sql); if ( !easyban_mysql_table_exists($wpdb, "banned")) { add_action('admin_menu', 'easyban_mysql_warning'); } } /* ------------------------------------------------------------- Name: easyban_mysql_table_exists Purpose: Check if the table exists in the database Receive: $wpdb, $table_name Return: -none- ------------------------------------------------------------- */ function easyban_mysql_table_exists($wpdb, $table) { if(!$wpdb->get_results("SHOW TABLES LIKE '%".$wpdb->prefix.$table."%'")) { return FALSE; } else { return TRUE; } } /* ------------------------------------------------------------- Name: easyban_mysql_warning Purpose: Database errors if things go wrong Receive: -none- Return: -none- ------------------------------------------------------------- */ function easyban_mysql_warning() { echo '

WARNING! The MySQL table was not created! You cannot store bans. Seek support at www.sothq.net.

'; } /* ------------------------------------------------------------- Name: easyban_remove_expired Purpose: Removes expired bans Receive: -none- Return: -none- ------------------------------------------------------------- */ function easyban_remove_expired() { global $wpdb; $SQL = "SELECT id, timespan FROM ".$wpdb->prefix."banned ORDER BY id asc"; $old_bans = $wpdb->get_results($SQL); foreach($old_bans as $ban) { if($ban->timespan >= date("U")) { $delSQL = "DELETE FROM ".$wpdb->prefix."banned WHERE id = ".$ban->id; $wpdb->query($delSQL); } } } /* ------------------------------------------------------------- Name: easyban_header Purpose: Checks if a user is banned or not Receive: -none- Return: -none- ------------------------------------------------------------- */ function easyban_header() { global $wpdb, $easyban_config; if($easyban_config['status'] == "on"){ ?> prefix."banned ORDER BY id asc"; $bans = $wpdb->get_results($SQL); foreach($bans as $ban) { if(netMatch($ban->address, $_SERVER['REMOTE_ADDR'])) { if(strlen($ban->redirto)>0){ $REDIR_URL=$ban->redirto; } else { $REDIR_URL=$easyban_config['redirect']; } ?>



You have been banned because of the reason bellow. Redirecting ...

Достъпът ви до този сайт е забранен поради причината по долу. Пренасочване ...


reason)>0) { ?>

reason;?>

= 10 ) { $address = htmlentities(trim($_POST['address'], "\t\n "), ENT_QUOTES); $reason = htmlentities(trim($_POST['reason'], "\t\n "), ENT_QUOTES); $timetype = htmlentities(trim($_POST['timetype'], "\t\n "), ENT_QUOTES); $timeset = htmlentities(trim($_POST['timeset'], "\t\n "), ENT_QUOTES); $redir_url = htmlentities(trim($_POST['redir_url'], "\t\n "), ENT_QUOTES); if(strlen($address)!=0 AND strlen($address)<=18 AND strlen($reason)<=255) { if($timetype == "d") { $timespan = ($timeset * 86400) + date("U"); } else if($timetype == "w") { $timespan = ($timeset * 604800) + date("U"); } else { $timespan = 0; } /* Query */ $postquery = "INSERT INTO ".$wpdb->prefix."banned (address, reason, thetime, timespan, redirto) VALUES ('$address', '$reason', '".date("U")."', '$timespan', '$redir_url') "; if($wpdb->query($postquery)) { header('Location: edit.php?page=wp-easyban.php&new_return=true'); } else { die(mysql_error()); } } } } /* ------------------------------------------------------------- Name: easyban_request_delete Purpose: Remove ban from database Receive: -none- Return: boolean ------------------------------------------------------------- */ function easyban_request_delete () { global $userdata, $wpdb; $ban_id = $_GET['delete_ban']; if($ban_id > 0) { $SQL = "SELECT ".$wpdb->prefix."banned.id, ".$wpdb->prefix."users.display_name as display_name FROM ".$wpdb->prefix."banned, ".$wpdb->prefix."users WHERE ".$wpdb->prefix."banned.id = '$ban_id'"; $ban = $wpdb->get_row($SQL); if ($userdata->user_level >= 10) { if(easyban_delete_banid($ban_id) == TRUE) { header('Location: edit.php?page=wp-easyban.php&deleted_return=true'); } else { die(mysql_error()); } } } } /* ------------------------------------------------------------- Name: easyban_delete_banid Purpose: Remove ban from database Receive: $ban_id Return: boolean ------------------------------------------------------------- */ function easyban_delete_banid ($ban_id) { if($ban_id > 0) { global $wpdb; $SQL = "DELETE FROM ".$wpdb->prefix."banned WHERE id = $ban_id"; if(!$wpdb->query($SQL)) { die(mysql_error()); } else { return TRUE; } } } /* ------------------------------------------------------------- Name: easyban_add_pages Purpose: Add pages to admin menus Receive: -none- Return: -none- ------------------------------------------------------------- */ function easyban_add_pages() { add_management_page('Bans', 'Bans', 10, __FILE__, 'easyban_manage_page'); add_options_page('Bans', 'Bans', 10, __FILE__, 'easyban_options_page'); } /* ------------------------------------------------------------- Name: easyban_manage_page Purpose: Admin management page Receive: -none- Return: -none- ------------------------------------------------------------- */ function easyban_manage_page() { global $wpdb, $easyban_config; if ($_GET['new_return'] == "true") : ?>

added.') ?>

deleted.') ?>

EasyBan management

Active IP bans get_results("SELECT * FROM " . $wpdb->prefix . "banned ORDER BY thetime asc"); ?>
ID Address Reason Date set Expiry date Redirect to
id; ?> address; ?> reason; ?> thetime); ?> timespan > 0) {echo date("d-m-Y H:i", $ban->timespan); } else { echo 'Never'; } ?> redirto; ?> Delete

Add ban

Address: (123.123.123.123)
Reason: (Max. 255 characters, if filled in this will be shown to the banned person.)
Redirect to (Max. 255 characters, if filled in the banned ip will be redirected to this)
How long: (Leave field empty when using permanent. Fill in a number higher than 0 when using another option!)
Hints and tips: * Banning someone with an address in the 10.x.x.x/ 169.254.x.x / 172.16.x.x or 192.168.x.x range might not work as expected. These are reserved addresses for Small networks like the one you use at home or your work!
* Never set a ban on 127.0.0.1!
* An IP address ALWAYS contains 4 parts with numbers no higher than 254 separated by a dot!
* If a ban does not seem to work try to find out if the person you're trying to ban doesn't use DHCP.
* For more questions please seek help at My forum.
* A timed ban is automatically removed when it expires.

= 10) { ?>

Ban options

Activate:
Enable timed bans:
Redirect to: (include 'http://')
Redirect delay: (default: 3 sec)

Uninstall EasyBan

Banned installs a table in MySQL. When you disable the plugin the table will not be deleted. To delete the table use the button below.

WARNING! -- This process is irreversible and will delete ALL active bans!

No other parts of your wordpress installation will be touched.

= 10 ) { //options page $option['status'] = trim($_POST['status'], "\t\n "); $option['redirect'] = trim($_POST['redirect'], "\t\n "); $option['delay'] = trim($_POST['delay'], "\t\n "); $option['length'] = trim($_POST['length'], "\t\n "); update_option('easyban_config', $option); } } /* ------------------------------------------------------------- Name: easyban_plugin_uninstall Purpose: Delete the entire database table and remove the options on uninstall. Receive: -none- Return: -none- ------------------------------------------------------------- */ function easyban_plugin_uninstall() { global $easyban_scriptname, $user_level; if ( $user_level >= 10 ) { // Drop MySQL Tables $SQL = "DROP TABLE ".$wpdb->prefix."banned"; $wpdb->query($SQL); // Delete Option delete_option('easyban_config'); // Deactivate Plugin $current = get_settings('active_plugins'); array_splice($current, array_search("$easyban_scriptname", $current), 1 ); update_option('active_plugins', $current); $redirect_url = wp_nonce_url("plugins.php?action=deactivate&plugin=wp-easyban.php", 'deactivate-plugin_wp-easyban.php'); header('Location: '.$redirect_url); die(); } } ?>