Fix pubkey #4
@ -15,7 +15,7 @@ config :chessh, RateLimits,
|
|||||||
jail_timeout_ms: 5 * 60 * 1000,
|
jail_timeout_ms: 5 * 60 * 1000,
|
||||||
jail_attempt_threshold: 15,
|
jail_attempt_threshold: 15,
|
||||||
max_concurrent_user_sessions: 5,
|
max_concurrent_user_sessions: 5,
|
||||||
player_session_message_burst_ms: 1_000,
|
player_session_message_burst_ms: 500,
|
||||||
player_session_message_burst_rate: 8
|
player_session_message_burst_rate: 8
|
||||||
|
|
||||||
import_config "#{config_env()}.exs"
|
import_config "#{config_env()}.exs"
|
||||||
|
@ -12,4 +12,5 @@ config :chessh, Chessh.Repo,
|
|||||||
pool: Ecto.Adapters.SQL.Sandbox
|
pool: Ecto.Adapters.SQL.Sandbox
|
||||||
|
|
||||||
config :chessh,
|
config :chessh,
|
||||||
|
port: 34_355,
|
||||||
key_dir: Path.join(Path.dirname(__DIR__), "priv/test_keys")
|
key_dir: Path.join(Path.dirname(__DIR__), "priv/test_keys")
|
||||||
|
@ -14,7 +14,7 @@ defmodule Chessh.PlayerSession do
|
|||||||
|
|
||||||
def changeset(player_session, attrs) do
|
def changeset(player_session, attrs) do
|
||||||
player_session
|
player_session
|
||||||
|> cast(attrs, [:login])
|
|> cast(attrs, [:login, :node_id, :process])
|
||||||
end
|
end
|
||||||
|
|
||||||
def concurrent_sessions(player) do
|
def concurrent_sessions(player) do
|
||||||
@ -58,12 +58,17 @@ defmodule Chessh.PlayerSession do
|
|||||||
"Creating session for player #{username} on node #{System.fetch_env!("NODE_ID")} with process #{inspect(self())}"
|
"Creating session for player #{username} on node #{System.fetch_env!("NODE_ID")} with process #{inspect(self())}"
|
||||||
)
|
)
|
||||||
|
|
||||||
Repo.insert(%PlayerSession{
|
now = DateTime.utc_now()
|
||||||
login: DateTime.utc_now(),
|
|
||||||
|
Repo.insert!(
|
||||||
|
%PlayerSession{
|
||||||
|
login: now,
|
||||||
node_id: System.fetch_env!("NODE_ID"),
|
node_id: System.fetch_env!("NODE_ID"),
|
||||||
player: player,
|
player: player,
|
||||||
process: Utils.pid_to_str(self())
|
process: Utils.pid_to_str(self())
|
||||||
})
|
},
|
||||||
|
on_conflict: :nothing
|
||||||
|
)
|
||||||
|
|
||||||
concurrent_sessions = PlayerSession.concurrent_sessions(player)
|
concurrent_sessions = PlayerSession.concurrent_sessions(player)
|
||||||
|
|
||||||
|
@ -15,7 +15,8 @@ defmodule Chessh.SSH.Daemon do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def init(state) do
|
def init(state) do
|
||||||
GenServer.cast(self(), :start)
|
send(self(), :start)
|
||||||
|
|
||||||
{:ok, state}
|
{:ok, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ defmodule Chessh.SSH.Daemon do
|
|||||||
def pwd_authenticate(username, password, inet, _state),
|
def pwd_authenticate(username, password, inet, _state),
|
||||||
do: pwd_authenticate(username, password, inet)
|
do: pwd_authenticate(username, password, inet)
|
||||||
|
|
||||||
def handle_cast(:start, state) do
|
def handle_info(:start, state) do
|
||||||
port = Application.fetch_env!(:chessh, :port)
|
port = Application.fetch_env!(:chessh, :port)
|
||||||
key_dir = String.to_charlist(Application.fetch_env!(:chessh, :key_dir))
|
key_dir = String.to_charlist(Application.fetch_env!(:chessh, :key_dir))
|
||||||
max_sessions = Application.fetch_env!(:chessh, :max_sessions)
|
max_sessions = Application.fetch_env!(:chessh, :max_sessions)
|
||||||
|
@ -4,6 +4,7 @@ defmodule Chessh.SSH.ServerKey do
|
|||||||
|
|
||||||
@behaviour :ssh_server_key_api
|
@behaviour :ssh_server_key_api
|
||||||
|
|
||||||
|
@impl true
|
||||||
def is_auth_key(key, username, _daemon_options) do
|
def is_auth_key(key, username, _daemon_options) do
|
||||||
PlayerSession.update_sessions_and_player_satisfies(
|
PlayerSession.update_sessions_and_player_satisfies(
|
||||||
username,
|
username,
|
||||||
@ -11,6 +12,7 @@ defmodule Chessh.SSH.ServerKey do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
def host_key(algorithm, daemon_options) do
|
def host_key(algorithm, daemon_options) do
|
||||||
:ssh_file.host_key(algorithm, daemon_options)
|
:ssh_file.host_key(algorithm, daemon_options)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user