Maxim Sokhatsky 11 лет назад
Родитель
Сommit
d3f53c83b0

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 RELEASE := kakaranet
 COOKIE  := node_runner
-APPS    := kernel stdlib sasl gproc cowboy mimetypes ranch erlydtl n2o face db server
+APPS    := kernel stdlib sasl gproc cowboy cowlib ranch erlydtl n2o face db server
 VER     := 1.0.0
 VM      := rels/web/files/vm.args
 SYS     := rels/web/files/sys.config

+ 16 - 0
apps/face/priv/ssl/cowboy-ca.crt

@@ -0,0 +1,16 @@
+-----BEGIN CERTIFICATE-----
+MIICeDCCAeGgAwIBAgIJAOvpU0y2e5J4MA0GCSqGSIb3DQEBBQUAMFUxCzAJBgNV
+BAYTAlVTMQ4wDAYDVQQIDAVUZXhhczETMBEGA1UECgwKTmluZSBOaW5lczEPMA0G
+A1UECwwGQ293Ym95MRAwDgYDVQQDDAdST09UIENBMB4XDTEzMDIyODA1MTAwMVoX
+DTMzMDIyMzA1MTAwMVowVTELMAkGA1UEBhMCVVMxDjAMBgNVBAgMBVRleGFzMRMw
+EQYDVQQKDApOaW5lIE5pbmVzMQ8wDQYDVQQLDAZDb3dib3kxEDAOBgNVBAMMB1JP
+T1QgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMzmY7Us06yjyUbpqwPx
+Iv+xh/g3V7we07ClC9GEYnvr3OQvdA1jFEHccMBUUjRoQ8DPd6uSyK5UkixABs08
+Tt5B3VsnGKr0DIN+IO4SN2PkmBqIU/BN3KdcwN65YNr3iM0KsKWeFtAZdYx4CakX
+7REbO0wjK20AH3xSBn3uFGiBAgMBAAGjUDBOMB0GA1UdDgQWBBRKfZ8KF2jlLBDm
+NL6IuEuGY0pdbzAfBgNVHSMEGDAWgBRKfZ8KF2jlLBDmNL6IuEuGY0pdbzAMBgNV
+HRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAG1I0kBxXiLkM1b7rl2zPLizREYg
+1m+ajb6rWzPOBg6TXjv58Be+H4tq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VdPvRxRznw5rZwaXesryXu1jVSZxTr3MYZdkG6KaAM0t90+YlGLZ
+UG8fAicx0Bf+
+-----END CERTIFICATE-----

+ 15 - 0
apps/face/priv/ssl/server.key

@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXQIBAAKBgQDNtbUaMQLMdRz9ZJOouIAaqMI1xxHmxpVL7KjPZI9GGmjJ/T+o
+GtfkFjS3OaCjOhOJF8TjAKJUP30Jz4Oun8Uzj2vgSll2hwii+muY6a/+DCSiP3nN
+oDo8o2fU52YOnaHAmxfZmbeSlsZRlPGMOSRxyaBRvgSMvuo0eruxpC2K9QIDAQAB
+AoGAaD85c/h6bpq7Aj7CBbLaWKhFI3OqwsTITB22vsM7SE+B4zsP02UnG1OVi3UM
+zytTUxpUkKV1njQ+bYZYOVqGWF4Up8tTqUglHn0FTPok1AIemELWtz3sXvdSHC1T
+lqvFBAZ9kibn13qGyVOiyCFaMwfOM/05RvV7p3jfUMTWnNECQQDs7yCJZ8Ol8MyH
+TGZzvkjoN2zg1KwmTbSD1hkP6QAJtPdRuqFbjlEru0/PefgOXsWLRIa3/3v0qw2G
+xGkV6AXTAkEA3kNbFisqUydjPnZIYv/P6SvPdUimHJEjXbAbfNfzS9dzszrOVJd2
+XqGH7z5yzjoH3IyaIMW8GnubVzGDSjrHFwJAKSU5vELlygpwKkrNO+pelN0TLlQg
+dSJnZ8GlZorq88SWcn37iX/EftivenNO7YftvEqxLoDSkOGnnrC7Iw/A+wJBAIEe
+L/QY72WPJCBNJpAce/PA96vyoE1II3txqwZDjZspdpVQPDz4IFOpEwbxCFC1dYuy
+Qnd3Z2cbF4r3wIWGz9ECQQCJGNhUNtY+Om1ELdqPcquxE2VRV/pucnvJSTKwyo2C
+Rvm6H7kFDwPDuN23YnTOlTiho0zzCkclcIukhIVJ+dKz
+-----END RSA PRIVATE KEY-----

+ 1 - 1
apps/face/priv/templates/index.html

@@ -10,7 +10,7 @@
 </head>
 <body>
 {{body}}
-<script>var transition = {pid: '', host: 'localhost', port:'8000'};</script>
+<script>var transition = {pid: '', host: 'localhost' };</script>
 <script>function handle_web_socket(body) { console.log(String(bert.decodebuf(body))); } </script>
 <script src='/static/nitrogen/bullet.js' type='text/javascript' charset='utf-8'></script>
 <script src='/static/nitrogen/n2o.js' type='text/javascript' charset='utf-8'></script>

+ 10 - 2
apps/face/src/web_sup.erl

@@ -17,6 +17,14 @@ init([]) ->
     {ok, _} = cowboy:start_http(http, 100, [{port, wf:config(n2o,transition_port,8000)}],
                                            [{env, [{dispatch, dispatch_rules()}]}]),
 
+    PrivDir = code:priv_dir(face),
+
+    {ok, _} = cowboy:start_https(https, 100, [
+        {port, 8443},
+        {cacertfile, PrivDir ++ "/ssl/cowboy-ca.crt"},
+        {certfile, PrivDir ++ "/ssl/server.crt"},
+        {keyfile, PrivDir ++ "/ssl/server.key"} ], [{env, [{dispatch, dispatch_rules()}]}]),
+
     users:init(),
     users:populate(?USERS),
 
@@ -25,8 +33,8 @@ init([]) ->
 dispatch_rules() ->
     cowboy_router:compile(
         [{'_', [
-            {"/static/[...]", cowboy_static, [{directory, {priv_dir, ?APP, [<<"static">>]}},
-                                                {mimetypes, {fun mimetypes:path_to_mimes/2, default}}]},
+            {"/static/[...]", cowboy_static,
+                {priv_dir, ?APP, <<"static">>,[{mimetypes,cow_mimetypes,all}]}},
             {"/rest/:resource", rest_cowboy, []},
             {"/rest/:resource/:id", rest_cowboy, []},
             {"/ws/[...]", bullet_handler, [{handler, n2o_bullet}]},

+ 10 - 10
apps/server/src/auth_server.erl

@@ -59,33 +59,33 @@ handle_call({store_token, GameId, Token, UserId}, _From, #state{tokens = E} = St
     {reply, Token, State};
 
 handle_call({get_user_info, Token}, _From, #state{tokens = E} = State) ->
-    gs:info("checking token: ~p", [Token]),
+    gas:info("checking token: ~p", [Token]),
     case ets:lookup(E, Token) of
         [] ->
-            gs:info("token not found", []),
+            gas:info("token not found", []),
             {reply, false, State};
         List ->
             {authtoken, _, UserId} = hd(List),
-            gs:info("token was registred, getting user info for ~p",[UserId]),
+            gas:info("token was registred, getting user info for ~p",[UserId]),
             Reply = case user_info(UserId) of
                 {ok, UserInfo} ->
-                    gs:info("..user info retrieved", []),
+                    gas:info("..user info retrieved", []),
                     UserInfo;
                 {error, user_not_found} ->
-                    gs:info("..no such user info, providing fake credentials", []),
+                    gas:info("..no such user info, providing fake credentials", []),
                     fake_credentials0(State#state.spare); %% for eunit tests. FIX
                 {badrpc, _} ->
-                    gs:info("..bad rpc, providing fake credentials", []),
+                    gas:info("..bad rpc, providing fake credentials", []),
                     fake_credentials0(State#state.spare)  %% for eunit tests. FIX
             end,
             {reply, Reply, State}
     end;
 
 handle_call({get_user_info, Token, Id}, _From, #state{tokens = E} = State) ->
-    gs:info("checking token: ~p", [Token]),
+    gas:info("checking token: ~p", [Token]),
     case ets:lookup(E, Token) of
         [] ->
-            gs:error("token not found", []),
+            gas:error("token not found", []),
             {reply, false, State};
         _List ->
             Reply0 = fake_credentials0(State#state.spare),
@@ -110,14 +110,14 @@ fake_credentials0(Spare) ->
     H0#'PlayerInfo'{id = Id}.
 
 store_token(GameId, E, Token, UserId) ->
-    gs:info("storing token: ~p", [Token]),
+    gas:info("storing token: ~p", [Token]),
     Data = #authtoken{token = Token, id = UserId},
     ets:insert(E, Data).
 
 user_info(UserId) ->
     case kvs:get(user,UserId) of
         {ok, UserData} ->
-            gs:info("User Data: ~p",[UserData]),
+            gas:info("User Data: ~p",[UserData]),
             {ok, #'PlayerInfo'{id = wf:to_binary(UserData#user.id),
                                login = wf:to_binary(UserData#user.username),
                                name = wf:to_binary(UserData#user.id),

+ 16 - 16
apps/server/src/game_session.erl

@@ -47,11 +47,11 @@ bot_session_attach(Pid, UserInfo) ->
 % TODO: in case of game requests from web page handle them here
 
 process_request(Pid, Msg) ->
-    gs:info("API payload ~p pid ~p",[Msg,Pid]),
+    gas:info("API payload ~p pid ~p",[Msg,Pid]),
     gen_server:call(Pid, {client_request, Msg}).
 
 process_request(Pid, Source, Msg) ->
-    gs:info("API from ~p payload ~p pid ~p",[Source,Msg,Pid]),
+    gas:info("API from ~p payload ~p pid ~p",[Source,Msg,Pid]),
     gen_server:call(Pid, {client_request, Msg}).
 
 init([RPC]) ->
@@ -62,7 +62,7 @@ handle_call({client_request, Request}, From, State) ->
     handle_client_request(Request, From, State);
 
 handle_call(Request, From, State) ->
-    gs:info("unrecognized call: ~p", [Request]),
+    gas:info("unrecognized call: ~p", [Request]),
     {stop, {unknown_call, From, Request}, State}.
 
 
@@ -71,7 +71,7 @@ handle_cast({bot_session_attach, UserInfo}, State = #state{user = undefined}) ->
     {noreply, State#state{user = UserInfo}};
 
 handle_cast(Msg, State) ->
-    gs:info("session: unrecognized cast: ~p", [Msg]),
+    gas:info("session: unrecognized cast: ~p", [Msg]),
     {stop, {error, {unknown_cast, Msg}}, State}.
 
 
@@ -79,7 +79,7 @@ handle_info({relay_event, SubscrId, RelayMsg}, State) ->
     handle_relay_message(RelayMsg, SubscrId, State);
 
 handle_info({relay_kick, SubscrId, Reason}, State) ->
-    gs:info("Recived a kick notification from the table: ~p", [Reason]),
+    gas:info("Recived a kick notification from the table: ~p", [Reason]),
     handle_relay_kick(Reason, SubscrId, State);
 
 handle_info({delivery, ["user_action", Action, Who, Whom], _} = Notification,
@@ -87,7 +87,7 @@ handle_info({delivery, ["user_action", Action, Who, Whom], _} = Notification,
                    user = User,
                    rpc = RPC
                   } = State) ->
-    gs:info("~w:handle_info/2 Delivery: ~p", [?MODULE, Notification]),
+    gas:info("~w:handle_info/2 Delivery: ~p", [?MODULE, Notification]),
     UserId = User#'PlayerInfo'.id,
     case list_to_binary(Who) of
         UserId ->
@@ -119,7 +119,7 @@ handle_info({delivery, ["user_action", Action, Who, Whom], _} = Notification,
 
 
 handle_info({'DOWN', MonitorRef, _Type, _Object, _Info} = Msg, State = #state{rpc_mon = MonitorRef}) ->
-    gs:info("connection closed, shutting down session:~p", [Msg]),
+    gas:info("connection closed, shutting down session:~p", [Msg]),
     {stop, normal, State};
 
 handle_info({'DOWN', OtherRef, process, _Object, Info} = _Msg,
@@ -136,7 +136,7 @@ handle_info({'DOWN', OtherRef, process, _Object, Info} = _Msg,
     end;
 
 handle_info(Info, State) ->
-    gs:info("session: unrecognized info: ~p", [Info]),
+    gas:info("session: unrecognized info: ~p", [Info]),
     {noreply, State}.
 
 terminate(Reason, #state{rels_notif_channel = RelsChannel}) ->
@@ -152,31 +152,31 @@ code_change(_OldVsn, State, _Extra) ->
 
 handle_client_request(#session_attach{token = Token}, _From,
                       #state{user = undefined} = State) ->
-    gs:info("checking session token: ~p", [Token]),
+    gas:info("checking session token: ~p", [Token]),
     case auth_server:get_user_info(Token) of
         false ->
-            gs:error("failed session attach: ~p", [Token]),
+            gas:error("failed session attach: ~p", [Token]),
             {stop, normal, {error, invalid_token}, State};
         UserInfo ->
-            gs:info("successfull session attach. Your user info: ~p", [UserInfo]),
+            gas:info("successfull session attach. Your user info: ~p", [UserInfo]),
             {reply, UserInfo, State#state{user = UserInfo}}
     end;
 
 handle_client_request(#session_attach_debug{token = Token, id = Id}, _From,
                       #state{user = undefined} = State) ->
-    gs:info("checking debug session token: ~p", [{Token,Id}]),
+    gas:info("checking debug session token: ~p", [{Token,Id}]),
     case {?IS_TEST, auth_server:get_user_info(Token, Id)} of
         {_Test, false} ->
-            gs:error("... ~p", [{_Test,false}]),
+            gas:error("... ~p", [{_Test,false}]),
             {stop, normal, {error, invalid_token}, State};
         {false, true} ->
-            gs:error("... ~p", [{false,true}]),
+            gas:error("... ~p", [{false,true}]),
             {stop, normal, {error, invalid_token}, State};
         {true, UserInfo} ->
-            gs:info("... ~p", [{true,UserInfo}]),
+            gas:info("... ~p", [{true,UserInfo}]),
             {reply, UserInfo, State#state{user = UserInfo}};
         {false, UserInfo} ->
-            gs:info("... ~p", [{true,UserInfo}]),
+            gas:info("... ~p", [{true,UserInfo}]),
             {reply, UserInfo, State#state{user = UserInfo}}
     end;
 

+ 1 - 1
apps/server/src/gs.erl → apps/server/src/gas.erl

@@ -1,4 +1,4 @@
--module(gs).
+-module(gas).
 -compile(export_all).
 
 info(String, Args) ->  error_logger:info_msg(String, Args).

+ 1 - 1
rels/web/reltool.config

@@ -8,8 +8,8 @@
          stdlib,
          sasl,
          shen,
-         mimetypes,
          gproc,
+         cowlib,
          n2o,
          erlydtl,
          db,