diff --git a/CHANGELOG.md b/CHANGELOG.md index df697777..cffce32e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +### v0.6.2 2017.02.18 + +- 兼容Orange与最新版本的[lor](https://github.com/sumory/lor), 即lor v0.3.0 + +注意: + +- 若使用的Orange版本在0.6.2以下,则应安装lor v0.2.*版本, 推荐lor v0.2.6 +- 若使用的Orange版本在0.6.2及以上,可升级lor到v0.3.0+版本 + ### v0.6.1 2017.02.09 添加property based rate limiting插件,该插件由[@noname007](https://github.com/noname007)贡献 diff --git a/README.md b/README.md index 35c45e99..f23c13db 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,11 @@ A Gateway based on OpenResty(Nginx+lua) for API Monitoring and Management. - MySQL v5.5+ - OpenResty v1.9.7.3+ or Nginx+lua module - install OpenResty with `--with-http_stub_status_module` option -- [Lor Framework](https://github.com/sumory/lor) v0.2.6, **not compatible** with lor v0.3.0 for now. +- [Lor Framework](https://github.com/sumory/lor) please mind: + - Orange v0.6.1 and versions before v0.6.1 are compatible with lor v0.2.* + - Orange v0.6.2+ is compatible with lor v0.3.0+ -Import the SQL file(e.g. install/orange-v0.6.1.sql) which is adapted to your Orange version to MySQL database named `orange`. +Import the SQL file(e.g. install/orange-v0.6.2.sql) which is adapted to your Orange version into MySQL database named `orange`. #### Install diff --git a/README_zh.md b/README_zh.md index 5bce20b0..f5976b51 100644 --- a/README_zh.md +++ b/README_zh.md @@ -19,17 +19,16 @@ Orange是一个基于OpenResty的API网关。除Nginx的基本功能外,它还 - OpenResty: 版本应在1.9.7.3+ - Orange的监控插件需要统计http的某些状态数据,所以需要编译OpenResty时添加`--with-http_stub_status_module` - 由于使用了*_block指令,所以OpenResty的版本最好在1.9.7.3以上. -- [lor](https://github.com/sumory/lor)框架: 版本v0.2.6 - - 暂时与lor v0.3.0(即master版本)不兼容 - - 下载0.2.6版本的release包,解压到lor文件夹 - - cd lor && sh install.sh +- [lor](https://github.com/sumory/lor)框架 + - 若使用的Orange版本低于v0.6.2则应安装lor v0.2.*版本 + - 若使用的Orange版本高于或等于v0.6.2则应安装lor v0.3.0+版本 - MySQL - 配置存储和集群扩展需要MySQL支持。从0.2.0版本开始,Orange去除了本地文件存储的方式,目前仅提供MySQL存储支持. #### 数据表导入MySQL - 在MySQL中创建数据库,名为orange -- 将与当前代码版本配套的SQL脚本(如install/orange-v0.6.1.sql)导入到orange库中 +- 将与当前代码版本配套的SQL脚本(如install/orange-v0.6.2.sql)导入到orange库中 #### 修改配置文件 @@ -45,10 +44,12 @@ orange.conf的配置如下,请按需修改: "redirect", "rewrite", "rate_limiting", + "property_rate_limiting", "basic_auth", "key_auth", "waf", - "divide" + "divide", + "kvstore" ], "store": "mysql",//目前仅支持mysql存储 diff --git a/api/server.lua b/api/server.lua index 9d22536a..a3835800 100644 --- a/api/server.lua +++ b/api/server.lua @@ -64,29 +64,26 @@ function _M:build_app() end end end - + auth_failed(res) end) -- routes app:use(router(config, store)()) - -- 404 error - app:use(function(req, res, next) + -- error handle middleware + app:erroruse(function(err, req, res, next) + ngx.log(ngx.ERR, err) if req:is_found() ~= true then - res:status(404):json({ + return res:status(404):json({ success = false, msg = "404! sorry, not found." }) end - end) - -- error handle middleware - app:erroruse(function(err, req, res, next) - ngx.log(ngx.ERR, err) res:status(500):json({ success = false, - msg = "500! unknown error." + msg = "500! server error." }) end) end diff --git a/dashboard/routes/auth.lua b/dashboard/routes/auth.lua index 87c9d3f5..eb85cd4d 100644 --- a/dashboard/routes/auth.lua +++ b/dashboard/routes/auth.lua @@ -49,7 +49,7 @@ return function(config, store) if result and not err then if result and #result == 1 then isExist = true - user = result[1] + user = result[1] userid = user.id end else @@ -91,7 +91,7 @@ return function(config, store) res.locals.userid = 0 res.locals.create_time = "" req.session.destroy() - res:redirect("/login") + res:redirect("/auth/login") end) diff --git a/dashboard/server.lua b/dashboard/server.lua index a4d6bc9a..5c6a021c 100755 --- a/dashboard/server.lua +++ b/dashboard/server.lua @@ -1,4 +1,5 @@ local string_find = string.find +local setmetatable = setmetatable local session_middleware = require("lor.lib.middleware.session") local check_login_middleware = require("dashboard.middleware.check_login") local check_is_admin_middleware = require("dashboard.middleware.check_is_admin") @@ -53,32 +54,29 @@ function _M:build_app() -- routes app:use(dashboard_router(config, store)()) - -- 404 error - app:use(function(req, res, next) + -- error handle middleware + app:erroruse(function(err, req, res, next) + ngx.log(ngx.ERR, err) + local is_json_accept = string_find(req.headers["Accept"], "application/json") + if req:is_found() ~= true then - if string_find(req.headers["Accept"], "application/json") then - res:status(404):json({ + if is_json_accept then + return res:status(404):json({ success = false, msg = "404! sorry, not found." }) - else - res:status(404):send("404! sorry, not found. " .. req.path or "") end + return res:status(404):send("404! sorry, not found. " .. (req.path or "")) end - end) - -- error handle middleware - app:erroruse(function(err, req, res, next) - ngx.log(ngx.ERR, err) - - if string_find(req.headers["Accept"], "application/json") then - res:status(500):json({ + if is_json_accept then + return res:status(500):json({ success = false, msg = "500! unknown error." }) - else - res:status(500):send("unknown error") end + + res:status(500):send("unknown error") end) end diff --git a/install/orange-v0.6.2.sql b/install/orange-v0.6.2.sql new file mode 100644 index 00000000..90b3cf19 --- /dev/null +++ b/install/orange-v0.6.2.sql @@ -0,0 +1,301 @@ +# ************************************************************ +# Sequel Pro SQL dump +# Version 4096 +# +# http://www.sequelpro.com/ +# http://code.google.com/p/sequel-pro/ +# +# Host: 127.0.0.1 (MySQL 5.6.15) +# Database: orange_test +# Generation Time: 2016-11-13 14:48:35 +0000 +# ************************************************************ + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + + +# Dump of table basic_auth +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `basic_auth`; + +CREATE TABLE `basic_auth` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL DEFAULT '', + `value` varchar(2000) NOT NULL DEFAULT '', + `type` varchar(11) DEFAULT '0', + `op_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +LOCK TABLES `basic_auth` WRITE; +/*!40000 ALTER TABLE `basic_auth` DISABLE KEYS */; + +INSERT INTO `basic_auth` (`id`, `key`, `value`, `type`, `op_time`) +VALUES + (1,'1','{}','meta','2016-11-11 11:11:11'); + +/*!40000 ALTER TABLE `basic_auth` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table dashboard_user +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `dashboard_user`; + +CREATE TABLE `dashboard_user` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `username` varchar(60) NOT NULL DEFAULT '' COMMENT '用户名', + `password` varchar(255) NOT NULL DEFAULT '' COMMENT '密码', + `is_admin` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否是管理员账户:0否,1是', + `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建或者更新时间', + `enable` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否启用该用户:0否1是', + PRIMARY KEY (`id`), + UNIQUE KEY `unique_username` (`username`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='dashboard users'; + +LOCK TABLES `dashboard_user` WRITE; +/*!40000 ALTER TABLE `dashboard_user` DISABLE KEYS */; + +INSERT INTO `dashboard_user` (`id`, `username`, `password`, `is_admin`, `create_time`, `enable`) +VALUES + (1,'admin','1fe832a7246fd19b7ea400a10d23d1894edfa3a5e09ee27e0c4a96eb0136763d',1,'2016-11-11 11:11:11',1); + +/*!40000 ALTER TABLE `dashboard_user` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table divide +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `divide`; + +CREATE TABLE `divide` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL DEFAULT '', + `value` varchar(2000) NOT NULL DEFAULT '', + `type` varchar(11) DEFAULT '0', + `op_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +LOCK TABLES `divide` WRITE; +/*!40000 ALTER TABLE `divide` DISABLE KEYS */; + +INSERT INTO `divide` (`id`, `key`, `value`, `type`, `op_time`) +VALUES + (1,'1','{}','meta','2016-11-11 11:11:11'); + +/*!40000 ALTER TABLE `divide` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table key_auth +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `key_auth`; + +CREATE TABLE `key_auth` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL DEFAULT '', + `value` varchar(2000) NOT NULL DEFAULT '', + `type` varchar(11) DEFAULT '0', + `op_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +LOCK TABLES `key_auth` WRITE; +/*!40000 ALTER TABLE `key_auth` DISABLE KEYS */; + +INSERT INTO `key_auth` (`id`, `key`, `value`, `type`, `op_time`) +VALUES + (1,'1','{}','meta','2016-11-11 11:11:11'); + +/*!40000 ALTER TABLE `key_auth` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table meta +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `meta`; + +CREATE TABLE `meta` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL DEFAULT '', + `value` varchar(5000) NOT NULL DEFAULT '', + `op_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + + +# Dump of table monitor +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `monitor`; + +CREATE TABLE `monitor` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL DEFAULT '', + `value` varchar(2000) NOT NULL DEFAULT '', + `type` varchar(11) DEFAULT '0', + `op_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +LOCK TABLES `monitor` WRITE; +/*!40000 ALTER TABLE `monitor` DISABLE KEYS */; + +INSERT INTO `monitor` (`id`, `key`, `value`, `type`, `op_time`) +VALUES + (1,'1','{}','meta','2016-11-11 11:11:11'); + +/*!40000 ALTER TABLE `monitor` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table rate_limiting +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `rate_limiting`; + +CREATE TABLE `rate_limiting` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL DEFAULT '', + `value` varchar(2000) NOT NULL DEFAULT '', + `type` varchar(11) DEFAULT '0', + `op_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +LOCK TABLES `rate_limiting` WRITE; +/*!40000 ALTER TABLE `rate_limiting` DISABLE KEYS */; + +INSERT INTO `rate_limiting` (`id`, `key`, `value`, `type`, `op_time`) +VALUES + (1,'1','{}','meta','2016-11-11 11:11:11'); + +/*!40000 ALTER TABLE `rate_limiting` ENABLE KEYS */; +UNLOCK TABLES; + +DROP TABLE IF EXISTS `property_rate_limiting`; + +CREATE TABLE `property_rate_limiting` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL DEFAULT '', + `value` varchar(2000) NOT NULL DEFAULT '', + `type` varchar(11) DEFAULT '0', + `op_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +LOCK TABLES `property_rate_limiting` WRITE; +/*!40000 ALTER TABLE `property_rate_limiting` DISABLE KEYS */; + +INSERT INTO `property_rate_limiting` (`id`, `key`, `value`, `type`, `op_time`) +VALUES + (1,'1','{}','meta','2016-11-11 11:11:11'); + +/*!40000 ALTER TABLE `property_rate_limiting` ENABLE KEYS */; +UNLOCK TABLES; + +# Dump of table redirect +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `redirect`; + +CREATE TABLE `redirect` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL DEFAULT '', + `value` varchar(2000) NOT NULL DEFAULT '', + `type` varchar(11) DEFAULT '0', + `op_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +LOCK TABLES `redirect` WRITE; +/*!40000 ALTER TABLE `redirect` DISABLE KEYS */; + +INSERT INTO `redirect` (`id`, `key`, `value`, `type`, `op_time`) +VALUES + (1,'1','{}','meta','2016-11-11 11:11:11'); + +/*!40000 ALTER TABLE `redirect` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table rewrite +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `rewrite`; + +CREATE TABLE `rewrite` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL DEFAULT '', + `value` varchar(2000) NOT NULL DEFAULT '', + `type` varchar(11) DEFAULT '0', + `op_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +LOCK TABLES `rewrite` WRITE; +/*!40000 ALTER TABLE `rewrite` DISABLE KEYS */; + +INSERT INTO `rewrite` (`id`, `key`, `value`, `type`, `op_time`) +VALUES + (1,'1','{}','meta','2016-11-11 11:11:11'); + +/*!40000 ALTER TABLE `rewrite` ENABLE KEYS */; +UNLOCK TABLES; + + +# Dump of table waf +# ------------------------------------------------------------ + +DROP TABLE IF EXISTS `waf`; + +CREATE TABLE `waf` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `key` varchar(255) NOT NULL DEFAULT '', + `value` varchar(2000) NOT NULL DEFAULT '', + `type` varchar(11) DEFAULT '0', + `op_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_key` (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +LOCK TABLES `waf` WRITE; +/*!40000 ALTER TABLE `waf` DISABLE KEYS */; + +INSERT INTO `waf` (`id`, `key`, `value`, `type`, `op_time`) +VALUES + (1,'1','{}','meta','2016-11-11 11:11:11'); + +/*!40000 ALTER TABLE `waf` ENABLE KEYS */; +UNLOCK TABLES; + + + +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/orange/version.lua b/orange/version.lua index a8e1b9ba..42910d7c 100644 --- a/orange/version.lua +++ b/orange/version.lua @@ -1,2 +1,2 @@ -local version = "0.6.1" +local version = "0.6.2" return version