Changeset 474
- Timestamp:
- Aug 24, 2023, 12:48:17 PM (15 months ago)
- Location:
- TFP-WebServer/WebServer/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TFP-WebServer/WebServer/src/Permissions/AdminApiTokens.cs
r440 r474 40 40 41 41 public void AddToken (string _name, string _secret, int _permissionLevel) { 42 ApiToken apiToken = new ApiToken (_name, _secret, _permissionLevel); 43 tokens [_name] = apiToken; 44 Parent.Save (); 42 lock (Parent) { 43 ApiToken apiToken = new ApiToken (_name, _secret, _permissionLevel); 44 tokens[_name] = apiToken; 45 Parent.Save (); 46 } 45 47 } 46 48 47 49 public bool RemoveToken (string _name) { 48 bool removed = tokens.Remove (_name); 49 if (removed) { 50 Parent.Save (); 50 lock (Parent) { 51 bool removed = tokens.Remove (_name); 52 if (removed) { 53 Parent.Save (); 54 } 55 56 return removed; 51 57 } 52 53 return removed;54 58 } 55 59 56 60 public Dictionary<string, ApiToken> GetTokens () { 57 return tokens; 61 lock (Parent) { 62 return tokens; 63 } 58 64 } 59 65 … … 113 119 114 120 public int GetPermissionLevel (string _name, string _secret) { 115 if (tokens.TryGetValue (_name, out ApiToken apiToken) && apiToken.Secret == _secret) { 116 return apiToken.PermissionLevel; 121 lock (Parent) { 122 if (tokens.TryGetValue (_name, out ApiToken apiToken) && apiToken.Secret == _secret) { 123 return apiToken.PermissionLevel; 124 } 125 126 if (IsCommandlineToken (_name, _secret)) { 127 return 0; 128 } 129 130 return int.MaxValue; 117 131 } 118 119 if (IsCommandlineToken (_name, _secret)) {120 return 0;121 }122 123 return int.MaxValue;124 132 } 125 133 -
TFP-WebServer/WebServer/src/Permissions/AdminWebModules.cs
r435 r474 41 41 42 42 public void AddModule (WebModule _module) { 43 lock ( this) {43 lock (Parent) { 44 44 allModulesList.Clear (); 45 45 … … 50 50 51 51 public bool RemoveModule (string _module) { 52 lock ( this) {52 lock (Parent) { 53 53 allModulesList.Clear (); 54 54 … … 63 63 64 64 public List<WebModule> GetModules () { 65 lock ( this) {65 lock (Parent) { 66 66 if (allModulesList.Count != 0) { 67 67 return allModulesList; … … 259 259 _module.IsDefault = true; 260 260 261 lock ( this) {261 lock (Parent) { 262 262 allModulesList.Clear (); 263 263 knownModules [_module.Name] = _module; … … 270 270 } 271 271 272 lock ( this) {272 lock (Parent) { 273 273 return knownModules.ContainsKey (_module); 274 274 } … … 276 276 277 277 public bool ModuleAllowedWithLevel (string _module, int _level) { 278 return GetModule (_module).LevelGlobal >= _level; 278 lock (Parent) { 279 return GetModule (_module).LevelGlobal >= _level; 280 } 279 281 } 280 282 281 283 public WebModule GetModule (string _module) { 282 if (modules.TryGetValue (_module, out WebModule result)) { 283 return result; 284 } 285 286 return knownModules.TryGetValue (_module, out result) ? result : defaultModulePermission; 284 lock (Parent) { 285 if (modules.TryGetValue (_module, out WebModule result)) { 286 return result; 287 } 288 289 return knownModules.TryGetValue (_module, out result) ? result : defaultModulePermission; 290 } 287 291 } 288 292 -
TFP-WebServer/WebServer/src/Permissions/AdminWebUsers.cs
r433 r474 43 43 44 44 public void AddUser (string _name, string _password, PlatformUserIdentifierAbs _userIdentifier, PlatformUserIdentifierAbs _crossPlatformIdentifier) { 45 WebUser p = new WebUser (_name, _password, _userIdentifier, _crossPlatformIdentifier); 46 47 // TODO: Check if another name exists with the same (crossplatform)identifier, remove that 48 users [_name] = p; 49 50 Parent.Save (); 45 lock (Parent) { 46 WebUser p = new WebUser (_name, _password, _userIdentifier, _crossPlatformIdentifier); 47 48 // TODO: Check if another name exists with the same (crossplatform)identifier, remove that 49 users[_name] = p; 50 51 Parent.Save (); 52 } 51 53 } 52 54 53 55 public bool RemoveUser (string _name) { 54 bool removed = users.Remove (_name); 55 if (removed) { 56 Parent.Save (); 56 lock (Parent) { 57 bool removed = users.Remove (_name); 58 if (removed) { 59 Parent.Save (); 60 } 61 62 return removed; 57 63 } 58 59 return removed;60 64 } 61 65 62 66 public Dictionary<string, WebUser> GetUsers () { 63 return users; 67 lock (Parent) { 68 return users; 69 } 64 70 } 65 71 … … 134 140 135 141 public bool TryGetUser (string _name, string _password, out WebUser _result) { 136 if (users.TryGetValue (_name, out _result) && _result.ValidatePassword (_password)) { 137 return true; 142 lock (Parent) { 143 if (users.TryGetValue (_name, out _result) && _result.ValidatePassword (_password)) { 144 return true; 145 } 146 147 _result = default; 148 return false; 138 149 } 139 140 _result = default;141 return false;142 150 } 143 151 144 152 public bool HasUser (PlatformUserIdentifierAbs _platformUser, PlatformUserIdentifierAbs _crossPlatformUser, out WebUser _result) { 145 _result = default; 146 147 foreach ((string _, WebUser webUser) in users) { 148 if (!PlatformUserIdentifierAbs.Equals (webUser.PlatformUser, _platformUser) || 149 !PlatformUserIdentifierAbs.Equals (webUser.CrossPlatformUser, _crossPlatformUser)) { 150 continue; 153 lock (Parent) { 154 _result = default; 155 156 foreach ((string _, WebUser webUser) in users) { 157 if (!PlatformUserIdentifierAbs.Equals (webUser.PlatformUser, _platformUser) || 158 !PlatformUserIdentifierAbs.Equals (webUser.CrossPlatformUser, _crossPlatformUser)) { 159 continue; 160 } 161 162 _result = webUser; 163 return true; 151 164 } 152 165 153 _result = webUser; 154 return true; 166 return false; 155 167 } 156 157 return false;158 168 } 159 169 -
TFP-WebServer/WebServer/src/Web.cs
r469 r474 236 236 } 237 237 238 // Force parsing the URL path as UTF8 so special characters get decoded properly 238 239 request.ContentEncoding = Encoding.UTF8; 239 240 RequestContext context = new RequestContext (requestPath, request, response, conn, permissionLevel);
Note:
See TracChangeset
for help on using the changeset viewer.