1
1
<template >
2
- <a-tabs v-model =" current_server_index" >
3
- <a-tab-pane :tab =" 'Server '+(k+1)" v-for =" (v,k) in ngx_config.servers" :key =" k" >
4
-
5
- <div class =" tab-content" >
6
- <template v-if =" support_ssl && enabled " >
7
- <cert-info :domain =" name" v-if =" name" />
8
- <issue-cert
9
- :current_server_directives =" current_server_directives"
10
- :directives-map =" directivesMap"
11
- v-model =" auto_cert"
12
- />
13
- <cert-info :current_server_directives =" current_server_directives"
14
- :directives-map =" directivesMap"
15
- v-model =" auto_cert" />
16
- </template >
17
-
18
- <a-form-item :label =" $gettext('Comments')" v-if =" v.comments" >
19
- <p style =" white-space : pre-wrap ;" >{{ v.comments }}</p >
20
- </a-form-item >
21
-
22
- <directive-editor :ngx_directives =" v.directives" :key =" update" />
23
-
24
- <location-editor :locations =" v.locations" />
25
- </div >
26
-
27
- </a-tab-pane >
28
- </a-tabs >
2
+ <div >
3
+ <a-form-item :label =" $gettext('Enable TLS')" v-if =" !support_ssl" >
4
+ <a-switch @change =" change_tls" />
5
+ </a-form-item >
6
+
7
+ <a-tabs v-model =" current_server_index" >
8
+ <a-tab-pane :tab =" 'Server '+(k+1)" v-for =" (v,k) in ngx_config.servers" :key =" k" >
9
+
10
+ <div class =" tab-content" >
11
+ <template v-if =" current_support_ssl && enabled " >
12
+ <cert-info :domain =" name" v-if =" name" />
13
+ <issue-cert
14
+ :current_server_directives =" current_server_directives"
15
+ :directives-map =" directivesMap"
16
+ v-model =" auto_cert"
17
+ />
18
+ <cert-info :current_server_directives =" current_server_directives"
19
+ :directives-map =" directivesMap"
20
+ v-model =" auto_cert" />
21
+ </template >
22
+
23
+ <a-form-item :label =" $gettext('Comments')" v-if =" v.comments" >
24
+ <p style =" white-space : pre-wrap ;" >{{ v.comments }}</p >
25
+ </a-form-item >
26
+
27
+ <directive-editor :ngx_directives =" v.directives" :key =" update" />
28
+
29
+ <location-editor :locations =" v.locations" />
30
+ </div >
31
+
32
+ </a-tab-pane >
33
+ </a-tabs >
34
+ </div >
35
+
29
36
</template >
30
37
31
38
<script >
@@ -47,6 +54,7 @@ export default {
47
54
current_server_index: 0 ,
48
55
update: 0 ,
49
56
name: this .$route .params ? .name ? .toString () ?? ' ' ,
57
+ init_ssl_status: false
50
58
}
51
59
},
52
60
model: {
@@ -58,7 +66,64 @@ export default {
58
66
if (this .name && this .$refs [' cert-info' + this .current_server_index ]) {
59
67
this .$refs [' cert-info' + this .current_server_index ].get ()
60
68
}
61
- }
69
+ },
70
+ change_tls (r ) {
71
+ if (r) {
72
+ // deep copy servers[0] to servers[1]
73
+ const server = JSON .parse (JSON .stringify (this .ngx_config .servers [0 ]))
74
+
75
+ this .ngx_config .servers .push (server)
76
+
77
+ this .current_server_index = 1
78
+
79
+ const servers = this .ngx_config .servers
80
+
81
+ let i = 0
82
+ while (i < servers[1 ].directives .length ) {
83
+ const v = servers[1 ].directives [i]
84
+ if (v .directive === ' listen' ) {
85
+ servers[1 ].directives .splice (i, 1 )
86
+ } else {
87
+ i++
88
+ }
89
+ }
90
+
91
+ servers[1 ].directives .splice (0 , 0 , {
92
+ directive: ' listen' ,
93
+ params: ' 443 ssl http2'
94
+ }, {
95
+ directive: ' listen' ,
96
+ params: ' [::]:443 ssl http2'
97
+ })
98
+
99
+ const directivesMap = this .directivesMap
100
+
101
+ const server_name = directivesMap[' server_name' ][0 ]
102
+
103
+ if (! directivesMap[' ssl_certificate' ]) {
104
+ servers[1 ].directives .splice (server_name .idx + 1 , 0 , {
105
+ directive: ' ssl_certificate' ,
106
+ params: ' '
107
+ })
108
+ }
109
+
110
+ setTimeout (() => {
111
+ if (! directivesMap[' ssl_certificate_key' ]) {
112
+ servers[1 ].directives .splice (server_name .idx + 2 , 0 , {
113
+ directive: ' ssl_certificate_key' ,
114
+ params: ' '
115
+ })
116
+ }
117
+ }, 100 )
118
+
119
+ } else {
120
+ // remove servers[1]
121
+ this .current_server_index = 0
122
+ if (this .ngx_config .servers .length === 2 ) {
123
+ this .ngx_config .servers .splice (1 , 1 )
124
+ }
125
+ }
126
+ },
62
127
},
63
128
computed: {
64
129
directivesMap: {
@@ -82,7 +147,19 @@ export default {
82
147
return this .ngx_config .servers [this .current_server_index ].directives
83
148
}
84
149
},
85
- support_ssl: {
150
+ support_ssl () {
151
+ const servers = this .ngx_config .servers
152
+ for (const server_key in servers) {
153
+ for (const k in servers[server_key].directives ) {
154
+ const v = servers[server_key].directives [k]
155
+ if (v .directive === ' listen' && v .params .indexOf (' ssl' ) > 0 ) {
156
+ return true
157
+ }
158
+ }
159
+ }
160
+ return false
161
+ },
162
+ current_support_ssl: {
86
163
get () {
87
164
if (this .directivesMap .listen ) {
88
165
for (const v of this .directivesMap .listen ) {
0 commit comments