12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package tcpprox
- import (
- "encoding/json"
- "net/http"
- "strconv"
- "imuslab.com/zoraxy/mod/utils"
- )
- /*
- Handler.go
- Handlers for the tcprox. Remove this file
- if your application do not need any http
- handler.
- */
- func (m *Manager) HandleAddProxyConfig(w http.ResponseWriter, r *http.Request) {
- name, err := utils.PostPara(r, "name")
- if err != nil {
- utils.SendErrorResponse(w, "name cannot be empty")
- return
- }
- portA, err := utils.PostPara(r, "portA")
- if err != nil {
- utils.SendErrorResponse(w, "first address cannot be empty")
- return
- }
- portB, err := utils.PostPara(r, "portB")
- if err != nil {
- utils.SendErrorResponse(w, "second address cannot be empty")
- return
- }
- timeoutStr, _ := utils.PostPara(r, "timeout")
- timeout := m.Options.DefaultTimeout
- if timeoutStr != "" {
- timeout, err = strconv.Atoi(timeoutStr)
- if err != nil {
- utils.SendErrorResponse(w, "invalid timeout value: "+timeoutStr)
- return
- }
- }
- modeValue := ProxyMode_Transport
- mode, err := utils.PostPara(r, "mode")
- if err != nil || mode == "" {
- utils.SendErrorResponse(w, "no mode given")
- } else if mode == "listen" {
- modeValue = ProxyMode_Listen
- } else if mode == "transport" {
- modeValue = ProxyMode_Transport
- } else if mode == "starter" {
- modeValue = ProxyMode_Starter
- } else {
- utils.SendErrorResponse(w, "invalid mode given. Only support listen / transport / starter")
- }
- //Create the target config
- newConfigUUID := m.NewConfig(&ProxyRelayOptions{
- Name: name,
- PortA: portA,
- PortB: portB,
- Timeout: timeout,
- Mode: modeValue,
- })
- js, _ := json.Marshal(newConfigUUID)
- utils.SendJSONResponse(w, string(js))
- }
- func (m *Manager) HandleListProxyConfigs(w http.ResponseWriter, r *http.Request) {
- }
|