mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-23 11:17:54 +08:00
assertJsonConfig 骨架
This commit is contained in:
@@ -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_\-\.]+/
|
||||
|
||||
@@ -21,3 +21,9 @@ Exception:
|
||||
* invalid_type
|
||||
* forbidden
|
||||
|
||||
* invalid_listen
|
||||
* invalid_server_name
|
||||
* invalid_index
|
||||
* invalid_root
|
||||
* invalid_location
|
||||
* fastcgi_index
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user