Permalink
Browse files

merged master into the secure-random-setters branch from Jeremy Wohl.

  • Loading branch information...
2 parents 5441a7e + 87d0ab2 commit c193183208ad2b290e034961920ac4b3c64473fc @agentzh agentzh committed May 10, 2012
View
@@ -56,6 +56,8 @@ src/hex.c
src/hex.h
src/hmac.c
src/hmac.h
+src/rotate.[ch]
+analyze
buildroot/
src/module.h
work/
View
83 README
@@ -6,9 +6,9 @@ Name
installation instructions.
Version
- This document describes set-misc-nginx-module v0.22rc3
- (<https://github.com/agentzh/set-misc-nginx-module/tags>) released on 10
- October 2011.
+ This document describes set-misc-nginx-module v0.22rc7
+ (<https://github.com/agentzh/set-misc-nginx-module/tags>) released on 17
+ April 2012.
Synopsis
location /foo {
@@ -756,7 +756,9 @@ Directives
(HttpEchoModule#echo)] here to output values of nginx variables
directly.
- This directive requires the OpenSSL library enabled in your Nignx build.
+ This directive requires the OpenSSL library enabled in your Nignx build
+ (usually by passing the "--with-http_ssl_module" option to the
+ "./configure" script).
set_random
syntax: *set_random $res <from> <to>*
@@ -773,7 +775,7 @@ Directives
Only non-negative numbers are allowed for the "<from>" and "<to>"
arguments.
- When "<$from>" is greater than "<$to>", their values will be exchanged
+ When "<from>" is greater than "<to>", their values will be exchanged
accordingly.
For instance,
@@ -793,6 +795,57 @@ Directives
Behind the scene, it makes use of the standard C function "rand()".
+ set_rotate
+ syntax: *set_random $value <from> <to>*
+
+ default: *no*
+
+ context: *location, location if*
+
+ phase: *rewrite*
+
+ Increments $value but keeps it in range from "<from>" to "<to>". If
+ $value is greater than "<to>" or less than "<from>" is will be set to
+ "<from>" value.
+
+ The current value after running this directive will always be saved on a
+ per-location basis. And the this saved value will be used for
+ incrementation when the $value is not initialized or has a bad value.
+
+ Only non-negative numbers are allowed for the "<from>" and "<to>"
+ arguments.
+
+ When "<from>" is greater than "<to>", their values will be exchanged
+ accordingly.
+
+ For instance,
+
+ location /rotate {
+ default_type text/plain;
+ set $counter $cookie_counter;
+ set_rotate $counter 1 5;
+ echo $counter;
+ add_header Set-Cookie counter=$counter;
+ }
+
+ then request "GET /rotate" will output next number between 1 and 5
+ (i.e., 1, 2, 3, 4, 5) on each refresh of the page. This directive may be
+ userful for banner rotation purposes.
+
+ Another example is to use server-side value persistence to do simple
+ round-robin:
+
+ location /rotate {
+ default_type text/plain;
+ set_rotate $counter 0 3;
+ echo $counter;
+ }
+
+ And accessing "/rotate" will also output integer sequence 0, 1, 2, 3, 0,
+ 1, 2, 3, and so on.
+
+ This directive was first introduced in the "v0.22rc7" release.
+
set_local_today
syntax: *set_local_today $dst*
@@ -823,22 +876,22 @@ Directives
mechanism in the Nginx core.
Caveats
- Do not use $arg_PARAMETER or $http_HEADER or other special variables
- defined in the nginx core module as the target variable in this module's
- directives. For instance,
+ Do not use $arg_PARAMETER, $cookie_COOKIE, $http_HEADER or other special
+ variables defined in the Nginx core module as the target variable in
+ this module's directives. For instance,
set_if_empty $arg_user 'foo'; # DO NOT USE THIS!
- may lead to data corruption.
+ may lead to segmentation faults.
Installation
Grab the nginx source code from nginx.org (<http://nginx.org/>), for
- example, the version 1.0.8 (see nginx compatibility), and then build the
- source with this module:
+ example, the version 1.0.15 (see nginx compatibility), and then build
+ the source with this module:
- wget 'http://nginx.org/download/nginx-1.0.8.tar.gz'
- tar -xzvf nginx-1.0.8.tar.gz
- cd nginx-1.0.8/
+ wget 'http://nginx.org/download/nginx-1.0.15.tar.gz'
+ tar -xzvf nginx-1.0.15.tar.gz
+ cd nginx-1.0.15/
# Here we assume you would install you nginx under /opt/nginx/.
./configure --prefix=/opt/nginx \
@@ -863,7 +916,7 @@ Compatibility
* 1.1.x (last tested: 1.1.5)
- * 1.0.x (last tested: 1.0.8)
+ * 1.0.x (last tested: 1.0.15)
* 0.9.x (last tested: 0.9.4)
View
@@ -8,7 +8,7 @@ Name
Version
=======
-This document describes set-misc-nginx-module [v0.22rc3](https://github.com/agentzh/set-misc-nginx-module/tags) released on 10 October 2011.
+This document describes set-misc-nginx-module [v0.22rc7](https://github.com/agentzh/set-misc-nginx-module/tags) released on 17 April 2012.
Synopsis
========
@@ -735,7 +735,7 @@ Then request `GET /test` will yield the following output
Please note that we're using [HttpEchoModule](http://wiki.nginx.org/HttpEchoModule)'s [echo directive](http://wiki.nginx.org/HttpEchoModule#echo) here to output values of nginx variables directly.
-This directive requires the OpenSSL library enabled in your Nignx build.
+This directive requires the OpenSSL library enabled in your Nignx build (usually by passing the `--with-http_ssl_module` option to the `./configure` script).
set_random
----------
@@ -751,7 +751,7 @@ Generates a (pseudo) random number (in textual form) within the range `[<$from>,
Only non-negative numbers are allowed for the `<from>` and `<to>` arguments.
-When `<$from>` is greater than `<$to>`, their values will be exchanged accordingly.
+When `<from>` is greater than `<to>`, their values will be exchanged accordingly.
For instance,
@@ -827,6 +827,55 @@ then request `GET /test` will output a string like "kcuxcddktffsippuekhshdaclaqu
This function depends on the presence of the "/dev/urandom" device, available on most UNIX-like systems.
+set_rotate
+----------
+**syntax:** *set_rotate $value &lt;from&gt; &lt;to&gt;*
+
+**default:** *no*
+
+**context:** *location, location if*
+
+**phase:** *rewrite*
+
+Increments `$value` but keeps it in range from `<from>` to `<to>`.
+If `$value` is greater than `<to>` or less than `<from>` is will be
+set to `<from>` value.
+
+The current value after running this directive will always be saved on a per-location basis. And the this saved value will be used for incrementation when the `$value` is not initialized or has a bad value.
+
+Only non-negative numbers are allowed for the `<from>` and `<to>` arguments.
+
+When `<from>` is greater than `<to>`, their values will be exchanged accordingly.
+
+For instance,
+
+
+ location /rotate {
+ default_type text/plain;
+ set $counter $cookie_counter;
+ set_rotate $counter 1 5;
+ echo $counter;
+ add_header Set-Cookie counter=$counter;
+ }
+
+
+then request `GET /rotate` will output next number between 1 and 5 (i.e., 1, 2, 3, 4, 5) on each
+refresh of the page. This directive may be userful for banner rotation purposes.
+
+Another example is to use server-side value persistence to do simple round-robin:
+
+
+ location /rotate {
+ default_type text/plain;
+ set_rotate $counter 0 3;
+ echo $counter;
+ }
+
+
+And accessing `/rotate` will also output integer sequence 0, 1, 2, 3, 0, 1, 2, 3, and so on.
+
+This directive was first introduced in the `v0.22rc7` release.
+
set_local_today
---------------
**syntax:** *set_local_today $dst*
@@ -861,24 +910,24 @@ Behind the scene, this directive utilizes the `ngx_time` API in the Nginx core,
Caveats
=======
-Do not use [$arg_PARAMETER](http://wiki.nginx.org/HttpCoreModule#.24arg_PARAMETER) or [$http_HEADER](http://wiki.nginx.org/HttpCoreModule#.24http_HEADER) or other special variables defined in the nginx core module as the target variable in this module's directives. For instance,
+Do not use [$arg_PARAMETER](http://wiki.nginx.org/HttpCoreModule#.24arg_PARAMETER), [$cookie_COOKIE](http://wiki.nginx.org/HttpCoreModule#.24cookie_COOKIE), [$http_HEADER](http://wiki.nginx.org/HttpCoreModule#.24http_HEADER) or other special variables defined in the Nginx core module as the target variable in this module's directives. For instance,
set_if_empty $arg_user 'foo'; # DO NOT USE THIS!
-may lead to data corruption.
+may lead to segmentation faults.
Installation
============
Grab the nginx source code from [nginx.org](http://nginx.org/), for example,
-the version 1.0.8 (see [nginx compatibility](http://wiki.nginx.org/HttpSetMiscModule#Compatibility)), and then build the source with this module:
+the version 1.0.15 (see [nginx compatibility](http://wiki.nginx.org/HttpSetMiscModule#Compatibility)), and then build the source with this module:
- wget 'http://nginx.org/download/nginx-1.0.8.tar.gz'
- tar -xzvf nginx-1.0.8.tar.gz
- cd nginx-1.0.8/
+ wget 'http://nginx.org/download/nginx-1.0.15.tar.gz'
+ tar -xzvf nginx-1.0.15.tar.gz
+ cd nginx-1.0.15/
# Here we assume you would install you nginx under /opt/nginx/.
./configure --prefix=/opt/nginx \
@@ -900,7 +949,7 @@ Compatibility
The following versions of Nginx should work with this module:
* **1.1.x** (last tested: 1.1.5)
-* **1.0.x** (last tested: 1.0.8)
+* **1.0.x** (last tested: 1.0.15)
* **0.9.x** (last tested: 0.9.4)
* **0.8.x** (last tested: 0.8.54)
* **0.7.x >= 0.7.46** (last tested: 0.7.68)
View
4 config
@@ -7,8 +7,8 @@ fi
ngx_addon_name=ngx_http_set_misc_module
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_set_misc_module"
-NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_set_base32.c $ngx_addon_dir/src/ngx_http_set_default_value.c $ngx_addon_dir/src/ngx_http_set_hashed_upstream.c $ngx_addon_dir/src/ngx_http_set_quote_sql.c $ngx_addon_dir/src/ngx_http_set_quote_json.c $ngx_addon_dir/src/ngx_http_set_unescape_uri.c $ngx_addon_dir/src/ngx_http_set_misc_module.c $ngx_addon_dir/src/ngx_http_set_escape_uri.c $ngx_addon_dir/src/ngx_http_set_hash.c $ngx_addon_dir/src/ngx_http_set_local_today.c $ngx_addon_dir/src/ngx_http_set_hex.c $ngx_addon_dir/src/ngx_http_set_base64.c $ngx_addon_dir/src/ngx_http_set_random.c $ngx_addon_dir/src/ngx_http_set_secure_random.c"
-NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ddebug.h $ngx_addon_dir/src/ngx_http_set_default_value.h $ngx_addon_dir/src/ngx_http_set_hashed_upstream.h $ngx_addon_dir/src/ngx_http_set_quote_sql.h $ngx_addon_dir/src/ngx_http_set_quote_json.h $ngx_addon_dir/src/ngx_http_set_unescape_uri.h $ngx_addon_dir/src/ngx_http_set_escape_uri.h $ngx_addon_dir/src/ngx_http_set_hash.h $ngx_addon_dir/src/ngx_http_set_local_today.h $ngx_addon_dir/src/ngx_http_set_hex.h $ngx_addon_dir/src/ngx_http_set_base64.h $ngx_addon_dir/src/ngx_http_set_random.h $ngx_addon_dir/src/ngx_http_set_misc_module.h"
+NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_set_base32.c $ngx_addon_dir/src/ngx_http_set_default_value.c $ngx_addon_dir/src/ngx_http_set_hashed_upstream.c $ngx_addon_dir/src/ngx_http_set_quote_sql.c $ngx_addon_dir/src/ngx_http_set_quote_json.c $ngx_addon_dir/src/ngx_http_set_unescape_uri.c $ngx_addon_dir/src/ngx_http_set_misc_module.c $ngx_addon_dir/src/ngx_http_set_escape_uri.c $ngx_addon_dir/src/ngx_http_set_hash.c $ngx_addon_dir/src/ngx_http_set_local_today.c $ngx_addon_dir/src/ngx_http_set_hex.c $ngx_addon_dir/src/ngx_http_set_base64.c $ngx_addon_dir/src/ngx_http_set_random.c $ngx_addon_dir/src/ngx_http_set_secure_random.c $ngx_addon_dir/src/ngx_http_set_rotate.c"
+NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ddebug.h $ngx_addon_dir/src/ngx_http_set_default_value.h $ngx_addon_dir/src/ngx_http_set_hashed_upstream.h $ngx_addon_dir/src/ngx_http_set_quote_sql.h $ngx_addon_dir/src/ngx_http_set_quote_json.h $ngx_addon_dir/src/ngx_http_set_unescape_uri.h $ngx_addon_dir/src/ngx_http_set_escape_uri.h $ngx_addon_dir/src/ngx_http_set_hash.h $ngx_addon_dir/src/ngx_http_set_local_today.h $ngx_addon_dir/src/ngx_http_set_hex.h $ngx_addon_dir/src/ngx_http_set_base64.h $ngx_addon_dir/src/ngx_http_set_random.h $ngx_addon_dir/src/ngx_http_set_rotate.h $ngx_addon_dir/src/ngx_http_set_misc_module.h"
if [ $USE_OPENSSL = YES ]; then
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ngx_http_set_hmac.h"
View
@@ -6,7 +6,7 @@
= Version =
-This document describes set-misc-nginx-module [https://github.com/agentzh/set-misc-nginx-module/tags v0.22rc3] released on 10 October 2011.
+This document describes set-misc-nginx-module [https://github.com/agentzh/set-misc-nginx-module/tags v0.22rc7] released on 17 April 2012.
= Synopsis =
@@ -713,7 +713,7 @@ R/pvxzHC4NLtj7S+kXFg/NePTmk=
Please note that we're using [[HttpEchoModule]]'s [[HttpEchoModule#echo|echo directive]] here to output values of nginx variables directly.
-This directive requires the OpenSSL library enabled in your Nignx build.
+This directive requires the OpenSSL library enabled in your Nignx build (usually by passing the <code>--with-http_ssl_module</code> option to the <code>./configure</code> script).
== set_random ==
'''syntax:''' ''set_random $res <from> <to>''
@@ -728,7 +728,7 @@ Generates a (pseudo) random number (in textual form) within the range <code>[<$f
Only non-negative numbers are allowed for the <code><from></code> and <code><to></code> arguments.
-When <code><$from></code> is greater than <code><$to></code>, their values will be exchanged accordingly.
+When <code><from></code> is greater than <code><to></code>, their values will be exchanged accordingly.
For instance,
@@ -748,6 +748,54 @@ For now, there's no way to configure a custom random generator seed.
Behind the scene, it makes use of the standard C function <code>rand()</code>.
+== set_rotate ==
+'''syntax:''' ''set_random $value <from> <to>''
+
+'''default:''' ''no''
+
+'''context:''' ''location, location if''
+
+'''phase:''' ''rewrite''
+
+Increments <code>$value</code> but keeps it in range from <code><from></code> to <code><to></code>.
+If <code>$value</code> is greater than <code><to></code> or less than <code><from></code> is will be
+set to <code><from></code> value.
+
+The current value after running this directive will always be saved on a per-location basis. And the this saved value will be used for incrementation when the <code>$value</code> is not initialized or has a bad value.
+
+Only non-negative numbers are allowed for the <code><from></code> and <code><to></code> arguments.
+
+When <code><from></code> is greater than <code><to></code>, their values will be exchanged accordingly.
+
+For instance,
+
+<geshi lang="nginx">
+ location /rotate {
+ default_type text/plain;
+ set $counter $cookie_counter;
+ set_rotate $counter 1 5;
+ echo $counter;
+ add_header Set-Cookie counter=$counter;
+ }
+</geshi>
+
+then request <code>GET /rotate</code> will output next number between 1 and 5 (i.e., 1, 2, 3, 4, 5) on each
+refresh of the page. This directive may be userful for banner rotation purposes.
+
+Another example is to use server-side value persistence to do simple round-robin:
+
+<geshi lang="nginx">
+ location /rotate {
+ default_type text/plain;
+ set_rotate $counter 0 3;
+ echo $counter;
+ }
+</geshi>
+
+And accessing <code>/rotate</code> will also output integer sequence 0, 1, 2, 3, 0, 1, 2, 3, and so on.
+
+This directive was first introduced in the <code>v0.22rc7</code> release.
+
== set_local_today ==
'''syntax:''' ''set_local_today $dst''
@@ -780,23 +828,23 @@ Behind the scene, this directive utilizes the <code>ngx_time</code> API in the N
= Caveats =
-Do not use [[HttpCoreModule#$arg_PARAMETER|$arg_PARAMETER]] or [[HttpCoreModule#$http_HEADER|$http_HEADER]] or other special variables defined in the nginx core module as the target variable in this module's directives. For instance,
+Do not use [[HttpCoreModule#$arg_PARAMETER|$arg_PARAMETER]], [[HttpCoreModule#$cookie_COOKIE|$cookie_COOKIE]], [[HttpCoreModule#$http_HEADER|$http_HEADER]] or other special variables defined in the Nginx core module as the target variable in this module's directives. For instance,
<geshi lang="nginx">
set_if_empty $arg_user 'foo'; # DO NOT USE THIS!
</geshi>
-may lead to data corruption.
+may lead to segmentation faults.
= Installation =
Grab the nginx source code from [http://nginx.org/ nginx.org], for example,
-the version 1.0.8 (see [[#Compatibility|nginx compatibility]]), and then build the source with this module:
+the version 1.0.15 (see [[#Compatibility|nginx compatibility]]), and then build the source with this module:
<geshi lang="bash">
- wget 'http://nginx.org/download/nginx-1.0.8.tar.gz'
- tar -xzvf nginx-1.0.8.tar.gz
- cd nginx-1.0.8/
+ wget 'http://nginx.org/download/nginx-1.0.15.tar.gz'
+ tar -xzvf nginx-1.0.15.tar.gz
+ cd nginx-1.0.15/
# Here we assume you would install you nginx under /opt/nginx/.
./configure --prefix=/opt/nginx \
@@ -817,7 +865,7 @@ Also, this module is included and enabled by default in the [http://openresty.or
The following versions of Nginx should work with this module:
* '''1.1.x''' (last tested: 1.1.5)
-* '''1.0.x''' (last tested: 1.0.8)
+* '''1.0.x''' (last tested: 1.0.15)
* '''0.9.x''' (last tested: 0.9.4)
* '''0.8.x''' (last tested: 0.8.54)
* '''0.7.x >= 0.7.46''' (last tested: 0.7.68)
Oops, something went wrong.

0 comments on commit c193183

Please sign in to comment.