assertJsonConfig 骨架

This commit is contained in:
jysperm
2014-06-29 22:07:10 +08:00
parent 360de90f99
commit 0532c8fb3b
3 changed files with 49 additions and 4 deletions

View File

@@ -2,3 +2,5 @@ exports.rx =
username: /^[0-9a-z_]{3,23}$/
email: /^\w+([-+.]\w+)*@\w+([-+.]\w+)*$/
passwd: /^.+$/
domain: /(\*\.)?[A-Za-z0-9]+(\-[A-Za-z0-9]+)*(\.[A-Za-z0-9]+(\-[A-Za-z0-9]+)*)*/
filename: /[A-Za-z0-9_\-\.]+/

View File

@@ -21,3 +21,9 @@ Exception:
* invalid_type
* forbidden
* invalid_listen
* invalid_server_name
* invalid_index
* invalid_root
* invalid_location
* fastcgi_index

View File

@@ -1,5 +1,6 @@
child_process = require 'child_process'
utils = require '../../core/router/utils'
plugin = require '../../core/plugin'
{requestAuthenticate} = require '../../core/router/middleware'
@@ -19,15 +20,12 @@ sample =
index: ['index.html']
# required
root: '/home/user/web'
# default []
# default {}
location:
'/':
fastcgi_pass: 'unix:///home/user/phpfpm.sock'
fastcgi_index: ['index.php']
assertJsonConfig = (config) ->
exports.use (req, res, next) ->
req.inject [requestAuthenticate], ->
unless 'nginx' in req.account.attribute.services
@@ -39,6 +37,45 @@ exports.post '/update_site/', (req, res) ->
unless req.body.action in ['create', 'update', 'delete']
return res.error 'invalid_action'
assertJsonConfig = (config) ->
checkHomeFile = (file) ->
unless config.listen in [80]
return 'invalid_listen'
for domain in config.server_name
unless utils.rx.test domain
return 'invalid_server_name'
if config.auto_index
config.auto_index = if config.auto_index then true else false
config.index ?= ['index']
for file in config.index
unless utils.rx.test file
return 'invalid_index'
unless checkHomeFile config.root
return 'invalid_root'
config.location ?= {}
for path, rules of config.location
unless path in ['/']
return 'invalid_location'
for name, value of rules
if name == 'fastcgi_pass'
# TODO: check unix socket path
if name == 'fastcgi_index'
for file in value
unless utils.rx.test file
return 'fastcgi_index'
return null
checkSite = (callback) ->
if req.body.action == 'create'
callback null