feat: expose transparent web device forwarders
This commit is contained in:
@@ -128,13 +128,22 @@ func (s *Service) Scan(r *http.Request) (*ScanResult, error) {
|
||||
}
|
||||
|
||||
s.allowIP(device.IP)
|
||||
forwardPort, forwardErr := s.EnsureForwarder(device.IP)
|
||||
if forwardErr != nil {
|
||||
result.Errors = append(result.Errors, fmt.Sprintf("%s: 启动%s透明转发失败: %v", iface.Name, device.IP, forwardErr))
|
||||
continue
|
||||
}
|
||||
|
||||
scheme, host := requestBase(r)
|
||||
|
||||
deviceInfo := DeviceInfo{
|
||||
IP: device.IP,
|
||||
Interface: iface.Name,
|
||||
Port: device.Port,
|
||||
TargetURL: fmt.Sprintf("http://%s/", device.IP),
|
||||
ProxyURL: fmt.Sprintf("/proxy/web/%s/", device.IP),
|
||||
IP: device.IP,
|
||||
Interface: iface.Name,
|
||||
Port: device.Port,
|
||||
TargetURL: fmt.Sprintf("http://%s/", device.IP),
|
||||
ProxyURL: fmt.Sprintf("/proxy/web/%s/", device.IP),
|
||||
DirectURL: buildDirectURL(scheme, host, forwardPort),
|
||||
ForwardPort: forwardPort,
|
||||
}
|
||||
result.Devices = append(result.Devices, deviceInfo)
|
||||
}
|
||||
|
||||
@@ -71,8 +71,11 @@ func TestScanBuildsProxyURLAndAllowList(t *testing.T) {
|
||||
if result.Devices[0].ProxyURL != "/proxy/web/192.168.1.124/" {
|
||||
t.Fatalf("ProxyURL = %q", result.Devices[0].ProxyURL)
|
||||
}
|
||||
if result.Devices[0].DirectURL != "" {
|
||||
t.Fatalf("DirectURL = %q, want empty", result.Devices[0].DirectURL)
|
||||
if result.Devices[0].DirectURL != "http://10.8.0.14:31124/" {
|
||||
t.Fatalf("DirectURL = %q", result.Devices[0].DirectURL)
|
||||
}
|
||||
if result.Devices[0].ForwardPort != 31124 {
|
||||
t.Fatalf("ForwardPort = %d, want 31124", result.Devices[0].ForwardPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user