- Timestamp:
- Jul 21, 2015, 9:51:32 PM (9 years ago)
- Location:
- binary-improvements/MapRendering/Web/Handlers
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/Handlers/ApiHandler.cs
r230 r244 6 6 using System.Threading; 7 7 8 namespace AllocsFixes.NetConnections.Servers.Web 8 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 9 9 { 10 public class ApiHandler : PathHandler 11 { 10 public class ApiHandler : PathHandler { 12 11 private string staticPart; 13 12 private Dictionary<String, WebAPI> apis = new Dictionary<string, WebAPI> (); 14 13 15 public ApiHandler (string staticPart) 16 { 14 public ApiHandler (string staticPart, string moduleName = null) : base(moduleName) { 17 15 this.staticPart = staticPart; 18 apis.Add ("getlandclaims", new GetLandClaims ()); 19 apis.Add ("getplayersonline", new GetPlayersOnline ()); 20 apis.Add ("getplayerslocation", new GetPlayersLocation ()); 21 apis.Add ("getplayerinventory", new GetPlayerInventory ()); 16 addApi ("getlandclaims", new GetLandClaims ()); 17 addApi ("getplayersonline", new GetPlayersOnline ()); 18 addApi ("getplayerslocation", new GetPlayersLocation ()); 19 addApi ("getplayerinventory", new GetPlayerInventory ()); 20 addApi ("getstats", new GetStats ()); 22 21 } 23 22 24 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user) 25 { 23 private void addApi (string _apiName, WebAPI _api) { 24 apis.Add (_apiName, _api); 25 WebPermissions.Instance.AddKnownModule ("webapi." + _apiName); 26 } 27 28 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 26 29 string apiName = req.Url.AbsolutePath.Remove (0, staticPart.Length); 27 if (!AuthorizeForCommand (apiName, user )) {30 if (!AuthorizeForCommand (apiName, user, permissionLevel)) { 28 31 resp.StatusCode = (int)HttpStatusCode.Forbidden; 32 if (user != null) { 33 Log.Out ("ApiHandler: user '{0}' not allowed to execute '{1}'", user.SteamID, apiName); 34 } else { 35 Log.Out ("ApiHandler: unidentified user from '{0}' not allowed to execute '{1}'", req.RemoteEndPoint.Address, apiName); 36 } 37 return; 29 38 } else { 30 39 foreach (KeyValuePair<string, WebAPI> kvp in apis) { 31 40 try { 32 41 if (apiName.StartsWith (kvp.Key)) { 33 kvp.Value.HandleRequest (req, resp, user );42 kvp.Value.HandleRequest (req, resp, user, permissionLevel); 34 43 return; 35 44 } … … 46 55 } 47 56 48 private bool AuthorizeForCommand (string apiName, HttpListenerBasicIdentity user) 49 { 50 return true; 57 private bool AuthorizeForCommand (string apiName, WebConnection user, int permissionLevel) { 58 return WebPermissions.Instance.ModuleAllowedWithLevel ("webapi." + apiName, permissionLevel); 51 59 } 52 60
Note:
See TracChangeset
for help on using the changeset viewer.