Changeset 997


Ignore:
Timestamp:
01/29/09 14:55:38 (3 years ago)
Author:
strat.cristian@…
Message:

Log remote IP and X-Forwarded-For header on job submit, textblock create/edit, and attachment upload. For privacy considerations, IP addresses are only displayed to admins and helpers.

  • Contains database migration script.
  • Adds new simplified security action. (sensitive-info)
Location:
trunk
Files:
1 added
34 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/common.php

    r935 r997  
    3838define("IA_RE_USER_NAME", '[_@a-z0-9][a-z0-9_\-\.\@]*'); 
    3939 
     40// IPv4 address, doesn't check for values greater than 255. 
     41define("IA_RE_IPV4", '(?:\d{1,3}\.){3}\d{1,3}'); 
     42// Full IPv6 address, doesn't match compressed IPv6 formats. 
     43define("IA_RE_IPV6_NO_COMPRESS", '(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}'); 
     44// IP address, matches IPv4 and non-compressed IPv6. 
     45define("IA_RE_IP_ADDRESS", IA_RE_IPV4."|".IA_RE_IPV6_NO_COMPRESS); 
     46 
    4047// Valid email. A complete check is not possible, see 
    4148// http://www.regular-expressions.info/email.html 
     
    101108    } 
    102109    return true; 
     110} 
     111 
     112// Check for (apparently) valid IP address. 
     113// It will match IPv4 and only non-compressed IPv6. Doesn't check 
     114// for values greater than 255. 
     115function is_valid_ip_address($ip_address) { 
     116    return preg_match('/^'.IA_RE_IP_ADDRESS.'$/xi', $ip_address); 
    103117} 
    104118 
  • trunk/common/db/attachment.php

    r852 r997  
    6565 
    6666// Update an attachment. FIXME: hash args. 
    67 function attachment_update($id, $name, $size, $mime_type, $page, $user_id) { 
     67function attachment_update($id, $name, $size, $mime_type, $page, $user_id, 
     68        $remote_ip_info) { 
    6869    $attachment = array( 
    6970            'id' => $id, 
     
    7475            'user_id' => $user_id, 
    7576            'timestamp' => db_date_format(), 
     77            'remote_ip_info' => $remote_ip_info, 
    7678    ); 
    7779 
     
    8284 
    8385// Inserts an attachment in the db 
    84 function attachment_insert($name, $size, $mime_type, $page, $user_id) { 
     86function attachment_insert($name, $size, $mime_type, $page, $user_id, 
     87        $remote_ip_info) { 
    8588    $attachment = array( 
    8689            'name' => $name, 
     
    9093            'user_id' => $user_id, 
    9194            'timestamp' => db_date_format(), 
     95            'remote_ip_info' => $remote_ip_info, 
    9296    ); 
    9397 
     
    9599    $attachment['id'] = db_insert_id(); 
    96100    _attachment_cache_add($attachment); 
    97      
     101 
    98102    return $attachment['id']; 
    99103} 
  • trunk/common/db/db.php

    r909 r997  
    262262} 
    263263 
     264// FIXME: This shouldn't be here. Move it in common/db/task.php or 
     265// common/db/round.php 
    264266function db_get_task_filter_clause($filter, $table_alias) { 
    265267    if ($filter == IA_TLF_SOLVED) { 
  • trunk/common/db/job.php

    r996 r997  
    2222 
    2323// Creates new eval job 
    24 function job_create($task_id, $round_id, $user_id, $compiler_id, $file_contents) { 
     24function job_create($task_id, $round_id, $user_id, $compiler_id, $file_contents, 
     25        $remote_ip_info = null) { 
    2526    $query = <<<SQL 
    2627        INSERT INTO ia_job 
    27             (`task_id`, `round_id`, `user_id`, `compiler_id`, `file_contents`, `submit_time`) 
    28         VALUES (%s, %s, %s, %s, %s, %s) 
     28            (`task_id`, `round_id`, `user_id`, `compiler_id`, `file_contents`, 
     29             `submit_time`, `remote_ip_info`) 
     30        VALUES (%s, %s, %s, %s, %s, %s, %s) 
    2931SQL; 
    3032    $query = sprintf($query, 
    3133            db_quote($task_id), db_quote($round_id), db_quote($user_id), 
    32             db_quote($compiler_id), db_quote($file_contents), db_quote(db_date_format())); 
     34            db_quote($compiler_id), db_quote($file_contents), 
     35            db_quote(db_date_format()), db_quote($remote_ip_info)); 
    3336    return db_query($query); 
    3437} 
     
    4043SELECT `job`.`id`, `job`.`user_id`, `job`.`task_id`, `job`.`round_id`, 
    4144       `job`.`compiler_id`, `job`.`status`, `job`.`submit_time`, 
    42        `job`.`eval_message`, `job`.`score`, `job`.`file_contents` 
     45       `job`.`eval_message`, `job`.`score`, `job`.`file_contents`, 
     46       `job`.`remote_ip_info` 
    4347    FROM `ia_job` AS `job` 
    4448    WHERE `job`.`id` = ( 
     
    8387    log_assert(is_whole_number($job_id)); 
    8488    $field_list = "`job`.`id`, job.`user_id`, `job`.`compiler_id`, `job`.`status`, 
    85                    `job`.`submit_time`, `job`.`eval_message`, `job`.`score`, `job`.`eval_log`, 
     89                   `job`.`submit_time`, `job`.`eval_message`, `job`.`score`, 
     90                   `job`.`eval_log`, `job`.`remote_ip_info`, 
    8691                   OCTET_LENGTH(`job`.`file_contents`) AS `job_size`, 
    8792                   `user`.`username` AS `user_name`, `user`.`full_name` AS `user_fullname`, 
     
    128133    $score_end = getattr($filters, 'score_end'); 
    129134    $eval_msg = getattr($filters, 'eval_msg'); 
     135    $remote_ip_info = getattr($filters, 'remote_ip_info'); 
    130136 
    131137    $wheres = array("TRUE"); 
     
    172178    if (!is_null($eval_msg)) { 
    173179        $wheres[] = sprintf("`job`.`eval_message` LIKE '%s%%'", db_escape($eval_msg)); 
     180    } 
     181    if (!is_null($remote_ip_info)) { 
     182        // We allow remote_ip_info to contain % wildcards. This will make it a bit 
     183        // easier to search for IP classes. 
     184        $wheres[] = sprintf("`job`.`remote_ip_info` LIKE '%s'", db_escape($remote_ip_info)); 
    174185    } 
    175186 
     
    232243            `job`.`eval_message`, 
    233244            `job`.`eval_log`, 
     245            `job`.`remote_ip_info`, 
    234246            OCTET_LENGTH(`job`.`file_contents`) AS `job_size`, 
    235247            `user`.`username` AS `user_name`, 
  • trunk/common/db/round.php

    r992 r997  
    2929// Create new round 
    3030// Return success. 
    31 function round_create($round, $round_params, $user_id) { 
     31function round_create($round, $round_params, $user_id, $remote_ip_info = null) { 
    3232    log_assert(is_user_id($user_id)); 
    3333    log_assert_valid(round_validate($round)); 
     
    4545        $replace = array("round_id" => $round['id']); 
    4646        textblock_copy_replace("template/newround", $round['page_name'], 
    47                 $replace, "round: {$round['id']}", $user_id); 
     47                $replace, "round: {$round['id']}", $user_id, $remote_ip_info); 
    4848 
    4949        _round_cache_add($round); 
  • trunk/common/db/task.php

    r982 r997  
    3535 
    3636// Create new task 
    37 function task_create($task, $task_params) { 
     37function task_create($task, $task_params, $remote_ip_info = null) { 
    3838    log_assert_valid(task_validate($task)); 
    3939    log_assert_valid(task_validate_parameters($task['type'], $task_params)); 
     
    4848        $replace = array("task_id" => $task['id'], "task_title" => ucfirst($task['id'])); 
    4949        textblock_copy_replace("template/newtask", $task['page_name'], 
    50                 $replace, "task: {$task['id']}", $task['user_id']); 
     50                $replace, "task: {$task['id']}", $task['user_id'], $remote_ip_info); 
    5151 
    5252        _task_cache_add($task); 
  • trunk/common/db/textblock.php

    r987 r997  
    1515function textblock_add_revision( 
    1616        $name, $title, $content, $user_id, $security = "public", 
    17         $forum_topic = null, $timestamp = null, $creation_timestamp = null) { 
     17        $forum_topic = null, $timestamp = null, $creation_timestamp = null, 
     18        $remote_ip_info = null) { 
    1819    $name = normalize_page_name($name); 
    1920    $tb = array( 
     
    2627            'timestamp' => $timestamp, 
    2728            'creation_timestamp' => $creation_timestamp, 
     29            'remote_ip_info' => $remote_ip_info, 
    2830    ); 
    2931    log_assert_valid(textblock_validate($tb)); 
     
    5961    } 
    6062    $query = sprintf("INSERT INTO ia_textblock 
    61                         (name, `text`, `title`, `creation_timestamp`, `timestamp`, `user_id`, `security`, `forum_topic`) 
    62                       VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', %s)", 
    63                      db_escape($name), db_escape($content), 
    64                      db_escape($title), db_escape($creation_timestamp),  
    65                      db_escape($timestamp), db_escape($user_id), 
    66                      db_escape($security), 
    67                      is_null($forum_topic) ? "NULL" : db_escape($forum_topic)); 
     63            (name, `text`, `title`, `creation_timestamp`, 
     64                    `timestamp`, `user_id`, `security`, `forum_topic`, 
     65                    `remote_ip_info`) 
     66            VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', %s, %s)", 
     67            db_escape($name), db_escape($content), db_escape($title), 
     68            db_escape($creation_timestamp), db_escape($timestamp), 
     69            db_escape($user_id), db_escape($security), db_quote($forum_topic), 
     70            db_quote($remote_ip_info)); 
    6871    return db_query($query); 
    6972} 
     
    7477    // log_print_r($options); 
    7578 
    76     $field_list = "`name`, `title`, `creation_timestamp`, `timestamp`, `security`, `user_id`, `forum_topic`"; 
     79    $field_list = "`name`, `title`, `creation_timestamp`, `timestamp`, `security`, `user_id`, 
     80            `forum_topic`, `remote_ip_info`"; 
    7781 
    7882    // Select content. 
     
    212216        $compare = "REGEXP"; 
    213217    } 
    214     $query = sprintf("SELECT `name`, `title`, `creation_timestamp`, `timestamp`, `user_id`, `security`, `forum_topic` 
     218    $query = sprintf("SELECT `name`, `title`, `creation_timestamp`, `timestamp`, 
     219                            `user_id`, `security`, `forum_topic`, 
     220                            `remote_ip_info` 
    215221                      FROM ia_textblock 
    216222                      WHERE `name` LIKE '%s' AND 
     
    289295} 
    290296 
    291 function textblock_copy($old_name, $new_name) { 
     297function textblock_copy($old_name, $new_name, $user_id, $remote_ip_info) { 
    292298    $old_name = normalize_page_name($old_name); 
    293299    $new_name = normalize_page_name($new_name); 
     
    297303    $new_textblock = textblock_get_revision($old_name); 
    298304    $new_textblock['name'] = $new_name; 
    299     $new_textblock['user_id'] = identity_get_user_id(); 
     305    $new_textblock['user_id'] = $user_id; 
    300306    textblock_add_revision($new_textblock['name'], $new_textblock['title'], 
    301307                           $new_textblock['text'], $new_textblock['user_id'], 
    302308                           $new_textblock['security'], 
    303                            $new_textblock['forum_topic'], null, null); 
     309                           $new_textblock['forum_topic'], null, null, 
     310                           $remote_ip_info); 
    304311 
    305312    // Get a list of attachments. 
     
    309316    foreach ($files as $file) { 
    310317        // Copy in db and get new id 
    311         $new_id = attachment_insert($file['name'], $file['size'], $file['mime_type'], $new_name, identity_get_user_id()); 
     318        $new_id = attachment_insert($file['name'], $file['size'], 
     319                $file['mime_type'], $new_name, $user_id, $remote_ip_info); 
    312320 
    313321        // Copy on hard drive 
  • trunk/common/db/user.php

    r911 r997  
    150150    $replace = array("user_id" => $user['username']); 
    151151    textblock_copy_replace("template/newuser", IA_USER_TEXTBLOCK_PREFIX.$user['username'], 
    152                            $replace, "public", $new_user['id']); 
     152                           $replace, "public", $new_user['id'], null); 
    153153 
    154154    // Create SMF user 
  • trunk/common/job.php

    r993 r997  
    7878        if (array_key_exists('round_id', $args)) { 
    7979            job_create($args['task_id'], $args['round_id'], $user['id'], 
    80                     $args['compiler_id'], $args['solution']); 
     80                    $args['compiler_id'], $args['solution'], 
     81                    getattr($args, 'remote_ip_info')); 
    8182        } else { 
    8283            $parent_rounds = task_get_parent_rounds($args['task_id']); 
     
    8485                // some jobs just don't have a round 
    8586                job_create($args['task_id'], '', $user['id'], 
    86                         $args['compiler_id'], $args['solution']); 
     87                        $args['compiler_id'], $args['solution'], 
     88                        getattr($args, 'remote_ip_info')); 
    8789            } 
    8890            else { 
     
    9092                    if (security_query($user, 'round-submit', round_get($round_id))) { 
    9193                        job_create($args['task_id'], $round_id, $user['id'], 
    92                                 $args['compiler_id'], $args['solution']); 
     94                                $args['compiler_id'], $args['solution'], 
     95                                getattr($args, 'remote_ip_info')); 
    9396                    } 
    9497                } 
  • trunk/common/log.php

    r934 r997  
    112112 
    113113// Use this for warning messages. 
    114 function log_warn($message, $include_origin = false) { 
     114function log_warn($message, $include_origin = false, $backtrace_level = 0) { 
    115115    if ($include_origin) { 
    116         $message = format_message_backtrace($message); 
     116        $message = format_message_backtrace($message, $backtrace_level); 
    117117    } 
    118118    trigger_error_split($message, E_USER_WARNING); 
  • trunk/common/security.php

    r996 r997  
    103103        case 'round-register-view': 
    104104            return 'simple-view'; 
     105 
     106        // View IP. 
     107        case 'attach-view-ip': 
     108        case 'textblock-view-ip': 
     109        case 'job-view-ip': 
     110            return 'sensitive-info'; 
    105111 
    106112        // Reversible edits access. 
     
    245251            } 
    246252 
     253        case 'sensitive-info': 
     254            return ($usersec == 'admin' || $usersec == 'helper'); 
     255 
    247256        // Reversible modifications. 
    248257        case 'simple-rev-edit': 
     
    410419            } 
    411420            return $can_view || $is_owner || $is_admin; 
     421 
     422        case 'sensitive-info': 
     423            return ($usersec == 'admin' || $usersec == 'helper'); 
    412424 
    413425        default: 
     
    466478            } 
    467479 
     480        case 'sensitive-info': 
     481            return ($usersec == 'admin' || $usersec == 'helper'); 
     482 
    468483        default: 
    469484            log_error('Invalid round action: '.$action); 
     
    520535    $can_view_score = ($job['round_public_eval'] == true) || $is_task_owner || $is_admin; 
    521536    $can_view_partial_feedback = $is_owner || $is_admin; 
     537    $can_view_sensitive_info = ($usersec == 'admin' || $usersec == 'helper'); 
    522538 
    523539    // Log query response. 
     
    550566            return $can_view_job && $can_view_partial_feedback; 
    551567 
     568        case 'sensitive-info': 
     569            return $can_view_job && $can_view_sensitive_info; 
     570 
    552571        default: 
    553572            log_error('Invalid job action: '.$action); 
  • trunk/common/textblock.php

    r970 r997  
    149149// 
    150150// Use this like textblock_copy_replace('template/newtask', 'problema/capsuni'); 
    151 function textblock_copy_replace($srcprefix, $dstprefix, $replace, $security, $user_id) 
    152 { 
     151function textblock_copy_replace($srcprefix, $dstprefix, $replace, $security, 
     152        $user_id, $remote_ip_info = null) { 
    153153    assert($srcprefix != $dstprefix); 
    154154    assert(is_textblock_security_descriptor($security)); 
     
    174174                $textblock['text'], $user_id, $textblock['security'], 
    175175                $textblock['forum_topic'], null, 
    176                 $first_textblock['creation_timestamp']); 
     176                $first_textblock['creation_timestamp'], $remote_ip_info); 
    177177    } 
    178178} 
  • trunk/junk/userpage-fix.php

    r852 r997  
    2424            $replace = array("user_id" => $user['username']); 
    2525            textblock_copy_replace("template/newuser", $tbname, $replace, 
    26                     "public", $user['id']); 
     26                    "public", $user['id'], null); 
    2727        } 
    2828    } 
  • trunk/scripts/init-blog-comments

    r864 r997  
    3838        $new_page['timestamp'] = null; 
    3939        $new_page['user_id'] = 1; // update as "domino" :) 
     40        $new_page['remote_ip_info'] = getattr($post, 'remote_ip_info'); 
    4041 
    4142        // It worked 
     
    4445                                   $new_page['text'], $new_page['user_id'], 
    4546                                   $new_page['security'], $new_page['timestamp'], 
    46                                    $new_page['creation_timestamp']); 
     47                                   $new_page['creation_timestamp'], 
     48                                   $new_page['remote_ip_info']); 
    4749        } else { 
    4850            log_error('Eroare la validarea textblock-ului!'); 
  • trunk/scripts/link-task-forum

    r945 r997  
    3939                               $new_page['text'], $new_page['user_id'], 
    4040                               $new_page['security'], $new_page['timestamp'], 
    41                                $new_page['creation_timestamp']); 
     41                               $new_page['creation_timestamp'], 
     42                               $new_page['remote_ip_info']); 
    4243    } else { 
    4344        log_error('Eroare la validarea textblock-ului!'); 
  • trunk/scripts/migrate-newsletters-to-html

    r987 r997  
    7474    textblock_add_revision($textblock['name'], $textblock['title'], 
    7575            $new_text, $textblock['user_id'], $textblock['security'], 
    76             $textblock['forum_topic'], null, $textblock['creation_timestamp']); 
     76            $textblock['forum_topic'], null, $textblock['creation_timestamp'], 
     77            getattr($textblock. 'remote_ip_info')); 
    7778} 
    7879 
  • trunk/scripts/textblock-add-topic-id

    r961 r997  
    2121                               $page['user_id'], $page['security'], 
    2222                               $page["forum_topic"], $page['timestamp'], 
    23                                $page['creation_timestamp']); 
     23                               $page['creation_timestamp'], 
     24                               getattr($page, 'remote_ip_info')); 
    2425    } else { 
    2526        log_error('Eroare la procesarea ia_blog_forum!'); 
     
    4849                                   $page['user_id'], $page['security'], 
    4950                                   $page["forum_topic"], $page['timestamp'], 
    50                                    $page['creation_timestamp']); 
     51                                   $page['creation_timestamp'], 
     52                                   getattr($page, 'remote_ip_info')); 
    5153        } else { 
    5254            log_error('Eroare la procesarea paginii ' . $page["name"] . '!'); 
  • trunk/www/controllers/account.php

    r852 r997  
    108108                    // Attachment already exists, overwrite. 
    109109                    attachment_update($attach['id'], $file_name, $avatar_size, 
    110                                       $mime_type, $user_page, $user['id']); 
     110                                      $mime_type, $user_page, $user['id'], 
     111                                      remote_ip_info()); 
    111112                } else { 
    112113                    // New attachment. Insert. 
    113114                    attachment_insert($file_name, $avatar_size, 
    114                                       $mime_type, $user_page, $user['id']); 
     115                                      $mime_type, $user_page, $user['id'], 
     116                                      remote_ip_info()); 
    115117                } 
    116118 
  • trunk/www/controllers/account_validator.php

    r986 r997  
    77    $errors = validate_user_data($data, true, null); 
    88 
    9     if(!IA_DEVELOPMENT_MODE) { 
     9    if (!IA_DEVELOPMENT_MODE) { 
    1010        $resp = recaptcha_check_answer(IA_CAPTCHA_PRIVATE_KEY, 
    1111                                       $_SERVER["REMOTE_ADDR"], 
  • trunk/www/controllers/attachment.php

    r938 r997  
    178178                // Attachment already exists, overwrite. 
    179179                identity_require('attach-overwrite', $attach); 
    180                 attachment_update($attach['id'], $file_att['name'], $file_att['size'], 
    181                                   $file_att['type'], $page_name, $identity_user['id']); 
     180                attachment_update($attach['id'], $file_att['name'], 
     181                        $file_att['size'], $file_att['type'], $page_name, 
     182                        $identity_user['id'], remote_ip_info()); 
    182183                $rewrite_count++; 
    183184            } 
    184185            else { 
    185186                // New attachment. Insert. 
    186                 attachment_insert($file_att['name'], $file_att['size'], $file_att['type'], 
    187                                   $page_name, $identity_user['id']); 
     187                attachment_insert($file_att['name'], $file_att['size'], 
     188                        $file_att['type'], $page_name, $identity_user['id'], 
     189                        remote_ip_info()); 
    188190            } 
    189191 
  • trunk/www/controllers/job_filters.php

    r852 r997  
    77                               'job_id', 'time_begin', 'time_end', 'compiler', 
    88                               'status', 'score_begin', 'score_end', 
    9                                'eval_msg', 'task_hidden'); 
     9                               'eval_msg', 'task_hidden', 'remote_ip_info'); 
    1010 
    1111    $filters = array(); 
  • trunk/www/controllers/monitor.php

    r996 r997  
    1313    $view['filters'] = job_get_filters(); 
    1414    $view['user_name'] = getattr($identity_user, 'username'); 
     15 
    1516    // First row. 
    1617    // FIXME: shouldn't this constant be in config.php?  
  • trunk/www/controllers/round.php

    r911 r997  
    218218 
    219219            // This should never fail. 
    220             log_assert(round_create( 
    221                         $round, 
    222                         $round_params, 
    223                         identity_get_user_id() 
    224             )); 
     220            log_assert(round_create($round, $round_params, 
     221                    identity_get_user_id(), remote_ip_info())); 
    225222            flash("O noua runda a fost creata, acum poti sa editezi detalii."); 
    226223            redirect(url_round_edit($round['id'])); 
  • trunk/www/controllers/submit.php

    r852 r997  
    1313        $values = array( 
    1414            'task_id' => getattr($_POST, 'task_id'), 
    15             'compiler_id' => getattr($_POST, 'compiler_id') 
     15            'compiler_id' => getattr($_POST, 'compiler_id'), 
     16            'remote_ip_info' => remote_ip_info(), 
    1617        ); 
    1718 
  • trunk/www/controllers/task.php

    r996 r997  
    176176 
    177177            // This should never fail. 
    178             log_assert(task_create($task, $task_params)); 
     178            log_assert(task_create($task, $task_params, remote_ip_info())); 
    179179            flash("Un nou task a fost creeat, acum poti sa-l editezi"); 
    180180            redirect(url_task_edit($task['id'])); 
  • trunk/www/controllers/textblock.php

    r987 r997  
    144144                           getattr($identity_user, 'id'), $rev['security'], 
    145145                           $rev['forum_topic'], null, 
    146                            $rev['creation_timestamp']); 
     146                           $rev['creation_timestamp'], 
     147                           remote_ip_info()); 
    147148    flash("Pagina a fost inlocuita cu revizia {$rev_num}"); 
    148149    redirect(url_textblock($page_name)); 
  • trunk/www/controllers/textblock_copy.php

    r989 r997  
    3131 
    3232        if (!$errors) { 
    33             textblock_copy($page_name, $new_name); 
     33            textblock_copy($page_name, $new_name, identity_get_user_id(), 
     34                    remote_ip_info()); 
    3435            flash("Pagina a fost copiata."); 
    3536            redirect(url_textblock($new_name)); 
  • trunk/www/controllers/textblock_edit.php

    r964 r997  
    7979                                   $new_page['forum_topic'], 
    8080                                   $new_page['timestamp'], 
    81                                    $new_page['creation_timestamp']); 
     81                                   $new_page['creation_timestamp'], 
     82                                   remote_ip_info()); 
    8283            if (identity_can('textblock-tag', $new_page)) { 
    8384                tag_update("textblock", $new_page['name'], $values['tags']); 
  • trunk/www/static/css/screen.css

    r992 r997  
    8888    list-style-type: disc; 
    8989} 
    90  
    91  
    9290 
    9391/* block quotes */ 
  • trunk/www/utilities.php

    r934 r997  
    207207} 
    208208 
     209// Return information about the remote IP address. Useful for logging. 
     210// This isn't necessarily just an IP address. It might contain proxy 
     211// information when available. 
     212function remote_ip_info() { 
     213    $ip_address = getattr($_SERVER, 'REMOTE_ADDR'); 
     214    if ($ip_address && !is_valid_ip_address($ip_address)) { 
     215        log_warn("Invalid IP address: {$ip_address}", true, 1); 
     216    } 
     217    // FIXME: Also validate XFF header. 
     218    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
     219        return getattr($_SERVER, 'REMOTE_ADDR')."; " 
     220                .$_SERVER['HTTP_X_FORWARDED_FOR']; 
     221    } else { 
     222        return getattr($_SERVER, 'REMOTE_ADDR'); 
     223    } 
     224} 
     225 
    209226?> 
  • trunk/www/views/changes.php

    r934 r997  
    2929            "diff"); 
    3030$tstamp = format_date($rev['timestamp']); 
    31 echo "$tstamp: $userlink a modificat $pagelink ($difflink)."; 
     31if (identity_can('textblock-view-ip', $rev) && $rev['remote_ip_info']) { 
     32    $remote_ip = '('.$rev['remote_ip_info'].') '; 
     33} else { 
     34    $remote_ip = ''; 
     35} 
     36echo "$tstamp: $userlink {$remote_ip}a modificat $pagelink ($difflink)."; 
    3237?> 
    3338    </li> 
  • trunk/www/views/job_detail.php

    r996 r997  
    2323    <th class="task-id">Problema</th> 
    2424    <td class="task-id"><?= format_link(url_textblock($job['task_page_name']), $job['task_title']) ?></td> 
    25     <th class="score">Scor</th> 
    26     <td class="score"><?= html_escape(is_null($job['score']) ? "Ascuns" : $job['score']) ?></td> 
    27 </tr> 
    28 </tr> 
    29 <tr> 
    30     <th class="compiler-id">Compilator</th> 
    31     <td class="compiler-id"><?= html_escape($job['compiler_id']) ?></td> 
    3225    <th class="status">Status</th> 
    3326    <td class="status"><strong><?= html_escape($job['status']) ?></strong></td> 
     
    3528<tr> 
    3629    <th class="round-id">Runda</th> 
    37     <td class="round-id" colspan="<?= identity_can('job-view-source', $job) ? 1 : 3 ?>"> 
     30    <td class="round-id"> 
    3831    <?= format_link(url_textblock($job['round_page_name']), $job['round_title']) ?></td> 
    39 <?php if (identity_can('job-view-source', $job)) { ?> 
    40     <th class="source">Sursa</th> 
    41     <td class="source"><?= format_link(url_job_view_source($job['id']), "Vezi sursa") ?></td> 
     32    <th class="compiler-id">Compilator</th> 
     33    <td class="compiler-id"> 
     34        <?= html_escape($job['compiler_id']) ?> 
     35        <?php if (identity_can('job-view-source', $job)) { ?> 
     36            | <?= format_link(url_job_view_source($job['id']), "Vezi sursa") ?> 
     37        <?php } ?> 
     38    </td> 
     39</tr> 
     40<tr> 
     41    <th class="score">Scor</th> 
     42    <td class="score" colspan="<?= identity_can('job-view-ip', $job) ? 1 : 3 ?>"> 
     43        <?= html_escape(is_null($job['score']) ? "Ascuns" : $job['score']) ?></td> 
     44<?php if (identity_can('job-view-ip', $job)) { ?> 
     45    <th class="ip">IP</th> 
     46    <td class="ip"><?= $job['remote_ip_info'] ? html_escape($job['remote_ip_info']) : '<em>lipseste</em>' ?></td> 
    4247<?php } ?> 
    4348</tr> 
  • trunk/www/views/listattach.php

    r980 r997  
    4848} 
    4949 
     50function format_ip($row) { 
     51    if ($row['remote_ip_info'] && identity_can('attach-view-ip', $row)) { 
     52        return html_escape($row['remote_ip_info']); 
     53    } else { 
     54        return 'N/A'; 
     55    } 
     56} 
     57 
    5058function format_operations($row) { 
    5159    global $page_name; 
     
    8896    ), 
    8997    array( 
     98        'title' => 'IP', 
     99        'rowform' => 'format_ip', 
     100    ), 
     101    array( 
    90102        'title' => 'Operatii', 
    91103        'rowform' => 'format_operations', 
  • trunk/www/views/textblock_history.php

    r984 r997  
    2020    $title = html_escape($row['title']); 
    2121    return "$title"; 
     22} 
     23 
     24function format_ip($row) { 
     25    if ($row['remote_ip_info'] && identity_can('textblock-view-ip', $row)) { 
     26        return html_escape($row['remote_ip_info']); 
     27    } else { 
     28        return 'N/A'; 
     29    } 
    2230} 
    2331 
     
    8391        'valform' => 'format_date', 
    8492    ), 
    85  
     93    array( 
     94        'title' => 'IP', 
     95        'rowform' => 'format_ip', 
     96    ), 
    8697    array( 
    8798        'title' => 'Operatii', 
Note: See TracChangeset for help on using the changeset viewer.