public static void Main(string[] args) { //DataStorage DB = DataStorage.Instance; //bool status = false; //status = DB.PhoneBooks.FixBrokenContacts(); //status = status && true; AdLib ad = new AdLib(); AdUserInfo userInfo = ad.GetUserAttributes("*****@*****.**"); //string result = string.Empty; //result = DB.NumberingPlans.GetTypeOfServiceByNumber("+962795797572"); //result = result + ""; //var users_summaries = DB.UsersCallsSummaries.GetBySipAccount("*****@*****.**", startDate, endDate); //users_summaries = DB.UsersCallsSummaries.GetBySite("MOA", startDate, endDate, Globals.CallsSummary.GroupBy.UserAndInvoiceFlag); //users_summaries = DB.UsersCallsSummaries.GetByGateway("10.1.1.3"); //var first_user_summary = summaries.First(); //var sites_summaries = DB.SitesCallsSummaries.GetBySite("MOA", startDate, endDate); //var yearsForAAlhour = DB.UsersCallsSummaries.GetYearsBySipAccount("*****@*****.**"); //var siteSummaries = DB.SitesCallsSummaries.GetBySite("MOA"); //siteSummaries = DB.SitesCallsSummaries.GetBySite("MOA", startDate, endDate); //var departmensSummaries = DB.DepartmensCallsSummaries.GetByDepartment("MOA", "ISD"); //var departmentTotal = DB.DepartmensCallsSummaries.GetTotalByDepartment("MOA", "ISD"); //var siteDepartmensTotals = DB.DepartmensCallsSummaries.GetTotalsForEachDepartmentInSite("MOA"); //var MOA_Gateways_Summaries = DB.GatewaysCallsSummaries.GetBySite("MOA", groupBy: Globals.CallsSummaryForGateway.GroupBy.GatewayNameOnly); //var MOA_101012_Summaries = DB.GatewaysCallsSummaries.GetBySiteAndGateway("MOA", "10.1.0.12"); //var Gateways_Usage = DB.GatewaysCallsSummaries.GetUsageForAllGateways(startDate, endDate); //var Usage_Stats = DB.GatewaysCallsSummaries.GetGatewaysStatisticsResults(Gateways_Usage); //var topNumbers = DB.TopDestinationNumbers.GetBySipAccount("*****@*****.**", 10); //var topCountriesForUser = DB.TopDestinationCountries.GetByUser("*****@*****.**", 10); //var topCountriesForDepartment = DB.TopDestinationCountries.GetByDepartment("MOA", "ISD", 10); //var topCountriesForSite = DB.TopDestinationCountries.GetBySite("MOA", 10); //var mailReportsForUser = DB.MailReports.GetByUser("*****@*****.**", (new DateTime(2013, 10, 1))); //var mailReportForUser = DB.MailReports.GetTotalByUser("*****@*****.**", (new DateTime(2013, 10, 1))); //var mailReportForDepartment = DB.MailReports.GetByDepartment("MOA", "ISD", (new DateTime(2013, 10, 1))); //var userChartReports = DB.ChartsReports.GetByUser("*****@*****.**"); //var departmentChartReports = DB.ChartsReports.GetByDepartment("MOA", "ISD"); //var siteChartsReports = DB.ChartsReports.GetBySite("MOA"); //var gatewayChartsReports = DB.ChartsReports.GetByGateway("MOA", "10.1.0.12"); }
/// <summary> /// Session managemenet routine. This is called from the SignButton_Click procedure. /// </summary> /// <param name="session">The current user session, sent by reference.</param> /// <param name="userInfo">The current user info</param> private void SetUserSessionFields(ref UserSession session, AdUserInfo userInfo) { //First and foremost initialize the user's most basic and mandatory fields session.User = Global.DATABASE.Users.GetBySipAccount(userInfo.SipAccount.Replace("sip:", "")); session.User.DisplayName = HelperFunctions.FormatUserDisplayName(userInfo.DisplayName, userInfo.SipAccount); session.DelegeeUserAccount = null; //Initialize his/her ROLES AND THEN DELEGEES information session.InitializeAllRolesInformation(session.User.SipAccount); //Initialize the Bundled Accounts List for the user session.InitializeBundledAccountsList(session.User.SipAccount); //Lastly, get some additional information about the user. session.IpAddress = HttpContext.Current.Request.UserHostAddress; session.UserAgent = HttpContext.Current.Request.UserAgent; }
// // This function is responsible for authenticating the user's information. protected void AuthenticateUser(object sender, EventArgs e) { bool status = false; AdUserInfo userInfo = new AdUserInfo(); string msg = string.Empty; string user_email = string.Empty; //Get the requests from the view. string requestedAccessLevel = this.ACCESS_LEVEL_FIELD.Value ?? string.Empty; string requestedDelegeeIdentity = this.DELEGEE_IDENTITY.Value ?? string.Empty; if (HttpContext.Current.Session != null && HttpContext.Current.Session.Contents["UserData"] != null) { CurrentSession = (UserSession)HttpContext.Current.Session.Contents["UserData"]; user_email = CurrentSession.User.SipAccount.ToLower(); if (this.ACCESS_LEVEL_FIELD != null) { status = athenticator.AuthenticateUser(user_email, this.password.Text, out msg); AuthenticationMessage = msg; /** * ------- * To spoof identity for intermediate authentication * status = true; * /* -------- **/ if (status == true) { //System Admin if (requestedAccessLevel == Functions.SystemAdminRoleName) { CurrentSession.ActiveRoleName = Functions.SystemAdminRoleName; Response.Redirect(GetHomepageLink(Functions.SystemAdminRoleName)); } //Sites Admin else if (requestedAccessLevel == Functions.SiteAdminRoleName) { CurrentSession.ActiveRoleName = Functions.SiteAdminRoleName; Response.Redirect(GetHomepageLink(Functions.SiteAdminRoleName)); } //Sites Accountant else if (requestedAccessLevel == Functions.SiteAccountantRoleName) { CurrentSession.ActiveRoleName = Functions.SiteAccountantRoleName; Response.Redirect(GetHomepageLink(Functions.SiteAccountantRoleName)); } //Departments Head else if (requestedAccessLevel == Functions.DepartmentHeadRoleName) { CurrentSession.ActiveRoleName = Functions.DepartmentHeadRoleName; Response.Redirect(GetHomepageLink(Functions.DepartmentHeadRoleName)); } //Sites Delegee else if (requestedAccessLevel == Functions.SiteDelegeeRoleName) { var role = CurrentSession.SiteDelegateRoles.Find(someRole => someRole.ManagedSite != null && someRole.ManagedUserSipAccount == requestedDelegeeIdentity); if (role != null) { SwitchToDelegeeAndRedirect(role.ManagedUserSipAccount, role.ManagedSite, Global.DATABASE.Roles.SiteDelegeeRoleID); } } //Departments Delegee else if (requestedAccessLevel == Functions.DepartmentDelegeeRoleName) { var role = CurrentSession.DepartmentDelegateRoles.Find(someRole => someRole.ManagedSiteDepartment != null && someRole.ManagedUserSipAccount == requestedDelegeeIdentity); if (role != null) { SwitchToDelegeeAndRedirect(role.ManagedUserSipAccount, role.ManagedSiteDepartment, Global.DATABASE.Roles.DepartmentDelegeeRoleID); } } //Users Delegee else if (requestedAccessLevel == Functions.UserDelegeeRoleName && this.DELEGEE_IDENTITY != null) { var role = CurrentSession.UserDelegateRoles.Find(someRole => someRole.ManagedUser != null && someRole.ManagedUserSipAccount == requestedDelegeeIdentity); if (role != null) { SwitchToDelegeeAndRedirect(role.ManagedUserSipAccount, role.ManagedUser, Global.DATABASE.Roles.UserDelegeeRoleID); } } //the value of the access_level hidden field has changed - fraud value! CurrentSession.ActiveRoleName = Functions.NormalUserRoleName; Response.Redirect(GetHomepageLink(Functions.NormalUserRoleName)); } } else { //the value of the access_level hidden field has changed - fraud value! CurrentSession.ActiveRoleName = Functions.NormalUserRoleName; Response.Redirect(GetHomepageLink(Functions.NormalUserRoleName)); } //Setup the authentication message. AuthenticationMessage = (!string.IsNullOrEmpty(AuthenticationMessage)) ? ("* " + AuthenticationMessage) : ""; } else { Response.Redirect(GetHomepageLink("login")); } }
protected void LogIn(object sender, EventArgs e) { UserSession session = new UserSession(); AdUserInfo userInfo = new AdUserInfo(); List <SystemRole> userSystemRoles = new List <SystemRole>(); LyncBillingBase.DataModels.User existingiBillUser; LyncBillingBase.DataModels.User iBillUser = new LyncBillingBase.DataModels.User(); //START bool status = false; string msg = string.Empty; if (IsValid) { status = ADConnector.AuthenticateUser(Email.Text, Password.Text, out msg); AuthenticationMessage = msg; // Impersonation example // email.Text = "*****@*****.**"; // status = true; if (status == true) { userInfo = ADConnector.GetUserAttributes(Email.Text); // Users Information was found in active directory if (userInfo != null && !string.IsNullOrEmpty(userInfo.SipAccount)) { //Try to get user from the database existingiBillUser = Global.DATABASE.Users.GetBySipAccount(userInfo.SipAccount.Replace("sip:", "")); //Update the user, if exists and if his/her info has changed... Insert te Users if s/he doesn't exist if (existingiBillUser != null) { //Make sure the user record was updated by ActiveDirectory and not by the System Admin //If the system admin has updated this user then you cannot update his record from Active Directory if (existingiBillUser.UpdatedByAd == Convert.ToByte(true)) { //If user information from Active directory doesnt match the one in Users Table : update user table if (existingiBillUser.EmployeeId.ToString() != userInfo.EmployeeId || existingiBillUser.FullName != String.Format("{0} {1}", userInfo.FirstName, userInfo.LastName) || existingiBillUser.SiteName != userInfo.PhysicalDeliveryOfficeName || existingiBillUser.DepartmentName != userInfo.department || existingiBillUser.TelephoneNumber != HelperFunctions.FormatUserTelephoneNumber(userInfo.Telephone)) { int employeeID = 0; // Validate employeeID if it could be parsed as integer or not bool result = Int32.TryParse(userInfo.EmployeeId, out employeeID); if (result) { iBillUser.EmployeeId = employeeID; } else { iBillUser.EmployeeId = 0; } iBillUser.SipAccount = userInfo.SipAccount.Replace("sip:", ""); iBillUser.FullName = String.Format("{0} {1}", userInfo.FirstName, userInfo.LastName); iBillUser.TelephoneNumber = HelperFunctions.FormatUserTelephoneNumber(userInfo.Telephone); iBillUser.DepartmentName = userInfo.department; iBillUser.SiteName = userInfo.PhysicalDeliveryOfficeName; iBillUser.UpdatedByAd = Convert.ToByte(true); Global.DATABASE.Users.Update(iBillUser); } } } else { // If user not found in Users tables that means this is his first login : insert his information into Users table int employeeID = 0; bool result = Int32.TryParse(userInfo.EmployeeId, out employeeID); if (result) { iBillUser.EmployeeId = employeeID; } else { iBillUser.EmployeeId = 0; } iBillUser.SipAccount = userInfo.SipAccount.Replace("sip:", ""); iBillUser.FullName = String.Format("{0} {1}", userInfo.FirstName, userInfo.LastName); iBillUser.TelephoneNumber = HelperFunctions.FormatUserTelephoneNumber(userInfo.Telephone); iBillUser.DepartmentName = userInfo.department; iBillUser.SiteName = userInfo.PhysicalDeliveryOfficeName; iBillUser.UpdatedByAd = Convert.ToByte(true); Global.DATABASE.Users.Insert(iBillUser); } // //Assign the current userInfo to the UserSession fields. SetUserSessionFields(ref session, userInfo); // // Encrypt the password and assign it to the session session.EncryptedPassword = Global.ENCRYPTION.EncryptRijndael(Password.Text); Session.Add("UserData", session); if (this.RedirectToUrl != null && !string.IsNullOrEmpty(this.RedirectToUrl.Value)) { Response.Redirect(this.RedirectToUrl.Value); } else { Response.Redirect(String.Format(@"{0}/User/Dashboard", Global.APPLICATION_URL)); } }//end-if-userInfo-noteq-null else { AuthenticationMessage = "Invalid ActiveDirectory Account."; } }//end-if-status-is-true if (AuthenticationMessage.ToString() != string.Empty) { AuthenticationMessage = "* " + AuthenticationMessage; } } //end-if-valid } //end-function
/** * Create Accounting Detailed Report * * @param response: Where to write the document * @param dt: The datatable which contains the data of the report. * @param pdfColumnsWidths: Array of integer numbers which specify the column widths of the report, from left to right. * @param pdfColumnsSchema: A list of column-names. This is to specify exactly what columns to include from the datatable in case we don't want to view all of its columns. * @param pdfDocumentHeaders: The header texts and paragraphs to be written on top of the main page. * @param handleName: How to divide the user data, say you pass "SourceUserId", then all the data will be divided based on the SourceUserId values, each collection on a separate page. This helps divides the listOfUsers phonecalls on pages. * @param UsersCollection: Collection of listOfUsers data, to optimize the performance and avoid getting it while creating the user report. This might cotnain some data fetched directly from the grid like Sip Accounts, Display Names, Summations and xtra Users Information. * * @return @variable document of type Document. */ public static Document CreateAccountingDetailedReport(HttpResponse responseStream, DataTable sourceDataTable, List <string> pdfColumnsSchema, int[] pdfColumnsWidths, Dictionary <string, string> pdfDocumentHeaders, string dataSeparatorName, Dictionary <string, Dictionary <string, object> > usersInfoCollections, Dictionary <string, CallsSummaryForUser> usersSummariesMap) { //---------------------------------- //INITIALIZE THE REQUIRED VARIABLES //---------------------------------- DataRow[] selectedDataRows; var selectExpression = string.Empty; var selectOrder = string.Empty; var pageTitleText = string.Empty; var cellText = string.Empty; Paragraph pageTitleParagraph; Paragraph pageSubTitleParagraph; var userInfo = new AdUserInfo(); var employeeIdKey = Globals.PhoneCallSummary.EmployeeId.Description(); var displayNameKey = Globals.PhoneCallSummary.DisplayName.Description(); var sipAccountKey = Globals.PhoneCallSummary.ChargingParty.Description(); //-------------------------------------------------------------------------------------------------------------------------------------------------------- //Exit the function in case the handles array is empty or the pdfColumnsSchema is either empty or it's size exceeds the DataTable's Columns number. //-------------------------------------------------------------------------------------------------------------------------------------------------------- if (responseStream == null || sourceDataTable == null || sourceDataTable.Rows.Count == 0 || usersSummariesMap == null || usersSummariesMap.Count == 0 || usersInfoCollections == null || usersInfoCollections.Count == 0 || pdfDocumentHeaders == null || pdfDocumentHeaders.Count == 0 || pdfColumnsSchema == null || pdfColumnsSchema.Count == 0 || pdfColumnsSchema.Count > sourceDataTable.Columns.Count) { return(null); } //---------------------------------- //INITIALIZE THE PDF DOCUMENT //---------------------------------- var document = new Document(); var writer = PdfWriter.GetInstance(document, responseStream.OutputStream); document.Open(); //---------------------------------- //INITIALIZE THE HEADERS //---------------------------------- if (pdfDocumentHeaders.Count > 0) { if (pdfDocumentHeaders.ContainsKey("title")) { var titleParagraph = new Paragraph("iBill | " + pdfDocumentHeaders["title"], TitleFont); titleParagraph.SpacingAfter = 5; document.Add(titleParagraph); } if (pdfDocumentHeaders.ContainsKey("subTitle")) { Paragraph subTitleParagraph; if (pdfDocumentHeaders.ContainsKey("siteName")) { subTitleParagraph = new Paragraph(pdfDocumentHeaders["siteName"] + " | " + pdfDocumentHeaders["subTitle"], SubTitleFont); } else { subTitleParagraph = new Paragraph(pdfDocumentHeaders["subTitle"], SubTitleFont); } subTitleParagraph.SpacingAfter = 5; document.Add(subTitleParagraph); } if (pdfDocumentHeaders.ContainsKey("comments")) { var commentsParagraph = new Paragraph(pdfDocumentHeaders["comments"], HeaderCommentsFont); commentsParagraph.SpacingBefore = 10; commentsParagraph.SpacingAfter = 5; document.Add(commentsParagraph); } } //-------------------------------------- //START CREATING THE REPORT DOCUMENT //-------------------------------------- //start by sorting the handles array. var sipAccounts = usersInfoCollections.Keys.ToList(); sipAccounts.Sort(); //Begin the construction of the document. foreach (var sipAccount in sipAccounts) { var pdfTable = InitializePdfTable(pdfColumnsSchema.Count, pdfColumnsWidths); document.NewPage(); if (dataSeparatorName == sipAccountKey) { var name = usersInfoCollections[sipAccount][displayNameKey].ToString(); var groupNo = usersInfoCollections[sipAccount][employeeIdKey].ToString(); if (string.IsNullOrEmpty(name)) { name = sipAccount.ToLower(); } if (!string.IsNullOrEmpty(groupNo)) { groupNo = " [Group No. " + usersInfoCollections[sipAccount][employeeIdKey] + "]"; } pageTitleText = name + groupNo; } else { pageTitleText = sipAccount; } pageTitleParagraph = new Paragraph(pageTitleText, SubTitleFont); pageTitleParagraph.SpacingAfter = 10; document.Add(pageTitleParagraph); pageSubTitleParagraph = new Paragraph(pdfDocumentHeaders["subTitle"], SubTitleFont); pageSubTitleParagraph.SpacingAfter = 20; document.Add(pageSubTitleParagraph); //Select the rows that are associated to the supplied handles if (pdfColumnsSchema.Contains("ResponseTime")) { selectOrder = "ResponseTime ASC"; } selectExpression = dataSeparatorName + " = '" + sipAccount + "'"; selectedDataRows = sourceDataTable.Select(selectExpression, selectOrder); //Print the report table columns headers foreach (var column in pdfColumnsSchema) { if (sourceDataTable.Columns.Contains(column)) { pdfTable.AddCell(new Phrase(ReportColumnsDescriptionsSection.GetDescription(column), BoldTableFont)); } } //Bind the data cells to the respective columns foreach (var r in selectedDataRows) { foreach (var column in pdfColumnsSchema) { if (sourceDataTable.Columns.Contains(column)) { //Declare the pdfTable cell and fill it. PdfPCell entryCell; //Check if the cell being processed in not empty nor null. cellText = r[column].ToString(); if (string.IsNullOrEmpty(cellText)) { cellText = "N/A"; } //Format the cell text if it's the case of Duration if (ReportColumnsDescriptionsSection.GetDescription(column) == Globals.PhoneCallSummary.Duration.Description() && cellText != "N/A") { entryCell = new PdfPCell(new Phrase(Convert.ToInt32(cellText).ConvertSecondsToReadable(), BodyFontSmall)); } else { entryCell = new PdfPCell(new Phrase(cellText, BodyFontSmall)); } //Set the cell padding, border configurations and then add it to the the pdfTable entryCell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER; entryCell.PaddingTop = 5; entryCell.PaddingBottom = 5; entryCell.PaddingLeft = 2; entryCell.PaddingRight = 2; pdfTable.AddCell(entryCell); } } } // Add the Paragraph object to the document document.Add(pdfTable); if (usersSummariesMap[sipAccount] != null) { AddAccountingDetailedReportTotalsRow(ref document, usersSummariesMap[sipAccount]); } selectExpression = string.Empty; selectOrder = string.Empty; Array.Clear(selectedDataRows, 0, selectedDataRows.Length); } //---------------------- // CLOSE THE DOCUMENT //---------------------- document.Close(); //---------------------- // RETURN THE DOCUMENT //---------------------- return(document); }