Advertisement
Guest User

Untitled

a guest
Jul 27th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 2.21 KB | None | 0 0
  1. -module(server1).
  2.  
  3. -export([init/0, start_ssh/0, start/0, dispatch/0, hello/0]).
  4.  
  5.  
  6. %% USE docker run --rm -it --net=host  simonswine/dropbear bash
  7. %% $ DROPBEAR_PASSWORD=aaaaaaaa dbclient  -l user -y -t -p 8989 -m hmac-sha1 -c 3des-cbc localhost
  8.  
  9. init() ->
  10.   ssh:start().
  11.  
  12. check_auth(Login, Pass) ->
  13.   io:format("checking ~p:~p~n", [Login, Pass]),
  14.   true.
  15.  
  16. check_auth(Login, Pass, Peer, State) ->
  17.   io:format("checking ~p:~p from ~p(~p)~n",
  18.     [Login, Pass, Peer, State]),
  19.   {true, State}.
  20.  
  21. connect_fun(User, Peer, Method) ->
  22.   io:format("~p logined from ~p using ~p~n", [User, Peer, Method]),
  23.   ok.
  24.  
  25. failed_handler_fun(User, Peer, Reason) ->
  26.   io:format("~p conn.failed from ~p -> ~p~n", [User, Peer, Reason]),
  27.   ok.
  28.  
  29. disconnect_handler_fun(Reason) ->
  30.   io:format("disconnected ~p~n", [Reason]),
  31.   ok.
  32.  
  33. dispatch() ->
  34.   erlang:spawn(fun() -> hello() end).
  35.  
  36. hello() ->
  37.    io:format("Hello user!\n"),
  38.    loop().
  39.  
  40. loop() ->
  41.    Line = io:get_line(""),
  42.    io:format(Line),
  43.    loop().
  44.  
  45. debug(ConnectionRef, true, Msg, LanguageTag) ->
  46.   io:print("~p, ~p, ~p, ~p~n", [ConnectionRef, true, Msg, LanguageTag]),
  47.   ok.
  48.  
  49. start_ssh() ->
  50.   Result = ssh:daemon(any, 8989, [
  51.     {system_dir, "/tmp/ssh_daemon"},
  52.     {user_dir, "/tmp/t_user/.ssh"},
  53.     {pwdfun, fun check_auth/4},
  54.     {connectfun, fun connect_fun/3},
  55.     {failfun, fun failed_handler_fun/3},
  56.     {ssh_msg_debug_fun, fun debug/4},
  57.     {preferred_algorithms, [
  58.       {public_key,
  59.         ['ssh-rsa','ssh-dss']
  60.       },
  61.       {cipher,
  62.         [
  63.           {client2server,['3des-cbc', 'aes128-cbc', 'aes128-ctr']},
  64.           {server2client,['3des-cbc', 'aes128-cbc', 'aes128-ctr']}
  65.         ]},
  66.       {mac,['hmac-sha1']},
  67.       {compression,[none]}
  68.     ]},
  69.     {shell, {server1,  dispatch, []}},
  70. %%    {subsystems, [{"echo_n", {ssh_echo_server, [10]}}]},
  71.     {disconnectfun, fun disconnect_handler_fun/1}
  72. %%    {exec, {direct, fun(Cmd) -> io:format("run ~p~n", [Cmd]), Cmd end}}
  73.   ]),
  74.   io:format("ssh start result ~p~n", [Result]),
  75.   case Result of
  76.     {ok, Sshd} ->
  77.       erlang:display(ssh:daemon_info(Sshd));
  78.     _Any ->
  79.       ok
  80.   end,
  81.   Result.
  82.  
  83.  
  84. start() ->
  85. %%  debugger:start(),
  86.   init(),
  87.   start_ssh(),
  88.   timer:sleep(10000000).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement