Changeset 244 for binary-improvements/MapRendering/Web/Handlers
- Timestamp:
- Jul 21, 2015, 9:51:32 PM (9 years ago)
- Location:
- binary-improvements/MapRendering/Web/Handlers
- Files:
-
- 3 added
- 5 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 -
binary-improvements/MapRendering/Web/Handlers/ItemIconHandler.cs
r242 r244 7 7 using UnityEngine; 8 8 9 namespace AllocsFixes.NetConnections.Servers.Web 9 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 10 10 { 11 11 public class ItemIconHandler : PathHandler … … 16 16 private bool loaded = false; 17 17 18 public ItemIconHandler (string staticPart, bool logMissingFiles ) {18 public ItemIconHandler (string staticPart, bool logMissingFiles, string moduleName = null) : base(moduleName) { 19 19 this.staticPart = staticPart; 20 20 this.logMissingFiles = logMissingFiles; 21 21 } 22 22 23 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user) {23 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 24 24 if (!loaded) { 25 25 if (!LoadIcons ()) { -
binary-improvements/MapRendering/Web/Handlers/PathHandler.cs
r230 r244 2 2 using System.Net; 3 3 4 namespace AllocsFixes.NetConnections.Servers.Web 4 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 5 5 { 6 6 public abstract class PathHandler 7 7 { 8 public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user); 8 private string moduleName = null; 9 public string ModuleName { 10 get { return moduleName; } 11 } 12 13 protected PathHandler (string _moduleName) { 14 this.moduleName = _moduleName; 15 WebPermissions.Instance.AddKnownModule (_moduleName); 16 } 17 18 public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel); 19 20 public bool IsAuthorizedForHandler (WebConnection user, int permissionLevel) { 21 if (moduleName != null) { 22 return WebPermissions.Instance.ModuleAllowedWithLevel (moduleName, permissionLevel); 23 } else { 24 return true; 25 } 26 } 9 27 } 10 28 } -
binary-improvements/MapRendering/Web/Handlers/SimpleRedirectHandler.cs
r230 r244 2 2 using System.Net; 3 3 4 namespace AllocsFixes.NetConnections.Servers.Web 4 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 5 5 { 6 6 public class SimpleRedirectHandler : PathHandler … … 8 8 string target; 9 9 10 public SimpleRedirectHandler (string target )10 public SimpleRedirectHandler (string target, string moduleName = null) : base(moduleName) 11 11 { 12 12 this.target = target; 13 13 } 14 14 15 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user)15 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 16 16 { 17 17 resp.Redirect (target); -
binary-improvements/MapRendering/Web/Handlers/StaticHandler.cs
r230 r244 5 5 using System.Threading; 6 6 7 namespace AllocsFixes.NetConnections.Servers.Web 7 namespace AllocsFixes.NetConnections.Servers.Web.Handlers 8 8 { 9 9 public class StaticHandler : PathHandler … … 14 14 private bool logMissingFiles; 15 15 16 public StaticHandler (string staticPart, string filePath, AllocsFixes.FileCache.AbstractCache cache, bool logMissingFiles )16 public StaticHandler (string staticPart, string filePath, AllocsFixes.FileCache.AbstractCache cache, bool logMissingFiles, string moduleName = null) : base(moduleName) 17 17 { 18 18 this.staticPart = staticPart; … … 22 22 } 23 23 24 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user)24 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 25 25 { 26 26 string fn = req.Url.AbsolutePath.Remove (0, staticPart.Length);
Note:
See TracChangeset
for help on using the changeset viewer.