summaryrefslogtreecommitdiff
path: root/lib/chessh/ssh/daemon.ex
diff options
context:
space:
mode:
authorSimponic <loganhunt@simponic.xyz>2022-12-31 16:32:56 -0700
committerSimponic <loganhunt@simponic.xyz>2022-12-31 16:33:12 -0700
commit52a3ed7c5700fa398efb8a4aff9d586a850e3d58 (patch)
tree0ac4b127c99d399265159182edf4dc63bd9ba675 /lib/chessh/ssh/daemon.ex
parent58d0b1a89c461467c9ea6229f9a6b3d5ed573da5 (diff)
downloadchessh-52a3ed7c5700fa398efb8a4aff9d586a850e3d58.tar.gz
chessh-52a3ed7c5700fa398efb8a4aff9d586a850e3d58.zip
Better logging, close previous sessions once session threshold has been reached
Diffstat (limited to 'lib/chessh/ssh/daemon.ex')
-rw-r--r--lib/chessh/ssh/daemon.ex32
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/chessh/ssh/daemon.ex b/lib/chessh/ssh/daemon.ex
index 24ad259..1748e9e 100644
--- a/lib/chessh/ssh/daemon.ex
+++ b/lib/chessh/ssh/daemon.ex
@@ -1,6 +1,8 @@
defmodule Chessh.SSH.Daemon do
alias Chessh.{Repo, PlayerSession, Utils}
alias Chessh.Auth.PasswordAuthenticator
+ alias Chessh.SSH.{ServerKey, Tui}
+
use GenServer
import Ecto.Query
@@ -30,24 +32,30 @@ defmodule Chessh.SSH.Daemon do
String.Chars.to_string(password)
) do
false ->
+ Logger.debug(
+ "#{username} on bucket #{rateId} got their password wrong, or they don't exist! Point at them and laugh!!!!"
+ )
+
case Hammer.check_rate_inc(rateId, jail_timeout_ms, jail_attempt_threshold, 1) do
{:allow, _count} ->
+ Logger.debug("Bucket #{rateId} can continue to brute force though")
false
{:deny, _limit} ->
+ Logger.debug("Bucket #{rateId} ran out of password attempts")
:disconnect
end
x ->
- if PlayerSession.player_within_concurrent_sessions_and_satisfies(username, fn _player ->
- x
- end),
- do: true,
- else: :disconnect
+ PlayerSession.update_sessions_and_player_satisfies(username, fn _player ->
+ x
+ end)
+
+ x
end
end
- def pwd_authenticate(username, password, inet, _address),
+ def pwd_authenticate(username, password, inet, _state),
do: pwd_authenticate(username, password, inet)
def handle_cast(:start, state) do
@@ -57,19 +65,19 @@ defmodule Chessh.SSH.Daemon do
case :ssh.daemon(
port,
- # shell: fn _username, _peer -> Process.sleep(5000) end,
system_dir: key_dir,
pwdfun: &pwd_authenticate/4,
- key_cb: Chessh.SSH.ServerKey,
- ssh_cli: {Chessh.SSH.Tui, []},
- # connectfun: &on_connect/3,
+ key_cb: ServerKey,
+ ssh_cli: {Tui, [%Tui.State{}]},
disconnectfun: &on_disconnect/1,
id_string: :random,
- subsystems: [],
parallel_login: true,
- max_sessions: max_sessions
+ max_sessions: max_sessions,
+ subsystems: []
) do
{:ok, pid} ->
+ Logger.info("SSH server started on port #{port}, on #{inspect(pid)}")
+
Process.link(pid)
{:noreply, %{state | pid: pid}, :hibernate}