(ctx echo.Context)
| 121 | } |
| 122 | |
| 123 | func PostSambaConnectionsCreate(ctx echo.Context) error { |
| 124 | connection := model.Connections{} |
| 125 | ctx.Bind(&connection) |
| 126 | if connection.Port == "" { |
| 127 | connection.Port = "445" |
| 128 | } |
| 129 | if connection.Username == "" || connection.Host == "" { |
| 130 | return ctx.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.CHARACTER_LIMIT, Message: common_err.GetMsg(common_err.CHARACTER_LIMIT)}) |
| 131 | } |
| 132 | |
| 133 | // if ok, _ := regexp.MatchString(`^[\w@#*.]{4,30}$`, connection.Password); !ok { |
| 134 | // return ctx.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.CHARACTER_LIMIT, Message: common_err.GetMsg(common_err.CHARACTER_LIMIT)}) |
| 135 | // return |
| 136 | // } |
| 137 | // if ok, _ := regexp.MatchString(`^[\w@#*.]{4,30}$`, connection.Username); !ok { |
| 138 | // return ctx.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) |
| 139 | // return |
| 140 | // } |
| 141 | // if !ip_helper.IsIPv4(connection.Host) && !ip_helper.IsIPv6(connection.Host) { |
| 142 | // return ctx.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) |
| 143 | // return |
| 144 | // } |
| 145 | // if ok, _ := regexp.MatchString("^[0-9]{1,6}$", connection.Port); !ok { |
| 146 | // return ctx.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) |
| 147 | // return |
| 148 | // } |
| 149 | |
| 150 | connection.Host = strings.Split(connection.Host, "/")[0] |
| 151 | // check is exists |
| 152 | connections := service.MyService.Connections().GetConnectionByHost(connection.Host) |
| 153 | if len(connections) > 0 { |
| 154 | return ctx.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.Record_ALREADY_EXIST, Message: common_err.GetMsg(common_err.Record_ALREADY_EXIST), Data: common_err.GetMsg(common_err.Record_ALREADY_EXIST)}) |
| 155 | } |
| 156 | // check connect is ok |
| 157 | directories, err := samba.GetSambaSharesList(connection.Host, connection.Port, connection.Username, connection.Password) |
| 158 | if err != nil { |
| 159 | return ctx.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()}) |
| 160 | } |
| 161 | |
| 162 | connectionDBModel := model2.ConnectionsDBModel{} |
| 163 | connectionDBModel.Username = connection.Username |
| 164 | connectionDBModel.Password = connection.Password |
| 165 | connectionDBModel.Host = connection.Host |
| 166 | connectionDBModel.Port = connection.Port |
| 167 | connectionDBModel.Directories = strings.Join(directories, ",") |
| 168 | baseHostPath := "/mnt/" + connection.Host |
| 169 | connectionDBModel.MountPoint = baseHostPath |
| 170 | connection.MountPoint = baseHostPath |
| 171 | file.IsNotExistMkDir(baseHostPath) |
| 172 | for _, v := range directories { |
| 173 | mountPoint := baseHostPath + "/" + v |
| 174 | file.IsNotExistMkDir(mountPoint) |
| 175 | service.MyService.Connections().MountSmaba(connectionDBModel.Username, connectionDBModel.Host, v, connectionDBModel.Port, mountPoint, connectionDBModel.Password) |
| 176 | } |
| 177 | |
| 178 | service.MyService.Connections().CreateConnection(&connectionDBModel) |
| 179 | |
| 180 | connection.ID = connectionDBModel.ID |
nothing calls this directly
no test coverage detected