├── .gitignore ├── Makefile ├── README.md ├── conf ├── mime.types └── nginx.conf ├── css ├── cn-home.css ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 ├── home.css ├── main.css └── vendor │ ├── bootstrap.min.css │ └── ie10-viewport-bug-workaround.css ├── html ├── cn-index.html ├── fail.html ├── index.html └── success.html ├── init └── mysql.sql ├── js └── vendor │ ├── bootstrap.min.js │ ├── ie-emulation-modes-warning.js │ ├── ie10-viewport-bug-workaround.js │ ├── jquery.min.js │ └── validator.min.js ├── logs └── README ├── lua └── survey │ └── post.lua └── template ├── cn-index.tt └── index.tt /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | *.swo 4 | *.bak 5 | *.pid 6 | *.log 7 | go 8 | upload 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | html_files := html/index.html html/cn-index.html 2 | 3 | .DELETE_ON_ERRORS: $(html_files) 4 | 5 | all: $(html_files) 6 | 7 | html/%.html: template/%.tt 8 | tpage $< > $@ 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Name 2 | ==== 3 | 4 | openresty-survey - OpenResty Web App for OpenResty User Survey 5 | 6 | Table of Contents 7 | ================= 8 | 9 | * [Name](#name) 10 | * [Initialize the MySQL database](#initialize-the-mysql-database) 11 | * [Run This App with OpenResty](#run-this-app-with-openresty) 12 | * [Author](#author) 13 | * [Copyright and License](#copyright-and-license) 14 | 15 | Description 16 | =========== 17 | 18 | This is the source code for the OpenResty User Survey app built upon OpenResty. 19 | 20 | See the sites alive below: 21 | 22 | * https://openresty.org/survey/ (English version) 23 | * https://openresty.org/survey/cn (Chinese version) 24 | 25 | Initialize the MySQL database 26 | ============================= 27 | 28 | Ensure you have the following lines added under the `[mysqld]` group in your `my.cnf` configuration 29 | file for your MySQL server (usually being `/etc/my.cnf`): 30 | 31 | ``` 32 | character-set-server=utf8 33 | collation-server=utf8_general_ci 34 | ``` 35 | 36 | such that your MySQL server uses the UTF-8 character encoding by default. Remember to restart 37 | your MySQL server after this change. 38 | 39 | Below we create a MySQL database named `ngx_test` as well as a MySQL user account named 40 | `ngx_test` with the password `ngx_test`. 41 | 42 | ```console 43 | $ mysql -u root 44 | mysql> create database ngx_test; 45 | mysql> create user 'ngx_test'@'localhost' identified by 'ngx_test'; 46 | mysql> grant all privileges on ngx_test.* to 'ngx_test'@'localhost' with grant option; 47 | ``` 48 | 49 | ```console 50 | $ cd /path/to/openresty-survey/ 51 | $ mysql -u ngx_test ngx_test -p < init/mysql.sql 52 | (type the password "ngx_test") 53 | ``` 54 | 55 | Run This App with OpenResty 56 | =========================== 57 | 58 | ```bash 59 | cd /path/to/openresty-survey/ 60 | # update conf/nginx.conf as needed 61 | /usr/local/openresty/nginx/sbin/nginx -p $PWD/ -c conf/nginx.conf 62 | ``` 63 | 64 | Here we assume you installed OpenResty with its default prefix, `/usr/local/openresty`. 65 | 66 | Author 67 | ====== 68 | 69 | Yichun Zhang (agentzh) <agentzh@gmail.com> 70 | 71 | [Back to TOC](#table-of-contents) 72 | 73 | Copyright and License 74 | ===================== 75 | 76 | This module is licensed under the BSD license. 77 | 78 | Copyright (C) 2015-2017, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>, OpenResty Inc. 79 | 80 | All rights reserved. 81 | 82 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 83 | 84 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 85 | 86 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 87 | 88 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 89 | 90 | [Back to TOC](#table-of-contents) 91 | 92 | -------------------------------------------------------------------------------- /conf/mime.types: -------------------------------------------------------------------------------- 1 | 2 | types { 3 | text/html html htm shtml; 4 | text/css css; 5 | text/xml xml; 6 | image/gif gif; 7 | image/jpeg jpeg jpg; 8 | application/javascript js; 9 | application/atom+xml atom; 10 | application/rss+xml rss; 11 | 12 | text/mathml mml; 13 | text/plain txt; 14 | text/vnd.sun.j2me.app-descriptor jad; 15 | text/vnd.wap.wml wml; 16 | text/x-component htc; 17 | 18 | image/png png; 19 | image/tiff tif tiff; 20 | image/vnd.wap.wbmp wbmp; 21 | image/x-icon ico; 22 | image/x-jng jng; 23 | image/x-ms-bmp bmp; 24 | image/svg+xml svg svgz; 25 | image/webp webp; 26 | 27 | application/font-woff woff; 28 | application/java-archive jar war ear; 29 | application/json json; 30 | application/mac-binhex40 hqx; 31 | application/msword doc; 32 | application/pdf pdf; 33 | application/postscript ps eps ai; 34 | application/rtf rtf; 35 | application/vnd.apple.mpegurl m3u8; 36 | application/vnd.ms-excel xls; 37 | application/vnd.ms-fontobject eot; 38 | application/vnd.ms-powerpoint ppt; 39 | application/vnd.wap.wmlc wmlc; 40 | application/vnd.google-earth.kml+xml kml; 41 | application/vnd.google-earth.kmz kmz; 42 | application/x-7z-compressed 7z; 43 | application/x-cocoa cco; 44 | application/x-java-archive-diff jardiff; 45 | application/x-java-jnlp-file jnlp; 46 | application/x-makeself run; 47 | application/x-perl pl pm; 48 | application/x-pilot prc pdb; 49 | application/x-rar-compressed rar; 50 | application/x-redhat-package-manager rpm; 51 | application/x-sea sea; 52 | application/x-shockwave-flash swf; 53 | application/x-stuffit sit; 54 | application/x-tcl tcl tk; 55 | application/x-x509-ca-cert der pem crt; 56 | application/x-xpinstall xpi; 57 | application/xhtml+xml xhtml; 58 | application/xspf+xml xspf; 59 | application/zip zip; 60 | 61 | application/octet-stream bin exe dll; 62 | application/octet-stream deb; 63 | application/octet-stream dmg; 64 | application/octet-stream iso img; 65 | application/octet-stream msi msp msm; 66 | 67 | application/vnd.openxmlformats-officedocument.wordprocessingml.document docx; 68 | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx; 69 | application/vnd.openxmlformats-officedocument.presentationml.presentation pptx; 70 | 71 | audio/midi mid midi kar; 72 | audio/mpeg mp3; 73 | audio/ogg ogg; 74 | audio/x-m4a m4a; 75 | audio/x-realaudio ra; 76 | 77 | video/3gpp 3gpp 3gp; 78 | video/mp2t ts; 79 | video/mp4 mp4; 80 | video/mpeg mpeg mpg; 81 | video/quicktime mov; 82 | video/webm webm; 83 | video/x-flv flv; 84 | video/x-m4v m4v; 85 | video/x-mng mng; 86 | video/x-ms-asf asx asf; 87 | video/x-ms-wmv wmv; 88 | video/x-msvideo avi; 89 | } 90 | -------------------------------------------------------------------------------- /conf/nginx.conf: -------------------------------------------------------------------------------- 1 | daemon on; 2 | master_process on; 3 | worker_processes 1; 4 | error_log logs/error.log debug; 5 | pid logs/nginx.pid; 6 | #pcre_jit on; 7 | 8 | events { 9 | accept_mutex off; 10 | } 11 | 12 | http { 13 | lua_package_path "$prefix/lua/?.lua;;"; 14 | lua_code_cache on; 15 | 16 | limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; 17 | limit_conn_zone $binary_remote_addr zone=addr:10m; 18 | 19 | server { 20 | listen 8080; 21 | 22 | include mime.types; 23 | 24 | location = /survey/cn { 25 | rewrite ^ /survey/cn-index.html last; 26 | } 27 | 28 | location /survey { 29 | alias html; 30 | index index.html; 31 | } 32 | 33 | location /survey/css { 34 | alias css; 35 | } 36 | 37 | location /survey/js { 38 | alias js; 39 | } 40 | 41 | location = /survey/post { 42 | client_body_buffer_size 20k; 43 | client_body_timeout 20s; 44 | client_max_body_size 20k; 45 | 46 | limit_req zone=one burst=5; 47 | limit_conn addr 1; 48 | 49 | content_by_lua_block { require("survey.post").go() } 50 | 51 | error_page 503 /survey/fail.html; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /css/cn-home.css: -------------------------------------------------------------------------------- 1 | #cnt1 { 2 | /* background-color: rgba(215, 212, 212, 0.88); */ 3 | margin-top: 10px; 4 | margin-bottom: 70px; 5 | } 6 | 7 | #panel1 { 8 | padding:20px; 9 | } 10 | 11 | .panel-body:not(.two-col) { 12 | padding: 0px; 13 | } 14 | 15 | .panel-body .radio, .panel-body .checkbox { 16 | margin-top: 0px; 17 | margin-bottom: 0px; 18 | } 19 | 20 | .panel-body .list-group { 21 | margin-bottom: 0; 22 | } 23 | 24 | .margin-bottom-none { 25 | margin-bottom: 0; 26 | } 27 | 28 | @media screen and (min-width: 480px) { 29 | .text-box-md { 30 | width: 20em; 31 | } 32 | 33 | .text-box-lg { 34 | width: 33em; 35 | } 36 | 37 | .text-label { 38 | display: inline-block; 39 | width: 6em; 40 | } 41 | 42 | .text-label-lg { 43 | display: inline-block; 44 | width: 17em; 45 | } 46 | } 47 | 48 | .success-icon { 49 | color: green; 50 | padding: 10px; 51 | font-size: 110%; 52 | } 53 | 54 | .fail-icon { 55 | color: red; 56 | padding: 10px; 57 | font-size: 110%; 58 | } 59 | 60 | .required-field { 61 | color: red; 62 | } 63 | -------------------------------------------------------------------------------- /css/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openresty/openresty-survey/d4ee1f4bd39b005e84b8c1393a32bb1eb2dedc1c/css/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /css/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openresty/openresty-survey/d4ee1f4bd39b005e84b8c1393a32bb1eb2dedc1c/css/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /css/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openresty/openresty-survey/d4ee1f4bd39b005e84b8c1393a32bb1eb2dedc1c/css/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /css/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openresty/openresty-survey/d4ee1f4bd39b005e84b8c1393a32bb1eb2dedc1c/css/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /css/home.css: -------------------------------------------------------------------------------- 1 | #cnt1 { 2 | /* background-color: rgba(215, 212, 212, 0.88); */ 3 | margin-top: 10px; 4 | margin-bottom: 70px; 5 | } 6 | 7 | #panel1 { 8 | padding:20px; 9 | } 10 | 11 | .panel-body:not(.two-col) { 12 | padding: 0px; 13 | } 14 | 15 | .panel-body .radio, .panel-body .checkbox { 16 | margin-top: 0px; 17 | margin-bottom: 0px; 18 | } 19 | 20 | .panel-body .list-group { 21 | margin-bottom: 0; 22 | } 23 | 24 | .margin-bottom-none { 25 | margin-bottom: 0; 26 | } 27 | 28 | @media screen and (min-width: 480px) { 29 | .text-box-md { 30 | width: 20em; 31 | } 32 | 33 | .text-box-lg { 34 | width: 33em; 35 | } 36 | 37 | .text-label { 38 | display: inline-block; 39 | width: 8em; 40 | } 41 | 42 | .text-label-lg { 43 | display: inline-block; 44 | width: 24em; 45 | } 46 | } 47 | 48 | .success-icon { 49 | color: green; 50 | padding: 10px; 51 | font-size: 110%; 52 | } 53 | 54 | .fail-icon { 55 | color: red; 56 | padding: 10px; 57 | font-size: 110%; 58 | } 59 | 60 | .required-field { 61 | color: red; 62 | } 63 | -------------------------------------------------------------------------------- /css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | } 4 | .starter-template { 5 | padding: 40px 15px; 6 | text-align: center; 7 | } 8 | -------------------------------------------------------------------------------- /css/vendor/ie10-viewport-bug-workaround.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * IE10 viewport hack for Surface/desktop Windows 8 bug 3 | * Copyright 2014-2015 Twitter, Inc. 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 5 | */ 6 | 7 | /* 8 | * See the Getting Started docs for more information: 9 | * http://getbootstrap.com/getting-started/#support-ie10-width 10 | */ 11 | @-webkit-viewport { width: device-width; } 12 | @-moz-viewport { width: device-width; } 13 | @-ms-viewport { width: device-width; } 14 | @-o-viewport { width: device-width; } 15 | @viewport { width: device-width; } 16 | -------------------------------------------------------------------------------- /html/cn-index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
67 | Please contact openresty@gmail.com
if the problem persists.
68 |
71 | Return to the survey page 72 |
73 |68 | Return to the OpenResty home 69 |
70 |