Allow an http call to set account details if AllowSetAccount = true in [UserAccountService].

As before, default is false to not allow these calls.
0.7.2-post-fixes
Justin Clark-Casey (justincc) 2011-10-19 00:06:40 +01:00
parent b7fcd6871e
commit 233127c696
3 changed files with 67 additions and 4 deletions

View File

@ -51,6 +51,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
private IUserAccountService m_UserAccountService; private IUserAccountService m_UserAccountService;
private bool m_AllowCreateUser = false; private bool m_AllowCreateUser = false;
private bool m_AllowSetAccount = false;
public UserAccountServerPostHandler(IUserAccountService service) public UserAccountServerPostHandler(IUserAccountService service)
: this(service, null) {} : this(service, null) {}
@ -61,7 +62,10 @@ namespace OpenSim.Server.Handlers.UserAccounts
m_UserAccountService = service; m_UserAccountService = service;
if (config != null) if (config != null)
{
m_AllowCreateUser = config.GetBoolean("AllowCreateUser", m_AllowCreateUser); m_AllowCreateUser = config.GetBoolean("AllowCreateUser", m_AllowCreateUser);
m_AllowSetAccount = config.GetBoolean("AllowSetAccount", m_AllowSetAccount);
}
} }
public override byte[] Handle(string path, Stream requestData, public override byte[] Handle(string path, Stream requestData,
@ -99,8 +103,12 @@ namespace OpenSim.Server.Handlers.UserAccounts
case "getaccounts": case "getaccounts":
return GetAccounts(request); return GetAccounts(request);
case "setaccount": case "setaccount":
if (m_AllowSetAccount)
return StoreAccount(request); return StoreAccount(request);
else
break;
} }
m_log.DebugFormat("[USER SERVICE HANDLER]: unknown method request: {0}", method); m_log.DebugFormat("[USER SERVICE HANDLER]: unknown method request: {0}", method);
} }
catch (Exception e) catch (Exception e)
@ -193,8 +201,56 @@ namespace OpenSim.Server.Handlers.UserAccounts
byte[] StoreAccount(Dictionary<string, object> request) byte[] StoreAccount(Dictionary<string, object> request)
{ {
// No can do. No changing user accounts from remote sims UUID principalID = UUID.Zero;
if (!(request.ContainsKey("UserID") && UUID.TryParse(request["UserID"].ToString(), out principalID)))
return FailureResult(); return FailureResult();
UUID scopeID = UUID.Zero;
if (request.ContainsKey("ScopeID") && !UUID.TryParse(request["ScopeID"].ToString(), out scopeID))
return FailureResult();
UserAccount existingAccount = m_UserAccountService.GetUserAccount(scopeID, principalID);
if (existingAccount == null)
return FailureResult();
Dictionary<string, object> result = new Dictionary<string, object>();
if (request.ContainsKey("FirstName"))
existingAccount.FirstName = request["FirstName"].ToString();
if (request.ContainsKey("LastName"))
existingAccount.LastName = request["LastName"].ToString();
if (request.ContainsKey("Email"))
existingAccount.Email = request["Email"].ToString();
int created = 0;
if (request.ContainsKey("Created") && int.TryParse(request["Created"].ToString(), out created))
existingAccount.Created = created;
int userLevel = 0;
if (request.ContainsKey("UserLevel") && int.TryParse(request["UserLevel"].ToString(), out userLevel))
existingAccount.UserFlags = userLevel;
int userFlags = 0;
if (request.ContainsKey("UserFlags") && int.TryParse(request["UserFlags"].ToString(), out userFlags))
existingAccount.UserFlags = userFlags;
if (request.ContainsKey("UserTitle"))
existingAccount.UserTitle = request["UserTitle"].ToString();
if (!m_UserAccountService.StoreUserAccount(existingAccount))
{
m_log.ErrorFormat(
"[USER ACCOUNT SERVER POST HANDLER]: Account store failed for account {0} {1} {2}",
existingAccount.FirstName, existingAccount.LastName, existingAccount.PrincipalID);
return FailureResult();
}
result["result"] = existingAccount.ToKeyValuePairs();
return ResultToBytes(result);
} }
byte[] CreateUser(Dictionary<string, object> request) byte[] CreateUser(Dictionary<string, object> request)

View File

@ -177,6 +177,10 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
;; Default is false. ;; Default is false.
; AllowCreateUser = false ; AllowCreateUser = false
;; Allow the service to process HTTP set account calls.
;; Default is false.
; AllowSetAccount = false
[GridUserService] [GridUserService]
; for the server connector ; for the server connector

View File

@ -154,13 +154,16 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
;; This switch creates the minimum set of body parts and avatar entries for a viewer 2 ;; This switch creates the minimum set of body parts and avatar entries for a viewer 2
;; to show a default "Ruth" avatar rather than a cloud for a newly created user. ;; to show a default "Ruth" avatar rather than a cloud for a newly created user.
;; Default is false ;; Default is false
;; If you enable this you will also need to uncomment the AvatarService line above
; CreateDefaultAvatarEntries = false ; CreateDefaultAvatarEntries = false
;; Allow the service to process HTTP create user calls. ;; Allow the service to process HTTP create user calls.
;; Default is false. ;; Default is false.
; AllowCreateUser = false ; AllowCreateUser = false
;; Allow the service to process HTTP set account calls.
;; Default is false.
; AllowSetAccount = false
[GridUserService] [GridUserService]
; for the server connector ; for the server connector