Compare commits
2 Commits
6c8625dead
...
473ea2ba74
Author | SHA1 | Date | |
---|---|---|---|
![]() |
473ea2ba74 | ||
![]() |
9547c72f5a |
@ -40,8 +40,8 @@ func load() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeReq(method string, url string, body io.Reader) error {
|
func makeReq(method string, url string) error {
|
||||||
req, err := http.NewRequest(method, url, body)
|
req, err := http.NewRequest(method, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ func main() {
|
|||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "id",
|
Name: "id",
|
||||||
Usage: "optional id of a client to fetch",
|
Usage: "optional id of the client to fetch",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: clients,
|
Action: clients,
|
||||||
@ -95,7 +95,7 @@ func main() {
|
|||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "id",
|
Name: "id",
|
||||||
Usage: "optional id of a client to log",
|
Usage: "optional id of the client to log",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "date",
|
Name: "date",
|
||||||
@ -112,6 +112,35 @@ func main() {
|
|||||||
},
|
},
|
||||||
Action: logs,
|
Action: logs,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "name",
|
||||||
|
Usage: "rename a client",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "id",
|
||||||
|
Usage: "id of the client",
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "new",
|
||||||
|
Usage: "new name of the client",
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "exit",
|
||||||
|
Usage: "request a client to disconnect",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "id",
|
||||||
|
Usage: "id of the client",
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: exit,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +164,7 @@ func clients(ctx context.Context, cmd *cli.Command) error {
|
|||||||
url = fmt.Sprintf("%s/admin/clients", server)
|
url = fmt.Sprintf("%s/admin/clients", server)
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeReq(http.MethodGet, url, nil)
|
return makeReq(http.MethodGet, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func logs(ctx context.Context, cmd *cli.Command) error {
|
func logs(ctx context.Context, cmd *cli.Command) error {
|
||||||
@ -170,5 +199,28 @@ func logs(ctx context.Context, cmd *cli.Command) error {
|
|||||||
url = fmt.Sprintf("%s/admin/logs", server)
|
url = fmt.Sprintf("%s/admin/logs", server)
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeReq(http.MethodGet, url, nil)
|
return makeReq(http.MethodGet, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
func name(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
err := load()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
id := cmd.String("id")
|
||||||
|
name := cmd.String("new")
|
||||||
|
url := fmt.Sprintf("%s/admin/name/%s?name=%s", server, id, name)
|
||||||
|
return makeReq(http.MethodPost, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
func exit(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
err := load()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
id := cmd.String("id")
|
||||||
|
url := fmt.Sprintf("%s/admin/exit/%s", server, id)
|
||||||
|
return makeReq(http.MethodPost, url)
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ func main() {
|
|||||||
})))
|
})))
|
||||||
|
|
||||||
app.POST("/admin/name/:id", authed(idparam(func(c echo.Context, id uuid.UUID) error {
|
app.POST("/admin/name/:id", authed(idparam(func(c echo.Context, id uuid.UUID) error {
|
||||||
name := c.Param("name")
|
name := c.QueryParam("name")
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return c.JSON(http.StatusBadRequest, "missing field 'name'")
|
return c.JSON(http.StatusBadRequest, "missing field 'name'")
|
||||||
}
|
}
|
||||||
@ -296,7 +296,6 @@ func keys(c echo.Context) error {
|
|||||||
fmt.Printf("%s client %s crashed (couldn't open file)\n", time.Now().Format(TimeFormat), client.ID)
|
fmt.Printf("%s client %s crashed (couldn't open file)\n", time.Now().Format(TimeFormat), client.ID)
|
||||||
now = time.Now()
|
now = time.Now()
|
||||||
|
|
||||||
client.ExitWanted = true
|
|
||||||
client.Connected = false
|
client.Connected = false
|
||||||
client.DisconnectedAt = now
|
client.DisconnectedAt = now
|
||||||
client.UpdatedAt = now
|
client.UpdatedAt = now
|
||||||
|
Loading…
x
Reference in New Issue
Block a user