Plugin Directory

Changeset 792002


Ignore:
Timestamp:
10/22/2013 08:23:15 PM (12 years ago)
Author:
v-media
Message:

Version 1.2: slight code refactoring + made plugin translatable

Location:
ip-dependent-cookies/trunk
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • ip-dependent-cookies/trunk/ip-dependent-cookies.class.php

    r411721 r792002  
    22
    33class IPDependentCookies {
    4     var $remote_addr;
    5     var $nonce;
    6     var $options;
     4    private $nonce;
     5    private $options;
    76
    8     function IPDependentCookies(){
    9         /*
    10         $plugin_active = get_option('ip_dependent_cookies_active');
    11         if ($plugin_active !== false) {
    12             $this->remote_addr = get_option('ip_dependent_cookies_remote_addr');
    13             if ($this->remote_addr === false)
    14                 $this->remote_addr = "";
    15         }
    16         */
    17         add_filter('salt', array(&$this, 'ip_salt'), 10, 2);
    18         add_action('admin_menu', array(&$this, 'config_page'));
    19        
    20         if ( !function_exists('wp_nonce_field') ) {
    21             $this->nonce = -1;
    22         } else {
    23             $this->nonce = 'ipdc-update-key';
    24         }
    25         $this->options = get_option('ipdc_options');
    26        
    27         if (!isset($this->options) || ($this->options === FALSE)) {
    28             $this->options = array();
    29             $this->options['ipdc_enabled'] = 0;
    30             $this->options['ipdc_forwarded'] = false;
    31         }
    32         add_filter( 'plugin_action_links', array( &$this, 'plugin_action_links' ), 10, 2 );
    33         $this->register_admin_notices();
    34     }
    35    
    36     function nonce_field($action = -1) {
    37         return wp_nonce_field($action);
    38     }
     7    public function __construct()
     8    {
     9        load_plugin_textdomain('ipdc', false, dirname(IPDC_PLUGIN_BASENAME).'/locale');
    3910
    40     function ip_salt($salt, $scheme){
    41         if (!$this->options['ipdc_enabled']) return $salt;
    42         if ($this->options['ipdc_forwarded'] && isset($_SERVER['HTTP_X_FORWARDED_FOR']))
    43             return $_SERVER['HTTP_X_FORWARDED_FOR'] . $salt;
    44         else
    45             return $_SERVER['REMOTE_ADDR'] . $salt;
     11        add_filter('salt', array($this, 'ip_salt'), 10, 2);
     12        add_action('admin_menu', array($this, 'config_page'));
     13
     14        if (!function_exists('wp_nonce_field') ) {
     15            $this->nonce = -1;
     16        } else {
     17            $this->nonce = 'ipdc-update-key';
     18        }
     19        $this->options = get_option('ipdc_options');
     20
     21        if (!isset($this->options) || ($this->options === false)) {
     22            $this->options = array();
     23            $this->options['ipdc_enabled'] = 0;
     24            $this->options['ipdc_forwarded'] = false;
     25        }
     26        add_filter('plugin_action_links', array($this, 'plugin_action_links' ), 10, 2);
     27        $this->register_admin_notices();
    4628    }
    4729
    48     function plugin_not_active(){
    49         if ( ! $this->options['ipdc_enabled'] ) {
    50             echo '<div id="ipdc-nag" class="updated fade">
    51                To start using <strong>IP Dependent Cookies</strong> you need to enable the plugin in its settings! <a href="' .
    52                IPDC_PLUGIN_SETTINGS_URL .
    53                '">Go to configuration</a>.
    54             </div>';
    55         }
    56     }
    57 
    58     function register_admin_notices() {
    59         add_action( 'admin_notices', array( &$this, 'plugin_not_active' ) );
    60     }
    61 
    62     function plugin_action_links( $links, $file ) {
    63         if ( $file != IPDC_PLUGIN_BASENAME )
    64             return $links;
    65 
    66         $settings_link = '<a href="' . esc_url( IPDC_PLUGIN_SETTINGS_URL ) . '">'
    67             . esc_html( __( 'Settings', 'ipdc' ) ) . '</a>';
    68 
    69         array_unshift( $links, $settings_link );
    70 
    71         return $links;
    72     }
    73 
    74     function config_page(){
    75         if ( function_exists('add_submenu_page') )
    76             add_submenu_page( IPDC_PLUGIN_MENU_PARENT, 'IP Dependent Cookies',
    77                 'IP Dependent Cookies', 'manage_options', IPDC_PLUGIN_FULL_PATH, array(&$this,'conf_page'));
     30    private function register_admin_notices() {
     31        add_action( 'admin_notices', array( $this, 'plugin_not_active' ) );
    7832    }
    7933
    80     function conf_page() {
    81         $message = NULL;
    82         if ( function_exists('current_user_can') && !current_user_can('manage_options') )
    83             die(__('Cheatin&#8217; uh?'));
     34    public function ip_salt($salt, $scheme) {
     35        if (!$this->options['ipdc_enabled']) return $salt;
    8436
    85         if (isset($_POST['action']) && $_POST['action'] == 'ipdc_update' && isset($_POST['Submit'])) {
    86             $message = 'IP Dependent Cookies settings updated. Please <a href="' . wp_login_url(wp_get_referer(), false) . '">log in</a> again.';
    87             $nonce = $_POST['nonce-ipdc'];
    88             if (!wp_verify_nonce($nonce, 'ipdc-nonce'))
    89                 die ('Security Check - If you receive this in error, log out and back in to WordPress');
    90             $this->options = array();
    91             $this->options['ipdc_enabled'] = $_POST['ipdc_enabled'];
    92             $this->options['ipdc_forwarded'] = isset($_POST['ipdc_forwarded']);
    93             update_option('ipdc_options', $this->options);
    94         }
    95        
    96         if ($message){
    97             echo "<div id=\"message\" class=\"updated fade\"><p>$message</p></div>";
    98         }
    99 ?>
    100 <div class="wrap">
    101        
    102         <h2>IP Dependent Cookies Options</h2>
    103 <p><strong>NB</strong>: After changing any of these options you will be forced to log in to WordPress again!</p>
    104 <script type="text/javascript">
    105 <!--
    106     function toggleVisibility(id) {
    107        var e = document.getElementById(id);
    108        if(e.style.display == 'block')
    109           e.style.display = 'none';
    110        else
    111           e.style.display = 'block';
     37        if ($this->options['ipdc_forwarded'] && isset($_SERVER['HTTP_X_FORWARDED_FOR']))
     38            return $_SERVER['HTTP_X_FORWARDED_FOR'] . $salt;
     39        else
     40            return $_SERVER['REMOTE_ADDR'] . $salt;
    11241    }
    113 //-->
    114 </script>
    115 <h3>Click on the option titles to get help!</h3>
    11642
    117 <form name="dofollow" action="" method="post">
    118 <table class="form-table">
     43    function plugin_not_active(){
     44        if ( ! $this->options['ipdc_enabled'] ) {
     45            echo '<div id="ipdc-nag" class="updated fade">
     46                '.__('To start using <strong>IP Dependent Cookies</strong> you need to enable the plugin in its settings!', 'ipdc').'
     47                <a href="' .esc_url(IPDC_PLUGIN_SETTINGS_URL) .'">'.__('Go to configuration', 'ipdc').'</a>.
     48            </div>';
     49        }
     50    }
    11951
    120 <tbody><tr>
    121 <th scope="row" style="text-align: right; vertical-align: top;">
    122 <a style="cursor: pointer;" title="Click for Help!" onclick="toggleVisibility('ipdc_enabled_tip');">
    123 Plugin Status:</a>
     52    public function plugin_action_links( $links, $file ) {
     53        if ( $file != IPDC_PLUGIN_BASENAME )
     54            return $links;
    12455
    125 </th><td>
    126 <input name="ipdc_enabled" value="1" <?php if ($this->options['ipdc_enabled'] == 1) echo 'checked="checked")';?> type="radio"> Enabled<br>
    127 <input name="ipdc_enabled" value="0" <?php if ($this->options['ipdc_enabled'] == 0) echo 'checked="checked")';?> type="radio"> Disabled
     56        $settings_link = '<a href="' . esc_url( IPDC_PLUGIN_SETTINGS_URL ) . '">'
     57            . esc_html( __( 'Settings', 'ipdc' ) ) . '</a>';
    12858
    129 <div style="max-width: 500px; text-align: left; display: none;" id="ipdc_enabled_tip">
    130 IP Dependent Cookies must be enabled for use.</div>
    131 </td>
    132 </tr>
     59        array_unshift( $links, $settings_link );
    13360
    134 <tr>
    135 <th scope="row" style="text-align: right; vertical-align: top;">
    136 <a style="cursor: pointer;" title="Click for Help!" onclick="toggleVisibility('ipdc_forwarded_tip');">
    137 HTTP_X_FORWARDED_FOR in place of REMOTE_ADDR:</a>
     61        return $links;
     62    }
    13863
    139 </th><td>
    140 <input name="ipdc_forwarded" <?php if ($this->options['ipdc_forwarded']) echo 'checked="1"';?> type="checkbox">
    141 <div style="max-width: 500px; text-align: left; display: none;" id="ipdc_forwarded_tip">
    142 Turn on this option if your http-server is behind frontend server.</div>
    143 </td>
    144 </tr>
     64    public function config_page(){
     65        if ( function_exists('add_submenu_page') )
     66            add_submenu_page( IPDC_PLUGIN_MENU_PARENT, __('IP Dependent Cookies', 'ipdc'),
     67                __('IP Dependent Cookies', 'ipdc'), 'manage_options', IPDC_PLUGIN_FULL_PATH, array($this,'conf_page'));
     68    }
    14569
    146 </tbody></table>
    147 <p class="submit">
    148 <input name="action" value="ipdc_update" type="hidden">
    149 <input type="hidden" name="nonce-ipdc" value="<?php echo wp_create_nonce('ipdc-nonce'); ?>" />
    150 <input name="page_options" value="ipdc_home_description" type="hidden">
    151 <input class="button-primary" name="Submit" value="Update Options »" type="submit">
    152 </p>
     70    public function conf_page() {
     71        $message = NULL;
     72        if ( function_exists('current_user_can') && !current_user_can('manage_options') )
     73            die(__('Cheatin&#8217; uh?'));
    15374
    154 <p>
    155 </div>
    156 <?php
     75        if (isset($_POST['action']) && $_POST['action'] == 'ipdc_update' && isset($_POST['Submit'])) {
     76            $message = sprintf(__('IP Dependent Cookies settings updated. Please <a href="%s">log in</a> again.', 'ipdc'), esc_url(wp_login_url(wp_get_referer(), false)));
     77            $nonce = $_POST['nonce-ipdc'];
     78            if (!wp_verify_nonce($nonce, 'ipdc-nonce'))
     79                die (__('Security Check - If you receive this in error, log out and back in to WordPress', 'ipdc'));
     80            $this->options = array();
     81            $this->options['ipdc_enabled'] = $_POST['ipdc_enabled'];
     82            $this->options['ipdc_forwarded'] = isset($_POST['ipdc_forwarded']);
     83            update_option('ipdc_options', $this->options);
     84        }
     85
     86        if ($message){
     87            echo '<div id="message" class="updated fade"><p>'.$message.'</p></div>';
     88        }
     89
     90        echo '
     91            <div class="wrap">
     92                <h2>'.__('IP Dependent Cookies Options', 'ipdc').'</h2>
     93                <p>'.__('<strong>NB</strong>: After changing any of these options you will be forced to log in to WordPress again!', 'ipdc').'</p>
     94                <h3>'.__('Click on the option titles to get help!', 'ipdc').'</h3>
     95
     96                <form name="dofollow" action="" method="post">
     97                    <table class="form-table">
     98                        <tbody>
     99                            <tr>
     100                                <th scope="row" style="text-align: right; vertical-align: top;">
     101                                    <a style="cursor: pointer;" title="'.esc_attr(__('Click for Help!', 'ipdc')).'" data-show-hide="#ipdc_enabled_tip" class="ipdc-show-hide">'.__('Plugin Status:', 'ipdc').'</a>
     102                                </th>
     103                                <td>
     104                                    <label>
     105                                        <input name="ipdc_enabled" value="1" '.checked(1, $this->options['ipdc_enabled'], false).' type="radio" /> '.__('Enabled', 'ipdc').'
     106                                    </label><br/>
     107                                    <label>
     108                                        <input name="ipdc_enabled" value="0" '.checked(0, $this->options['ipdc_enabled'], false).' type="radio" /> '.__('Disabled', 'ipdc').'
     109                                    </label>
     110
     111                                    <div style="max-width: 500px; text-align: left; display: none;" id="ipdc_enabled_tip">
     112                                        '.__('IP Dependent Cookies must be enabled for use.', 'ipdc').'
     113                                    </div>
     114                                </td>
     115                            </tr>
     116                            <tr>
     117                                <th scope="row" style="text-align: right; vertical-align: top;">
     118                                    <a style="cursor: pointer;" title="'.esc_attr(__('Click for Help!', 'ipdc')).'" data-show-hide="#ipdc_forwarded_tip" class="ipdc-show-hide");">
     119                                        '.__('HTTP_X_FORWARDED_FOR in place of REMOTE_ADDR:', 'ipdc').'
     120                                    </a>
     121                                </th>
     122                                <td>
     123                                    <input name="ipdc_forwarded" '.checked(true, $this->options['ipdc_forwarded'], false).' type="checkbox" />
     124                                    <div style="max-width: 500px; text-align: left; display: none;" id="ipdc_forwarded_tip">
     125                                        '.__('Turn on this option if your http-server is behind frontend server.', 'ipdc').'
     126                                    </div>
     127                                </td>
     128                            </tr>
     129                        </tbody>
     130                    </table>
     131                    <p class="submit">
     132                        <input name="action" value="ipdc_update" type="hidden" />
     133                        <input type="hidden" name="nonce-ipdc" value="'.wp_create_nonce('ipdc-nonce').'" />
     134                        <input name="page_options" value="ipdc_home_description" type="hidden" />
     135                        <input class="button-primary" name="Submit" value="'.esc_attr(__('Update Options »', 'ipdc')).'" type="submit" />
     136                    </p>
     137                </form>
     138                <script type="text/javascript">
     139                    jQuery(document).ready(function($) {
     140                        $(\'.ipdc-show-hide\').click(function(){
     141                            var el = $(this).data(\'show-hide\');
     142                            $(el).slideToggle();
     143                        });
     144                    });
     145                </script>
     146            </div>
     147        ';
    157148    }
    158149}
  • ip-dependent-cookies/trunk/ip-dependent-cookies.php

    r411721 r792002  
    44Plugin URI: http://v-media.cz/ip-dependent-cookies/
    55Description: Plugin IP Dependent Cookies makes your Wordpress installation more secure adding your IP to salt. Even if someone steals your cookies he (or she) won't be able to use them.
    6 Version: 1.1
    7 Author: Art Prima
     6Version: 1.2
     7Author: Artprima
    88Author URI: http://artprima.cz/
    99License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
     
    2525
    2626if ( ! defined( 'IPDC_PLUGIN_FULL_PATH' ) )
    27         define( 'IPDC_PLUGIN_FULL_PATH', __FILE__ );
     27    define( 'IPDC_PLUGIN_FULL_PATH', __FILE__ );
    2828
    2929if ( ! defined( 'IPDC_PLUGIN_BASENAME' ) )
    30         define( 'IPDC_PLUGIN_BASENAME', plugin_basename( IPDC_PLUGIN_FULL_PATH ) );
     30    define( 'IPDC_PLUGIN_BASENAME', plugin_basename( IPDC_PLUGIN_FULL_PATH ) );
    3131
    3232if ( ! defined( 'IPDC_PLUGIN_MENU_PARENT' ) )
    33         define( 'IPDC_PLUGIN_MENU_PARENT', 'options-general.php' );
     33    define( 'IPDC_PLUGIN_MENU_PARENT', 'options-general.php' );
    3434
    3535if ( ! defined( 'IPDC_PLUGIN_SETTINGS_URL' ) )
    36         define( 'IPDC_PLUGIN_SETTINGS_URL', admin_url(IPDC_PLUGIN_MENU_PARENT . '?page=' . IPDC_PLUGIN_BASENAME) );
     36    define( 'IPDC_PLUGIN_SETTINGS_URL', admin_url(IPDC_PLUGIN_MENU_PARENT . '?page=' . IPDC_PLUGIN_BASENAME) );
    3737
    3838$ip_dependent_cookies = new IPDependentCookies();
  • ip-dependent-cookies/trunk/readme.txt

    r411721 r792002  
    44Tags: cookies, safety, auth, security
    55Requires at least: 2.9
    6 Tested up to: 3.2.1
     6Tested up to: 3.6.1
    77Stable tag: trunk
    88
    99Plugin IP Dependent Cookies makes your Wordpress installation more secure adding your IP to salt (which makes cookies IP-dependent).
     10In fact, all the fields (nonce's, for example) that use salt will use your ip. This means that even if someone somehow
     11steals your sensitive auth information, this person will not be able to use it.
    1012
    1113== Description ==
     
    3234== Changelog ==
    3335
     36= 1.2 =
     37* Changed: code refactoring
     38* Added: plugin made translatable
     39
    3440= 1.1 =
    3541* Added: quick link to settings from the plugins list
     
    3945* First public release
    4046
    41 == Upgrade Notice ==
    42 
    43 = 1.1 =
    44 Added a quick link to settings from the plugins list and a nag when plugin is disabled, some code clean-ups.
Note: See TracChangeset for help on using the changeset viewer.