public static void SendData(Guid applicationId, List <Guid> userIds, RealTimeAction actionName, string jsonString) { if (!RaaiVanSettings.RealTime(applicationId) || userIds == null) { return; } string name = actionName.ToString().ToLower(); IHubContext context = GlobalHost.ConnectionManager.GetHubContext <RaaiVanHub>(); foreach (Guid uId in userIds.Distinct()) { if (!UserConnectionsDic.ContainsKey(uId)) { continue; } foreach (string connId in UserConnectionsDic[uId]) { if (ConnectedUsers.ContainsKey(connId) && ConnectedUsers[connId].Events.Any(u => u == name)) { context.Clients.Client(connId).GetData(name, jsonString); } } } }
public static void SendData(Guid applicationId, string feedId, RealTimeAction actionName, string jsonString) { if (!RaaiVanSettings.RealTime(applicationId) || string.IsNullOrEmpty(feedId)) { return; } feedId = feedId.ToLower(); string name = actionName.ToString().ToLower(); if (!Feeds.ContainsKey(feedId) || !Feeds[feedId].ContainsKey(name)) { return; } IHubContext context = GlobalHost.ConnectionManager.GetHubContext <RaaiVanHub>(); foreach (string connId in Feeds[feedId][name]) { if (ConnectedUsers.ContainsKey(connId)) { context.Clients.Client(connId).GetData(name, jsonString); } } }
protected void Page_Load(object sender, EventArgs e) { paramsContainer = new ParamsContainer(HttpContext.Current); initialJson.Value = PublicMethods.toJSON(RouteList.get_data_server_side(paramsContainer, RouteName.error)); Page.Title = RaaiVanSettings.SystemTitle(paramsContainer.ApplicationID); }
public static bool validate_user(Guid?applicationId, string username, string password) { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return(false); } string savedPass = string.Empty, savedSalt = string.Empty; UsersController.get_current_password(applicationId, username, ref savedPass, ref savedSalt); bool loggedIn = false; int failedLoginAttemptsCount = 0; if (string.IsNullOrEmpty(savedPass) || string.IsNullOrEmpty(savedSalt)) { return(false); } password = PublicMethods.verify_string(password); loggedIn = UserUtilities.encode_password(password, savedSalt) == savedPass; failedLoginAttemptsCount = UsersController.login_attempt(applicationId, username, loggedIn); if (!loggedIn && failedLoginAttemptsCount >= RaaiVanSettings.AllowedConsecutiveFailedLoginAttempts(applicationId)) { UsersController.lock_user(applicationId, username); } return(loggedIn); }
public override Task OnConnected() { Guid tenantId = Guid.Empty; try { tenantId = PublicMethods.get_current_tenant(Context.Request.GetHttpContext().GetOwinContext().Request, RaaiVanSettings.Tenants).Id; } catch (Exception ex) { return(base.OnConnected()); } if (!RaaiVanSettings.RealTime(tenantId)) { return(base.OnConnected()); } Guid currentUserId = get_current_user_id(); if (currentUserId == Guid.Empty) { return(base.OnConnected()); } if (!UserConnectionsDic.ContainsKey(currentUserId)) { UserConnectionsDic[currentUserId] = new List <string>(); } bool added = false; if (!UserConnectionsDic[currentUserId].Any(u => u == Context.ConnectionId)) { UserConnectionsDic[currentUserId].Add(Context.ConnectionId); added = true; } ConnectedUsers.Add(Context.ConnectionId, new Registration(Context.ConnectionId, tenantId, currentUserId, new List <string>())); //if the user is now online, tell his/her friends if (UserConnectionsDic[currentUserId].Count == 1 && added) { prepare_user(tenantId, currentUserId); string userJson = _get_user_json(tenantId, currentUserId); RaaiVanHub.SendData(tenantId, get_friends(tenantId, currentUserId), RealTimeAction.IsOnline, userJson); } return(base.OnConnected()); }
protected void Page_Load(object sender, EventArgs e) { paramsContainer = new ParamsContainer(HttpContext.Current); initialJson.Value = PublicMethods.toJSON(RouteList.get_data_server_side(paramsContainer, RouteName.login)); Page.Title = RaaiVanSettings.SystemTitle(paramsContainer.ApplicationID); string returnUrl = Request.Params["ReturnUrl"]; if (RaaiVanSettings.IgnoreReturnURLOnLogin(paramsContainer.ApplicationID) && !string.IsNullOrEmpty(returnUrl)) { Response.Redirect(PublicConsts.LoginPage); } if (!string.IsNullOrEmpty(RaaiVanSettings.Google.Captcha.URL)) { Page.Header.Controls.Add(new LiteralControl("<script type='text/javascript' src='" + RaaiVanSettings.Google.Captcha.URL + "'></script>")); } }
public void Configuration(IAppBuilder app) { RVScheduler.run_jobs(); // Any connection or hub wire up and configuration should go here if (RaaiVanSettings.RealTime(null)) { app.MapSignalR("/signalr", new HubConfiguration()); } else { app.Map("/signalr", conf => { conf.Use((context, next) => { ParamsContainer paramsContainer = new ParamsContainer(HttpContext.Current); paramsContainer.file_response("var daslkdjhalskfh84t94uthgk = {\"Message\":\"-)\"};", "empty.js", "text/javascript", isAttachment: false); return(next()); }); }); } //Ignore SSL certificate check for web requests ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); }; //end of Ignore SSL certificate check for web requests app.Map("/ui", spa => { spa.Use((context, next) => { context.Request.Path = new PathString("/ui/build/index.html"); return(next()); }); spa.UseStaticFiles(); }); ConfigureAuth(app); }
public static string theme_name(Guid?applicationId, Guid?userId, HttpContext context) { string theme = userId.HasValue && RaaiVanSettings.EnableThemes(applicationId) ? UsersController.get_theme(applicationId, userId.Value) : string.Empty; if (!userId.HasValue) { theme = context.Request.Cookies["ck_theme"] == null ? string.Empty : context.Request.Cookies["ck_theme"].Value; if (!string.IsNullOrEmpty(theme)) { theme = theme.Split(',')[0]; } } if (string.IsNullOrEmpty(theme) || !RaaiVanSettings.Themes.Any(t => t.ToLower().IndexOf(theme.ToLower()) >= 0)) { theme = RaaiVanSettings.DefaultTheme(applicationId); } return(theme); }
protected void Page_Load(object sender, EventArgs e) { paramsContainer = new ParamsContainer(HttpContext.Current); initialJson.Value = PublicMethods.toJSON(RouteList.get_data_server_side(paramsContainer, RouteName.node)); try { Guid?nodeId = PublicMethods.parse_guid(Request.Params["ID"], alternatvieValue: PublicMethods.parse_guid(Request.Params["NodeID"])); if (Request.Url.ToString().ToLower().Contains("_escaped_fragment_=") && nodeId.HasValue) { ParamsContainer paramsContainer = new ParamsContainer(HttpContext.Current); Modules.CoreNetwork.Node _nd = CNController.get_node(paramsContainer.Tenant.Id, nodeId.Value, true); string htmlContent = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" + "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>" + _nd.Name + " - " + RaaiVanSettings.SystemTitle(paramsContainer.Tenant.Id) + "</title></head><body>" + "<div>" + _nd.Name + "</div>" + "<div>" + ProviderUtil.list_to_string <string>(_nd.Tags, ' ') + "</div>" + "<div>" + PublicMethods.shuffle_text(PublicMethods.markup2plaintext(paramsContainer.Tenant.Id, _nd.Description, true)) + "</div>" + "<div>" + PublicMethods.markup2plaintext(paramsContainer.Tenant.Id, Modules.Wiki.WikiController.get_wiki_content(paramsContainer.Tenant.Id, nodeId.Value), true) + "</div>" + "</body></html>"; paramsContainer.return_response(htmlContent); return; } } catch { } }
protected void send_message(Guid?forwardedFrom, string title, string messageText, bool?isGroup, List <Guid> receiverUserIds, Guid?threadId, List <DocFileInfo> attachedFiles, Guid?groupId, string _ref, ref string responseText) { //GroupID will not be stored in the database and is just used for chat //Privacy Check: OK if (!paramsContainer.GBEdit) { return; } if (!string.IsNullOrEmpty(title) && title.Length > 490) { responseText = "{\"ErrorText\":\"" + Messages.MaxAllowedInputLengthExceeded + "\"}"; return; } else if (!PublicMethods.is_secure_title(title)) { responseText = "{\"ErrorText\":\"" + Messages.TheTextIsFormattedBadly + "\"}"; return; } if (!isGroup.HasValue) { isGroup = false; } Guid messageId = Guid.NewGuid(); isGroup = receiverUserIds.Count == 1 ? false : isGroup; bool selfChat = !isGroup.Value && ( (receiverUserIds.Count == 1 && receiverUserIds.First() == paramsContainer.CurrentUserID.Value) || (threadId == paramsContainer.CurrentUserID) ); if (!threadId.HasValue && ((isGroup.Value && receiverUserIds.Count > 1) || (!isGroup.Value && receiverUserIds.Count == 1))) { threadId = isGroup.Value ? Guid.NewGuid() : (receiverUserIds.Count == 1 ? receiverUserIds.First() : threadId); } if (attachedFiles != null) { attachedFiles.ForEach(f => f.move(paramsContainer.Tenant.Id, FolderNames.TemporaryFiles, FolderNames.Attachments)); } long result = MSGController.send_message(paramsContainer.Tenant.Id, messageId, forwardedFrom, paramsContainer.CurrentUserID.Value, title, messageText, isGroup.Value, receiverUserIds, threadId, attachedFiles); if (result <= 0 && attachedFiles != null) { attachedFiles.ForEach(f => f.move(paramsContainer.Tenant.Id, FolderNames.Attachments, FolderNames.TemporaryFiles)); } List <User> receiverUsers; User senderUser = UsersController.get_user(paramsContainer.Tenant.Id, paramsContainer.CurrentUserID.Value); responseText = result <= 0 ? "{\"ErrorText\":\"" + Messages.OperationFailed + "\"}" : "{\"Succeed\":\"" + Messages.OperationCompletedSuccessfully + "\""; bool sendForMany = !isGroup.Value && receiverUserIds.Count > 1; if (result > 0 && !sendForMany) { int msgCount = 0, sentCount = 0, notSeenCount = 0; MSGController.get_thread_info(paramsContainer.Tenant.Id, paramsContainer.CurrentUserID.Value, threadId.Value, ref msgCount, ref sentCount, ref notSeenCount); receiverUsers = UsersController.get_users(paramsContainer.Tenant.Id, receiverUserIds); responseText += ",\"Thread\":{" + "\"ThreadID\":\"" + threadId.ToString() + "\"" + ",\"IsGroup\":" + isGroup.ToString().ToLower() + ",\"UsersCount\":" + receiverUserIds.Count.ToString().ToLower() + ",\"MessagesCount\":" + msgCount.ToString() + ",\"SentCount\":" + sentCount.ToString() + ",\"NotSeenCount\":" + notSeenCount.ToString() + ",\"Users\":[" + ProviderUtil.list_to_string <string>(receiverUsers.Select( u => "{\"UserID\":\"" + u.UserID.ToString() + "\"" + ",\"UserName\":\"" + Base64.encode(u.UserName) + "\"" + ",\"FirstName\":\"" + Base64.encode(u.FirstName) + "\"" + ",\"LastName\":\"" + Base64.encode(u.LastName) + "\"" + ",\"ProfileImageURL\":\"" + DocumentUtilities.get_personal_image_address( paramsContainer.Tenant.Id, u.UserID.Value) + "\"" + "}").ToList()) + "]" + "}"; if (threadId == senderUser.UserID || (receiverUserIds != null && receiverUserIds.Contains(senderUser.UserID.Value))) { responseText += ",\"SenderIsReceiver\":" + true.ToString().ToLower(); } for (int i = 0; i < attachedFiles.Count; ++i) { attachedFiles[i].OwnerID = messageId; } responseText += ",\"Message\":{" + "\"ID\":" + result.ToString() + ",\"ReceiverID\":" + (result + 1).ToString() + ",\"MessageID\":\"" + messageId.ToString() + "\"" + ",\"ThreadID\":\"" + threadId.Value.ToString() + "\"" + ",\"ForwardedFrom\":\"" + (!forwardedFrom.HasValue ? "" : forwardedFrom.ToString()) + "\"" + ",\"IsGroup\":" + isGroup.ToString().ToLower() + ",\"GroupID\":\"" + (groupId.HasValue && groupId.HasValue ? groupId.Value : Guid.NewGuid()).ToString() + "\"" + ",\"SelfChat\":" + selfChat.ToString().ToLower() + ",\"IsSender\":" + true.ToString().ToLower() + ",\"Seen\":" + true.ToString().ToLower() + ",\"Title\":\"" + string.Empty + "\"" + ",\"MessageText\":\"" + Base64.encode(messageText) + "\"" + ",\"SendDate\":\"" + PublicMethods.get_local_date(DateTime.Now, true) + "\"" + ",\"SenderUserID\":\"" + senderUser.UserID.ToString() + "\"" + ",\"SenderUserName\":\"" + Base64.encode(senderUser.UserName) + "\"" + ",\"SenderFirstName\":\"" + Base64.encode(senderUser.FirstName) + "\"" + ",\"SenderLastName\":\"" + Base64.encode(senderUser.LastName) + "\"" + ",\"ProfileImageURL\":\"" + DocumentUtilities.get_personal_image_address( paramsContainer.Tenant.Id, senderUser.UserID.Value) + "\"" + ",\"AttachedFiles\":" + DocumentUtilities.get_files_json(paramsContainer.Tenant.Id, attachedFiles, true) + ",\"Ref\":\"" + (string.IsNullOrEmpty(_ref) ? string.Empty : _ref) + "\"" + "}"; } responseText += "}"; //Send RealTime Data if (result > 0 && RaaiVanSettings.RealTime(paramsContainer.Tenant.Id) && !sendForMany) { List <Guid> userIds = new List <Guid>(); if (!isGroup.Value) { userIds = new List <Guid>() { threadId.Value, senderUser.UserID.Value } } ; else { userIds = receiverUserIds.Count > 0 ? receiverUserIds : MSGController.get_thread_users(paramsContainer.Tenant.Id, threadId.Value, paramsContainer.CurrentUserID.Value, 1000, null).Select(u => u.UserID.Value).ToList(); if (receiverUserIds.Count > 0) { userIds.Add(senderUser.UserID.Value); } } if (userIds.Count > 0) { RaaiVanHub.SendData(paramsContainer.Tenant.Id, userIds, RaaiVanHub.RealTimeAction.NewMessage, responseText); } } //end of Send RealTime Data }
public string url(Guid applicationId) { return(!NodeID.HasValue ? string.Empty : PublicConsts.NodePage.Replace("~", RaaiVanSettings.RaaiVanURL(applicationId)) + "/" + NodeID.ToString()); }
public static Dictionary <Guid, List <PermissionType> > CheckAccess(Guid applicationId, Guid?userId, List <Guid> objectIds, PrivacyObjectType objectType, List <PermissionType> permissions) { if (!userId.HasValue) { userId = Guid.NewGuid(); } if (objectIds.Count == 0) { return(new Dictionary <Guid, List <PermissionType> >()); } if (permissions.Count == 0) { foreach (string s in Enum.GetNames(typeof(PermissionType))) { PermissionType pt = PermissionType.None; if (Enum.TryParse <PermissionType>(s, out pt) && pt != PermissionType.None) { permissions.Add(pt); } } } SqlConnection con = new SqlConnection(ProviderUtil.ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; //Add ObjectIDs DataTable objectIdsTable = new DataTable(); objectIdsTable.Columns.Add("Value", typeof(Guid)); foreach (Guid id in objectIds) { objectIdsTable.Rows.Add(id); } SqlParameter objectIdsParam = new SqlParameter("@ObjectIDs", SqlDbType.Structured); objectIdsParam.TypeName = "[dbo].[GuidTableType]"; objectIdsParam.Value = objectIdsTable; //end of Add ObjectIDs //Add Permissions DataTable permissionsTable = new DataTable(); permissionsTable.Columns.Add("GuidValue", typeof(string)); permissionsTable.Columns.Add("FirstValue", typeof(string)); foreach (PermissionType p in permissions) { if (p == PermissionType.None) { continue; } List <PermissionType> defaultItems = new List <PermissionType>() { PermissionType.Create, PermissionType.View, PermissionType.ViewAbstract, PermissionType.ViewRelatedItems, PermissionType.Download }; string defaultPrivacy = defaultItems.Any(d => d == p) ? RaaiVanSettings.DefaultPrivacy(applicationId) : string.Empty; permissionsTable.Rows.Add(p.ToString(), defaultPrivacy); } SqlParameter permissionsParam = new SqlParameter("@Permissions", SqlDbType.Structured); permissionsParam.TypeName = "[dbo].[StringPairTableType]"; permissionsParam.Value = permissionsTable; //end of Add Permissions cmd.Parameters.AddWithValue("@ApplicationID", applicationId); cmd.Parameters.AddWithValue("@UserID", userId); if (objectType != PrivacyObjectType.None) { cmd.Parameters.AddWithValue("@ObjectType", objectType.ToString()); } cmd.Parameters.Add(objectIdsParam); cmd.Parameters.Add(permissionsParam); cmd.Parameters.AddWithValue("@Now", DateTime.Now); string spName = GetFullyQualifiedName("CheckAccess"); string sep = ", "; string arguments = "@ApplicationID" + sep + "@UserID" + sep + (objectType == PrivacyObjectType.None ? "null" : "@ObjectType") + sep + "@ObjectIDs" + sep + "@Permissions" + sep + "@Now"; cmd.CommandText = ("EXEC" + " " + spName + " " + arguments); con.Open(); try { IDataReader reader = (IDataReader)cmd.ExecuteReader(); return(_parse_access_checked_items(ref reader)); } catch (Exception ex) { LogController.save_error_log(applicationId, null, spName, ex, ModuleIdentifier.PRVC); return(new Dictionary <Guid, List <PermissionType> >()); } finally { con.Close(); } }