Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def reboot(conn, %{"url" => url, "port" => port, "user" => user, "password" => password} = _params) do
- with %User{} <- conn.assigns[:current_user] do
- with %Porcelain.Result{err: nil, out: output, status: 0} <- Porcelain.shell("nvr_reboot #{url} #{port} #{user} #{password}") do
- String.match?(output, ~r/success/)
- |> case do
- true -> conn |> put_status(201) |> json(%{reboot: true})
- _ -> render_error(conn, 400, "Failed to reboot NVR.")
- end
- else
- _ -> render_error(conn, 400, "Failed to reboot NVR.")
- end
- else
- nil ->
- render_error(conn, 401, "Unauthorized")
- end
- end
Add Comment
Please, Sign In to add comment