From f7c2ccbe26dc808e4a7eae9a378e6c382220961a Mon Sep 17 00:00:00 2001 From: Simponic Date: Thu, 22 Dec 2022 15:27:55 -0700 Subject: Remove shell and esshd - moving to erlang ssh server --- lib/chessh/auth/keys.ex | 1 - lib/chessh/auth/password.ex | 1 - lib/chessh/shell.ex | 51 --------------------------------------------- lib/chessh/ssh/server.ex | 0 4 files changed, 53 deletions(-) delete mode 100644 lib/chessh/shell.ex create mode 100644 lib/chessh/ssh/server.ex (limited to 'lib') diff --git a/lib/chessh/auth/keys.ex b/lib/chessh/auth/keys.ex index e90f101..a29d169 100644 --- a/lib/chessh/auth/keys.ex +++ b/lib/chessh/auth/keys.ex @@ -1,6 +1,5 @@ defmodule Chessh.Auth.KeyAuthenticator do alias Chessh.{Key, Repo} - use Sshd.PublicKeyAuthenticator import Ecto.Query def authenticate(username, public_key) do diff --git a/lib/chessh/auth/password.ex b/lib/chessh/auth/password.ex index e2c26d6..8a6c683 100644 --- a/lib/chessh/auth/password.ex +++ b/lib/chessh/auth/password.ex @@ -1,7 +1,6 @@ defmodule Chessh.Auth.PasswordAuthenticator do alias Chessh.Player alias Chessh.Repo - use Sshd.PasswordAuthenticator def authenticate(username, password) do case Repo.get_by(Player, username: String.Chars.to_string(username)) do diff --git a/lib/chessh/shell.ex b/lib/chessh/shell.ex deleted file mode 100644 index cf65ad4..0000000 --- a/lib/chessh/shell.ex +++ /dev/null @@ -1,51 +0,0 @@ -defmodule Chessh.Shell do - use Sshd.ShellHandler - - def on_shell(_username, _pubkey, _ip, _port) do - IO.puts("Looks like you're on #{inspect(self())}") - loop() - 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() do - self_pid = self() - IO.write([IO.ANSI.home(), IO.ANSI.clear()]) - IO.puts("#{inspect(:io.columns())}") - IO.puts("#{inspect(:io.rows())}") - input = spawn(fn -> io_get(self_pid) end) - wait_input(input) - end - - defp wait_input(input) do - receive do - {:hello, message} -> - IO.puts(message) - loop() - - {:input, ^input, x} -> - IO.puts(x) - loop() - - x -> - Logger.debug(inspect(x)) - loop() - end - end - - defp io_get(pid) do - send(pid, {:input, self(), IO.gets("")}) - end -end diff --git a/lib/chessh/ssh/server.ex b/lib/chessh/ssh/server.ex new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3-70-g09d2