Purge SSH frontend (#23)
authorfloatingghost <hannah@coffee-and-dreams.uk>
Mon, 27 Jun 2022 11:32:06 +0000 (11:32 +0000)
committerfloatingghost <hannah@coffee-and-dreams.uk>
Mon, 27 Jun 2022 11:32:06 +0000 (11:32 +0000)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/23

CHANGELOG.md
config/config.exs
docs/configuration/cheatsheet.md
lib/pleroma/bbs/authenticator.ex [deleted file]
lib/pleroma/bbs/handler.ex [deleted file]
mix.exs
test/pleroma/bbs/handler_test.exs [deleted file]

index ebbbc3be8d2cf82189e86ba99c3f708013bedb42..a3824e8b79c85b18c3dbde998912fa8fe87ed686 100644 (file)
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
 ## [Unreleased]
 
+### Removed
+- SSH frontend, to be potentially re-enabled via a bridge rather than wired into the main system
+
 ## 2.5.2
 
 ### Added
index 827b85f265cc56acbf32b1be86b2bbe7ab0a8f4e..850a42eea9c0c61174e1c95b15ccdf98c5032f0f 100644 (file)
@@ -607,9 +607,6 @@ config :pleroma, :ldap,
   base: System.get_env("LDAP_BASE") || "dc=example,dc=com",
   uid: System.get_env("LDAP_UID") || "cn"
 
-config :esshd,
-  enabled: false
-
 oauth_consumer_strategies =
   System.get_env("OAUTH_CONSUMER_STRATEGIES")
   |> to_string()
index 7700bf65a1378b63716e70a10f648b0744e09efc..caa7f2edc693e447b3c1c230807e4d35da82c2b8 100644 (file)
@@ -835,24 +835,6 @@ This will probably take a long time.
 
 ## Alternative client protocols
 
-### BBS / SSH access
-
-To enable simple command line interface accessible over ssh, add a setting like this to your configuration file:
-
-```exs
-app_dir = File.cwd!
-priv_dir = Path.join([app_dir, "priv/ssh_keys"])
-
-config :esshd,
-  enabled: true,
-  priv_dir: priv_dir,
-  handler: "Pleroma.BBS.Handler",
-  port: 10_022,
-  password_authenticator: "Pleroma.BBS.Authenticator"
-```
-
-Feel free to adjust the priv_dir and port number. Then you will have to create the key for the keys (in the example `priv/ssh_keys`) and create the host keys with `ssh-keygen -m PEM -N "" -b 2048 -t rsa -f ssh_host_rsa_key`. After restarting, you should be able to connect to your Pleroma instance with `ssh username@server -p $PORT`
-
 ### :gopher
 * `enabled`: Enables the gopher interface
 * `ip`: IP address to bind to
diff --git a/lib/pleroma/bbs/authenticator.ex b/lib/pleroma/bbs/authenticator.ex
deleted file mode 100644 (file)
index 241fcb5..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.BBS.Authenticator do
-  use Sshd.PasswordAuthenticator
-  alias Pleroma.User
-  alias Pleroma.Web.Plugs.AuthenticationPlug
-
-  def authenticate(username, password) do
-    username = to_string(username)
-    password = to_string(password)
-
-    with %User{} = user <- User.get_by_nickname(username) do
-      AuthenticationPlug.checkpw(password, user.password_hash)
-    else
-      _e -> false
-    end
-  end
-end
diff --git a/lib/pleroma/bbs/handler.ex b/lib/pleroma/bbs/handler.ex
deleted file mode 100644 (file)
index a38faa5..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.BBS.Handler do
-  use Sshd.ShellHandler
-  alias Pleroma.Activity
-  alias Pleroma.HTML
-  alias Pleroma.Web.ActivityPub.ActivityPub
-  alias Pleroma.Web.CommonAPI
-
-  def on_shell(username, _pubkey, _ip, _port) do
-    :ok = IO.puts("Welcome to #{Pleroma.Config.get([:instance, :name])}!")
-    user = Pleroma.User.get_cached_by_nickname(to_string(username))
-    Logger.debug("#{inspect(user)}")
-    loop(run_state(user: user))
-  end
-
-  def on_connect(username, ip, port, method) do
-    Logger.debug(fn ->
-      """
-      Incoming SSH shell #{inspect(self())} requested for #{username} from #{inspect(ip)}:#{inspect(port)} using #{inspect(method)}
-      """
-    end)
-  end
-
-  def on_disconnect(username, ip, port) do
-    Logger.debug(fn ->
-      "Disconnecting SSH shell for #{username} from #{inspect(ip)}:#{inspect(port)}"
-    end)
-  end
-
-  defp loop(state) do
-    self_pid = self()
-    counter = state.counter
-    prefix = state.prefix
-    user = state.user
-
-    input = spawn(fn -> io_get(self_pid, prefix, counter, user.nickname) end)
-    wait_input(state, input)
-  end
-
-  def puts_activity(activity) do
-    status = Pleroma.Web.MastodonAPI.StatusView.render("show.json", %{activity: activity})
-    IO.puts("-- #{status.id} by #{status.account.display_name} (#{status.account.acct})")
-    IO.puts(HTML.strip_tags(status.content))
-    IO.puts("")
-  end
-
-  def handle_command(state, "help") do
-    IO.puts("Available commands:")
-    IO.puts("help - This help")
-    IO.puts("home - Show the home timeline")
-    IO.puts("p <text> - Post the given text")
-    IO.puts("r <id> <text> - Reply to the post with the given id")
-    IO.puts("quit - Quit")
-
-    state
-  end
-
-  def handle_command(%{user: user} = state, "r " <> text) do
-    text = String.trim(text)
-    [activity_id, rest] = String.split(text, " ", parts: 2)
-
-    with %Activity{} <- Activity.get_by_id(activity_id),
-         {:ok, _activity} <-
-           CommonAPI.post(user, %{status: rest, in_reply_to_status_id: activity_id}) do
-      IO.puts("Replied!")
-    else
-      _e -> IO.puts("Could not reply...")
-    end
-
-    state
-  end
-
-  def handle_command(%{user: user} = state, "p " <> text) do
-    text = String.trim(text)
-
-    with {:ok, _activity} <- CommonAPI.post(user, %{status: text}) do
-      IO.puts("Posted!")
-    else
-      _e -> IO.puts("Could not post...")
-    end
-
-    state
-  end
-
-  def handle_command(state, "home") do
-    user = state.user
-
-    params =
-      %{}
-      |> Map.put(:type, ["Create"])
-      |> Map.put(:blocking_user, user)
-      |> Map.put(:muting_user, user)
-      |> Map.put(:user, user)
-
-    activities =
-      [user.ap_id | Pleroma.User.following(user)]
-      |> ActivityPub.fetch_activities(params)
-
-    Enum.each(activities, fn activity ->
-      puts_activity(activity)
-    end)
-
-    state
-  end
-
-  def handle_command(state, command) do
-    IO.puts("Unknown command '#{command}'")
-    state
-  end
-
-  defp wait_input(state, input) do
-    receive do
-      {:input, ^input, "quit\n"} ->
-        IO.puts("Exiting...")
-
-      {:input, ^input, code} when is_binary(code) ->
-        code = String.trim(code)
-
-        state = handle_command(state, code)
-
-        loop(%{state | counter: state.counter + 1})
-
-      {:error, :interrupted} ->
-        IO.puts("Caught Ctrl+C...")
-        loop(%{state | counter: state.counter + 1})
-
-      {:input, ^input, msg} ->
-        :ok = Logger.warn("received unknown message: #{inspect(msg)}")
-        loop(%{state | counter: state.counter + 1})
-    end
-  end
-
-  defp run_state(opts) do
-    %{prefix: "pleroma", counter: 1, user: opts[:user]}
-  end
-
-  defp io_get(pid, prefix, counter, username) do
-    prompt = prompt(prefix, counter, username)
-    send(pid, {:input, self(), IO.gets(:stdio, prompt)})
-  end
-
-  defp prompt(prefix, counter, username) do
-    prompt = "#{username}@#{prefix}:#{counter}>"
-    prompt <> " "
-  end
-end
diff --git a/mix.exs b/mix.exs
index 163d498b715c0eeea1fa3d126fc68317229a3e9c..8df00154ecaa4475f9680333ea6288c1431350b6 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -179,7 +179,6 @@ defmodule Pleroma.Mixfile do
       {:joken, "~> 2.0"},
       {:benchee, "~> 1.0"},
       {:pot, "~> 1.0"},
-      {:esshd, "~> 0.1.0", runtime: Application.get_env(:esshd, :enabled, false)},
       {:ex_const, "~> 0.2"},
       {:plug_static_index_html, "~> 1.0.0"},
       {:flake_id, "~> 0.1.0"},
diff --git a/test/pleroma/bbs/handler_test.exs b/test/pleroma/bbs/handler_test.exs
deleted file mode 100644 (file)
index 3990f82..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.BBS.HandlerTest do
-  use Pleroma.DataCase, async: true
-  alias Pleroma.Activity
-  alias Pleroma.BBS.Handler
-  alias Pleroma.Object
-  alias Pleroma.Repo
-  alias Pleroma.User
-  alias Pleroma.Web.CommonAPI
-
-  import ExUnit.CaptureIO
-  import Pleroma.Factory
-  import Ecto.Query
-
-  test "getting the home timeline" do
-    user = insert(:user)
-    followed = insert(:user)
-
-    {:ok, user, followed} = User.follow(user, followed)
-
-    {:ok, _first} = CommonAPI.post(user, %{status: "hey"})
-    {:ok, _second} = CommonAPI.post(followed, %{status: "hello"})
-
-    output =
-      capture_io(fn ->
-        Handler.handle_command(%{user: user}, "home")
-      end)
-
-    assert output =~ user.nickname
-    assert output =~ followed.nickname
-
-    assert output =~ "hey"
-    assert output =~ "hello"
-  end
-
-  test "posting" do
-    user = insert(:user)
-
-    output =
-      capture_io(fn ->
-        Handler.handle_command(%{user: user}, "p this is a test post")
-      end)
-
-    assert output =~ "Posted"
-
-    activity =
-      Repo.one(
-        from(a in Activity,
-          where: fragment("?->>'type' = ?", a.data, "Create")
-        )
-      )
-
-    assert activity.actor == user.ap_id
-    object = Object.normalize(activity, fetch: false)
-    assert object.data["content"] == "this is a test post"
-  end
-
-  test "replying" do
-    user = insert(:user)
-    another_user = insert(:user)
-
-    {:ok, activity} = CommonAPI.post(another_user, %{status: "this is a test post"})
-    activity_object = Object.normalize(activity, fetch: false)
-
-    output =
-      capture_io(fn ->
-        Handler.handle_command(%{user: user}, "r #{activity.id} this is a reply")
-      end)
-
-    assert output =~ "Replied"
-
-    reply =
-      Repo.one(
-        from(a in Activity,
-          where: fragment("?->>'type' = ?", a.data, "Create"),
-          where: a.actor == ^user.ap_id
-        )
-      )
-
-    assert reply.actor == user.ap_id
-
-    reply_object_data = Object.normalize(reply, fetch: false).data
-    assert reply_object_data["content"] == "this is a reply"
-    assert reply_object_data["inReplyTo"] == activity_object.data["id"]
-  end
-end