Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(server1).
- -export([init/0, start_ssh/0, start/0, dispatch/0, hello/0]).
- %% USE docker run --rm -it --net=host simonswine/dropbear bash
- %% $ DROPBEAR_PASSWORD=aaaaaaaa dbclient -l user -y -t -p 8989 -m hmac-sha1 -c 3des-cbc localhost
- init() ->
- ssh:start().
- check_auth(Login, Pass) ->
- io:format("checking ~p:~p~n", [Login, Pass]),
- true.
- check_auth(Login, Pass, Peer, State) ->
- io:format("checking ~p:~p from ~p(~p)~n",
- [Login, Pass, Peer, State]),
- {true, State}.
- connect_fun(User, Peer, Method) ->
- io:format("~p logined from ~p using ~p~n", [User, Peer, Method]),
- ok.
- failed_handler_fun(User, Peer, Reason) ->
- io:format("~p conn.failed from ~p -> ~p~n", [User, Peer, Reason]),
- ok.
- disconnect_handler_fun(Reason) ->
- io:format("disconnected ~p~n", [Reason]),
- ok.
- dispatch() ->
- erlang:spawn(fun() -> hello() end).
- hello() ->
- io:format("Hello user!\n"),
- loop().
- loop() ->
- Line = io:get_line(""),
- io:format(Line),
- loop().
- debug(ConnectionRef, true, Msg, LanguageTag) ->
- io:print("~p, ~p, ~p, ~p~n", [ConnectionRef, true, Msg, LanguageTag]),
- ok.
- start_ssh() ->
- Result = ssh:daemon(any, 8989, [
- {system_dir, "/tmp/ssh_daemon"},
- {user_dir, "/tmp/t_user/.ssh"},
- {pwdfun, fun check_auth/4},
- {connectfun, fun connect_fun/3},
- {failfun, fun failed_handler_fun/3},
- {ssh_msg_debug_fun, fun debug/4},
- {preferred_algorithms, [
- {public_key,
- ['ssh-rsa','ssh-dss']
- },
- {cipher,
- [
- {client2server,['3des-cbc', 'aes128-cbc', 'aes128-ctr']},
- {server2client,['3des-cbc', 'aes128-cbc', 'aes128-ctr']}
- ]},
- {mac,['hmac-sha1']},
- {compression,[none]}
- ]},
- {shell, {server1, dispatch, []}},
- %% {subsystems, [{"echo_n", {ssh_echo_server, [10]}}]},
- {disconnectfun, fun disconnect_handler_fun/1}
- %% {exec, {direct, fun(Cmd) -> io:format("run ~p~n", [Cmd]), Cmd end}}
- ]),
- io:format("ssh start result ~p~n", [Result]),
- case Result of
- {ok, Sshd} ->
- erlang:display(ssh:daemon_info(Sshd));
- _Any ->
- ok
- end,
- Result.
- start() ->
- %% debugger:start(),
- init(),
- start_ssh(),
- timer:sleep(10000000).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement