mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-01-12 22:27:09 +08:00
向导模式与 JSON 格式同步
This commit is contained in:
@@ -135,8 +135,8 @@
|
||||
* location - proxy_set_header
|
||||
|
||||
* 在转发至 http 服务器时设置 HTTP 头
|
||||
* 字符串,可选指令
|
||||
* 值为一个域名或 `$host`
|
||||
* 对象,可选指令
|
||||
* 键名为 `Host` 时,值为一个域名或 `$host`
|
||||
|
||||
* location - proxy_redirect
|
||||
|
||||
|
||||
@@ -31,8 +31,99 @@ $ ->
|
||||
.success ->
|
||||
location.reload()
|
||||
|
||||
$('#nginx-type-json textarea').on 'change keyup paste', ->
|
||||
try
|
||||
JSON.parse($('#nginx-type-json textarea').val())
|
||||
$('.json-error').parent().addClass 'hide'
|
||||
catch err
|
||||
console.log err
|
||||
$('.json-error').text err.toString()
|
||||
$('.json-error').parent().removeClass 'hide'
|
||||
|
||||
syncToJSON = ->
|
||||
username = $('.nav.navbar-nav.navbar-right li:first a').text()
|
||||
|
||||
try
|
||||
config = JSON.parse($('#nginx-type-json textarea').val())
|
||||
catch e
|
||||
config = {}
|
||||
|
||||
config['is_enable'] = $('.option-is-enable input').prop('checked')
|
||||
config['server_name'] = $('.option-server-name input').val().split ' '
|
||||
|
||||
switch $('.option-type :radio:checked').val()
|
||||
when 'fastcgi'
|
||||
config['root'] = $('.option-root input').val() or $('.option-root input').prop('placeholder')
|
||||
config['location'] ?= {}
|
||||
config['location']['/'] =
|
||||
try_files: ['$uri', '$uri/', '/index.php?$args']
|
||||
config['location']['~ \\.php$'] =
|
||||
fastcgi_pass: "unix:///home/#{username}/phpfpm.sock"
|
||||
include: 'fastcgi_params'
|
||||
|
||||
when 'proxy'
|
||||
config['location'] ?= {}
|
||||
config['location']['/'] =
|
||||
proxy_pass: $('.option-proxy input').val() or $('.option-proxy input').prop('placeholder')
|
||||
proxy_set_header:
|
||||
Host: '$host'
|
||||
|
||||
when 'uwsgi'
|
||||
config['location'] ?= {}
|
||||
config['location']['/'] =
|
||||
uwsgi_pass: $('.option-uwsgi input').val() or $('.option-uwsgi input').prop('placeholder')
|
||||
include: 'uwsgi_params'
|
||||
|
||||
when 'static'
|
||||
config['root'] = $('.option-root input').val() or $('.option-root input').prop('placeholder')
|
||||
|
||||
json = $('#nginx-type-json textarea').val JSON.stringify(config, null, ' ')
|
||||
return json
|
||||
|
||||
$('#nginx-modal ul li a').click ->
|
||||
switch $(@).prop('href').match(/.*#nginx-type-(.*)/)[1]
|
||||
when 'json'
|
||||
syncToJSON()
|
||||
when 'guide'
|
||||
$('.json-error').parent().addClass 'hide'
|
||||
|
||||
try
|
||||
config = JSON.parse($('#nginx-type-json textarea').val())
|
||||
catch e
|
||||
return
|
||||
|
||||
$('.option-is-enable input').prop 'checked', config['is_enable']
|
||||
$('.option-server-name input').val config['server_name']?.join ' '
|
||||
$('.option-root input').val config['root']
|
||||
|
||||
type = do ->
|
||||
unless config['location']['/']
|
||||
return 'static'
|
||||
|
||||
if config['location']['/']['proxy_pass']
|
||||
return 'proxy'
|
||||
|
||||
if config['location']['/']['uwsgi_pass']
|
||||
return 'uwsgi'
|
||||
|
||||
if config['location']['/']?['try_files']
|
||||
for item in config['location']['/']['try_files']
|
||||
if item.match(/\.php/)
|
||||
return 'factcgi'
|
||||
|
||||
return 'static'
|
||||
|
||||
$("#nginx-modal :radio[value=#{type}]").click()
|
||||
|
||||
switch type
|
||||
when 'proxy'
|
||||
$('.option-proxy input').val config['location']['/']['proxy_pass']
|
||||
when 'uwsgi'
|
||||
$('.option-uwsgi input').val config['location']['/']['uwsgi_pass']
|
||||
when 'static', 'fastcgi'
|
||||
$('.option-root input').val config['root']
|
||||
|
||||
$('#nginx-modal .radio input').click ->
|
||||
console.log $(@).val()
|
||||
options = ['root', 'proxy', 'uwsgi']
|
||||
|
||||
mapping_table =
|
||||
@@ -50,10 +141,10 @@ $ ->
|
||||
$("#nginx-modal .option-#{item}").addClass 'hide'
|
||||
|
||||
$('#nginx-modal .modal-footer button.btn-success').click ->
|
||||
type = $('#nginx-modal ul.config-type').find('.active a').attr('href')['#nginx-type-'.length..]
|
||||
type = $('#nginx-modal ul.config-type').find('.active a').prop('href')['#nginx-type-'.length..]
|
||||
|
||||
if type == 'guide'
|
||||
config = {}
|
||||
config = syncToJSON()
|
||||
|
||||
else if type == 'json'
|
||||
try
|
||||
@@ -116,7 +207,7 @@ $ ->
|
||||
$.post '/plugin/nginx/update_site', JSON.stringify {
|
||||
action: 'delete'
|
||||
id: id
|
||||
type: $('#nginxConfigType').find('.active a').attr('href').substr 1
|
||||
type: $('#nginxConfigType').find('.active a').prop('href').substr 1
|
||||
}
|
||||
.success ->
|
||||
location.reload()
|
||||
|
||||
@@ -63,8 +63,13 @@ exports.assert = (account, config, site_id, callback) ->
|
||||
return callback 'invalid_proxy_pass'
|
||||
|
||||
when 'proxy_set_header'
|
||||
unless value == '$host' or utils.rx.domain.test value
|
||||
return callback 'proxy_set_header'
|
||||
for header_name, header_value of value
|
||||
switch header_name
|
||||
when 'Host'
|
||||
unless header_value == '$host' or utils.rx.domain.test header_value
|
||||
return callback 'invalid_proxy_set_header'
|
||||
else
|
||||
return callback 'invalid_proxy_set_header'
|
||||
|
||||
when 'proxy_redirect'
|
||||
config.location['proxy_redirect'] = if value then true else false
|
||||
|
||||
@@ -36,24 +36,24 @@ table.table.table-hover
|
||||
.tab-pane.active#nginx-type-guide
|
||||
form.form-horizontal(role='form')
|
||||
h3 常规
|
||||
.form-group
|
||||
.form-group.option-is-enable
|
||||
label.col-sm-2.control-label »
|
||||
.checkbox.col-sm-10
|
||||
label
|
||||
input(type='checkbox')
|
||||
input(type='checkbox', checked)
|
||||
| 启用站点
|
||||
.form-group
|
||||
.form-group.option-server-name
|
||||
label.col-sm-2.control-label 域名
|
||||
.col-sm-10
|
||||
input.form-control(type='text', placeholder='example.com example.net')
|
||||
|
||||
h3 类型
|
||||
.form-group
|
||||
.form-group.option-type
|
||||
label.col-sm-2.control-label »
|
||||
.controls.col-sm-10
|
||||
.radio
|
||||
label
|
||||
input(type='radio', name='site-type', value='fastcgi')
|
||||
input(type='radio', name='site-type', value='fastcgi', checked)
|
||||
| fastcgi (PHP)
|
||||
.radio
|
||||
label
|
||||
@@ -69,7 +69,7 @@ table.table.table-hover
|
||||
| static (静态文件)
|
||||
|
||||
h3 选项
|
||||
.form-group.option-root.hide
|
||||
.form-group.option-root
|
||||
label.col-sm-2.control-label 根目录
|
||||
.col-sm-10
|
||||
input.form-control(type='text', placeholder='/home/#{account.username}/web')
|
||||
@@ -88,5 +88,9 @@ table.table.table-hover
|
||||
.tab-pane#nginx-type-original
|
||||
p 即将支持
|
||||
.modal-footer
|
||||
p.pull-left.hide
|
||||
span.glyphicon.glyphicon-warning-sign
|
||||
|
|
||||
span.json-error.text-danger 错误信息
|
||||
button.btn.btn-danger(type='button', data-dismiss='modal') 关闭
|
||||
button.btn.btn-success(type='button') 保存
|
||||
|
||||
Reference in New Issue
Block a user