Skip to content

Commit

Permalink
feat: https proxy compatible old rtty
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Sep 25, 2022
1 parent 1193295 commit 58c29ec
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func apiStart(br *broker) {
Description string `json:"description"`
Bound bool `json:"bound"`
Online bool `json:"online"`
Proto uint8 `json:"proto"`
}

db, err := instanceDB(cfg.DB)
Expand Down Expand Up @@ -274,6 +275,7 @@ func apiStart(br *broker) {
di.Connected = uint32(time.Now().Unix() - dev.timestamp)
di.Uptime = dev.uptime
di.Online = true
di.Proto = dev.proto
}

devs = append(devs, di)
Expand Down
19 changes: 12 additions & 7 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,27 @@ type HttpProxyWriter struct {
srcAddr []byte
hostHeaderRewrite string
br *broker
devid string
dev *device
https bool
}

func (rw *HttpProxyWriter) Write(p []byte) (n int, err error) {
msg := []byte{0}
msg := []byte{}
dev := rw.dev

if rw.https {
msg[0] = 1
if dev.proto > 3 {
if rw.https {
msg = append(msg, 1)
} else {
msg = append(msg, 0)
}
}

msg = append(msg, rw.srcAddr...)
msg = append(msg, rw.destAddr...)
msg = append(msg, p...)

rw.br.httpReq <- &httpReq{rw.devid, msg}
rw.br.httpReq <- &httpReq{dev.id, msg}

return len(p), nil
}
Expand All @@ -119,7 +124,7 @@ func doHttpProxy(brk *broker, c net.Conn) {
}
devid := cookie.Value

_, ok := brk.devices[devid]
dev, ok := brk.devices[devid]
if !ok {
return
}
Expand Down Expand Up @@ -170,7 +175,7 @@ func doHttpProxy(brk *broker, c net.Conn) {
return
}

hpw := &HttpProxyWriter{destAddr, srcAddr, hostHeaderRewrite, brk, devid, https}
hpw := &HttpProxyWriter{destAddr, srcAddr, hostHeaderRewrite, brk, dev.(*device), https}

req.Host = hostHeaderRewrite
hpw.WriteRequest(req)
Expand Down
3 changes: 2 additions & 1 deletion ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
"There are no offline devices in selected devices": "There are no offline devices in selected devices",
"Invalid address": "Invalid address",
"Already copied to clipboard": "Already copied to clipboard",
"Please use shortcut \"Shift+Insert\"": "Please use shortcut \"Shift+Insert\""
"Please use shortcut \"Shift+Insert\"": "Please use shortcut \"Shift+Insert\"",
"Your device's rtty does not support https proxy, please upgrade it.": "Your device's rtty does not support https proxy, please upgrade it."
}
3 changes: 2 additions & 1 deletion ui/src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@
"There are no offline devices in selected devices": "所选设备中无离线设备",
"Invalid address": "无效的地址",
"Already copied to clipboard": "已复制到剪切板",
"Please use shortcut \"Shift+Insert\"": "请使用快捷键 \"Shift+Insert\""
"Please use shortcut \"Shift+Insert\"": "请使用快捷键 \"Shift+Insert\"",
"Your device's rtty does not support https proxy, please upgrade it.": "你的设备的 rtty 不支持 https 代理,请升级"
}
11 changes: 8 additions & 3 deletions ui/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<i class="iconfont icon-shell" style="font-size: 40px; color: black; cursor:pointer;" @click="connectDevice(row.id)"/>
</Tooltip>
<Tooltip v-if="row.online" placement="top" :content="$t('Access your devices\'s Web')">
<i class="iconfont icon-web" style="font-size: 40px; color: #409EFF; cursor:pointer;" @click="connectDeviceWeb(row.id)"/>
<i class="iconfont icon-web" style="font-size: 40px; color: #409EFF; cursor:pointer;" @click="connectDeviceWeb(row)"/>
</Tooltip>
<span v-if="!row.online" style="margin-left: 10px; color: red">{{ $t('Device offline') }}</span>
</template>
Expand Down Expand Up @@ -343,7 +343,7 @@ export default {
connectDevice(devid) {
window.open('/rtty/' + devid);
},
connectDeviceWeb(devid) {
connectDeviceWeb(dev) {
let addr = '127.0.0.1';
this.$Modal.confirm({
Expand Down Expand Up @@ -377,6 +377,11 @@ export default {
proto = 'https';
}
if (dev.proto < 4 && proto === 'https') {
this.$Message.error(this.$t('Your device\'s rtty does not support https proxy, please upgrade it.'));
return;
}
let [addrs, ...path] = addr.split('/');
path = '/' + path.join('/');
Expand Down Expand Up @@ -406,7 +411,7 @@ export default {
}
addr = encodeURIComponent(`${ip}:${port}${path}`);
window.open(`/web/${devid}/${proto}/${addr}`);
window.open(`/web/${dev.id}/${proto}/${addr}`);
}
});
},
Expand Down

0 comments on commit 58c29ec

Please sign in to comment.