Просмотр исходного кода

feat(config): add ws-host configuration (#156)

lejianwen месяцев назад: 11
Родитель
Сommit
08420f9db6
5 измененных файлов с 22 добавлено и 135 удалено
  1. 3 64
      README.md
  2. 2 63
      README_EN.md
  3. 1 0
      conf/config.yaml
  4. 2 1
      config/rustdesk.go
  5. 14 7
      http/controller/web/index.go

+ 3 - 64
README.md

@@ -108,8 +108,7 @@
108 108
       * 可以官方指令
109 109
       * 可以添加自定义指令
110 110
       * 可以执行自定义指令
111
-    
112
-    ![rustdesk_command_advance](./docs/rustdesk_command_advance.png)
111
+
113 112
  
114 113
 11. **LDAP 支持**, 当在API Server上设置了LDAP(已测试AD和LDAP),可以通过LDAP中的用户信息进行登录 https://github.com/lejianwen/rustdesk-api/issues/114 ,如果LDAP验证失败,返回本地用户
115 114
 
@@ -146,72 +145,11 @@
146 145
 
147 146
 ### 相关配置
148 147
 
148
+* [配置文件](./conf/config.yaml)
149 149
 * 参考`conf/config.yaml`配置文件,修改相关配置。
150 150
 * 如果`gorm.type`是`sqlite`,则不需要配置mysql相关配置。
151 151
 * 语言如果不设置默认为`zh-CN`
152 152
 
153
-```yaml
154
-lang: "en"
155
-app:
156
-  web-client: 1  # 1:启用 0:禁用
157
-  register: false #是否开启注册
158
-  show-swagger: 0 #是否显示swagger文档
159
-  web-sso: true #是否显示web sso
160
-  token-expire: 168h #token有效时长
161
-  disable-pwd-login: false #是否禁用密码登录
162
-gin:
163
-  api-addr: "0.0.0.0:21114"
164
-  mode: "release"
165
-  resources-path: 'resources'
166
-  trust-proxy: ""
167
-gorm:
168
-  type: "sqlite"
169
-  max-idle-conns: 10
170
-  max-open-conns: 100
171
-mysql:
172
-  username: "root"
173
-  password: "111111"
174
-  addr: "192.168.1.66:3308"
175
-  dbname: "rustdesk"
176
-rustdesk:
177
-  id-server: "192.168.1.66:21116"
178
-  relay-server: "192.168.1.66:21117"
179
-  api-server: "http://192.168.1.66:21114"
180
-  key: "123456789"
181
-  personal: 1
182
-logger:
183
-  path: "./runtime/log.txt"
184
-  level: "warn" #trace,debug,info,warn,error,fatal
185
-  report-caller: true
186
-proxy:
187
-  enable: false
188
-  host: ""
189
-jwt:
190
-  key: ""
191
-  expire-duration: 168h
192
-ldap:
193
-  enable: false
194
-  url: "ldap://ldap.example.com:389"
195
-  tls: false
196
-  tls-verify: false
197
-  base-dn: "dc=example,dc=com"
198
-  bind-dn: "cn=admin,dc=example,dc=com"
199
-  bind-password: "password"
200
-
201
-  user:
202
-    base-dn: "ou=users,dc=example,dc=com"
203
-    enable-attr: ""       #The attribute name of the user for enabling, in AD it is "userAccountControl", empty means no enable attribute, all users are enabled
204
-    enable-attr-value: "" # The value of the enable attribute when the user is enabled. If you are using AD, just set random value, it will be ignored.
205
-    filter: "(cn=*)"
206
-    username: "uid"       # The attribute name of the user for usernamem if you are using AD, it should be "sAMAccountName"
207
-    email: "mail"
208
-    first-name: "givenName"
209
-    last-name: "sn"
210
-    sync: false         # If true, the user will be synchronized to the database when the user logs in. If false, the user will be synchronized to the database when the user be created.
211
-    admin-group: "cn=admin,dc=example,dc=com" # The group name of the admin group, if the user is in this group, the user will be an admin.
212
-
213
-```
214
-
215 153
 ### 环境变量
216 154
 环境变量和配置文件`conf/config.yaml`中的配置一一对应,变量名前缀是`RUSTDESK_API`
217 155
 下面表格并未全部列出,可以参考`conf/config.yaml`中的配置。
@@ -248,6 +186,7 @@ ldap:
248 186
 | RUSTDESK_API_RUSTDESK_KEY                              | Rustdesk的key                                                                   | 123456789                    |
249 187
 | RUSTDESK_API_RUSTDESK_KEY_FILE                         | Rustdesk存放key的文件                                                               | `./conf/data/id_ed25519.pub` |
250 188
 | RUSTDESK_API_RUSTDESK_WEBCLIENT<br/>_MAGIC_QUERYONLINE | Web client v2 中是否启用新的在线状态查询方法; `1`:启用,`0`:不启用,默认不启用                            | `0`                          |
189
+| RUSTDESK_API_RUSTDESK_WS_HOST                          | 自定义Websocket Host                                                              |                              |
251 190
 | ----PROXY配置-----                                       | ----------                                                                     | ----------                   |
252 191
 | RUSTDESK_API_PROXY_ENABLE                              | 是否启用代理:`false`, `true`                                                         | `false`                      |
253 192
 | RUSTDESK_API_PROXY_HOST                                | 代理地址                                                                           | `http://127.0.0.1:1080`      |

+ 2 - 63
README_EN.md

@@ -109,8 +109,6 @@ displaying data.Frontend code is available at [rustdesk-api-web](https://github.
109 109
     * Custom commands can be added
110 110
     * Custom commands can be executed
111 111
 
112
-    ![rustdesk_command_advance](./docs/en_img/rustdesk_command_advance.png)
113
-
114 112
 11. **LDAP Support**, When you setup the LDAP(test for OpenLDAP and AD), you can login with the LDAP's user. https://github.com/lejianwen/rustdesk-api/issues/114 , if LDAP fail fallback local user
115 113
   
116 114
 ### Web Client:
@@ -145,71 +143,11 @@ displaying data.Frontend code is available at [rustdesk-api-web](https://github.
145 143
 
146 144
 ### Configuration
147 145
 
146
+* [Config File](./conf/config.yaml)
148 147
 * Modify the configuration in `conf/config.yaml`. 
149 148
 * If `gorm.type` is set to `sqlite`, MySQL-related configurations are not required.
150 149
 * Language support: `en` and `zh-CN` are supported. The default is `zh-CN`.
151 150
 
152
-```yaml
153
-lang: "en"
154
-app:
155
-  web-client: 1  # web client route 1:open 0:close  
156
-  register: false #register enable
157
-  show-swagger: 0 #show swagger 1:open 0:close
158
-  web-sso: true #web sso
159
-  token-expire: 168h #token expire duration
160
-  disable-pwd-login: false #disable password login
161
-gin:
162
-  api-addr: "0.0.0.0:21114"
163
-  mode: "release"
164
-  resources-path: 'resources'
165
-  trust-proxy: ""
166
-gorm:
167
-  type: "sqlite"
168
-  max-idle-conns: 10
169
-  max-open-conns: 100
170
-mysql:
171
-  username: "root"
172
-  password: "111111"
173
-  addr: "192.168.1.66:3308"
174
-  dbname: "rustdesk"
175
-rustdesk:
176
-  id-server: "192.168.1.66:21116"
177
-  relay-server: "192.168.1.66:21117"
178
-  api-server: "http://192.168.1.66:21114"
179
-  key: "123456789"
180
-  personal: 1
181
-logger:
182
-  path: "./runtime/log.txt"
183
-  level: "warn" #trace,debug,info,warn,error,fatal
184
-  report-caller: true
185
-proxy:
186
-  enable: false
187
-  host: ""
188
-jwt:
189
-  key: ""
190
-  expire-duration: 360000
191
-ldap:
192
-  enable: false
193
-  url: "ldap://ldap.example.com:389"
194
-  tls: false
195
-  tls-verify: false
196
-  base-dn: "dc=example,dc=com"
197
-  bind-dn: "cn=admin,dc=example,dc=com"
198
-  bind-password: "password"
199
-
200
-  user:
201
-    base-dn: "ou=users,dc=example,dc=com"
202
-    enable-attr: ""       #The attribute name of the user for enabling, in AD it is "userAccountControl", empty means no enable attribute, all users are enabled
203
-    enable-attr-value: "" # The value of the enable attribute when the user is enabled. If you are using AD, just set random value, it will be ignored.
204
-    filter: "(cn=*)"
205
-    username: "uid"       # The attribute name of the user for usernamem if you are using AD, it should be "sAMAccountName"
206
-    email: "mail"
207
-    first-name: "givenName"
208
-    last-name: "sn"
209
-    sync: false         # If true, the user will be synchronized to the database when the user logs in. If false, the user will be synchronized to the database when the user be created.
210
-    admin-group: "cn=admin,dc=example,dc=com" # The group name of the admin group, if the user is in this group, the user will be an admin.
211
-
212
-```
213 151
 
214 152
 ### Environment Variables
215 153
 The environment variables correspond one-to-one with the configurations in the `conf/config.yaml` file. The prefix for variable names is `RUSTDESK_API`.
@@ -247,6 +185,7 @@ The table below does not list all configurations. Please refer to the configurat
247 185
 | RUSTDESK_API_RUSTDESK_KEY                              | Rustdesk key                                                                                                                                        | 123456789                     |
248 186
 | RUSTDESK_API_RUSTDESK_KEY_FILE                         | Rustdesk key file                                                                                                                                   | `./conf/data/id_ed25519.pub`  |
249 187
 | RUSTDESK_API_RUSTDESK<br/>_WEBCLIENT_MAGIC_QUERYONLINE | New online query method is enabled in the web client v2; '1': Enabled, '0': Disabled, not enabled by default                                        | `0`                           |
188
+| RUSTDESK_API_RUSTDESK_WS_HOST                          | Custom Websocket Host                                                                                                                               |                               |
250 189
 | ---- PROXY -----                                       | ---------------                                                                                                                                     | ----------                    |
251 190
 | RUSTDESK_API_PROXY_ENABLE                              | proxy_enable :`false`, `true`                                                                                                                       | `false`                       |
252 191
 | RUSTDESK_API_PROXY_HOST                                | proxy_host                                                                                                                                          | `http://127.0.0.1:1080`       |

+ 1 - 0
conf/config.yaml

@@ -32,6 +32,7 @@ rustdesk:
32 32
   key-file: "/data/id_ed25519.pub"
33 33
   personal: 1
34 34
   webclient-magic-queryonline: 0
35
+  ws-host: ""
35 36
 logger:
36 37
   path: "./runtime/log.txt"
37 38
   level: "info" #trace,debug,info,warn,error,fatal

+ 2 - 1
config/rustdesk.go

@@ -21,7 +21,8 @@ type Rustdesk struct {
21 21
 	KeyFile         string `mapstructure:"key-file"`
22 22
 	Personal        int    `mapstructure:"personal"`
23 23
 	//webclient-magic-queryonline
24
-	WebclientMagicQueryonline int `mapstructure:"webclient-magic-queryonline"`
24
+	WebclientMagicQueryonline int    `mapstructure:"webclient-magic-queryonline"`
25
+	WsHost                    string `mapstructure:"ws-host"`
25 26
 }
26 27
 
27 28
 func (rd *Rustdesk) LoadKeyFile() {

+ 14 - 7
http/controller/web/index.go

@@ -1,9 +1,9 @@
1 1
 package web
2 2
 
3 3
 import (
4
+	"fmt"
4 5
 	"github.com/gin-gonic/gin"
5 6
 	"github.com/lejianwen/rustdesk-api/v2/global"
6
-	"strconv"
7 7
 )
8 8
 
9 9
 type Index struct {
@@ -15,13 +15,20 @@ func (i *Index) Index(c *gin.Context) {
15 15
 
16 16
 func (i *Index) ConfigJs(c *gin.Context) {
17 17
 	apiServer := global.Config.Rustdesk.ApiServer
18
-	magicQueryonline := strconv.Itoa(global.Config.Rustdesk.WebclientMagicQueryonline)
19
-	tmp := `
20
-localStorage.setItem('api-server', "` + apiServer + `")
21
-const ws2_prefix = 'wc-'
22
-localStorage.setItem(ws2_prefix+'api-server', "` + apiServer + `")
18
+	magicQueryonline := global.Config.Rustdesk.WebclientMagicQueryonline
19
+	tmp := fmt.Sprintf(`localStorage.setItem('api-server', '%v');
20
+const ws2_prefix = 'wc-';
21
+localStorage.setItem(ws2_prefix+'api-server', '%v');
23 22
 
24
-window.webclient_magic_queryonline = ` + magicQueryonline + ``
23
+window.webclient_magic_queryonline = %d;
24
+window.ws_host = '%v';
25
+`, apiServer, apiServer, magicQueryonline, global.Config.Rustdesk.WsHost)
26
+	//	tmp := `
27
+	//localStorage.setItem('api-server', "` + apiServer + `")
28
+	//const ws2_prefix = 'wc-'
29
+	//localStorage.setItem(ws2_prefix+'api-server', "` + apiServer + `")
30
+	//
31
+	//window.webclient_magic_queryonline = ` + magicQueryonline + ``
25 32
 
26 33
 	c.Header("Content-Type", "application/javascript")
27 34
 	c.String(200, tmp)