diff --git a/ClientServerLib/ClientServerLib/CServer.cs b/ClientServerLib/ClientServerLib/CServer.cs
index 4bd9e39e..07dec143 100644
--- a/ClientServerLib/ClientServerLib/CServer.cs
+++ b/ClientServerLib/ClientServerLib/CServer.cs
@@ -94,6 +94,45 @@ namespace ServerLib
}
+ #endregion
+
+ #region user management
+
+ private static SetPasswordDelegate setPassword;
+ public static SetPasswordDelegate SetPassword
+ {
+ internal get { return CServer.setPassword; }
+ set { CServer.setPassword = value; }
+ }
+
+ private static ValidatePasswordDelegate validatePassword;
+ public static ValidatePasswordDelegate ValidatePassword
+ {
+ internal get { return CServer.validatePassword; }
+ set { CServer.validatePassword = value; }
+ }
+
+ private static GetUserRoleDelegate getUserRole;
+ public static GetUserRoleDelegate GetUserRole
+ {
+ internal get { return CServer.getUserRole; }
+ set { CServer.getUserRole = value; }
+ }
+
+ private static SetUserRoleDelegate setUserRole;
+ public static SetUserRoleDelegate SetUserRole
+ {
+ internal get { return CServer.setUserRole; }
+ set { CServer.setUserRole = value; }
+ }
+
+ private static GetUserIdFromUsernameDelegate getUserIdFromUsername;
+ public static GetUserIdFromUsernameDelegate GetUserIdFromUsername
+ {
+ internal get { return CServer.getUserIdFromUsername; }
+ set { CServer.getUserIdFromUsername = value; }
+ }
+
#endregion
public CServer(int port, bool encrypted)
@@ -101,6 +140,8 @@ namespace ServerLib
init(port, encrypted);
}
+ #region server control
+
private void init(int port, bool encrypted)
{
string hostname = Dns.GetHostName();
@@ -178,7 +219,7 @@ namespace ServerLib
private void registerUrlAndCert(int port)
{
- #if WIN
+#if WIN
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "WebserverInitalConfig.exe";
@@ -194,11 +235,14 @@ namespace ServerLib
p.Close();
}
- #else
+#else
//Required?
- #endif
+#endif
}
+
+ #endregion
+
}
}
diff --git a/ClientServerLib/ClientServerLib/CWebservice.cs b/ClientServerLib/ClientServerLib/CWebservice.cs
index e812491e..9e77c0bc 100644
--- a/ClientServerLib/ClientServerLib/CWebservice.cs
+++ b/ClientServerLib/ClientServerLib/CWebservice.cs
@@ -6,6 +6,7 @@ using System.Text;
using System.ServiceModel.Web;
using System.Web.Services;
using System.IO;
+using System.ServiceModel.Channels;
namespace ServerLib
{
@@ -20,6 +21,12 @@ namespace ServerLib
#region profile
+ [OperationContract]
+ [WebInvoke(Method = "GET",
+ ResponseFormat = WebMessageFormat.Json,
+ UriTemplate = "/getOwnProfileId")]
+ int getOwnProfileId();
+
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
@@ -53,6 +60,12 @@ namespace ServerLib
#region website
+ [OperationContract]
+ [WebInvoke(Method = "GET",
+ ResponseFormat = WebMessageFormat.Json,
+ UriTemplate = "/login?username={username}&password={password}")]
+ Guid login(string username, string password);
+
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
@@ -114,8 +127,35 @@ namespace ServerLib
{
}
+ private static Guid getSession()
+ {
+ Guid sessionKey = Guid.Empty;
+ string sessionHeader =
+ ((HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties["httpRequest"]).Headers["session"];
+ if (sessionHeader == null || sessionHeader == "")
+ {
+ return sessionKey;
+ }
+ try
+ {
+ sessionKey = Guid.Parse(sessionHeader);
+ }
+ catch (Exception e)
+ {
+ }
+ return sessionKey;
+ }
+
public bool sendKeyEvent(string key)
{
+ Guid sessionKey = getSession();
+
+ if (sessionKey == Guid.Empty || !SessionControl.requestRight(sessionKey, UserRights.UseKeyboard))
+ {
+ WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
+ return false;
+ }
+
if (CServer.SendKeyEvent == null)
{
return false;
@@ -125,22 +165,58 @@ namespace ServerLib
#region profile
+ public int getOwnProfileId()
+ {
+ Guid sessionKey = getSession();
+ if (sessionKey == Guid.Empty)
+ {
+ WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
+ return -1;
+ }
+
+ return SessionControl.getUserIdFromSession(sessionKey);
+ }
+
public bool sendProfile(ProfileData profile)
{
- if (CServer.SendProfileData == null)
+ Guid sessionKey = getSession();
+
+ if (sessionKey == Guid.Empty || (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) &&
+ SessionControl.getUserIdFromSession(sessionKey) != profile.ProfileId))
{
+ WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
return false;
}
+
+ if (CServer.SendProfileData == null)
+ {
+ WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
+ return false;
+ }
+
return CServer.SendProfileData(profile);
}
public ProfileData getProfile(int profileId)
{
+ Guid sessionKey = getSession();
+
+ if (sessionKey == Guid.Empty || (!SessionControl.requestRight(sessionKey, UserRights.ViewOtherProfiles) &&
+ SessionControl.getUserIdFromSession(sessionKey) != profileId))
+ {
+ WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
+ return new ProfileData();
+ }
+
if (CServer.GetProfileData == null)
{
return new ProfileData();
}
- return CServer.GetProfileData(profileId);
+
+ bool isReadonly = (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) &&
+ SessionControl.getUserIdFromSession(sessionKey) != profileId);
+
+ return CServer.GetProfileData(profileId, isReadonly);
}
public ProfileData[] getProfileList()
@@ -158,6 +234,13 @@ namespace ServerLib
public bool sendPhoto(PhotoData photo)
{
+ Guid sessionKey = getSession();
+ if (!SessionControl.requestRight(sessionKey, UserRights.UploadPhotos))
+ {
+ WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
+ return false;
+ }
+
return CServer.SendPhoto(photo);
}
@@ -165,6 +248,16 @@ namespace ServerLib
#region website
+ public Guid login(string username, string password)
+ {
+ Guid sessionId = SessionControl.openSession(username, password);
+ if (sessionId == Guid.Empty)
+ {
+ WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
+ }
+ return sessionId;
+ }
+
public Stream Index()
{
if (WebOperationContext.Current != null)
@@ -277,6 +370,5 @@ namespace ServerLib
}
#endregion
-
}
}
diff --git a/ClientServerLib/ClientServerLib/DataStructs.cs b/ClientServerLib/ClientServerLib/DataStructs.cs
index a32f6498..700f76fa 100644
--- a/ClientServerLib/ClientServerLib/DataStructs.cs
+++ b/ClientServerLib/ClientServerLib/DataStructs.cs
@@ -15,7 +15,7 @@ namespace ServerLib
#region profile
- public delegate ProfileData GetProfileDataDelegate(int profileId);
+ public delegate ProfileData GetProfileDataDelegate(int profileId, bool isReadonly);
public delegate bool SendProfileDataDelegate(ProfileData profile);
public delegate ProfileData[] GetProfileListDelegate();
@@ -121,4 +121,18 @@ namespace ServerLib
}
#endregion
+
+ #region user management
+
+ public delegate void SetPasswordDelegate(int profileId, string newPassword);
+
+ public delegate bool ValidatePasswordDelegate(int profileId, string password);
+
+ public delegate int GetUserRoleDelegate(int profileId);
+
+ public delegate void SetUserRoleDelegate(int profileId, int userRole);
+
+ public delegate int GetUserIdFromUsernameDelegate(string username);
+
+ #endregion
}
diff --git a/ClientServerLib/ClientServerLib/ServerLib.csproj b/ClientServerLib/ClientServerLib/ServerLib.csproj
index 023b4bc6..417c9063 100644
--- a/ClientServerLib/ClientServerLib/ServerLib.csproj
+++ b/ClientServerLib/ClientServerLib/ServerLib.csproj
@@ -52,6 +52,11 @@
+
+
+
+
+
-
-
-
-
-
-
-
-
-
Volcaluxe
-
-
-
-
-
-
-
-
-
-
-
All profiles
-
-
-
-
-
-
-
-
-
-
-
Profile
-
-
-
-
-

-
-
-
-
-
-
-
-
-
Save and upload
-
-
-
-
-
-
-
-
No current song
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
All songs
-
-
-
-
-
-
-
-
-
-
-
Keyboard
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-