Remove shell and esshd - moving to erlang ssh server

This commit is contained in:
Simponic 2022-12-22 15:27:55 -07:00
parent fed5d8a9e7
commit f7c2ccbe26
7 changed files with 6 additions and 66 deletions

View File

@ -1,15 +1,9 @@
import Config
config :chessh, ecto_repos: [Chessh.Repo]
config :esshd,
enabled: true,
config :chessh,
ecto_repos: [Chessh.Repo],
priv_dir: Path.join(Path.dirname(__DIR__), "priv/keys"),
handler: {Chessh.Shell, :on_shell, 4},
port: 42069,
password_authenticator: Chessh.Auth.PasswordAuthenticator,
public_key_authenticator: Chessh.Auth.KeyAuthenticator,
# TODO - benchmark
max_sessions: 128
max_sessions: 255
import_config "#{config_env()}.exs"

View File

@ -7,5 +7,5 @@ config :chessh, Chessh.Repo,
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox
config :esshd,
priv_dir: Path.join(Path.dirname(__DIR__), "priv/test_keys")
config :chessh,
priv_dir: Path.join(Path.dirname(__DIR__), "priv/keys")

View File

@ -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

View File

@ -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

View File

@ -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

0
lib/chessh/ssh/server.ex Normal file
View File

View File

@ -17,7 +17,7 @@ defmodule Chessh.MixProject do
def application do
[
mod: {Chessh.Application, []},
extra_applications: [:esshd, :logger]
extra_applications: [:logger, :crypto, :ssh]
]
end
@ -28,7 +28,6 @@ defmodule Chessh.MixProject do
defp deps do
[
{:chess, "~> 0.4.1"},
{:esshd, "~> 0.2.1"},
{:ecto, "~> 3.9"},
{:ecto_sql, "~> 3.9"},
{:postgrex, "~> 0.16.5"},