Index: apache.conf
===================================================================
--- apache.conf	(revision 0)
+++ apache.conf	(revision 0)
@@ -0,0 +1,27 @@
+## infoarena apache config
+
+# Allow both <?php ?> and <? ?>
+# Also allow <?= ?>
+php_value short_open_tag 1
+
+# Forum config
+Alias /infoarena2-dev/forum "/home/stanandrei/trunk/smf/"
+<Directory "/home/stanandrei/trunk/smf/">
+    Order deny,allow
+    Deny from all
+    Allow from 127.0.0.1
+    AllowOverride All
+    DirectoryIndex index.php
+</Directory>
+
+# Main site.
+Alias /infoarena2-dev/ "/home/stanandrei/trunk/www/"
+<Directory "/home/stanandrei/trunk/www/">
+    Order deny,allow
+    Deny from all
+    Allow from 127.0.0.1
+    AllowOverride All
+    DirectoryIndex index.php
+</Directory>
+
+
Index: common/ban.php
===================================================================
--- common/ban.php	(revision 0)
+++ common/ban.php	(revision 0)
@@ -0,0 +1,57 @@
+<?php
+
+require_once(IA_ROOT_DIR . "common/db/db.php");
+require_once(IA_ROOT_DIR . "common/user.php");
+
+// The next two functions add a ban for the current user
+function username_add_ban($username, $expire_date) {
+    $safe_user = db_escape($username);
+    db_query("INSERT INTO ia_ban_user (username, expire)
+              VALUES ('$safe_user', '$expire_date') ");
+}
+
+function userip_add_ban($user_ip, $expire_date) {
+    $safe_ip = db_escape($user_ip);
+    db_query("INSERT INTO ia_ban_ip (user_ip, expire)
+              VALUES ('$safe_ip', '$expire_date') ");
+}
+
+// The next two functions remove the ban from the current user
+function username_remove_ban($username) {
+    $safe_user = db_escape($username);
+    db_query("DELETE FROM ia_ban_user
+              WHERE username = '$safe_user' ");
+}
+
+function userip_remove_ban($user_ip) {
+    $safe_ip = db_escape($user_ip);
+    db_query("DELETE FROM ia_ban_ip
+              WHERE user_ip = '$safe_ip' ");
+}
+
+//Checks if the current user has a banned username or ip
+function user_test_ban($username, $user_ip) {
+    $current_date = date("Y-m-d");
+    $is_banned = false;
+    $safe_user = db_escape($username);
+
+    error_log($current_date);
+
+    $rows = db_fetch_all("SELECT *
+                          FROM ia_ban_user
+                          WHERE username = '$safe_user'
+                          AND expire > '$current_date'");
+    if ($rows != NULL)
+        $is_banned = true;
+
+    $rows = db_fetch_all("SELECT *
+                          FROM ia_ban_ip
+                          WHERE user_ip = '$user_ip'
+                          AND expire > '$current_date'");
+    if ($rows !=  NULL)
+        $is_banned = true;
+
+    return $is_banned;
+}
+
+?>
Index: common/lcs
===================================================================

Property changes on: common/lcs
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + application/octet-stream

Index: config.php
===================================================================
--- config.php	(revision 0)
+++ config.php	(revision 0)
@@ -0,0 +1,157 @@
+<?php
+
+// Global configuration file.
+// This is just a sample file. Copy this over to config.php and edit.
+
+// Here is the essential configuration. You only need to modify this
+// to get it working.
+
+// This is the subversion checkout directory. include trailing slash.
+define("IA_ROOT_DIR", '/home/stanandrei/trunk/');
+
+// Database host. Probably localhost.
+define("IA_DB_HOST", 'localhost');
+
+// Database name.
+define("IA_DB_NAME", 'infoarena2');
+
+// Database user.
+define("IA_DB_USER", 'root');
+
+// Database password
+define("IA_DB_PASS", '');
+
+// Keep database connection alive when lost
+define("IA_DB_KEEP_ALIVE", false);
+
+// Web host. This is probably localhost. no trailing slash here
+define("IA_URL_HOST", "http://localhost");
+
+// URL prefix, without the IA_URL_HOST part
+// (only the part relative to the web server).
+// Slashes at both ends.
+define("IA_URL_PREFIX", "/infoarena2-dev/");
+
+
+// Congratulations! You're done with the essential configuration.
+// --------------------------------------------------------------
+// There are some more settings to adjust but they are optional.
+
+// Enable this when working on your own local copy. It gives you a few
+// debugging & profiling tools. Additionally, it disables Google Analytics
+// or other external resources.
+define("IA_DEVELOPMENT_MODE", true);
+
+// Determine if script is runing in an HTTP environment. Otherwise it is
+// probably running in CLI mode. Don't change it.
+// FIXME: move to common/common.php
+define("IA_HTTP_ENV", isset($_SERVER['REQUEST_URI']));
+
+// SMF database prefix (required!)
+define("IA_SMF_DB_PREFIX", 'ia_smf_');
+
+// "The" url to infoarena home page.
+define("IA_URL", IA_URL_HOST . IA_URL_PREFIX);
+
+// URL to SMF. No trailing slash
+// Example: http://localhost/infoarena_smf
+define("IA_SMF_URL", IA_URL . 'forum');
+
+// cookie domain
+// leave null when working on localhost
+define("IA_COOKIE_DOMAIN", null);
+
+// infoarena session lifetime
+// defaults to 5days
+define("IA_SESSION_LIFETIME_SECONDS", 5*24*3600);
+
+// Fatal error mask.
+// These are the errors the scripts halts on.
+// E_ALL & ~ (E_USER_NOTICE | E_USER_WARNING)
+// FIXME: Why isn't this configurable in php.ini?
+define("IA_PHP_FATAL_ERROR_MASK", 0x19FF);
+
+// If this is true then the site is in debug.
+// NOTE: set this to false when public.
+define("IA_DEBUG_MODE", true);
+
+// This aren't really settings.
+// FIXME: Couldn't find a better place to put this in.
+//  - NOTE: it can't reside in common/db/*.php files since SMF
+//    cannot link db api.
+//  - NOTE: it can't reside in www/* since judge needs it too
+define("IA_TASK_TEXTBLOCK_PREFIX", 'problema/');
+define("IA_USER_TEXTBLOCK_PREFIX", 'utilizator/');
+define("IA_NEWSLETTER_TEXTBLOCK_PREFIX", 'newsletter/');
+// FIXME: Do we really need this?
+define("IA_ROUND_TEXTBLOCK_PREFIX", 'runda/');
+
+// Secret code
+// Random string used as salt in various places where hashing is needed.
+// For security reasons, this should be changed when uploading to a production
+// website.
+define("IA_SECRET", "developersetup");
+
+// Mail setup
+
+// Enable this only if you have a SMTP server around
+define("IA_SMTP_ENABLED", false);
+
+if (IA_SMTP_ENABLED) {
+    // only if SMTP is enabled, you can configure these
+    define("IA_SMTP_HOST", "localhost");
+    define("IA_SMTP_PORT", "25");
+}
+
+// Disable mysql_unbuffered_query
+define("IA_DB_MYSQL_UNBUFFERED_QUERY", false);
+
+// Enable the DB cache by default.
+// If it's broken then you have a bug.
+// Disabling it might still be usefull for mysql tweaking.
+define("IA_ENABLE_DB_CACHE", true);
+
+// Enabled the create_function_cached cached.
+// If false then create_function_cached_cached is the same as create_function_cached
+define("IA_ENABLE_CREATE_FUNCTION_CACHE", true);
+
+
+// Disable memory cache by default because it requires additional stuff
+define("IA_MEM_CACHE_METHOD", "none");
+
+// Default TTL for cache items.
+define("IA_MEM_CACHE_EXPIRATION", 3600);
+
+// Round TTL. Smaller because of evaluator.
+define("IA_MEM_CACHE_ROUND_EXPIRATION", 10);
+
+// Task TTL. Smaller because of evaluator.
+define("IA_MEM_CACHE_TASK_EXPIRATION", 10);
+
+// TTL for tag caches.
+define("IA_MEM_CACHE_TAGS_EXPIRATION", 600);
+
+// Logging options. Anything else in normal operation is a bug.
+// Filling error_log on a production machine sucks.
+
+// If true then log all security checks.
+// Warning: tons of output.
+define("IA_LOG_SECURITY", false);
+
+// If true then log disk cache hits/misses
+define("IA_LOG_DISK_CACHE", false);
+
+// If true then log mem cache hits/misses
+define("IA_LOG_MEM_CACHE", false);
+
+// Log each and every SQL query. Not for the faint of heart.
+define("IA_LOG_SQL_QUERY", false);
+
+// Try to EXPLAIN every select query, useful when optimizing.
+define("IA_LOG_SQL_QUERY_EXPLAIN", false);
+
+// CAPTHCA Keys
+define("IA_CAPTCHA_PUBLIC_KEY", "6LesuwQAAAAAAPHgdh9Hem1KJfvd5Ng1yRoIweio");
+define("IA_CAPTCHA_PRIVATE_KEY", "6LesuwQAAAAAAF3FUPWFGQD1xPITFagjqWUO9Urs");
+
+?>
Index: scripts/migrate-ban-ip.php
===================================================================
--- scripts/migrate-ban-ip.php	(revision 0)
+++ scripts/migrate-ban-ip.php	(revision 0)
@@ -0,0 +1,18 @@
+#! /usr/bin/env php
+<?php
+    //This script creates the two necessary tables for banning users
+    require_once(dirname($argv[0]) . "/utilities.php");
+    db_connect();
+
+    $query = "CREATE TABLE `ia_ban_user` (
+              `username` VARCHAR(64) NOT NULL,
+              `expire` timestamp,
+              PRIMARY KEY (username))";
+    db_query($query);
+
+    $query = "CREATE TABLE `ia_ban_ip` (
+              `user_ip` VARCHAR(64) NOT NULL,
+              `expire` timestamp,
+              PRIMARY KEY (user_ip))";
+    db_query($query);
+?>

Property changes on: scripts/migrate-ban-ip.php
___________________________________________________________________
Added: svn:executable
   + *

Index: www/controllers/ban.php
===================================================================
--- www/controllers/ban.php	(revision 0)
+++ www/controllers/ban.php	(revision 0)
@@ -0,0 +1,54 @@
+<?php
+    require_once(IA_ROOT_DIR . "common/ban.php");
+    require_once(IA_ROOT_DIR . "common/db/db.php");
+    require_once(IA_ROOT_DIR . "common/user.php");
+    require_once(IA_ROOT_DIR . "common/common.php");
+
+    function controller_ban() {
+        $view = array();
+        $view['title'] = 'Formular de banare';
+
+		// the data for banning is stored in an array
+        $data = array();
+
+        // this is where the validation errors are stored
+        $errors = array();
+
+        $submit = request_is_post();
+
+        if ($submit) {
+            //Validate data and place stuff in errors
+            $data['username'] = getattr($_POST, 'username');
+            $data['IP'] = getattr($_POST, 'IP');
+            $data['expire_date'] = getattr($_POST, 'expire_date');
+            $data['ban_username'] = getattr($_POST, 'ban_username');
+            $data['ban_userip'] = getattr($_POST, 'ban_userip');
+
+            $errors['valid_ip'] = is_valid_ip_address($data['IP']);
+            $errors['valid_date'] = is_db_date($data['expire_date']);
+            $errors['select'] = $data['ban_username'] || $data['ban_userip'];
+
+            if ($erorrs['select']) {
+                flash_error("Selectati un tip pentru ban!");
+            } else {
+                if ($errors['valid_ip'] == false && $data['ban_userip'] == true) {
+                    flash_error('Reintroduceti ip-ul utilizatorului!');
+                } else {
+                    if ($errors['valid_date'] == false) {
+                        flash_error('Reintroduceti data expirarii banului!');
+				    } else {
+                        if ($data['ban_username']) {
+                            username_add_ban($data['username'], $data['expire_date']);
+                        }
+
+                        if ($data['ban_userip']) {
+                            userip_add_ban($data['IP'], $data['expire_date']);
+                        }
+                    }
+                }
+            }
+        }
+
+        execute_view_die('views/ban.php', $view);
+    }
+?>
Index: www/controllers/login.php
===================================================================
--- www/controllers/login.php	(revision 1150)
+++ www/controllers/login.php	(working copy)
@@ -1,6 +1,7 @@
 <?php
 
 require_once(IA_ROOT_DIR . "common/db/user.php");
+require_once(IA_ROOT_DIR . "common/ban.php");
 
 function controller_login() {
     global $identity_user;
@@ -21,7 +22,14 @@
         $data['username'] = getattr($_POST, 'username');
         $data['password'] = getattr($_POST, 'password');
         $data['remember'] = getattr($_POST, 'remember');
+        $data['user_ip'] = $_SERVER["REMOTE_ADDR"];
+
         $user = user_test_password($data['username'], $data['password']);
+        $ban_user = user_test_ban($data['username'], $data['user_ip']);
+        if ($ban_user) {
+           $errors = true;
+        }
+
         if (!$user) {
             $user = user_test_ia1_password($data['username'], $data['password']);
             if (!$user) {
@@ -73,8 +81,13 @@
                 $_SESSION['_ia_redirect'] = $_SERVER['HTTP_REFERER'];
             }
 
-            flash_error('Numele de utilizator inexistent sau parola ' .
-                        'incorecta. Incearca din nou.');
+            if (!$user) {
+                flash_error('Numele de utilizator inexistent sau parola' .
+                            'incorecta. Incearca din nou!');
+            }
+            else {
+                flash_error('Contul sau IP-ul tau a fost suspendat!');
+            }
         }
     }
 
Index: www/index.php
===================================================================
--- www/index.php	(revision 1150)
+++ www/index.php	(working copy)
@@ -1,4 +1,5 @@
 <?php
+
 require_once("../config.php");
 require_once(IA_ROOT_DIR."www/config.php");
 require_once(IA_ROOT_DIR."common/log.php");
@@ -64,6 +65,12 @@
     $fname($page_id);
 }
 
+// Ban page
+else if ($page == 'ban') {
+    require_once(IA_ROOT_DIR.'www/controllers/ban.php');
+                 controller_ban();
+}
+
 // Account edit page
 else if ($urlstart == 'account') {
     require_once(IA_ROOT_DIR.'www/controllers/account.php');
Index: www/static/images/ban.png
===================================================================

Property changes on: www/static/images/ban.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Index: www/static/images/icons/ban.png
===================================================================

Property changes on: www/static/images/icons/ban.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Index: www/url.php
===================================================================
--- www/url.php	(revision 1150)
+++ www/url.php	(working copy)
@@ -387,6 +387,10 @@
     return IA_SMF_URL;
 }
 
+function url_ban() {
+    return url_complex("ban", array());
+}
+
 // Newsletter
 
 function url_newsletter($page_name, $rev = null) {
Index: www/utilities.php
===================================================================
--- www/utilities.php	(revision 1150)
+++ www/utilities.php	(working copy)
@@ -73,7 +73,7 @@
 // printing stuff too early or you're trying to redirect too late (view?).
 // Either way, it is a bug and it must be solved rather than handled gracefully
 //
-// FIXME: bool to se ia_redirect to REQUEST_URI? might be usefull.
+// FIXME: bool to see ia_redirect to REQUEST_URL? might be usefull.
 function redirect($absolute_url) {
     header("Location: {$absolute_url}\n\n");
     session_write_close();
Index: www/views/ban.php
===================================================================
--- www/views/ban.php	(revision 0)
+++ www/views/ban.php	(revision 0)
@@ -0,0 +1,22 @@
+<?php
+    global $identity_user;
+
+    require_once(IA_ROOT_DIR.'www/format/format.php');
+    require_once(IA_ROOT_DIR.'www/wiki/wiki.php');
+    require_once(IA_ROOT_DIR.'www/identity.php');
+    require_once(IA_ROOT_DIR.'www/url.php');
+    require_once(IA_ROOT_DIR.'common/user.php');
+
+    if (!user_is_admin($identity_user) || identity_is_anonymous()) {
+        flash_error("Nu aveti permisiunile necesare pentru a accesa aceasta pagina!");
+        redirect(url_home());
+    } else {
+        include('header.php');
+
+        echo format_tag('h1', html_escape($view['title']));
+        echo ("Completati datele necesare, iar apoi selectati tipul banului(username sau ip).");
+        include(IA_ROOT_DIR.'www/views/form_ban.php');
+
+        include('footer.php');
+    }
+?>
Index: www/views/form_ban.php
===================================================================
--- www/views/form_ban.php	(revision 0)
+++ www/views/form_ban.php	(revision 0)
@@ -0,0 +1,36 @@
+<form action="<?= html_escape(url_ban()) ?>" method="post" class="ban">
+<fieldset>
+    <legend><img src="<?= html_escape(url_static('images/ban.png')) ?>" alt="!" /> </legend>
+    <ul class="form">
+<?= view_form_field_li(array(
+        'name' => 'Cont de utilizator',
+        'type' => 'string',
+        'access_key' => 'c',
+), 'username') ?>
+<?= view_form_field_li(array(
+        'name' => 'IP',
+        'type' => 'string',
+        'access_key' => 'i',
+), 'IP') ?>
+<?= view_form_field_li(array(
+        'name' => 'Data expirarii banului (in format YYYY-MM-DD)',
+        'type' => 'string',
+        'access_key' => 'd',
+), 'expire_date') ?>
+
+        <li>
+			<input type="checkbox" value="on" id="form_remember" name="ban_username" class="checkbox"<?= fval('ban_username') ? ' checked="checked"' : '' ?>/>
+			<label class="checkbox"> ban pe username</label>
+
+			<br/>
+
+			<input type="checkbox" value="on" id="form_remember" name="ban_userip" class="checkbox"<?= fval('ban_username') ? ' checked="checked"' : '' ?>/>
+			<label class="checkbox"> ban pe ip</label>
+        </li>
+        <li>
+            <input type="submit" value="Baneaza!" id="form_submit" class="button important" />
+        </li>
+    </ul>
+</fieldset>
+</form>
+
