@@ -230,7 +230,7 @@ func (s *Service) refreshFlag() {
230230 // Replace the flag placeholder.
231231 // strings.ReplaceAll need Go 1.13+, so we use strings.Replace here.
232232 command := strings .Replace (challenge .Command , "{{FLAG}}" , flag .Flag , - 1 )
233- err := utils .SSHExecute (gamebox .IP , gamebox .SSHPort , gamebox .SSHUser , gamebox .SSHPassword , command )
233+ _ , err := utils .SSHExecute (gamebox .IP , gamebox .SSHPort , gamebox .SSHUser , gamebox .SSHPassword , command )
234234 if err != nil {
235235 s .NewLog (IMPORTANT , "ssh_error" , fmt .Sprintf ("Team:%d Gamebox:%d Round:%d SSH 更新 Flag 失败:%v" , gamebox .TeamID , gamebox .ID , s .Timer .NowRound , err .Error ()))
236236 }
@@ -240,7 +240,7 @@ func (s *Service) refreshFlag() {
240240 }
241241}
242242
243- func (s * Service ) testSSH (c * gin.Context ) (int , interface {}) {
243+ func (s * Service ) testAllSSH (c * gin.Context ) (int , interface {}) {
244244 var challenges []Challenge
245245 s .Mysql .Model (& Challenge {}).Where (& Challenge {AutoRefreshFlag : true }).Find (& challenges )
246246
@@ -261,7 +261,7 @@ func (s *Service) testSSH(c *gin.Context) (int, interface{}) {
261261 wg .Add (1 )
262262 go func (gamebox GameBox , challenge Challenge ) {
263263 defer wg .Done ()
264- err := utils .SSHExecute (gamebox .IP , gamebox .SSHPort , gamebox .SSHUser , gamebox .SSHPassword , "whoami" )
264+ _ , err := utils .SSHExecute (gamebox .IP , gamebox .SSHPort , gamebox .SSHUser , gamebox .SSHPassword , "whoami" )
265265 if err != nil {
266266 errs = append (errs , errorMessage {
267267 TeamID : gamebox .TeamID ,
@@ -276,3 +276,25 @@ func (s *Service) testSSH(c *gin.Context) (int, interface{}) {
276276 wg .Wait ()
277277 return utils .MakeSuccessJSON (errs )
278278}
279+
280+ func (s * Service ) testSSH (c * gin.Context ) (int , interface {}) {
281+ var inputForm struct {
282+ IP string `binding:"required"`
283+ Port string `binding:"required"`
284+ User string `binding:"required"`
285+ Password string `binding:"required"`
286+ Command string `binding:"required"`
287+ }
288+ err := c .BindJSON (& inputForm )
289+ if err != nil {
290+ return utils .MakeErrJSON (400 , 40036 ,
291+ locales .I18n .T (c .GetString ("lang" ), "general.error_payload" ),
292+ )
293+ }
294+
295+ output , err := utils .SSHExecute (inputForm .IP , inputForm .Port , inputForm .User , inputForm .Password , inputForm .Command )
296+ if err != nil {
297+ return utils .MakeErrJSON (400 , 40037 , err )
298+ }
299+ return utils .MakeSuccessJSON (output )
300+ }
0 commit comments